add group creation.

This commit is contained in:
mohammedzeglam-pg
2024-08-06 18:03:00 +02:00
parent 4e30eda06f
commit afe59f5a3a
3 changed files with 61 additions and 13 deletions

View File

@@ -74,7 +74,8 @@ export default function BatchCreateUser({ user }: { user: User }) {
country,
passport_id,
email,
phone
phone,
group
] = row as string[];
return EMAIL_REGEX.test(email.toString().trim())
? {
@@ -82,6 +83,7 @@ export default function BatchCreateUser({ user }: { user: User }) {
name: `${firstName ?? ""} ${lastName ?? ""}`.trim().toLowerCase(),
type: type,
passport_id: passport_id?.toString().trim() || undefined,
groupName: group,
demographicInformation: {
country: country,
passport_id: passport_id?.toString().trim() || undefined,
@@ -122,13 +124,15 @@ export default function BatchCreateUser({ user }: { user: User }) {
)
if (!confirmed)
return;
if (newUsers.length > 0)
{
setIsLoading(true);
Promise.all(newUsers.map((user) => {
return axios.post("/api/make_user", user)
})).finally(() => {
Promise.all(newUsers.map(async (user) => {
await axios.post("/api/make_user", user)
})).then((res) =>{
toast.success(
`Successfully added ${newUsers.length} user(s)!`
)}).finally(() => {
return clear();
})
}
@@ -163,6 +167,9 @@ export default function BatchCreateUser({ user }: { user: User }) {
<th className="border border-neutral-200 px-2 py-1">
Phone Number
</th>
<th className="border border-neutral-200 px-2 py-1">
Group Name
</th>
</tr>
</thead>
</table>