From d0aeb72e62b478189270a416b6da138c4bcf2bd5 Mon Sep 17 00:00:00 2001 From: xyntechx Date: Mon, 27 Nov 2023 19:31:29 -0800 Subject: [PATCH] Enable autofill for enrollment and grades --- .../ClassSearchBar/EnrollmentSearchBar.jsx | 15 +++++++++++++-- .../components/ClassSearchBar/GradesSearchBar.jsx | 14 +++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/ClassSearchBar/EnrollmentSearchBar.jsx b/frontend/src/components/ClassSearchBar/EnrollmentSearchBar.jsx index f320e166d..08e3f27df 100644 --- a/frontend/src/components/ClassSearchBar/EnrollmentSearchBar.jsx +++ b/frontend/src/components/ClassSearchBar/EnrollmentSearchBar.jsx @@ -89,9 +89,12 @@ export default function EnrollmentSearchBar({ fromCatalog }) { const [selectedClass, setSelectedClass] = useState(0); - const { sections, selectPrimary, selectSecondary } = useSelector((state) => state.enrollment); + const { sections, selectPrimary, selectSecondary, selectedCourses } = useSelector( + (state) => state.enrollment + ); const [localSelectPrimary, setLocalSelectPrimary] = useState(selectPrimary); const [localSelectSecondary, setLocalSelectSecondary] = useState(selectSecondary); + const [selectedClassVal, setSelectedClassVal] = useState(undefined); const dispatch = useDispatch(); const handleClassSelect = useCallback( @@ -103,6 +106,7 @@ export default function EnrollmentSearchBar({ } setSelectedClass(updatedClass.value); + setSelectedClassVal(updatedClass); setLocalSelectPrimary(''); setLocalSelectSecondary(''); dispatch(fetchEnrollSelected(updatedClass)); @@ -117,6 +121,13 @@ export default function EnrollmentSearchBar({ useEffect(() => setLocalSelectPrimary(selectPrimary), [selectPrimary]); useEffect(() => setLocalSelectSecondary(selectSecondary), [selectSecondary]); + useEffect(() => { + if (selectedCourses && selectedCourses.length > 0) { + const course = selectedCourses[selectedCourses.length - 1]; + const payload = { value: course.courseID, label: course.course, course }; + handleClassSelect(payload); + } + }, [selectedCourses]); const handlePrimarySelect = (primary) => { setLocalSelectPrimary(primary ? primary.value : ''); @@ -222,7 +233,7 @@ export default function EnrollmentSearchBar({ courseSearch name="selectClass" placeholder="Choose a class..." - // value={selectedClass} + value={selectedClassVal} options={buildCoursesOptions(classes)} onChange={handleClassSelect} components={{ diff --git a/frontend/src/components/ClassSearchBar/GradesSearchBar.jsx b/frontend/src/components/ClassSearchBar/GradesSearchBar.jsx index 39038bedc..aa480c04a 100644 --- a/frontend/src/components/ClassSearchBar/GradesSearchBar.jsx +++ b/frontend/src/components/ClassSearchBar/GradesSearchBar.jsx @@ -150,9 +150,12 @@ const customStyles = { }; export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobile, classes }) { - const { sections, selectPrimary, selectSecondary } = useSelector((state) => state.grade); + const { sections, selectPrimary, selectSecondary, selectedCourses } = useSelector( + (state) => state.grade + ); const [localSelectPrimary, setLocalSelectPrimary] = useState(selectPrimary); const [localSelectSecondary, setLocalSelectSecondary] = useState(selectSecondary); + const [selectedClassVal, setSelectedClassVal] = useState(undefined); const [selectedClass, setSelectedClass] = useState(0); const [selectType, setSelectType] = useState('instructor'); const dispatch = useDispatch(); @@ -168,6 +171,7 @@ export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobi } setSelectedClass(updatedClass.value); + setSelectedClassVal(updatedClass); dispatch(fetchGradeSelected(updatedClass)); }, [dispatch] @@ -183,6 +187,13 @@ export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobi useEffect(() => setLocalSelectPrimary(selectPrimary), [selectPrimary]); useEffect(() => setLocalSelectSecondary(selectSecondary), [selectSecondary]); + useEffect(() => { + if (selectedCourses && selectedCourses.length > 0) { + const course = selectedCourses[selectedCourses.length - 1]; + const payload = { value: course.courseID, label: course.course, course }; + handleClassSelect(payload); + } + }, [selectedCourses]); const handleSortSelect = (sortBy) => { setSelectType(sortBy.value); @@ -301,6 +312,7 @@ export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobi courseSearch name="selectClass" placeholder="Choose a class..." + value={selectedClassVal} options={buildCoursesOptions(classes)} onChange={handleClassSelect} components={{