Skip to content

Commit

Permalink
Merge pull request #463 from ertush/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
ertush authored Aug 28, 2024
2 parents 5cdf15f + 4f5e4cc commit b8551ee
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 61 deletions.
8 changes: 5 additions & 3 deletions pages/facilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,9 @@ export async function getServerSideProps(ctx) {

// const previousURL = ctx?.query?.previous

const defaultURL = `${`${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/` + `${page ? '?page=' + page + '&': '?' }` + 'page_size=10'}`
console.log({query: ctx?.query})

const defaultURL = ctx?.query?.q ? `${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/` : `${`${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/` + `${page ? '?page=' + page + '&': '?' }` + 'page_size=10'}`

let url = nextURL ?? previousURL ?? defaultURL

Expand All @@ -897,7 +899,7 @@ export async function getServerSideProps(ctx) {

if (ctx?.query?.q) {
query.searchTerm = ctx.query.q
url += `&search={"query":{"query_string":{"default_field":"name","query":"${query.searchTerm}"}}}`
url += `?search={"query":{"query_string":{"default_field":"name","query":"${query.searchTerm}"}}}`
}

const other_posssible_filters = [
Expand Down Expand Up @@ -953,7 +955,7 @@ export async function getServerSideProps(ctx) {
}



console.log({url})
try {
facilities = (await (await fetch(url, {
headers: {
Expand Down
116 changes: 58 additions & 58 deletions pages/public/chu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import { useRouter } from 'next/router';
// import { SearchIcon } from "@heroicons/react/solid";
import Select from 'react-select'
import Alert from '@mui/material/Alert'
import {v4 as uuid} from 'uuid';
import {uuid as uid} from 'react-use-uuid'


function Home(props) {


const router = useRouter();

const [cus, setcus] = useState(props?.data)
Expand All @@ -29,11 +33,9 @@ function Home(props) {
const ward = useRef(null)
const constituency = useRef(null)
const [isClient, setIsClient] = useState(false)

const status_options = props.filters?.chu_status || props.filters?.status || [];
const counties = props?.filters?.county || [];
const [units, setUnits] = useState([])
const status = useRef(null)



useEffect(() => {
Expand All @@ -55,19 +57,19 @@ function Home(props) {
useEffect(() => {
setIsClient(true)

console.log({props})
// console.log({props})

if (!(props?.current_url.includes('q') || router.asPath.includes('q'))) {
setViewAll(true)
// handleSubmit()
}
}, [])

const administrative_units = [
{ label: 'county', ref: county, array: counties },
{ label: 'subcounty', ref: subcounty, array: units['sub_counties'] },
{ label: 'constituency', ref: constituency, array: units['sub_counties'] },
{ label: 'wards', ref: ward, array: units['wards'] }
const administrativeUnits = [
{ label: 'county', ref: county, array: props?.filters?.counties },
{ label: 'subcounty', ref: subcounty, array: units['sub_county'] ?? props?.filters?.subCounties },
{ label: 'constituency', ref: constituency, array: units['constituency'] ?? props?.filters?.constituencies },
{ label: 'wards', ref: ward, array: units['ward'] ?? props?.filters?.wards }
]


Expand Down Expand Up @@ -114,11 +116,11 @@ function Home(props) {

if (node.type == "text") {

status.current.select.clearValue();
county.current.select.clearValue();
subcounty.current.select.clearValue();
ward.current.select.clearValue();
constituency.current.select.clearValue();
status.current?.select?.clearValue();
county.current?.select?.clearValue();
subcounty.current?.select?.clearValue();
ward.current.select?.clearValue();
constituency.current?.select?.clearValue();

}

Expand Down Expand Up @@ -238,20 +240,11 @@ function Home(props) {
</button>

<button
type="button"
type="submit"
className="bg-gray-50 rounded border-1 border-black text-black flex items-center justify-center px-4 py-1 "
onClick={() => {

setReset(true)
// setDrillDown({})
// name.current.value = '';
// code.current.value = '';
// status.current.select.clearValue();
// allchus.current.value = '';
// county.current.select.clearValue();
// subcounty.current.select.clearValue();
// ward.current.select.clearValue();
// constituency.current.select.clearValue();
}}
>
Reset
Expand All @@ -264,12 +257,13 @@ function Home(props) {
{/* &nbsp; */}
<input
name="allchus"
id="search-input"
id="search-name"
className="flex-none bg-gray-50 rounded p-2 flex-grow shadow-sm mt-2 border placeholder-gray-500 w-full border-gray-400 focus:shadow-none focus:bg-white focus:border-black outline-none"
type="search"
placeholder="Search all CHUs"
/>
</div>


<div className="card col-span-6 rounded md:col-span-2 flex flex-col gap-3 items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '50px' }}>
<h2>Community Health Info</h2>
Expand All @@ -286,13 +280,19 @@ function Home(props) {
{/* <label className=" text-gray-600">CHU Code</label> */}
<input
name="code"
id="search-input"
id="search-code"
className="flex-none bg-gray-50 rounded p-2 flex-grow shadow-sm border placeholder-gray-500 w-full border-gray-400 focus:shadow-none focus:bg-white focus:border-black outline-none"
type="search"
placeholder="CHU Code"
/>

{/* <label className=" text-gray-600">Status</label> */}
{/* <pre>
{
JSON.stringify(props?.filters?.statuses, null, 2)
}
</pre> */}

<Select name="status" ref={status} className="w-full md:max-w-xs rounded border border-gray-400"
styles={{
control: (baseStyles) => ({
Expand All @@ -309,28 +309,19 @@ function Home(props) {

}}
options={
(() => {
let opts = [...Array.from(status_options || [],
fltopt => {
if (fltopt.id != null && fltopt.id.length > 0) {
return {
value: fltopt.id, label: fltopt.name
}
}
})]
return opts
})()
props?.filters?.statuses
}
placeholder={'Select status'}
/>
</div>


<div className="card col-span-6 rounded md:col-span-2 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '50px' }}>
<h2>Administrative Units</h2> &nbsp;
<div className="w-full md:max-w-xs flex flex-col gap-3 items-start justify-start mb-3" id='first'>
{
administrative_units?.map((ct, i) => (
<Select key={i} name={ct.label} ref={ct.ref} defaultValue={drillDown[ct.label] || "national"} id={ct.label} className="w-full md:max-w-xs rounded border border-gray-400"
administrativeUnits?.map((ct, i) => (
<Select key={uuid()} name={ct.label} ref={ct.ref} defaultValue={drillDown[ct.label] || "national"} id={ct.label} className="w-full md:max-w-xs rounded border border-gray-400"
styles={{
control: (baseStyles) => ({
...baseStyles,
Expand All @@ -347,17 +338,20 @@ function Home(props) {
}}

options={
(() => {
let opts = [...Array.from(ct.array || [],
fltopt => {
if (fltopt.id != null && fltopt.id.length > 0) {
return {
value: fltopt.id, label: fltopt.name
}
}
})]
return opts
})()
Array.from(ct.array, obj => ({value: obj?.id, label: obj?.name}))
// (() => {
// let opts = [...Array.from(ct.array || [],

// fltopt => {
// console.log(fltopt)
// if (fltopt.id != null && fltopt.id.length > 0) {
// return {
// value: fltopt.id, label: fltopt.name
// }
// }
// })]
// return opts
// })()
}
placeholder={`Select ${ct.label}`}
onChange={sl => {
Expand All @@ -382,15 +376,14 @@ function Home(props) {

</form>


{/* Main body */}
<div className="col-span-1 rounded md:col-span-4 px-4 md:px-0 flex max-h-min md:h-[752px] overflow-y-scroll bg-gray-50 shadow-md flex-col gap-4 order-last md:order-none"> {/* CHANGED colspan */}
<div className="w-full flex justify-end pt-2 px-4 border-b border-gray-300">
<p className='text-end text-gray-500 font-semibold'>{props?.chuCount > 0 ? '30': '0'} of {props?.chuCount}</p>
</div>

<div className='flex flex-col justify-center items-center overflow-scroll-y w-full '>
{/* <pre>{JSON.stringify(cus[0], null, 2)}</pre> */}

{cus?.results?.length > 0 ? (
cus?.results?.map((comm_unit, index) => (
Expand Down Expand Up @@ -573,9 +566,9 @@ Home.getInitialProps = async (ctx) => {

const fetchFilters = async (token) => {

let filters_url = `${API_URL}/common/filtering_summaries/?fields=county,chu_status`;
let filters_url = `${API_URL}/common/filtering_summaries/?fields=county,chu_status,sub_county,constituency,ward`;

fetch(filters_url, {
return fetch(filters_url, {
headers: {
Authorization: 'Bearer ' + token,
Accept: 'application/json',
Expand All @@ -597,8 +590,8 @@ Home.getInitialProps = async (ctx) => {
};

const fetchData = async (token) => {
let filterQuery = JSON.parse(JSON.stringify(ctx.query));
let qry = ''
// let filterQuery = JSON.parse(JSON.stringify(ctx.query));
// let qry = ''
let url = API_URL + `/chul/units/?fields=id,code,name,status_name,date_established,facility,facility_name,facility_county,facility_subcounty,facility_ward,facility_constituency`;
let query = { searchTerm: '' };
if (ctx?.query?.q) {
Expand Down Expand Up @@ -632,13 +625,20 @@ Home.getInitialProps = async (ctx) => {
},
});
const json = await r.json();
const ft = await fetchFilters(token);
const filters = await fetchFilters(token)
const counties = filters?.county?.map(({id, name}) => ({id, name}))
const subCounties = filters?.sub_county?.map(({id, name}) => ({id, name}))
const constituencies = filters?.constituency?.map(({id, name}) => ({id, name}))
const wards = filters?.ward?.map(({id, name}) => ({id, name}))
const statuses = filters?.chu_status?.map(({id, name}) => ({value:id, label:name}))


return {
data: json,
chuCount: json?.count,
query,
token,
filters: { ...ft },
filters: { counties, statuses, subCounties, constituencies, wards },
path: ctx.asPath || '/chu/community_units',
current_url: current_url,
};
Expand Down
1 change: 1 addition & 0 deletions pages/public/facilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Select from 'react-select'
import { Alert } from '@mui/lab'
import Spinner from '../../../components/Spinner'


function Home(props) {
// console.log(props)
const router = useRouter();
Expand Down

0 comments on commit b8551ee

Please sign in to comment.