Skip to content

Commit

Permalink
Merge pull request #459 from ertush/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
ertush authored Aug 21, 2024
2 parents e5b782b + a7bff6b commit 983b273
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
89 changes: 78 additions & 11 deletions components/Forms/BasicDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function BasicDeatilsForm({ editMode }) {

const submitType = useRef(null)

const [facilityId, setFacilityId] = useMemo(() => {
const [__, setFacilityId] = useMemo(() => {

let id = ''

Expand All @@ -50,13 +50,12 @@ export function BasicDeatilsForm({ editMode }) {
setId(new URL(window.location.href).searchParams.get('facilityId') ?? '')
}

// console.log({id})

return [id, setId]
}, [])

const [submitting, setSubmitting] = useState(false);
const [touchedFields, setTouchedFields] = useState([]);
const [_, setTouchedFields] = useState([]);
const [formError, setFormError] = useState(null);


Expand All @@ -79,7 +78,7 @@ export function BasicDeatilsForm({ editMode }) {
const [constituencyOptions, setConstituencyOptions] = useState(options?.constituencies)
const [wardOptions, setWardOptions] = useState(options?.wards)

const facilityTypeValue = options?.facility_types?.find(({label}) => label.toLowerCase().trim() == options?.data?.facility_type_parent.toLowerCase().trim())?.value
const facilityTypeValue = options?.facility_types?.find(({label}) => label?.toLowerCase().trim() == options?.data?.facility_type_parent?.toLowerCase().trim())?.value

const operationStatusOptions = [
{
Expand Down Expand Up @@ -586,7 +585,7 @@ export function BasicDeatilsForm({ editMode }) {


// console.log({facility: options?.data})
async function updateFacilityTypeDetailOptions(e) {
async function updateFacilityTypeDetailOptions(e) {
try {
const facilityTypeDetails = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facility_types_details/?is_parent=false`, {
headers: {
Expand Down Expand Up @@ -617,7 +616,7 @@ export function BasicDeatilsForm({ editMode }) {
}
}

updateFacilityTypeDetailOptions()
updateFacilityTypeDetailOptions()

function getFacilityTypeDetailsParent(facilityTypeId, token) {

Expand All @@ -634,7 +633,7 @@ export function BasicDeatilsForm({ editMode }) {
}


function getFacilityTypeDetails(facilityTypeId, token) {
function getFacilityTypeDetails(facilityTypeId, token) {

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

}


// async function fetchDetailOptions() {
// if (facilityTypeValue) {
// try {
// const facilityTypeDetails = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facility_types_details/?is_parent=false&parent=${facilityTypeValue}`, {
// headers: {
// 'Accept': 'application/json',
// 'Authorization': `Bearer ${options?.token}`
// }
// })

// const filteredFacilityType = (await facilityTypeDetails.json())?.results



// const facilityType = Array.from(options?.facility_types, ({ id, name }) => {
// return {
// label: name,
// value: id
// }
// })


// setFacilityTypeDetailOptions(facilityType ?? options?.facility_type_details)

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

// if(options?.data?.owner_type){

// try {
// const owners = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/owners/?owner_type=${options?.data?.owner_type}`, {
// headers: {
// 'Accept': 'application/json',
// 'Authorization': `Bearer ${options?.token}`
// }
// })

// const filteredOwners = (await owners.json())?.results

// if (!filteredOwners) throw Error('Unable to Fetch Owner Type Details')


// const facilityOwnerOptions = Array.from(filteredOwners, ({ id, name }) => {
// return {
// label: name,
// value: id
// }
// })


// setOwnerTypeDetailsOptions(facilityOwnerOptions ?? options?.owner_types)

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


// }
// }


// fetchDetailOptions()
}


setIsClient(true)


}, [])


Expand Down Expand Up @@ -833,7 +900,7 @@ export function BasicDeatilsForm({ editMode }) {

<CustomSelect
options={options?.facility_types}
defaultValue={facilityTypeValue}
defaultValue={facilityTypeValue ?? ''}
placeholder="Select a facility type..."
required
name='facility_type_parent' // facility_type
Expand Down Expand Up @@ -862,7 +929,7 @@ export function BasicDeatilsForm({ editMode }) {
placeholder="Select facility type details..."
onChange={handleSelectChange}
onFocus={handleFocus}
defaultValue={options?.data?.facility_type/*options?.facility_type_details?.find(({ label }) => label == options?.data?.facility_type_name)?.value*/}
defaultValue={options?.data?.facility_type ?? '' /*options?.facility_type_details?.find(({ label }) => label == options?.data?.facility_type_name)?.value*/}
required
name='facility_type' // facility_type_details

Expand Down
23 changes: 11 additions & 12 deletions components/Forms/CommunityUnitsForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ function EditCommunityUnitsBasicDeatilsForm(props) {

setSubmitting(true)

console.log({submitting})



const payload = {}
const formData = new FormData(event.target)
Expand Down Expand Up @@ -170,6 +173,7 @@ function EditCommunityUnitsBasicDeatilsForm(props) {
}



try {

fetch(`${process.env.NEXT_PUBLIC_API_URL}/chul/units/${props?.id}/`, {
Expand Down Expand Up @@ -214,10 +218,7 @@ function EditCommunityUnitsBasicDeatilsForm(props) {
setSubmitting(true)
console.error('Error Occured: ' + e.message)
}
finally {
setSubmitting(false)

}




Expand All @@ -237,8 +238,6 @@ function EditCommunityUnitsBasicDeatilsForm(props) {
onSubmit={handleFormSubmit}
>



{formError && <Alert severity="error" sx={{ width: '100%', marginY: '15px' }}>{formError}</Alert>}

{/* CHU Name */}
Expand Down Expand Up @@ -775,17 +774,17 @@ function EditCommunityUnitsBasicDeatilsForm(props) {
<span className="text-medium font-semibold text-white">
{
submitting ?
<Spinner />
<div className='flex gap-2'>
<Spinner />
<span className='text-white'>Saving.. </span>
</div>

:
'Save and Finish'

}
</span>
{
submitting &&
<span className='text-white'>Saving.. </span>
}


</button>

</div>
Expand Down
2 changes: 1 addition & 1 deletion components/Forms/FacilityContactsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function FacilityContactsForm() {

const currentUrl = new URL(window.document.location.href)

if(options?.data?.facility_contacts.length > 0){
if(options?.data?.facility_contacts?.length > 0){
// const uid = uuid()
setFacilityContacts(
options?.data?.facility_contacts?.map((_, i) => (
Expand Down
2 changes: 1 addition & 1 deletion components/Forms/RegulationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function handleLicenseFileChange (e) {

const filteredRegOptions = regOptions.filter(({ label }) => label !== 'Other')

if (options?.data?.owner_type_name.toLowerCase().trim() == "ministry of health") {
if (options?.data?.owner_type_name?.toLowerCase().trim() == "ministry of health") {
return filteredRegOptions.filter(({ label }) => {
return label.toLowerCase().trim() == "ministry of health"

Expand Down

0 comments on commit 983b273

Please sign in to comment.