-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] 登録されたデータが編集モーダルに反映されるよう修正 #696
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
動作確認できました。
ちょっと気になったところコメントしてます
useEffect(() => { | ||
const teacher = props.teachers.find((teacher) => teacher.departmentID === departmentID); | ||
if (teacher && teacher.id) { | ||
setFormData({ ...formData, teacherID: teacher.id }); | ||
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 }); | ||
} | ||
} | ||
}, [departmentID]); | ||
}, [departmentID, props.teachers]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultValueなくてもいけるのではないでしょうか
useEffect(() => {
const selectedTeacher = props.teachers.find(
(teacher) => teacher.id === props.fundInformation.teacherID,
);
if (selectedTeacher?.id) {
setDepartmentID(selectedTeacher.departmentID);
setFormData({ ...formData, teacherID: selectedTeacher.id });
} else {
const relatedTeachers = props.teachers.filter(
(teacher) => teacher.departmentID === departmentID,
);
if (relatedTeachers) {
setFormData({ ...formData, teacherID: relatedTeachers[0].id || 0 });
}
}
}, [departmentID, props.teachers]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS
いけませんでした。忘れてください
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
対応ありがとうございます!
少し、コメントしました!
動作おかしいやこっちのがいいなどあれば気軽に言ってください
view/next-project/src/components/fund_information/EditModal.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
対応Issue
resolve #663
概要
Issue内容は、担当者が各局の一番上の人になるバグの解消です。
しかし、教員の所属・教員名・担当者の局の項目でも同様のバグが発生していたため、まとめて修正しました。
修正内容は、各項目の初期値として登録される値を、既に登録されている内容から参照するように変更しました。
画面スクリーンショット等
テスト項目
http://localhost:3000/fund_informations
へアクセスできることを確認する。(各項目が全て1番目の要素に初期化されていないか。)
備考
24/03/29 更新:モーダルの展開時はpropsの値を表示し、セレクト要素の選択時にUseEffectの再レンダリングで教員名の初期値を設定するようにしました。もっと良い方法あれば教えて下さい。