Skip to content

Commit

Permalink
Sub county and constitutency filters added
Browse files Browse the repository at this point in the history
  • Loading branch information
ertush committed Dec 6, 2023
1 parent 6497261 commit 802e431
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions components/Forms/BasicDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,35 +215,37 @@ export function BasicDeatilsForm() {

if (e.target?.value) {

try{
const _wards = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/common/wards/?sub_county=${e.target.value}`, {
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${options?.token}`
}
})

console.log({name: e.target.name, value: e.target.value})
// try{
// const _wards = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/common/wards/?sub_county=${e.target.value}`, {
// headers: {
// 'Accept': 'application/json',
// 'Authorization': `Bearer ${options?.token}`
// }
// })

const wards = (await _wards.json())?.results
// const wards = (await _wards.json())?.results

if(!_wards) throw Error('Unable to Fetch sub counties')
// if(!_wards) throw Error('Unable to Fetch sub counties')



const filteredWards = Array.from(wards, ({id, name}) => {
return {
label: name,
value: id
}
})

console.log({filteredWards, wards})
// const filteredWards = Array.from(wards, ({id, name}) => {
// return {
// label: name,
// value: id
// }
// })

// console.log({filteredWards, wards})

setWardOptions(filteredWards ?? options?.sub_counties)
// setWardOptions(filteredWards ?? options?.sub_counties)

}
catch (e) {
console.error(e.message)
}
// }
// catch (e) {
// console.error(e.message)
// }
}
}
}
Expand Down Expand Up @@ -1013,7 +1015,6 @@ if(isClient){
required
placeholder="Select Sub County..."
onChange={handleSelectChange}

defaultValue={options?.data?.sub_county_id ?? ''}
name='sub_county_id'

Expand Down

0 comments on commit 802e431

Please sign in to comment.