diff --git a/src/components/ImportSummaries/User.tsx b/src/components/ImportSummaries/User.tsx index 6168ae84..c89e3f4a 100644 --- a/src/components/ImportSummaries/User.tsx +++ b/src/components/ImportSummaries/User.tsx @@ -199,7 +199,7 @@ const UserImportSummary: React.FC = ({ parsedExcel, newUsers, enlistedUse - setShowEnlistedModal(false)}> + setShowEnlistedModal(false)} maxWidth='max-w-[85%]'> <>
diff --git a/src/pages/(admin)/Lists/BatchCreateUser.tsx b/src/pages/(admin)/Lists/BatchCreateUser.tsx index 0460babc..6acc7921 100644 --- a/src/pages/(admin)/Lists/BatchCreateUser.tsx +++ b/src/pages/(admin)/Lists/BatchCreateUser.tsx @@ -87,7 +87,15 @@ export default function BatchCreateUser({ user, entities = [], permissions, onFi const [isExpiryDateEnabled, setIsExpiryDateEnabled] = useState(true); const [type, setType] = useState("student"); const [showHelp, setShowHelp] = useState(false); - const [entity, setEntity] = useState((entities || [])[0]?.id || undefined) + const [entity, setEntity] = useState<{id: string | null, label: string | null}| undefined>(() => { + if (!entities?.length) { + return undefined; + } + return { + id: entities[0].id, + label: entities[0].label + }; + }); const { openFilePicker, filesContent, clear } = useFilePicker({ accept: ".xlsx", @@ -291,11 +299,28 @@ export default function BatchCreateUser({ user, entities = [], permissions, onFi if (!!crossRefEmails) { const existingEmails = new Set(crossRefEmails.map((x: any) => x.email)); const dupes = infos.filter(info => existingEmails.has(info.email)); - const newUsersList = infos.filter(info => !existingEmails.has(info.email)); + const newUsersList = infos + .filter(info => !existingEmails.has(info.email)) + .map(info => ({ + ...info, + entityLabels: [entity!.label!] + })); setNewUsers(newUsersList); - setDuplicatedUsers(dupes); + + const {data: emailEntityMap} = await axios.post("/api/users/controller?op=getEntities", { + emails: dupes.map((x) => x.email) + }); + const withLabels = dupes.map((u) => ({ + ...u, + entityLabels: emailEntityMap.find((e: any) => e.email === u.email)?.entityLabels || [] + })) + setDuplicatedUsers(withLabels); } else { - setNewUsers(infos); + const withLabel = infos.map(info => ({ + ...info, + entityLabels: [entity!.label!] + })); + setNewUsers(withLabel); } } catch (error) { toast.error("Something went wrong, please try again later!"); @@ -305,7 +330,7 @@ export default function BatchCreateUser({ user, entities = [], permissions, onFi if (infos.length > 0) { crossReferenceEmails(); } - }, [infos]); + }, [infos, entity]); const makeUsers = async () => { const newUsersSentence = newUsers.length > 0 ? `create ${newUsers.length} user(s)` : undefined; @@ -459,7 +484,16 @@ export default function BatchCreateUser({ user, entities = [], permissions, onFi