mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Reworked the onboarding apis to follow standard format
This commit is contained in:
parent
df58613d4b
commit
f503f060f2
3 changed files with 21 additions and 15 deletions
|
@ -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];
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
}));
|
||||
|
|
Loading…
Reference in a new issue