From 715b9ea2758b46ea4c75506e7095093d2a47e976 Mon Sep 17 00:00:00 2001 From: Tereshchenko Aleksandr Date: Fri, 3 May 2024 15:44:48 +0300 Subject: [PATCH] Better UX for selecting supervisors for a thesis --- .../ThesisPage/SupervisorSelect.tsx | 89 +++++++++++-------- .../components/ThesisPage/ThesisEditForm.tsx | 16 ++-- 2 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/client/components/ThesisPage/SupervisorSelect.tsx b/src/client/components/ThesisPage/SupervisorSelect.tsx index 717b0e9..40656ea 100644 --- a/src/client/components/ThesisPage/SupervisorSelect.tsx +++ b/src/client/components/ThesisPage/SupervisorSelect.tsx @@ -52,52 +52,71 @@ const SupervisorSelect: React.FC<{ 0 ) const totalPercentage = getTotalPercentage() + const selectedSupervisorIds = supervisorSelections.map( + (selection) => selection.userId + ) return ( - {supervisorSelections.map((selection, index) => ( - // eslint-disable-next-line react/no-array-index-key - - - - Select supervisor - - + handleSupervisorChange(index, event.target.value as string) + } + > + {supervisorOptions.map((supervisor) => ( + + {supervisor.firstName} {supervisor.lastName} + + ))} + + + - handleSupervisorChange(index, event.target.value as string) + handlePercentageChange(index, parseInt(event.target.value, 10)) } - > - {supervisors.map((supervisor) => ( - - {supervisor.firstName} {supervisor.lastName} - - ))} - - - - handlePercentageChange(index, parseInt(event.target.value, 10)) - } - /> - - - ))} + /> + + + ) + })} {totalPercentage !== 100 && ( } severity="error"> {t('thesisForm:supervisionPercentageError')} )} - + ) } diff --git a/src/client/components/ThesisPage/ThesisEditForm.tsx b/src/client/components/ThesisPage/ThesisEditForm.tsx index 0abb7a3..4930b0f 100644 --- a/src/client/components/ThesisPage/ThesisEditForm.tsx +++ b/src/client/components/ThesisPage/ThesisEditForm.tsx @@ -27,7 +27,7 @@ const ThesisEditForm: React.FC<{ onSubmit: (data: ThesisData) => Promise }> = ({ initialThesis, supervisors, onSubmit, onClose }) => { const { t } = useTranslation() - const [editedTesis, setEditedThesis] = useState( + const [editedThesis, setEditedThesis] = useState( initialThesis ) @@ -42,7 +42,7 @@ const ThesisEditForm: React.FC<{ onSubmit: async (event: React.FormEvent) => { event.preventDefault() - await onSubmit(editedTesis) + await onSubmit(editedThesis) }, }} > @@ -56,7 +56,7 @@ const ThesisEditForm: React.FC<{ id="topic" name="topic" label={t('topicHeader')} - value={editedTesis.topic} + value={editedThesis.topic} onChange={(event) => { setEditedThesis((oldThesis) => ({ ...oldThesis, @@ -72,7 +72,7 @@ const ThesisEditForm: React.FC<{ { @@ -128,7 +128,7 @@ const ThesisEditForm: React.FC<{ { setEditedThesis((oldThesis) => ({ @@ -140,7 +140,7 @@ const ThesisEditForm: React.FC<{ { setEditedThesis((oldThesis) => ({