diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index 5a5ddcb..c63d096 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -147,14 +147,13 @@ export async function GetCourses() { }) .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 getting courses", error_message); - return false; + return [false, error_message]; }); } @@ -168,14 +167,13 @@ export async function GetSemesters() { }) .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 getting semesters", error_message); - return false; + return [false, error_message]; }); } @@ -189,14 +187,13 @@ export async function GetYearLevels() { }) .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 getting year levels", error_message); - return false; + return [false, error_message]; }); } diff --git a/src/interfaces/Interfaces.tsx b/src/interfaces/Interfaces.tsx index 09c02cb..ed57230 100644 --- a/src/interfaces/Interfaces.tsx +++ b/src/interfaces/Interfaces.tsx @@ -47,24 +47,30 @@ export interface ActivationParams { token: string; } -export interface SemesterParams { +export interface Semester { id: string; name: string; shortname: string; } -export interface YearLevelParams { +export type SemesterParams = [boolean, Semester]; + +export interface YearLevel { id: string; name: string; shortname: string; } -export interface CourseParams { +export type YearLevelParams = [boolean, YearLevel]; + +export interface Course { id: string; name: string; shortname: string; } +export type CourseParams = [boolean, Course]; + export interface OnboardingParams { year_level: string; course: string; diff --git a/src/routes/Onboarding/Onboarding.tsx b/src/routes/Onboarding/Onboarding.tsx index d8e5fff..fa356d7 100644 --- a/src/routes/Onboarding/Onboarding.tsx +++ b/src/routes/Onboarding/Onboarding.tsx @@ -3,9 +3,12 @@ import styles from "../../styles"; import { View, Text } from "react-native"; import { useNavigation } from "@react-navigation/native"; import { + Course, CourseParams, RootDrawerParamList, + Semester, SemesterParams, + YearLevel, YearLevelParams, } from "../../interfaces/Interfaces"; import { colors } from "../../styles"; @@ -40,7 +43,7 @@ export default function Onboarding() { queryKey: ["semesters"], queryFn: GetSemesters, onSuccess: (data) => { - let semesters = data.map((item: SemesterParams) => ({ + let semesters = data[1].map((item: Semester) => ({ label: item.name, value: item.name, })); @@ -58,7 +61,7 @@ export default function Onboarding() { queryKey: ["year_levels"], queryFn: GetYearLevels, onSuccess: (data) => { - let year_levels = data.map((item: YearLevelParams) => ({ + let year_levels = data[1].map((item: YearLevel) => ({ label: item.name, value: item.name, })); @@ -79,7 +82,7 @@ export default function Onboarding() { queryKey: ["courses"], queryFn: GetCourses, onSuccess: (data) => { - let courses = data.map((item: CourseParams) => ({ + let courses = data[1].map((item: Course) => ({ label: item.name, value: item.name, }));