From 563e8d7b2bc49a296c8182012bf548635e9da3c1 Mon Sep 17 00:00:00 2001 From: TkymHrt <23.h.takayama.nutfes@gmail.com> Date: Tue, 5 Mar 2024 15:55:37 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[fix]=20=E7=99=BB=E9=8C=B2=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9F=E3=83=87=E3=83=BC=E3=82=BF=E3=81=8C=E7=B7=A8?= =?UTF-8?q?=E9=9B=86=E3=83=A2=E3=83=BC=E3=83=80=E3=83=AB=E3=81=AB=E5=8F=8D?= =?UTF-8?q?=E6=98=A0=E3=81=95=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/fund_information/EditModal.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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]); From 154ec9a0ca3e8f4969a7a5f84a0577bba7c078d4 Mon Sep 17 00:00:00 2001 From: TkymHrt <23.h.takayama.nutfes@gmail.com> Date: Wed, 6 Mar 2024 14:13:32 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[fix]=20=E6=95=99=E5=93=A1=E3=81=AE?= =?UTF-8?q?=E6=89=80=E5=B1=9E=E3=82=92=E5=8F=8D=E6=98=A0=E3=81=97=E3=81=A6?= =?UTF-8?q?=E6=95=99=E5=93=A1=E5=90=8D=E3=81=8C=E7=99=BB=E9=8C=B2=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/next-project/src/components/fund_information/EditModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/next-project/src/components/fund_information/EditModal.tsx b/view/next-project/src/components/fund_information/EditModal.tsx index ed2d596f3..0ff44486d 100644 --- a/view/next-project/src/components/fund_information/EditModal.tsx +++ b/view/next-project/src/components/fund_information/EditModal.tsx @@ -34,7 +34,7 @@ export default function EditModal(props: ModalProps) { useEffect(() => { const teacher = props.teachers.find((teacher) => teacher.departmentID === departmentID); if (teacher && teacher.id) { - setFormData({ ...formData, teacherID: props.fundInformation.teacherID }); + setFormData({ ...formData, teacherID: teacher.id }); } }, [departmentID]); From 49bd4811fe1ba60a13f4f412e4edc180e3ba853d Mon Sep 17 00:00:00 2001 From: TkymHrt <23.h.takayama.nutfes@gmail.com> Date: Wed, 6 Mar 2024 14:18:22 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[fix]=20=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E5=90=8D=E3=81=8C=E6=AD=A3=E3=81=97=E3=81=8Fset?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/next-project/src/components/fund_information/EditModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/next-project/src/components/fund_information/EditModal.tsx b/view/next-project/src/components/fund_information/EditModal.tsx index 0ff44486d..f4ad660cd 100644 --- a/view/next-project/src/components/fund_information/EditModal.tsx +++ b/view/next-project/src/components/fund_information/EditModal.tsx @@ -78,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: props.fundInformation.userID }); + if (res.length !== 0) setFormData({ ...formData, userID: res[0].id }); return res; }, [bureauId]); From 46ddcb2a744b89a1a45a0d14e7104743c181a3bb Mon Sep 17 00:00:00 2001 From: TkymHrt <23.h.takayama.nutfes@gmail.com> Date: Mon, 18 Mar 2024 22:17:47 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[fix]=20=E7=99=BB=E9=8C=B2=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9F=E3=83=87=E3=83=BC=E3=82=BF=E3=81=AE=E5=8F=8D?= =?UTF-8?q?=E6=98=A0=E3=81=A8=E6=9B=B4=E6=96=B0=E3=81=AEUseEffect=E3=82=92?= =?UTF-8?q?=E5=86=8D=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/fund_information/EditModal.tsx | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/view/next-project/src/components/fund_information/EditModal.tsx b/view/next-project/src/components/fund_information/EditModal.tsx index f4ad660cd..a583e51a8 100644 --- a/view/next-project/src/components/fund_information/EditModal.tsx +++ b/view/next-project/src/components/fund_information/EditModal.tsx @@ -30,22 +30,29 @@ export default function EditModal(props: ModalProps) { }); const [departmentID, setDepartmentID] = useState(1); + const [defaultValue, setDefaultValue] = useState(false); useEffect(() => { - const teacher = props.teachers.find((teacher) => teacher.departmentID === departmentID); - if (teacher && teacher.id) { - setFormData({ ...formData, teacherID: teacher.id }); - } - }, [departmentID]); - - useEffect(() => { - const selectedTeacher = props.teachers.find( - (teacher) => teacher.id === props.fundInformation.teacherID, - ); - if (selectedTeacher) { - setDepartmentID(selectedTeacher.departmentID); + if (defaultValue == false) { + const selectedTeacher = props.teachers.find( + (teacher) => teacher.id === props.fundInformation.teacherID, + ); + if (selectedTeacher?.id) { + setDepartmentID(selectedTeacher.departmentID); + setFormData({ ...formData, teacherID: selectedTeacher.id }); + } + setTimeout(() => { + setDefaultValue(true); + }); + } else { + const relatedTeachers = props.teachers.filter( + (teacher) => teacher.departmentID === departmentID, + ); + if (relatedTeachers) { + setFormData({ ...formData, teacherID: relatedTeachers[0].id || 0 }); + } } - }, [props.teachers, props.fundInformation.teacherID]); + }, [departmentID, props.teachers]); const handler = (input: string) => From 6392ed0ce3d8c55d4f0f37c790995235fecd73e8 Mon Sep 17 00:00:00 2001 From: TkymHrt <23.h.takayama.nutfes@gmail.com> Date: Thu, 21 Mar 2024 16:40:56 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[fix]=20=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=81=A8=E8=A1=A8=E7=A4=BA=E3=81=AE=E4=BB=95?= =?UTF-8?q?=E7=B5=84=E3=81=BF=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/fund_information/EditModal.tsx | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/view/next-project/src/components/fund_information/EditModal.tsx b/view/next-project/src/components/fund_information/EditModal.tsx index a583e51a8..be5f8ea42 100644 --- a/view/next-project/src/components/fund_information/EditModal.tsx +++ b/view/next-project/src/components/fund_information/EditModal.tsx @@ -29,30 +29,25 @@ export default function EditModal(props: ModalProps) { receivedAt: props.fundInformation.receivedAt, }); - const [departmentID, setDepartmentID] = useState(1); - const [defaultValue, setDefaultValue] = useState(false); + const defaultTeacher = props.teachers.find( + (teacher) => teacher.id === props.fundInformation.teacherID, + ); + const [teacher, setTeacher] = useState(defaultTeacher); + const [departmentID, setDepartmentID] = useState(defaultTeacher?.departmentID || 1); useEffect(() => { - if (defaultValue == false) { - const selectedTeacher = props.teachers.find( - (teacher) => teacher.id === props.fundInformation.teacherID, - ); - if (selectedTeacher?.id) { - setDepartmentID(selectedTeacher.departmentID); - setFormData({ ...formData, teacherID: selectedTeacher.id }); - } - setTimeout(() => { - setDefaultValue(true); - }); - } else { + if (teacher?.departmentID !== departmentID) { const relatedTeachers = props.teachers.filter( (teacher) => teacher.departmentID === departmentID, ); - if (relatedTeachers) { - setFormData({ ...formData, teacherID: relatedTeachers[0].id || 0 }); - } + relatedTeachers && + setFormData({ + ...formData, + teacherID: relatedTeachers[0]?.id || 0, + }); + setTeacher(relatedTeachers[0]); } - }, [departmentID, props.teachers]); + }, [departmentID]); const handler = (input: string) =>