Skip to content

Commit

Permalink
Merge pull request #343 from ertush/felix_v3
Browse files Browse the repository at this point in the history
updated the facility_type_details parent fetching and display
  • Loading branch information
ertush authored Mar 13, 2024
2 parents aac06cc + 6c05aa3 commit 903ebf9
Show file tree
Hide file tree
Showing 2 changed files with 6,398 additions and 2,381 deletions.
31 changes: 27 additions & 4 deletions components/Forms/BasicDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export function BasicDeatilsForm({ editMode }) {
}
})


setFacilityTypeDetailOptions(facilityType ?? options?.facility_type_details)

}
Expand All @@ -577,6 +577,19 @@ export function BasicDeatilsForm({ editMode }) {

updateFacilityTypeDetailOptions()

function getFacilityTypeDetails_parent(facilityTypeId, token) {

return fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facility_types_details/?id=${facilityTypeId}`, {
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
}
})
.then(resp => resp.json())
.then(resp => resp?.results)
.catch(console.error)

}
function getFacilityTypeDetails(facilityTypeId, token) {

return fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facility_types_details/?is_parent=false&parent=${facilityTypeId}`, {
Expand Down Expand Up @@ -627,12 +640,22 @@ export function BasicDeatilsForm({ editMode }) {

}
else if (editMode) {
getFacilityTypeDetails(options?.data?.facility_type, options?.token)
var parent="";
getFacilityTypeDetails_parent(options?.data?.facility_type, options?.token)
.then(facilityTypeDetails => {

parent=facilityTypeDetails[0]?.parent;
if(parent)
{
document.getElementsByName('facility_type_parent')[0].value = parent.toString();
}
})

getFacilityTypeDetails(parent, options?.token)
.then(facilityTypeDetails => {

console.log({ facilityTypeDetails })
const _options = facilityTypeDetails?.map(({ id: value, name: label }) => ({ label, value }))

const _options = facilityTypeDetails?.map(({ id: value, name: label }) => ({ label, value }))
setFacilityTypeDetailOptions(_options)
})
}
Expand Down
Loading

0 comments on commit 903ebf9

Please sign in to comment.