import React from 'react'; import { MdGroup } from 'react-icons/md'; import BaseModal from '@educt/components/Modal'; import SelectStudentsInput from '@educt/components/SelectStudentsInput'; import { UserRoleEnum } from '@educt/enums'; /** * Types */ import { ICourse, IUser } from '@educt/interfaces'; /** * Hooks */ import { useState } from 'react'; import { useAttachStudents } from '@educt/hooks/queries'; type AddStudentsModalPropsType = { course: Omit; currentStudents: ICourse['students']; isOpen: boolean; onClose: () => void; onAdded: (users: Array) => void; }; const AddStudentsModal: React.FC = ({ isOpen, onClose, onAdded, currentStudents, course, }) => { const { attachStudents, isLoading } = useAttachStudents(); const [selected, setSelected] = useState>([]); const handleSelectStudents = (students: Array) => setSelected(students); const handleAttachStudents = async () => { if (selected.length !== 0) { try { const ids = selected.map(s => s.id); await attachStudents(course.id, ids); onAdded(selected); onClose(); } catch (error) { console.error(error); } } }; return ( handleSelectStudents(selected)} placeholder='Search for students...' searchParams={{ role: UserRoleEnum.STUDENT }} /> ); }; export default AddStudentsModal;