-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
242 additions
and
28 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {keepPreviousData, useQuery} from "@tanstack/react-query"; | ||
import {Instance} from "@/services/axios.ts"; | ||
|
||
const instance: Instance = new Instance(); | ||
|
||
export function useAnnouncements() { | ||
const data = useQuery({ | ||
queryKey: ["announcements"], | ||
queryFn: () => instance.getAnnouncements(), | ||
placeholderData: keepPreviousData, | ||
staleTime: 30000, | ||
}); | ||
if (data) { | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {keepPreviousData, useQuery} from "@tanstack/react-query"; | ||
import {Instance} from "@/services/axios.ts"; | ||
|
||
const instance: Instance = new Instance(); | ||
|
||
export function useCourses() { | ||
const data = useQuery({ | ||
queryKey: ["courses"], | ||
queryFn: () => instance.getCourses(), | ||
placeholderData: keepPreviousData, | ||
staleTime: 30000, | ||
}); | ||
if (data) { | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {keepPreviousData, useQuery} from "@tanstack/react-query"; | ||
import {Instance} from "@/services/axios.ts"; | ||
|
||
const instance: Instance = new Instance(); | ||
|
||
export function useIssues() { | ||
const data = useQuery({ | ||
queryKey: ["issues"], | ||
queryFn: () => instance.getIssues(), | ||
placeholderData: keepPreviousData, | ||
staleTime: 30000, | ||
}); | ||
if (data) { | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {keepPreviousData, useQuery} from "@tanstack/react-query"; | ||
import {Instance} from "@/services/axios.ts"; | ||
|
||
const instance: Instance = new Instance(); | ||
|
||
export function useProfessors() { | ||
const data = useQuery({ | ||
queryKey: ["professors"], | ||
queryFn: () => instance.getProfessors(), | ||
placeholderData: keepPreviousData, | ||
staleTime: 30000, | ||
}); | ||
if (data) { | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {keepPreviousData, useQuery} from "@tanstack/react-query"; | ||
import {Instance} from "@/services/axios.ts"; | ||
|
||
const instance: Instance = new Instance(); | ||
|
||
export function useSections() { | ||
const data = useQuery({ | ||
queryKey: ["sections"], | ||
queryFn: () => instance.getSections(), | ||
placeholderData: keepPreviousData, | ||
staleTime: 30000, | ||
}); | ||
if (data) { | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {keepPreviousData, useQuery} from "@tanstack/react-query"; | ||
import {Instance} from "@/services/axios.ts"; | ||
|
||
const instance: Instance = new Instance(); | ||
|
||
export function useTickets() { | ||
const data = useQuery({ | ||
queryKey: ["tickets"], | ||
queryFn: () => instance.getTickets(), | ||
placeholderData: keepPreviousData, | ||
staleTime: 30000, | ||
}); | ||
if (data) { | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {keepPreviousData, useQuery} from "@tanstack/react-query"; | ||
import {Instance} from "@/services/axios.ts"; | ||
|
||
const instance: Instance = new Instance(); | ||
|
||
export function useTutors() { | ||
const data = useQuery({ | ||
queryKey: ["tutors"], | ||
queryFn: () => instance.getTutors(), | ||
placeholderData: keepPreviousData, | ||
staleTime: 30000, | ||
}); | ||
if (data) { | ||
return data; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import axios, {AxiosInstance, AxiosRequestConfig} from "axios"; | ||
|
||
export class Instance { | ||
private _instance: AxiosInstance; | ||
constructor() { | ||
this._instance = axios.create({ | ||
baseURL: "/api/", | ||
timeout: 30000, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
} | ||
|
||
async get(endpoint: string) { | ||
const response = await this._instance.get(endpoint); | ||
return response.data; | ||
} | ||
|
||
async post(endpoint: string, data: any, headers: AxiosRequestConfig | undefined = undefined) { | ||
const response = await this._instance.post(endpoint, data, headers); | ||
return response.data; | ||
} | ||
|
||
private cookie(name: string): string | undefined { | ||
const value: string = `; ${document.cookie}`; | ||
const parts: string[] = value.split(`; ${name}=`); | ||
if (parts.length === 2 && !!parts) return parts.pop()?.split(";").shift(); | ||
} | ||
|
||
async createTicket(data: any): Promise<any> { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post("tickets/", data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async updateTicket(data: any) { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post(`tickets/${data.id}/`, data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async getTickets() { | ||
return await this.get("tickets"); | ||
} | ||
|
||
async createAnnouncement(data: any) { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post("announcements", data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async getAnnouncements() { | ||
return await this.get("announcements"); | ||
} | ||
|
||
async createCourse(data: any) { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post("courses", data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async getCourses() { | ||
return await this.get("courses"); | ||
} | ||
|
||
async createIssue(data: any) { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post("issues", data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async getIssues() { | ||
return await this.get("issues"); | ||
} | ||
|
||
async createProfessor(data: any) { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post("professors", data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async getProfessors() { | ||
return await this.get("professors"); | ||
} | ||
|
||
async createSection(data: any) { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post("sections", data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async getSections() { | ||
return await this.get("sections"); | ||
} | ||
|
||
async createTutor(data: any) { | ||
const csrf: string | undefined = this.cookie("csrftoken"); | ||
return await this.post("tutors", data, { | ||
headers: {"X-CSRFToken": csrf}, | ||
}); | ||
} | ||
|
||
async getTutors() { | ||
return await this.get("users/?tutor=1"); | ||
} | ||
} |