Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix dev #286

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 31 additions & 33 deletions components/Forms/CommunityUnitsForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,10 +974,9 @@ function EditCommunityUnitsServicesForm(props) {
})(options?.services ?? [])


function handleSubmit (token, selectedServices, chulId) {
function handleSubmit (selectedServices, chulId) {
// console.log({stateSetters, chulId})


const _payload = selectedServices.map(({value}) => ({ service: value }))

_payload.forEach(obj => obj['health_unit'] = chulId)
Expand All @@ -996,38 +995,39 @@ function EditCommunityUnitsServicesForm(props) {
body: JSON.stringify({services: _payload})
})

// .then(async resp => {
// if (resp.status == 200 || resp.status == 204) {

// setSubmitting(false)

// alert.success(`${props?.name} services have been updated successfully`, {
// containerStyle: {
// backgroundColor: "green",
// color: "#fff"
// },
// timeout: 10000
// })

// } else {
// // const detail = await resp.json()

// setSubmitting(false)
// // setFormError(Array.isArray(Object.values(detail)) && Object.values(detail).length == 1 && typeof Object.values(detail)[0] == 'string' && detail[0][0])
// alert.error(`Unable to update ${props?.name} services`, {
// timeout: 10000
// })
// }
// })




}
catch (e) {
console.error(e.message)
}
}

};
};


function handleCHUServiceUpdate (selectedServices, chulId) {

const _payload = selectedServices.map(({value}) => ({ service: value }))

_payload.forEach(obj => obj['health_unit'] = chulId)

try {
return fetch(`${process.env.NEXT_PUBLIC_API_URL}/chul/units/${chulId}/`, {
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=utf-8',
'Authorization': `Bearer ${props?.token}`
},
method: 'PATCH',
body: JSON.stringify({services: _payload})
})

}
catch (e) {
console.error(e.message)
}
}



Expand All @@ -1053,14 +1053,12 @@ function EditCommunityUnitsServicesForm(props) {


<EditListItem
initialSelectedItems={currentServices}
itemData={currentServices}
categoryItems={serviceOptions[0]?.options} //serviceOptions
itemId={props?.id} //chulId
item={null}
token={props?.token}
token={props?.token}
handleItemsSubmit={handleSubmit} //handleCHUServiceSubmit
handleItemsUpdate={() => null} //handleServiceUpdates
setNextItemCategory={null}
handleItemsUpdate={handleCHUServiceUpdate} //handleServiceUpdates
setSubmitting={setSubmitting}
submitting={submitting}
options={serviceOptions[0]?.options}
Expand Down
7 changes: 0 additions & 7 deletions components/Forms/InfrastructureForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,19 @@ export function InfrastructureForm() {

{/* Edit List With Count*/}
<EditListWithCount
initialSelectedItems={options?.data? options?.data.facility_infrastructure:[]}
otherItemsCategory={null}
itemsCategoryName={'infrastructure'}
categoryItems={infrastructureOption.categories}
options={options.infrastructure}
token={options.token}
itemId={facilityId ?? options?.data?.id}
item={options?.data ?? null}
handleItemsSubmit={handleInfrastructureSubmit}
handleItemsUpdate={handleInfrastructureUpdates}
setSubmitting={setSubmitting}
submitting={submitting}
removeItemHandler={() => null}
handleItemPrevious={handleInfrastructurePrevious}
setNextItemCategory={setFormId}
setItemsUpdateData={updateFacilityUpdateData}
nextItemCategoryId={formId}
nextItemCategory={'human resource'}
previousItemCategory={'services'}
setIsSaveAndFinish={updatedSavedChanges}
itemData={options?.data ? options?.data?.facility_infrastructure : null}
title={tableheaders}

Expand Down
13 changes: 3 additions & 10 deletions components/Forms/ServicesForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,19 @@ export function ServicesForm() {
<div className='flex items-center w-full h-auto min-h-[300px]'>

<EditListItem
initialSelectedItems={options?.data ? options?.data.facility_services:[]}
itemData={options?.data ? options?.data.facility_services : null}
categoryItems={serviceOptions.categories}
itemsCategoryName={'Services'}
itemId={facilityId ?? options?.data?.id}
setItems={setServices}
item={options?.data ?? null}
options={options?.services}
token={options?.token}
itemName={'facility_services'}
removeItemHandler={handleServiceDelete}
handleItemsSubmit={handleServiceSubmit}
handleItemsUpdate={handleServiceUpdates}
setSubmitting={setSubmitting}
submitting={submitting}
setItemsUpdateData={updateFacilityUpdateData}
handleItemPrevious={handleServicePrevious}
setIsSaveAndFinish={updatedSavedChanges}
servicesData={options?.data ? options?.data?.facility_services: null}

/>

/>

</div>
</div>
Expand Down
Loading
Loading