Add base_url env

This commit is contained in:
adam-skowronek 2022-11-16 23:15:03 +01:00
parent b0e48d3703
commit 3125a696e4
8 changed files with 40 additions and 68 deletions

1
frontend/.env.example Normal file
View File

@ -0,0 +1 @@
REACT_APP_BASE_URL=http://localhost:5000/api/

2
frontend/.gitignore vendored
View File

@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env

View File

@ -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

View File

@ -18,9 +18,6 @@ export const getEnrollmentList = (
email: string
mode: number
}[]
}>(
`http://127.0.0.1:5000/api/students/registrations/${params.year_group_id}`,
{
}>(`students/registrations/${params.year_group_id}`, {
params,
},
)
})

View File

@ -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}/`)

View File

@ -28,17 +28,12 @@ export const getLeaders = (
}> = {},
) =>
axiosInstance.get<LeaderResponse>(
`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}/`)

View File

@ -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`,
{
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`,
{
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',
},

View File

@ -28,30 +28,20 @@ export const getStudents = (
}> = {},
) =>
axiosInstance.get<StudentResponse>(
`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,
)}`,
{
axiosInstance.post(`coordinator/students/download/?mode=${Number(mode)}`, {
responseType: 'blob',
},
)
})