diff --git a/components/Forms/CommunityUnitsForms.js b/components/Forms/CommunityUnitsForms.js index 31025b73..d452aced 100644 --- a/components/Forms/CommunityUnitsForms.js +++ b/components/Forms/CommunityUnitsForms.js @@ -736,7 +736,7 @@ function EditCommunityUnitsCHEWSForm(props) { const [healthUnitWorkers, setHealthUnitWorkers] = useState(props?.health_unit_workers) const alert = useAlert() - const [deleteButton, setDeleteButton] = useState(props?.health_unit_workers.map((_, i) => ({[i]: false}))) + const [deleteButton, setDeleteButton] = useState(props?.health_unit_workers?.map((_, i) => ({[i]: false}))) console.log({deleteButton}) diff --git a/components/Forms/formComponents/EditListItem.js b/components/Forms/formComponents/EditListItem.js index 1a75ff04..fc3ad2fb 100644 --- a/components/Forms/formComponents/EditListItem.js +++ b/components/Forms/formComponents/EditListItem.js @@ -189,13 +189,14 @@ function EditListItem({ if( itemName == 'chul_services' && editMode && itemData && itemData?.partners !== null && - itemData?.partners.length > 0){ + itemData?.partners?.length > 0){ setPartners(itemData?.partners) } if (Array.isArray(itemData?.currentServices)) { + const result = [] setSelectedItems(() => { diff --git a/pages/community-units/edit/[id].js b/pages/community-units/edit/[id].js index 04a40df2..f87278f4 100644 --- a/pages/community-units/edit/[id].js +++ b/pages/community-units/edit/[id].js @@ -1,6 +1,7 @@ import { CommunityUnitEditForm } from '../../../components/Forms/CommunityUnitsForms' import { useState, useEffect, createContext } from 'react' import { checkToken } from '../../../controllers/auth/auth' +import {z} from 'zod' // import Alert from '@mui/material/Alert' @@ -50,8 +51,13 @@ export async function getServerSideProps(ctx) { "services" ] + const zSchema = z.object({ + id: z.string().uuid('Should be a uuid string'), + }) + const queryId = zSchema.parse(ctx.query).id + function fetchFacilities(url) { @@ -93,7 +99,7 @@ export async function getServerSideProps(ctx) { switch (option) { case "cu": - const cu = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chul/units/${ctx?.query.id}/`, { + const cu = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chul/units/${queryId}/`, { headers: { 'Authorization': 'Bearer ' + token, 'Accept': 'application/json' @@ -119,7 +125,7 @@ export async function getServerSideProps(ctx) { case "facilities": - const url = `${process.env.NEXT_PUBLIC_API_URL}/common/sub_counties/?name=${response?.cu?.facility_subcounty.split(' ').join('+')}` + const url = `${process.env.NEXT_PUBLIC_API_URL}/common/sub_counties/?name=${response?.cu?.facility_subcounty.split(' ').join('+')}` response['facilities'] = await fetchFacilities(url)