Skip to content

Commit

Permalink
Merge pull request #696 from NUTFes/fix/yama/663-fix-modal-bug
Browse files Browse the repository at this point in the history
[fix] 登録されたデータが編集モーダルに反映されるよう修正
  • Loading branch information
Kubosaka authored Mar 22, 2024
2 parents be88557 + 6392ed0 commit d07bbea
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions view/next-project/src/components/fund_information/EditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ export default function EditModal(props: ModalProps) {
receivedAt: props.fundInformation.receivedAt,
});

const [departmentID, setDepartmentID] = useState<number | string>(1);
const defaultTeacher = props.teachers.find(
(teacher) => teacher.id === props.fundInformation.teacherID,
);
const [teacher, setTeacher] = useState<Teacher | undefined>(defaultTeacher);
const [departmentID, setDepartmentID] = useState<number>(defaultTeacher?.departmentID || 1);

useEffect(() => {
const teacher = props.teachers.find((teacher) => teacher.departmentID === departmentID);
if (teacher && teacher.id) {
setFormData({ ...formData, teacherID: teacher.id });
if (teacher?.departmentID !== departmentID) {
const relatedTeachers = props.teachers.filter(
(teacher) => teacher.departmentID === departmentID,
);
relatedTeachers &&
setFormData({
...formData,
teacherID: relatedTeachers[0]?.id || 0,
});
setTeacher(relatedTeachers[0]);
}
}, [departmentID]);

Expand Down

0 comments on commit d07bbea

Please sign in to comment.