-
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.
feat: integrate api with register patient page
- Loading branch information
whosyourtaco
committed
Jul 7, 2021
1 parent
8f531c6
commit 255fa65
Showing
16 changed files
with
244 additions
and
43 deletions.
There are no files selected for viewing
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,5 @@ | ||
import patientsAPI from './patientsAPI'; | ||
|
||
export default { | ||
single: patientsAPI, | ||
}; |
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,9 @@ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
import { RegisterPatientPayload } from '../../models/apiTypes'; | ||
import { METHODS, request } from '../axiosInstances'; | ||
|
||
export default { | ||
getHospitals: () => request(METHODS.GET, '/hospitals/', {}), | ||
registerPatient: (params: RegisterPatientPayload) => | ||
request(METHODS.POST, '/patients/', { params }), | ||
}; |
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,57 @@ | ||
import { AxiosError } from 'axios'; | ||
import { ReactQueryKeys } from 'hooks/constants'; | ||
import { useMutation, useQuery } from 'react-query'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
import patientsAPI from '../../api/patientsAPI'; | ||
import { HospitalsResponse, RegisterPatientPayload } from '../../models/apiTypes'; | ||
import { RegisterPatientFormType } from '../../pages/RegisterPatient/types'; | ||
import urls from '../../routing/urls'; | ||
|
||
export const useGetHospitals = () => { | ||
return useQuery<HospitalsResponse, AxiosError, HospitalsResponse>( | ||
ReactQueryKeys.HospitalsQuery, | ||
async () => { | ||
const { request } = patientsAPI.single.getHospitals(); | ||
const data = await request(); | ||
|
||
return data; | ||
}, | ||
{ | ||
onError: (errors) => { | ||
console.log(errors); | ||
}, | ||
|
||
retry: false, | ||
} | ||
); | ||
}; | ||
|
||
export const useRegisterPatient = () => { | ||
const history = useHistory(); | ||
|
||
return useMutation<RegisterPatientPayload, AxiosError, RegisterPatientFormType>( | ||
(params) => { | ||
const { request } = patientsAPI.single.registerPatient({ | ||
full_name: params.name, | ||
address: params.address, | ||
age: params.age, | ||
year_of_birth: params.yearOfBirth, | ||
phone_1: params.phone1, | ||
phone_2: params.phone2, | ||
hospital_id: params.center.value, | ||
national_id: params.nationalId, | ||
gender: params.gender, | ||
}); | ||
return request(); | ||
}, | ||
{ | ||
onSuccess: () => { | ||
history.replace(urls.patients()); | ||
}, | ||
onError: (errors) => { | ||
console.log(errors); | ||
}, | ||
} | ||
); | ||
}; |
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,4 @@ | ||
export const ReactQueryKeys = { | ||
PatientsQuery: 'patientsQuery', | ||
HospitalsQuery: 'hospitalsQuery', | ||
}; |
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
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
Oops, something went wrong.