Made subjects menu functional in user info

This commit is contained in:
Keannu Bernasol 2023-07-18 16:06:58 +08:00
parent 1aed66150c
commit ffde700a36
3 changed files with 11 additions and 15 deletions

View file

@ -89,6 +89,7 @@ export function UserLogin(user: LoginParams) {
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_message);
return [false, error_message]; return [false, error_message];
}); });
} }

View file

@ -30,8 +30,8 @@ export default function Login() {
const [creds, setCreds] = useState({ const [creds, setCreds] = useState({
username: "", username: "",
password: "", password: "",
error: "",
}); });
const [error, setError] = useState("");
return ( return (
<View style={styles.background}> <View style={styles.background}>
<AnimatedContainer> <AnimatedContainer>
@ -67,7 +67,7 @@ export default function Login() {
}} }}
/> />
<View style={{ paddingVertical: 2 }} /> <View style={{ paddingVertical: 2 }} />
<Text style={styles.text_white_small}>{creds.error}</Text> <Text style={styles.text_white_small}>{error}</Text>
<View style={{ paddingVertical: 4 }} /> <View style={{ paddingVertical: 4 }} />
<Button <Button
onPress={async () => { onPress={async () => {
@ -94,10 +94,8 @@ export default function Login() {
} }
console.log(JSON.stringify(user_info)); console.log(JSON.stringify(user_info));
} else { } else {
setUser({ console.log("heh", ParseLoginError(JSON.stringify(result[1])));
...creds, setError(ParseLoginError(JSON.stringify(result[1])));
error: ParseLoginError(JSON.stringify(result[1])),
});
} }
}); });
}} }}

View file

@ -7,10 +7,8 @@ import {
NativeSyntheticEvent, NativeSyntheticEvent,
TextInputChangeEventData, TextInputChangeEventData,
} from "react-native"; } from "react-native";
import { useEffect, useState } from "react"; import { useState } from "react";
import { useNavigation } from "@react-navigation/native";
import { import {
RootDrawerParamList,
SemesterParams, SemesterParams,
UserInfoParams, UserInfoParams,
Semester, Semester,
@ -20,7 +18,7 @@ import {
Course, Course,
} from "../../interfaces/Interfaces"; } from "../../interfaces/Interfaces";
import Button from "../../components/Button/Button"; import Button from "../../components/Button/Button";
import { TouchableOpacity, Image } from "react-native"; import { Image } from "react-native";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { import {
GetCourses, GetCourses,
@ -88,7 +86,6 @@ export default function UserInfoPage() {
queryKey: ["semesters"], queryKey: ["semesters"],
queryFn: GetSemesters, queryFn: GetSemesters,
onSuccess: (data: SemesterParams) => { onSuccess: (data: SemesterParams) => {
console.log("Semesters", data[1]);
let semestersData = data[1].map((semester: Semester) => ({ let semestersData = data[1].map((semester: Semester) => ({
label: semester.name, label: semester.name,
value: semester.name, value: semester.name,
@ -96,7 +93,6 @@ export default function UserInfoPage() {
})); }));
// Update the 'semesters' state // Update the 'semesters' state
setSemesters(semestersData); setSemesters(semestersData);
console.log(semesters);
}, },
}); });
@ -132,6 +128,7 @@ export default function UserInfoPage() {
if (!data[1]) { if (!data[1]) {
throw new Error("User has no course, year level, or semester!"); throw new Error("User has no course, year level, or semester!");
} }
console.log("Subjects available:", data[1]);
} }
return data; return data;
@ -140,7 +137,7 @@ export default function UserInfoPage() {
let subjectsData = data[1].map((subject: Subject) => ({ let subjectsData = data[1].map((subject: Subject) => ({
id: Number(subject.id), id: Number(subject.id),
label: subject.name, label: subject.name,
value: subject.id, value: subject.name,
shortname: subject.code, shortname: subject.code,
})); }));
@ -305,7 +302,6 @@ export default function UserInfoPage() {
setSubjectsOpen(false); setSubjectsOpen(false);
}} }}
onChangeValue={() => { onChangeValue={() => {
console.log(selected_semester);
setUser({ ...user, semester: selected_semester }); setUser({ ...user, semester: selected_semester });
}} }}
setValue={setSelectedSemester} setValue={setSelectedSemester}
@ -410,12 +406,13 @@ export default function UserInfoPage() {
color={colors.secondary_3} color={colors.secondary_3}
onPress={() => { onPress={() => {
if (isEditable) { if (isEditable) {
console.log(selected_subjects);
mutation.mutate({ mutation.mutate({
first_name: user.first_name, first_name: user.first_name,
last_name: user.last_name, last_name: user.last_name,
course: selected_course, course: selected_course,
semester: selected_semester, semester: selected_semester,
subjects: [], subjects: selected_subjects,
year_level: selected_yearlevel, year_level: selected_yearlevel,
}); });
} }