Solved some issues related to the BatchCreateUser
This commit is contained in:
@@ -88,7 +88,7 @@ export default function BatchCreateUser({user}: {user: User}) {
|
||||
return EMAIL_REGEX.test(email.toString().trim())
|
||||
? {
|
||||
email: email.toString().trim().toLowerCase(),
|
||||
name: `${firstName ?? ""} ${lastName ?? ""}`.trim().toLowerCase(),
|
||||
name: `${firstName ?? ""} ${lastName ?? ""}`.trim(),
|
||||
type: type,
|
||||
passport_id: passport_id?.toString().trim() || undefined,
|
||||
groupName: group,
|
||||
@@ -111,6 +111,7 @@ export default function BatchCreateUser({user}: {user: User}) {
|
||||
return clear();
|
||||
}
|
||||
|
||||
console.log(information);
|
||||
setInfos(information);
|
||||
} catch {
|
||||
toast.error(
|
||||
@@ -125,24 +126,22 @@ export default function BatchCreateUser({user}: {user: User}) {
|
||||
|
||||
const makeUsers = async () => {
|
||||
const newUsers = infos.filter((x) => !users.map((u) => u.email).includes(x.email));
|
||||
const confirmed = confirm(`You are about to add ${newUsers.length}, are you sure you want to continue?`);
|
||||
if (!confirmed) return;
|
||||
if (!confirm(`You are about to add ${newUsers.length}, are you sure you want to continue?`)) return;
|
||||
|
||||
if (newUsers.length > 0) {
|
||||
setIsLoading(true);
|
||||
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();
|
||||
});
|
||||
|
||||
try {
|
||||
for (const newUser of newUsers) await axios.post("/api/make_user", {...newUser, type, expiryDate});
|
||||
toast.success(`Successfully added ${newUsers.length} user(s)!`);
|
||||
} catch {
|
||||
toast.error("Something went wrong, please try again later!");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
setInfos([]);
|
||||
clear();
|
||||
}
|
||||
}
|
||||
setIsLoading(false);
|
||||
setInfos([]);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user