From ecfbfb7cfbf4a3a8a08fa5e35fca939861780714 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 18 Jan 2024 17:42:31 +0300 Subject: [PATCH] Fixed Public Facilities Filters --- components/Forms/BasicDetailsForm.js | 2 +- components/Forms/FacilityContactsForm.js | 2 +- components/Forms/GeolocationForm.js | 4 +- components/HeaderLayout.js | 6 +- pages/facilities/approve_reject/[id].js | 2 +- pages/public/chu/index.js | 9 +- pages/public/facilities/index.js | 1002 +++++++++++++--------- 7 files changed, 599 insertions(+), 428 deletions(-) diff --git a/components/Forms/BasicDetailsForm.js b/components/Forms/BasicDetailsForm.js index 49a3d3b6..c33fd675 100644 --- a/components/Forms/BasicDetailsForm.js +++ b/components/Forms/BasicDetailsForm.js @@ -618,7 +618,7 @@ export function BasicDeatilsForm({ editMode }) { className='flex flex-col w-full mt-4 items-start bg-blue-50 p-3 justify-start gap-3'> { - formError && {formError} + formError && {formError} } {/* Facility Official Name */} diff --git a/components/Forms/FacilityContactsForm.js b/components/Forms/FacilityContactsForm.js index 98479fa0..da6f85f9 100644 --- a/components/Forms/FacilityContactsForm.js +++ b/components/Forms/FacilityContactsForm.js @@ -391,7 +391,7 @@ export function FacilityContactsForm() { > { - formError && {formError} + formError && {formError} } {/* Contacts */} diff --git a/components/Forms/GeolocationForm.js b/components/Forms/GeolocationForm.js index bd894ca9..bc440343 100644 --- a/components/Forms/GeolocationForm.js +++ b/components/Forms/GeolocationForm.js @@ -340,7 +340,7 @@ export function GeolocationForm({ editMode }) { > { - formError && {formError} + formError && {formError} } {/* Collection Date */} @@ -431,7 +431,7 @@ export function GeolocationForm({ editMode }) { : - Geolocation Data is Missing For this facility + Geolocation Data is Missing For this facility } diff --git a/components/HeaderLayout.js b/components/HeaderLayout.js index 63e8ae49..fdc377a0 100644 --- a/components/HeaderLayout.js +++ b/components/HeaderLayout.js @@ -323,7 +323,7 @@ export default function HeaderLayout({ hidden sm:inline cursor-pointer - ${(currentPath == "/public/facility/facilities" || currentPath == "/public/chu/community_units" + ${(currentPath == "/public/facilities" || currentPath == "/public/chu/community_units" ? activeClasses : inactiveClasses) }`}> @@ -429,13 +429,13 @@ export default function HeaderLayout({ className="inline-flex flex-row justify-start flex-grow mt-2 lg:py-0" action= {(()=>{ if(searchOption == "Facilities"){ - return "/public/facility/facilities" + return "/public/facilities" }else if(searchOption == "Community Health Unit"){ return "/public/chu/community_units" }else if(searchOption == "Services"){ return "/public/services" }else{ - return router.asPath.includes('searchTerm')? router.route : "/public/facility/facilities" + return router.asPath.includes('searchTerm')? router.route : "/public/facilities" } })()} > diff --git a/pages/facilities/approve_reject/[id].js b/pages/facilities/approve_reject/[id].js index bf006391..1a427923 100644 --- a/pages/facilities/approve_reject/[id].js +++ b/pages/facilities/approve_reject/[id].js @@ -317,7 +317,7 @@ function ApproveReject(props) { > {/* Alert Section */} - {formError && {formError}} + {formError && {formError}} { diff --git a/pages/public/chu/index.js b/pages/public/chu/index.js index 5ad1685c..87f8000e 100644 --- a/pages/public/chu/index.js +++ b/pages/public/chu/index.js @@ -9,8 +9,7 @@ import {SearchIcon } from "@heroicons/react/solid"; import Select from 'react-select' - -const Home = (props) => { +function Home(props) { const router = useRouter(); // const cus = props?.data?.results; const [cus, setcus] = useState([]) @@ -180,11 +179,11 @@ const Home = (props) => { {/* Filter section */} -
filterCHUs(e)}> + filterCHUs(e)}> {/*
*/}
- {/* */} +

Search for a Community Health Unit

{/*   */} {

Administrative Units

 
- {administrative_units.map(ct=>( + {administrative_units?.map(ct=>( <> {/* */} - - -
-   -
-

Facility Info

-   - - - - - -
-   -
-

Administrative Unit

  -
- {administrative_units.map(ct=>( - <> - - + + +
+ +
+

Facility Info

+ + + + + +
+ +
+

Administrative Unit

+
+ {administrative_units?.map((ct, i) => ( + <> + + { - let opts = [...Array.from(ct.array || [], - fltopt => { - if (fltopt.id != null && fltopt.id.length > 0) { - return { - value: fltopt.id, label: fltopt.name - } - } - })] - return opts - })() - } - placeholder={`Select ${ct.label}`} - onChange={sl => { - let nf = {} - if (sl && sl !== null && typeof sl === 'object' && !Array.isArray(sl)) { - nf[ct.label] = sl.value - } else { - delete nf[ct.label] - } - ct.label == 'county' && sl?.value !== undefined && getUnits('sub_counties', sl?.value) - ct.label == 'subcounty' && sl?.value !== undefined && getUnits('wards', sl?.value) - }} - /> - - ))} -
- +
+ + +
+

Services

+
+ {service_units.map((ct, i) => ( + <> + + { - let opts = [...Array.from(ct.array || [], - fltopt => { - if (fltopt.id != null && fltopt.id.length > 0) { - return { - value: fltopt.id, label: fltopt.name - } - } - })] - return opts - })() - } - placeholder={`Select ${ct.label}`} - onChange={sl => { - let nf = {} - if (sl && sl !== null && typeof sl === 'object' && !Array.isArray(sl)) { - nf[ct.label] = sl.value - } else { - delete nf[ct.label] - } - ct.label == 'county' && sl?.value !== undefined && getUnits('sub_counties', sl?.value) - ct.label == 'subcounty' && sl?.value !== undefined && getUnits('wards', sl?.value) - }} - /> - - ))} -
-
+
+ + +
+

Facility Details

+
+ {facility_details.map((ct, i) => ( + <> + + - - -
-
+ + type="checkbox" + name='number_of_beds' + id='number_of_beds' + /> + + + + + +
+
- - -
+ + type="checkbox" + name='number_of_cots' + id='number_of_cots' + /> + + + +
-
-   -
-

Availability

  -
-
+
+ + +
+

Availability

+
+
- - -
-
+ + type="checkbox" + name='available_holiday' + id='available_holiday' + /> + + + + +
+
- - -
-
+ + type="checkbox" + name='available_weekends' + id='available_weekends' + /> + + + +
+
- - -
+ + type="checkbox" + name='available_24hrs' + id='available_24hrs' + /> + + +
- +
-   -
- - -
- -
- - {/* Main body */} +
+ + + + + + {/*
+						{JSON.stringify(facilities, null, 2)}
+					
*/} + + + {/* Main body */} {/*
*/} -
{/* CHANGED colspan */} - {/*
- - {viewAll &&
- {facilities.count && facilities?.count > 0 && {facilities?.start_index || 0} - {facilities?.end_index || 0} of {facilities?.count || 0} } -
} -
*/} +
{/* CHANGED colspan */} + + { + formError && {formError} + } + + + { + submitting && Loading... + } + +
{/*
{JSON.stringify(facilities[0], null, 2)}
*/} {viewAll && facilities?.results && facilities?.results.length > 0 ? ( facilities?.results.map((hf, index) => (
+ key={index} + className='px-1 md:px-3 grid grid-cols-8 gap-4 border-b border-blue-600 py-4 hover:bg-gray-50 w-full'>

{

- {(hf?.facility_type_category) ? {hf?.facility_type_category} : ""} + {(hf?.facility_type_category) ? {hf?.facility_type_category} : ""}

- {(hf?.facility_type_name) ? {hf?.facility_type_name} : ""} + {(hf?.facility_type_name) ? {hf?.facility_type_name} : ""}

-
+
- + + {hf.facility_county || hf.county_name || @@ -554,9 +732,8 @@ const Home = (props) => {
- + + {hf.facility_subcounty || hf.sub_county_name || @@ -564,13 +741,12 @@ const Home = (props) => {
- + {hf.ward_name || 'N/A'}
- + + {hf.constituency_name || hf.constituency_name || @@ -579,62 +755,58 @@ const Home = (props) => {
-
- {(hf?.operational || hf?.operation_status_name) ? Operational : ""} +
+ {(hf?.operational || hf?.operation_status_name) ? Operational : ""}
)) ) : ( -
- - No facilities found - -
+ <>{!formError && !submitting && Could not find facility} )} {viewAll && facilities?.results && facilities?.results.length >= 30 && (
)}

- +
@@ -683,7 +855,7 @@ Home.getInitialProps = async (ctx) => { }; const fetchData = async (token) => { - let url = API_URL +`/facilities/material/?fields=id,code,name,regulatory_status_name,facility_type_name,owner_name,county,constituency,ward_name,keph_level,operation_status_name` + let url = API_URL + `/facilities/material/?fields=id,code,name,regulatory_status_name,facility_type_name,owner_name,county,constituency,ward_name,keph_level,operation_status_name` let query = { searchTerm: '' }; if (ctx?.query?.q) { query.searchTerm = ctx.query.q;