Updated the batch user creation to work without corporate
This commit is contained in:
@@ -112,7 +112,7 @@ export default function BatchCreateUser({user, users, entities = [], permissions
|
|||||||
const information = uniqBy(
|
const information = uniqBy(
|
||||||
rows
|
rows
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
const [firstName, lastName, studentID, passport_id, email, phone, corporate, group, country] = row as string[];
|
const [firstName, lastName, studentID, passport_id, email, phone, group, country] = row as string[];
|
||||||
const countryItem =
|
const countryItem =
|
||||||
countryCodes.findOne("countryCode" as any, country.toUpperCase()) ||
|
countryCodes.findOne("countryCode" as any, country.toUpperCase()) ||
|
||||||
countryCodes.all().find((x) => x.countryNameEn.toLowerCase() === country.toLowerCase());
|
countryCodes.all().find((x) => x.countryNameEn.toLowerCase() === country.toLowerCase());
|
||||||
@@ -124,7 +124,6 @@ export default function BatchCreateUser({user, users, entities = [], permissions
|
|||||||
type: type,
|
type: type,
|
||||||
passport_id: passport_id?.toString().trim() || undefined,
|
passport_id: passport_id?.toString().trim() || undefined,
|
||||||
groupName: group,
|
groupName: group,
|
||||||
corporate,
|
|
||||||
studentID,
|
studentID,
|
||||||
entity,
|
entity,
|
||||||
demographicInformation: {
|
demographicInformation: {
|
||||||
@@ -147,7 +146,9 @@ export default function BatchCreateUser({user, users, entities = [], permissions
|
|||||||
}
|
}
|
||||||
|
|
||||||
setInfos(information);
|
setInfos(information);
|
||||||
} catch {
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
|
|
||||||
toast.error(
|
toast.error(
|
||||||
"Please upload an Excel file containing user information, one per line! All already registered e-mails have also been ignored!",
|
"Please upload an Excel file containing user information, one per line! All already registered e-mails have also been ignored!",
|
||||||
);
|
);
|
||||||
@@ -166,7 +167,8 @@ export default function BatchCreateUser({user, users, entities = [], permissions
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await axios.post("/api/batch_users", {users: newUsers.map((user) => ({...user, type, expiryDate}))});
|
const result = await axios.post("/api/batch_users", {users: newUsers.map((user) => ({...user, type, expiryDate}))});
|
||||||
|
console.log(result)
|
||||||
toast.success(`Successfully added ${newUsers.length} user(s)!`);
|
toast.success(`Successfully added ${newUsers.length} user(s)!`);
|
||||||
onFinish();
|
onFinish();
|
||||||
} catch {
|
} catch {
|
||||||
@@ -193,7 +195,6 @@ export default function BatchCreateUser({user, users, entities = [], permissions
|
|||||||
<th className="border border-neutral-200 px-2 py-1">Passport/National ID</th>
|
<th className="border border-neutral-200 px-2 py-1">Passport/National ID</th>
|
||||||
<th className="border border-neutral-200 px-2 py-1">E-mail</th>
|
<th className="border border-neutral-200 px-2 py-1">E-mail</th>
|
||||||
<th className="border border-neutral-200 px-2 py-1">Phone Number</th>
|
<th className="border border-neutral-200 px-2 py-1">Phone Number</th>
|
||||||
{user?.type !== "corporate" && <th className="border border-neutral-200 px-2 py-1">Corporate (e-mail)</th>}
|
|
||||||
<th className="border border-neutral-200 px-2 py-1">Classroom Name</th>
|
<th className="border border-neutral-200 px-2 py-1">Classroom Name</th>
|
||||||
<th className="border border-neutral-200 px-2 py-1">Country</th>
|
<th className="border border-neutral-200 px-2 py-1">Country</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import {capitalize, uniqBy} from "lodash";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import {useRouter} from "next/router";
|
import {useRouter} from "next/router";
|
||||||
|
import { useMemo } from "react";
|
||||||
import {BsBook, BsClipboard, BsFileEarmarkText, BsHeadphones, BsMegaphone, BsPen, BsPencil, BsStar} from "react-icons/bs";
|
import {BsBook, BsClipboard, BsFileEarmarkText, BsHeadphones, BsMegaphone, BsPen, BsPencil, BsStar} from "react-icons/bs";
|
||||||
import {ToastContainer} from "react-toastify";
|
import {ToastContainer} from "react-toastify";
|
||||||
|
|
||||||
@@ -58,14 +59,13 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
|||||||
const entityIDS = mapBy(user.entities, "id") || [];
|
const entityIDS = mapBy(user.entities, "id") || [];
|
||||||
|
|
||||||
const entities = await getEntitiesWithRoles(entityIDS);
|
const entities = await getEntitiesWithRoles(entityIDS);
|
||||||
const allAssignments = await getAssignmentsByAssignee(user.id, {archived: false});
|
const assignments = await getAssignmentsByAssignee(user.id, {archived: false});
|
||||||
const stats = await getStatsByUser(user.id);
|
const stats = await getStatsByUser(user.id);
|
||||||
const sessions = await getSessionsByUser(user.id, 10);
|
const sessions = await getSessionsByUser(user.id, 10);
|
||||||
const invites = await getInvitesByInvitee(user.id);
|
const invites = await getInvitesByInvitee(user.id);
|
||||||
const grading = await getGradingSystemByEntity(entityIDS[0] || "");
|
const grading = await getGradingSystemByEntity(entityIDS[0] || "");
|
||||||
|
|
||||||
const formattedInvites = await Promise.all(invites.map(convertInvitersToUsers));
|
const formattedInvites = await Promise.all(invites.map(convertInvitersToUsers));
|
||||||
const assignments = allAssignments.filter(activeAssignmentFilter);
|
|
||||||
|
|
||||||
const examIDs = uniqBy(
|
const examIDs = uniqBy(
|
||||||
assignments.flatMap((a) =>
|
assignments.flatMap((a) =>
|
||||||
@@ -104,7 +104,7 @@ export default function Dashboard({user, entities, assignments, stats, invites,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const studentAssignments = assignments.filter(activeAssignmentFilter);
|
const studentAssignments = useMemo(() => assignments.filter(activeAssignmentFilter), [assignments]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import { getEntitiesWithRoles, getEntityWithRoles } from "@/utils/entities.be";
|
|||||||
import { mapBy, serialize, redirect } from "@/utils";
|
import { mapBy, serialize, redirect } from "@/utils";
|
||||||
import { EntityWithRoles } from "@/interfaces/entity";
|
import { EntityWithRoles } from "@/interfaces/entity";
|
||||||
import { requestUser } from "@/utils/api";
|
import { requestUser } from "@/utils/api";
|
||||||
|
import { isAdmin } from "@/utils/users";
|
||||||
|
|
||||||
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||||
const user = await requestUser(req, res)
|
const user = await requestUser(req, res)
|
||||||
@@ -41,7 +42,7 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
|||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
const permissions = await getUserPermissions(user.id);
|
const permissions = await getUserPermissions(user.id);
|
||||||
const entities = await getEntitiesWithRoles(mapBy(user.entities, 'id')) || []
|
const entities = isAdmin(user) ? await getEntitiesWithRoles() : await getEntitiesWithRoles(mapBy(user.entities, 'id'))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: serialize({ user, permissions, entities }),
|
props: serialize({ user, permissions, entities }),
|
||||||
|
|||||||
Reference in New Issue
Block a user