Merged develop into ENCOA-82_Permissions
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 (
|
||||
|
||||
@@ -47,6 +47,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// cleaning data
|
||||
delete req.body.passport_id;
|
||||
delete req.body.groupName;
|
||||
delete req.body.expiryDate;
|
||||
|
||||
await createUserWithEmailAndPassword(auth, email.toLowerCase(), passport_id)
|
||||
.then(async (userCredentials) => {
|
||||
@@ -57,11 +58,12 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
bio: "",
|
||||
type: type,
|
||||
focus: "academic",
|
||||
status: "paymentDue",
|
||||
status: "active",
|
||||
desiredLevels: DEFAULT_DESIRED_LEVELS,
|
||||
levels: DEFAULT_LEVELS,
|
||||
isFirstLogin: false,
|
||||
isVerified: true,
|
||||
registrationDate: new Date(),
|
||||
subscriptionExpirationDate: expiryDate || null,
|
||||
};
|
||||
await setDoc(doc(db, "users", userId), user);
|
||||
@@ -120,10 +122,13 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Returning - ${email}`);
|
||||
return res.status(200).json({ok: true});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`Failing - ${email}`);
|
||||
console.log(error);
|
||||
return res.status(401).json({error});
|
||||
});
|
||||
return res.status(200).json({ok: true});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user