Reworked the onboarding apis to follow standard format

This commit is contained in:
Keannu Bernasol 2023-07-17 15:57:23 +08:00
parent df58613d4b
commit f503f060f2
3 changed files with 21 additions and 15 deletions

View file

@ -147,14 +147,13 @@ export async function GetCourses() {
}) })
.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 getting courses", error_message); return [false, error_message];
return false;
}); });
} }
@ -168,14 +167,13 @@ export async function GetSemesters() {
}) })
.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 getting semesters", error_message); return [false, error_message];
return false;
}); });
} }
@ -189,14 +187,13 @@ export async function GetYearLevels() {
}) })
.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 getting year levels", error_message); return [false, error_message];
return false;
}); });
} }

View file

@ -47,24 +47,30 @@ export interface ActivationParams {
token: string; token: string;
} }
export interface SemesterParams { export interface Semester {
id: string; id: string;
name: string; name: string;
shortname: string; shortname: string;
} }
export interface YearLevelParams { export type SemesterParams = [boolean, Semester];
export interface YearLevel {
id: string; id: string;
name: string; name: string;
shortname: string; shortname: string;
} }
export interface CourseParams { export type YearLevelParams = [boolean, YearLevel];
export interface Course {
id: string; id: string;
name: string; name: string;
shortname: string; shortname: string;
} }
export type CourseParams = [boolean, Course];
export interface OnboardingParams { export interface OnboardingParams {
year_level: string; year_level: string;
course: string; course: string;

View file

@ -3,9 +3,12 @@ import styles from "../../styles";
import { View, Text } from "react-native"; import { View, Text } from "react-native";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import { import {
Course,
CourseParams, CourseParams,
RootDrawerParamList, RootDrawerParamList,
Semester,
SemesterParams, SemesterParams,
YearLevel,
YearLevelParams, YearLevelParams,
} from "../../interfaces/Interfaces"; } from "../../interfaces/Interfaces";
import { colors } from "../../styles"; import { colors } from "../../styles";
@ -40,7 +43,7 @@ export default function Onboarding() {
queryKey: ["semesters"], queryKey: ["semesters"],
queryFn: GetSemesters, queryFn: GetSemesters,
onSuccess: (data) => { onSuccess: (data) => {
let semesters = data.map((item: SemesterParams) => ({ let semesters = data[1].map((item: Semester) => ({
label: item.name, label: item.name,
value: item.name, value: item.name,
})); }));
@ -58,7 +61,7 @@ export default function Onboarding() {
queryKey: ["year_levels"], queryKey: ["year_levels"],
queryFn: GetYearLevels, queryFn: GetYearLevels,
onSuccess: (data) => { onSuccess: (data) => {
let year_levels = data.map((item: YearLevelParams) => ({ let year_levels = data[1].map((item: YearLevel) => ({
label: item.name, label: item.name,
value: item.name, value: item.name,
})); }));
@ -79,7 +82,7 @@ export default function Onboarding() {
queryKey: ["courses"], queryKey: ["courses"],
queryFn: GetCourses, queryFn: GetCourses,
onSuccess: (data) => { onSuccess: (data) => {
let courses = data.map((item: CourseParams) => ({ let courses = data[1].map((item: Course) => ({
label: item.name, label: item.name,
value: item.name, value: item.name,
})); }));