Finished up onboarding page

This commit is contained in:
Keannu Bernasol 2023-07-06 21:27:36 +08:00
parent c4e34e7496
commit b72c8cb236
2 changed files with 37 additions and 20 deletions

View file

@ -209,13 +209,13 @@ export async function OnboardingUpdateStudentInfo(info: OnboardingParams) {
.patch("/api/v1/accounts/users/me/", info, { headers }) .patch("/api/v1/accounts/users/me/", info, { headers })
.then((response) => { .then((response) => {
console.log(JSON.stringify(response.data)); console.log(JSON.stringify(response.data));
return response.data; return [true, response.data];
}) })
.catch((error) => { .catch((error) => {
let error_message = ""; let error_message = "";
if (error.response) error_message = error.response.data; if (error.response) error_message = error.response.data;
else error_message = "Unable to reach servers"; else error_message = "Unable to reach servers";
console.log("Error updating onboarding info", error_message); console.log("Error updating onboarding info", error_message);
return false; return [false, error_message];
}); });
} }

View file

@ -21,12 +21,16 @@ import {
GetYearLevels, GetYearLevels,
OnboardingUpdateStudentInfo, OnboardingUpdateStudentInfo,
} from "../../components/Api/Api"; } 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() { export default function Onboarding() {
const navigation = useNavigation<RootDrawerParamList>(); const navigation = useNavigation<RootDrawerParamList>();
// const dispatch = useDispatch(); const dispatch = useDispatch();
// const creds = useSelector((state: RootState) => state.auth.creds); // const creds = useSelector((state: RootState) => state.auth.creds);
const [error, setError] = useState("");
// Semesters // Semesters
const [semester, setSemester] = useState(""); const [selected_semester, setSelectedSemester] = useState("");
const [semesterOpen, setSemesterOpen] = useState(false); const [semesterOpen, setSemesterOpen] = useState(false);
const [semesters, setSemesters] = useState([ const [semesters, setSemesters] = useState([
{ label: "1st Semester", value: "1st Sem" }, { label: "1st Semester", value: "1st Sem" },
@ -44,7 +48,7 @@ export default function Onboarding() {
}, },
}); });
// Year Level // Year Level
const [year_level, setYearLevel] = useState(""); const [selected_yearlevel, setSelectedYearLevel] = useState("");
const [yearLevelOpen, setYearLevelOpen] = useState(false); const [yearLevelOpen, setYearLevelOpen] = useState(false);
const [year_levels, setYearLevels] = useState([ const [year_levels, setYearLevels] = useState([
{ label: "1st Year", value: "1st Year" }, { label: "1st Year", value: "1st Year" },
@ -62,7 +66,7 @@ export default function Onboarding() {
}, },
}); });
// Course // Course
const [course, setCourse] = useState(""); const [selected_course, setSelectedCourse] = useState("");
const [courseOpen, setCourseOpen] = useState(false); const [courseOpen, setCourseOpen] = useState(false);
const [courses, setCourses] = useState([ const [courses, setCourses] = useState([
{ {
@ -127,20 +131,20 @@ export default function Onboarding() {
<MotiView <MotiView
from={{ opacity: 0 }} from={{ opacity: 0 }}
animate={{ opacity: 1 }} animate={{ opacity: 1 }}
transition={{ type: "timing", duration: 900, delay: 2000 }} transition={{ type: "timing", duration: 400, delay: 1700 }}
> >
<Text style={styles.text_white_medium}>Academic Info</Text> <Text style={styles.text_white_medium}>Academic Info</Text>
<DropDownPicker <DropDownPicker
zIndex={3000} zIndex={3000}
open={courseOpen} open={courseOpen}
value={course} value={selected_course}
items={courses} items={courses}
setOpen={(open) => { setOpen={(open) => {
setCourseOpen(open); setCourseOpen(open);
setSemesterOpen(false); setSemesterOpen(false);
setYearLevelOpen(false); setYearLevelOpen(false);
}} }}
setValue={setCourse} setValue={setSelectedCourse}
placeholder="Choose your course" placeholder="Choose your course"
containerStyle={{ containerStyle={{
...styles.dropdown_template, ...styles.dropdown_template,
@ -151,14 +155,14 @@ export default function Onboarding() {
<DropDownPicker <DropDownPicker
zIndex={2000} zIndex={2000}
open={semesterOpen} open={semesterOpen}
value={semester} value={selected_semester}
items={semesters} items={semesters}
setOpen={(open) => { setOpen={(open) => {
setSemesterOpen(open); setSemesterOpen(open);
setCourseOpen(false); setCourseOpen(false);
setYearLevelOpen(false); setYearLevelOpen(false);
}} }}
setValue={setSemester} setValue={setSelectedSemester}
placeholder="Current semester" placeholder="Current semester"
containerStyle={{ containerStyle={{
...styles.dropdown_template, ...styles.dropdown_template,
@ -169,14 +173,14 @@ export default function Onboarding() {
<DropDownPicker <DropDownPicker
zIndex={1000} zIndex={1000}
open={yearLevelOpen} open={yearLevelOpen}
value={year_level} value={selected_yearlevel}
items={year_levels} items={year_levels}
setOpen={(open) => { setOpen={(open) => {
setYearLevelOpen(open); setYearLevelOpen(open);
setSemesterOpen(false); setSemesterOpen(false);
setCourseOpen(false); setCourseOpen(false);
}} }}
setValue={setYearLevel} setValue={setSelectedYearLevel}
placeholder="Your Year Level" placeholder="Your Year Level"
containerStyle={{ containerStyle={{
...styles.dropdown_template, ...styles.dropdown_template,
@ -188,18 +192,31 @@ export default function Onboarding() {
<MotiView <MotiView
from={{ opacity: 0 }} from={{ opacity: 0 }}
animate={{ opacity: 1, zIndex: -1 }} animate={{ opacity: 1, zIndex: -1 }}
transition={{ type: "timing", duration: 900, delay: 2000 }} transition={{ type: "timing", duration: 400, delay: 1700 }}
style={styles.button_template} style={styles.button_template}
> >
<Text style={styles.text_white_small}>{error}</Text>
<Button <Button
disabled={!year_level || !course || !semester} disabled={
!selected_yearlevel || !selected_course || !selected_semester
}
onPress={async () => { onPress={async () => {
console.log(semester, course, year_level); let result = await OnboardingUpdateStudentInfo({
await OnboardingUpdateStudentInfo({ semester: selected_semester,
semester: semester, course: selected_course,
course: course, year_level: selected_yearlevel,
year_level: year_level,
}); });
if (result[0]) {
dispatch(unsetOnboarding());
setSelectedCourse("");
setSelectedYearLevel("");
setSelectedSemester("");
setError("Success!");
dispatch(setUser(result[1]));
navigation.navigate("Home");
} else {
setError(result[1]);
}
}} }}
color={colors.blue_3} color={colors.blue_3}
> >