ENCOA-123: Improved the options of users for the Group Creator
This commit is contained in:
@@ -7,7 +7,7 @@ import {CorporateUser, Group, User} from "@/interfaces/user";
|
|||||||
import {createColumnHelper, flexRender, getCoreRowModel, useReactTable} from "@tanstack/react-table";
|
import {createColumnHelper, flexRender, getCoreRowModel, useReactTable} from "@tanstack/react-table";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {capitalize, uniq} from "lodash";
|
import {capitalize, uniq} from "lodash";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useMemo, useState} from "react";
|
||||||
import {BsPencil, BsQuestionCircleFill, BsTrash} from "react-icons/bs";
|
import {BsPencil, BsQuestionCircleFill, BsTrash} from "react-icons/bs";
|
||||||
import Select from "react-select";
|
import Select from "react-select";
|
||||||
import {toast} from "react-toastify";
|
import {toast} from "react-toastify";
|
||||||
@@ -65,6 +65,14 @@ const CreatePanel = ({user, users, group, onClose}: CreateDialogProps) => {
|
|||||||
readAs: "ArrayBuffer",
|
readAs: "ArrayBuffer",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const availableUsers = useMemo(() => {
|
||||||
|
if (user.type === "teacher") return users.filter((x) => ["student"].includes(x.type));
|
||||||
|
if (user.type === "corporate") return users.filter((x) => ["teacher", "student"].includes(x.type));
|
||||||
|
if (user.type === "mastercorporate") return users.filter((x) => ["corporate", "teacher", "student"].includes(x.type));
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}, [user, users]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (filesContent.length > 0) {
|
if (filesContent.length > 0) {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@@ -155,15 +163,7 @@ const CreatePanel = ({user, users, group, onClose}: CreateDialogProps) => {
|
|||||||
value: x,
|
value: x,
|
||||||
label: `${users.find((y) => y.id === x)?.email} - ${users.find((y) => y.id === x)?.name}`,
|
label: `${users.find((y) => y.id === x)?.email} - ${users.find((y) => y.id === x)?.name}`,
|
||||||
}))}
|
}))}
|
||||||
options={users
|
options={availableUsers.map((x) => ({value: x.id, label: `${x.email} - ${x.name}`}))}
|
||||||
.filter((x) =>
|
|
||||||
user.type === "teacher"
|
|
||||||
? x.type === "student"
|
|
||||||
: user.type === "corporate"
|
|
||||||
? x.type === "student" || x.type === "teacher"
|
|
||||||
: x.type === "student" || x.type === "teacher" || x.type === "corporate",
|
|
||||||
)
|
|
||||||
.map((x) => ({value: x.id, label: `${x.email} - ${x.name}`}))}
|
|
||||||
onChange={(value) => setParticipants(value.map((x) => x.value))}
|
onChange={(value) => setParticipants(value.map((x) => x.value))}
|
||||||
isMulti
|
isMulti
|
||||||
isSearchable
|
isSearchable
|
||||||
|
|||||||
Reference in New Issue
Block a user