diff --git a/frontend/.env.example b/frontend/.env.example new file mode 100644 index 0000000..980d14d --- /dev/null +++ b/frontend/.env.example @@ -0,0 +1 @@ +REACT_APP_BASE_URL=http://localhost:5000/api/ \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore index 4d29575..532eddc 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -21,3 +21,5 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +.env \ No newline at end of file diff --git a/frontend/src/api/axiosInstance.ts b/frontend/src/api/axiosInstance.ts index 055ef28..84b245d 100644 --- a/frontend/src/api/axiosInstance.ts +++ b/frontend/src/api/axiosInstance.ts @@ -1,5 +1,7 @@ -import axios from "axios"; +import axios from 'axios' -const axiosInstance = axios.create({}); +const axiosInstance = axios.create({ + baseURL: process.env.REACT_APP_BASE_URL, +}) -export default axiosInstance; +export default axiosInstance diff --git a/frontend/src/api/enrollment.ts b/frontend/src/api/enrollment.ts index 5970030..4df8486 100644 --- a/frontend/src/api/enrollment.ts +++ b/frontend/src/api/enrollment.ts @@ -18,9 +18,6 @@ export const getEnrollmentList = ( email: string mode: number }[] - }>( - `http://127.0.0.1:5000/api/students/registrations/${params.year_group_id}`, - { - params, - }, - ) + }>(`students/registrations/${params.year_group_id}`, { + params, + }) diff --git a/frontend/src/api/groups.ts b/frontend/src/api/groups.ts index 2d3d720..d63ba43 100644 --- a/frontend/src/api/groups.ts +++ b/frontend/src/api/groups.ts @@ -27,17 +27,14 @@ export const getGroups = ( }>, ) => axiosInstance.get<{ max_pages: number; groups: Group[] }>( - `http://127.0.0.1:5000/api/coordinator/groups/${params.year_group_id}`, + `coordinator/groups/${params.year_group_id}`, { params, }, ) export const createGroup = (year_group_id: number, payload: CreateGroup) => - axiosInstance.post( - `http://127.0.0.1:5000/api/coordinator/groups/${year_group_id}`, - payload, - ) + axiosInstance.post(`coordinator/groups/${year_group_id}`, payload) export const deleteGroup = (id: number) => - axiosInstance.delete(`http://127.0.0.1:5000/api/coordinator/groups/${id}/`) + axiosInstance.delete(`coordinator/groups/${id}/`) diff --git a/frontend/src/api/leaders.ts b/frontend/src/api/leaders.ts index c148e34..9f33f7f 100644 --- a/frontend/src/api/leaders.ts +++ b/frontend/src/api/leaders.ts @@ -28,17 +28,12 @@ export const getLeaders = ( }> = {}, ) => axiosInstance.get( - `http://127.0.0.1:5000/api/coordinator/project_supervisor/${params.year_group_id}`, + `coordinator/project_supervisor/${params.year_group_id}`, { params }, ) export const createLeader = (payload: Leader) => - axiosInstance.post( - 'http://127.0.0.1:5000/api/coordinator/project_supervisor/', - payload, - ) + axiosInstance.post('coordinator/project_supervisor/', payload) export const deleteLeader = (id: number) => - axiosInstance.delete( - `http://127.0.0.1:5000/api/coordinator/project_supervisor/${id}/`, - ) + axiosInstance.delete(`coordinator/project_supervisor/${id}/`) diff --git a/frontend/src/api/schedule.ts b/frontend/src/api/schedule.ts index eab074e..7a26be2 100644 --- a/frontend/src/api/schedule.ts +++ b/frontend/src/api/schedule.ts @@ -12,9 +12,7 @@ export const getTermsOfDefences = (scheduleId: number) => { } group: { name: string } }[] - }>( - `http://127.0.0.1:5000/api/coordinator/enrollments/${scheduleId}/term-of-defences/`, - ) + }>(`coordinator/enrollments/${scheduleId}/term-of-defences/`) } export const getStudentsTermsOfDefences = (scheduleId: number) => { @@ -29,9 +27,7 @@ export const getStudentsTermsOfDefences = (scheduleId: number) => { } group: { name: string } }[] - }>( - `http://127.0.0.1:5000/api/students/examination-schedule/${scheduleId}/enrollments/`, - ) + }>(`students/examination-schedule/${scheduleId}/enrollments/`) } export const getSchedules = (year_group_id: number = 1) => { return axiosInstance.get<{ @@ -42,9 +38,7 @@ export const getSchedules = (year_group_id: number = 1) => { title: string mode: boolean }[] - }>( - `http://127.0.0.1:5000/api/coordinator/examination_schedule/${year_group_id}?per_page=10000`, - ) + }>(`coordinator/examination_schedule/${year_group_id}?per_page=10000`) } export const createEvent = ({ @@ -58,14 +52,11 @@ export const createEvent = ({ scheduleId: number project_supervisors: number[] }) => { - return axiosInstance.post( - `http://127.0.0.1:5000/api/coordinator/enrollments/${scheduleId}/add`, - { - start_date, - end_date, - project_supervisors, - }, - ) + return axiosInstance.post(`coordinator/enrollments/${scheduleId}/add`, { + start_date, + end_date, + project_supervisors, + }) } export const createSchedule = ( @@ -73,7 +64,7 @@ export const createSchedule = ( payload: { title: string; start_date: string; end_date: string }, ) => { return axiosInstance.post( - `http://127.0.0.1:5000/api/coordinator/examination_schedule/${year_group_id}/`, + `coordinator/examination_schedule/${year_group_id}/`, payload, ) } @@ -87,13 +78,10 @@ export const setEventDate = ({ start_date: string end_date: string }) => { - return axiosInstance.put( - `http://127.0.0.1:5000/api/coordinator/examination_schedule/${id}/date`, - { - start_date, - end_date, - }, - ) + return axiosInstance.put(`coordinator/examination_schedule/${id}/date`, { + start_date, + end_date, + }) } export const assignGroup = ({ @@ -106,7 +94,7 @@ export const assignGroup = ({ studentIndex: number }) => { return axiosInstance.post( - `http://127.0.0.1:5000/api/students/${scheduleId}/enrollments/${enrollmentId}/`, + `students/${scheduleId}/enrollments/${enrollmentId}/`, { student_index: studentIndex, }, @@ -123,7 +111,7 @@ export const assignSupervisor = ({ supervisorId: number }) => { return axiosInstance.post( - `http://127.0.0.1:5000/api/project_supervisor/${scheduleId}/enrollments/${enrollmentId}/`, + `project_supervisor/${scheduleId}/enrollments/${enrollmentId}/`, { project_supervisor_id: supervisorId, }, @@ -132,7 +120,7 @@ export const assignSupervisor = ({ export const downloadSchedule = (scheduleId: number) => axiosInstance.post( - `http://127.0.0.1:5000/api/coordinator/examination_schedule/${scheduleId}/download/`, + `coordinator/examination_schedule/${scheduleId}/download/`, { responseType: 'blob', }, diff --git a/frontend/src/api/students.ts b/frontend/src/api/students.ts index d18e191..d4f8ef3 100644 --- a/frontend/src/api/students.ts +++ b/frontend/src/api/students.ts @@ -28,30 +28,20 @@ export const getStudents = ( }> = {}, ) => axiosInstance.get( - `http://127.0.0.1:5000/api/coordinator/students/${params.year_group_id}`, + `coordinator/students/${params.year_group_id}`, { params }, ) export const createStudent = (payload: Student) => - axiosInstance.post('http://127.0.0.1:5000/api/coordinator/students/', payload) + axiosInstance.post('coordinator/students/', payload) export const uploadStudents = (payload: FormData) => - axiosInstance.post( - 'http://127.0.0.1:5000/api/coordinator/students/upload/', - payload, - ) + axiosInstance.post('coordinator/students/upload/', payload) export const deleteStudent = (index: number) => - axiosInstance.delete( - `http://127.0.0.1:5000/api/coordinator/students/${index}/`, - ) + axiosInstance.delete(`coordinator/students/${index}/`) export const downloadStudents = (mode: boolean) => - axiosInstance.post( - `http://127.0.0.1:5000/api/coordinator/students/download/?mode=${Number( - mode, - )}`, - { - responseType: 'blob', - }, - ) + axiosInstance.post(`coordinator/students/download/?mode=${Number(mode)}`, { + responseType: 'blob', + })