diff --git a/view/next-project/src/components/fund_information/EditModal.tsx b/view/next-project/src/components/fund_information/EditModal.tsx index 651e00355..ed2d596f3 100644 --- a/view/next-project/src/components/fund_information/EditModal.tsx +++ b/view/next-project/src/components/fund_information/EditModal.tsx @@ -34,10 +34,19 @@ export default function EditModal(props: ModalProps) { useEffect(() => { const teacher = props.teachers.find((teacher) => teacher.departmentID === departmentID); if (teacher && teacher.id) { - setFormData({ ...formData, teacherID: teacher.id }); + setFormData({ ...formData, teacherID: props.fundInformation.teacherID }); } }, [departmentID]); + useEffect(() => { + const selectedTeacher = props.teachers.find( + (teacher) => teacher.id === props.fundInformation.teacherID, + ); + if (selectedTeacher) { + setDepartmentID(selectedTeacher.departmentID); + } + }, [props.teachers, props.fundInformation.teacherID]); + const handler = (input: string) => ( @@ -69,7 +78,7 @@ export default function EditModal(props: ModalProps) { .filter((user, index, self) => { return self.findIndex((u) => u.name === user.name) === index; }); - if (res.length !== 0) setFormData({ ...formData, userID: res[0].id }); + if (res.length !== 0) setFormData({ ...formData, userID: props.fundInformation.userID }); return res; }, [bureauId]);