From 6e04c99f21c8f2088ff145eee970c6154b1ed45f Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 9 Mar 2024 16:42:25 +0300 Subject: [PATCH] Updated EditListWithCount.js and GeolocationForm.js --- components/Forms/BasicDetailsForm.js | 17 +++++--- components/Forms/GeolocationForm.js | 33 +++++++++------ .../Forms/formComponents/EditListWithCount.js | 41 +++++++++---------- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/components/Forms/BasicDetailsForm.js b/components/Forms/BasicDetailsForm.js index c32f9950..38960a4a 100644 --- a/components/Forms/BasicDetailsForm.js +++ b/components/Forms/BasicDetailsForm.js @@ -1581,15 +1581,22 @@ export function BasicDeatilsForm({ editMode }) { checklist file upload - - : + - + } + diff --git a/components/Forms/GeolocationForm.js b/components/Forms/GeolocationForm.js index 0edca90f..66a7f6d9 100644 --- a/components/Forms/GeolocationForm.js +++ b/components/Forms/GeolocationForm.js @@ -109,7 +109,7 @@ export function GeolocationForm({ editMode }) { if (payload) { - fetch(`${process.env.NEXT_PUBLIC_API_URL}/gis/facility_coordinates${options?.data?.lat_long ? '/' + options?.data?.coordinates + '/' : '/'}`, { + fetch(`${process.env.NEXT_PUBLIC_API_URL}/gis/facility_coordinates${options?.data?.lat_long ? `/options?.data?.coordinates/` : '/'}`, { headers: { 'Authorization': 'Bearer ' + options?.token, 'Accept': 'application/json, text/plain, */*', @@ -173,20 +173,34 @@ export function GeolocationForm({ editMode }) { const data = Object.fromEntries(formData) + setSubmitting(true) + const payload = { + coordinates: { + coordinates: [Number(data?.longitude), Number(data?.latitude)], + type: "point", + }, + + latitude: Number(data?.latitude), + longitude: Number(data?.longitude), + facility: facilityId + } + + console.log({payload}) - fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/${facilityId}/`, { - method: 'PATCH', + + fetch(`${process.env.NEXT_PUBLIC_API_URL}/gis/facility_coordinates/`, { + method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json;charset=UTF-8', 'Authorization': `Bearer ${options?.token}` }, - body: JSON.stringify(data) + body: JSON.stringify(payload) }) .then(res => { - if (res.status == 204 || res.status == 200) { + if (res.ok) { alert.success('Facility Geolocation Details have been saved successfully') setSubmitting(false) @@ -215,14 +229,7 @@ export function GeolocationForm({ editMode }) { if(navigated) setFormId(2) }) - // const url = new URL(`${window.location.origin}/facilities/add?formData=${base64EncParams}`) - - // url.searchParams.set('formId', '2') - - // url.searchParams.set('facilityId', facilityId) - - // window.location.href = url - + } else { setSubmitting(false) alert.error('Unable to save to Geolocation details') diff --git a/components/Forms/formComponents/EditListWithCount.js b/components/Forms/formComponents/EditListWithCount.js index cb9953ab..493dd9e7 100644 --- a/components/Forms/formComponents/EditListWithCount.js +++ b/components/Forms/formComponents/EditListWithCount.js @@ -445,9 +445,9 @@ function EditListWithCount( {formError && {formError}} -
-
-

Categories

+
+
+

Categories

onSearch(e, true, false)} className="col-span-12 border border-gray-600 p-2 placeholder-gray-500 focus:shadow-none focus:bg-white focus:border-black outline-none w-full" placeholder="Search" /> {!showItemCategory &&
{`Search for ${itemsCategoryName.includes('infrastructure') ? 'infrastructure' : 'a speciality' }`}
} @@ -455,8 +455,8 @@ function EditListWithCount( { showItemCategory &&
    - {categoryOptions.map(({ label, value, catcount }, i) => ( -
    ( +
  • { filterSpecialities(value) }} - >{label}
  • + key={value}>{label} ({catcount} selected)
    @@ -474,8 +474,8 @@ function EditListWithCount( }
    -
    -

    {itemsCategoryName.includes('human resource') ? 'Specialities' : itemsCategoryName.includes('infrastructure') ? 'Infrastructure' : null}

    +
    +

    {itemsCategoryName.includes('human resource') ? 'Specialities' : itemsCategoryName.includes('infrastructure') ? 'Infrastructure' : null}

    onSearch(e, false, true)} className="col-span-12 border border-gray-600 p-2 placeholder-gray-500 focus:shadow-none focus:bg-white focus:border-black outline-none w-full" placeholder="Search" />
    @@ -489,18 +489,18 @@ function EditListWithCount( {specialities.length === 0 && {`No ${itemsCategoryName.includes('infrastructure') ? 'infrastructure' : 'specialities'} found`}} - {specialities.map((row, i) => ( + {specialities.map((row) => ( - - + + - + item?.rowid?.includes(row?.id))} onChange={(e) => handleCheckboxChange( itemsCategoryName?.includes('human resource') ? row?.id : itemsCategoryName.includes('infrastructure') ? row?.id : "", @@ -510,10 +510,9 @@ function EditListWithCount( row?.count ? row?.count : 0, e.target.checked) } - /> - Yes + /> Yes - + {/* summary table */} -
    +
    @@ -549,9 +548,9 @@ function EditListWithCount( {selectedRows.length === 0 && } {/* {selectedRows.pop()} */} - {selectedRows.map((row, i) => { + {selectedRows.map((row) => { // if(row.name !== "Vaccine Carriers" || row.name !== "Public Health Technician"){ - return ( + return ( {row?.iscategoryvisible ? :null } @@ -592,8 +591,8 @@ function EditListWithCount(
    No specialities found
    {row?.sname}{row?.category_name}Yes