From b72c8cb2360e82cd9d6e2870153841144a35140d Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Thu, 6 Jul 2023 21:27:36 +0800 Subject: [PATCH] Finished up onboarding page --- src/components/Api/Api.tsx | 4 +-- src/routes/Onboarding/Onboarding.tsx | 53 ++++++++++++++++++---------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index 38d2a54..5a5ddcb 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -209,13 +209,13 @@ export async function OnboardingUpdateStudentInfo(info: OnboardingParams) { .patch("/api/v1/accounts/users/me/", info, { headers }) .then((response) => { console.log(JSON.stringify(response.data)); - return response.data; + return [true, response.data]; }) .catch((error) => { let error_message = ""; if (error.response) error_message = error.response.data; else error_message = "Unable to reach servers"; console.log("Error updating onboarding info", error_message); - return false; + return [false, error_message]; }); } diff --git a/src/routes/Onboarding/Onboarding.tsx b/src/routes/Onboarding/Onboarding.tsx index 16eb9f5..d8e5fff 100644 --- a/src/routes/Onboarding/Onboarding.tsx +++ b/src/routes/Onboarding/Onboarding.tsx @@ -21,12 +21,16 @@ import { GetYearLevels, OnboardingUpdateStudentInfo, } from "../../components/Api/Api"; +import { useDispatch } from "react-redux"; +import { unsetOnboarding } from "../../features/redux/slices/StatusSlice/StatusSlice"; +import { setUser } from "../../features/redux/slices/UserSlice/UserSlice"; export default function Onboarding() { const navigation = useNavigation(); - // const dispatch = useDispatch(); + const dispatch = useDispatch(); // const creds = useSelector((state: RootState) => state.auth.creds); + const [error, setError] = useState(""); // Semesters - const [semester, setSemester] = useState(""); + const [selected_semester, setSelectedSemester] = useState(""); const [semesterOpen, setSemesterOpen] = useState(false); const [semesters, setSemesters] = useState([ { label: "1st Semester", value: "1st Sem" }, @@ -44,7 +48,7 @@ export default function Onboarding() { }, }); // Year Level - const [year_level, setYearLevel] = useState(""); + const [selected_yearlevel, setSelectedYearLevel] = useState(""); const [yearLevelOpen, setYearLevelOpen] = useState(false); const [year_levels, setYearLevels] = useState([ { label: "1st Year", value: "1st Year" }, @@ -62,7 +66,7 @@ export default function Onboarding() { }, }); // Course - const [course, setCourse] = useState(""); + const [selected_course, setSelectedCourse] = useState(""); const [courseOpen, setCourseOpen] = useState(false); const [courses, setCourses] = useState([ { @@ -127,20 +131,20 @@ export default function Onboarding() { Academic Info { setCourseOpen(open); setSemesterOpen(false); setYearLevelOpen(false); }} - setValue={setCourse} + setValue={setSelectedCourse} placeholder="Choose your course" containerStyle={{ ...styles.dropdown_template, @@ -151,14 +155,14 @@ export default function Onboarding() { { setSemesterOpen(open); setCourseOpen(false); setYearLevelOpen(false); }} - setValue={setSemester} + setValue={setSelectedSemester} placeholder="Current semester" containerStyle={{ ...styles.dropdown_template, @@ -169,14 +173,14 @@ export default function Onboarding() { { setYearLevelOpen(open); setSemesterOpen(false); setCourseOpen(false); }} - setValue={setYearLevel} + setValue={setSelectedYearLevel} placeholder="Your Year Level" containerStyle={{ ...styles.dropdown_template, @@ -188,18 +192,31 @@ export default function Onboarding() { + {error}