Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problem in public site naviagtion of facilities #491

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions components/FacilityDetailsTabsPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import Link from 'next/link'

function FacilityDetailsTabsPulic({ facility }) {

const [user, setUser] = useState(null);
// const [user, setUser] = useState(null);

//rating
const [rating, setRating] = useState(0);
const [comment, setComment] = useState("");

const userCtx = useContext(UserContext);
// const userCtx = useContext(UserContext);

//alert
const alert = useAlert();
Expand All @@ -23,14 +23,14 @@ function FacilityDetailsTabsPulic({ facility }) {
// const [isFormVisible, setIsFormVisible] = useState(false);
const [formVisibility, setFormVisibility] = useState(Array(facility?.facility_services?.length).fill(false) ?? []);

useEffect(() => {
// let user_id
if (userCtx) {
let s_r = userCtx
user_id = s_r.id
setUser(s_r)
}
}, [userCtx])
// useEffect(() => {
// // let user_id
// if (userCtx) {
// let s_r = userCtx
// user_id = s_r.id
// setUser(s_r)
// }
// }, [userCtx])


const handleServiceRating = async (event, serviceId) => {
Expand Down
6 changes: 3 additions & 3 deletions pages/community-units/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ function CommunityUnit(props) {
(active ? 'bg-gray-200' : '')
}
onClick={() => {
window.location.href = `${process.env.NEXT_PUBLIC_API_URL}/chul/units/?format=csv&access_token=${props.token}&page_size=${orgUnitFilter !== "" ? props?.count : 30}&page=1${orgUnitFilter}`;
window.location.href = `${process.env.NEXT_PUBLIC_API_URL}/chul/units/?format=csv&access_token=${props.token}&page_size=${props?.count}&page=1${orgUnitFilter}&fields=name,facility_name,code,facility_ward,facility_subcounty,facility_county,status_name,lat_long,chps_present,chps_trained,chas_present,chas_trained,chcs_present,chcs_trained,households_monitored`;
}}>
<DownloadIcon className='w-4 h-4 mr-1' />
<span>CSV</span>
</button>
)}
</Menu.Item>
<Menu.Item
{/* <Menu.Item
as='li'
className='p-0 flex items-center w-full text-center hover:bg-gray-200 focus:bg-gray-200 active:bg-gray-200'>
{({ active }) => (
Expand All @@ -169,7 +169,7 @@ function CommunityUnit(props) {
<span>Excel</span>
</button>
)}
</Menu.Item>
</Menu.Item> */}
</Menu.Items>
</Menu>
)}
Expand Down
9 changes: 4 additions & 5 deletions pages/public/facilities/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ function FacilityDetails(props) {
const wardName = props?.data?.ward_name;
const center = props?.geo_details?.geoLocation.center;

// const [isViewChangeLog, setIsViewChangeLog] = useState(false)

const router = useRouter()

const handlePrint = (accessToken, id) => {
const url = `${process.env.NEXT_PUBLIC_API_URL}/facilities/facility_detail_report/${id}/?format=pdf&access_token=${accessToken}`;
router.push(url);
};
// const handlePrint = (accessToken, id) => {
// const url = `${process.env.NEXT_PUBLIC_API_URL}/facilities/facility_detail_report/${id}/?format=pdf&access_token=${accessToken}`;
// router.push(url);
// };

return (
<>
Expand Down
121 changes: 113 additions & 8 deletions pages/public/facilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,86 @@ function Home(props) {

{/* Main body */}
{/* <div className='col-span-5 md:col-span-4 flex flex-col items-center gap-4 mt-2 order-last md:order-none'> */}
<div className={`${(Array.isArray(facilities) && facilities?.length == 0) || (!formError || !submitting) && 'p-4'} col-span-1 rounded bg-gray-50 md:h-[1670px] md:px-0 overflow-y-scroll p-4 shadow-md md:col-span-4 flex flex-col items-center justify-start md:gap-4 order-last md:order-none`}> {/* CHANGED colspan */}
<div className={`${(Array.isArray(facilities) && facilities?.length == 0) || (!formError || !submitting) && 'p-4'} col-span-1 rounded bg-gray-50 md:h-[1670px] md:px-0 p-4 shadow-md md:col-span-4 flex flex-col items-center justify-start md:gap-4 order-last md:order-none`}> {/* CHANGED colspan */}
<div className='w-full flex justify-end'>
{viewAll && facilities?.results && facilities?.results.length >= 30 && (
<ul className='list-none flex p-2 flex-row w-max justify-self-end gap-2 items-center'>
{
facilities?.current_page >= 6 &&
<>
<li className='text-base text-gray-600'>
<a href="/public/facilities?page=1" className='text-gray-800 p-2 hover:underline active:underline focus:underline'>
1
</a>
</li>
<li className='text-base text-gray-600'>
<a href="/public/facilities?page=2" className='text-gray-800 p-2 hover:underline active:underline focus:underline'>
2
</a>
</li>
<li className='text-sm text-gray-400 flex'>
<DotsHorizontalIcon className='h-3' />
</li>
</>
}
<li className='text-base text-gray-600'>

<a
href={
(() =>
props.path.includes('?page') ?
props.path.replace(/\?page=\d+/, `?page=${facilities?.current_page}`)
:
props.path.includes('?q') && props.path.includes('&page') ?
props.path.replace(/&page=\d+/, `&page=${facilities?.current_page}`)
:
props.path.includes('?q') ?
`${props.path}&page=${facilities?.current_page}`
:
`${props.path}?page=${facilities?.current_page}`
)()
}
className='text-gray-400 border border-gray-400 rounded font-semibold p-2 hover:underline active:underline focus:underline'>
{facilities?.current_page}
</a>
</li>
{facilities?.near_pages &&
facilities?.near_pages.map((page, i) => (
<li key={i} className='text-base text-gray-600'>

<a
href={
`
/public
${
(() =>
props.path.includes('?page') ?
props.path.replace(/\?page=\d+/, `?page=${page}`)
:
props.path.includes('?q') && props.path.includes('&page') ?
props.path.replace(/&page=\d+/, `&page=${page}`)
:
props.path.includes('?q') ?
`${props.path}&page=${page}`
:
`${props.path}?page=${page}`

)()
}
`
}
className='text-gray-800 p-2 hover:underline active:underline focus:underline'>
{page}
</a>
</li>
))}
{/* <li className='text-sm text-gray-400 flex'>
<DotsHorizontalIcon className='h-3' />
</li> */}

</ul>
)}
</div>
{
formError && <Alert severity='error' className='w-full border-2 border-red-500 rounded-none'>{formError}</Alert>
}
Expand All @@ -606,7 +684,7 @@ function Home(props) {



<div className='flex flex-col justify-center items-center md:col-span-4 w-full '>
<div className='flex flex-col overflow-y-scroll my-4 justify-center items-center md:col-span-4 w-full '>

<div className="w-full flex justify-end pt-2 px-1 border-b border-gray-500">
<p className='text-end text-gray-500 font-semibold'>{props?.facilityCount > 0 ? '30': '0'} of {props?.facilityCount}</p>
Expand Down Expand Up @@ -714,8 +792,29 @@ function Home(props) {
) : (
<div className='w-full px-4 my-6'>{!formError && !submitting && <Alert severity='warning' className='border-2 border-yellow-500 rounded-none'>No facility found </Alert>}</div>
)}
{viewAll && facilities?.results && facilities?.results.length >= 30 && (
<ul className='list-none flex p-2 flex-row gap-2 w-full items-center my-2'>

</div>
<div className='w-full flex justify-end'>
{viewAll && facilities?.results && facilities?.results.length >= 30 && (
<ul className='list-none flex p-2 flex-row w-max justify-self-end gap-2 items-center'>
{
facilities?.current_page >= 6 &&
<>
<li className='text-base text-gray-600'>
<a href="/public/facilities?page=1" className='text-gray-800 p-2 hover:underline active:underline focus:underline'>
1
</a>
</li>
<li className='text-base text-gray-600'>
<a href="/public/facilities?page=2" className='text-gray-800 p-2 hover:underline active:underline focus:underline'>
2
</a>
</li>
<li className='text-sm text-gray-400 flex'>
<DotsHorizontalIcon className='h-3' />
</li>
</>
}
<li className='text-base text-gray-600'>

<a
Expand All @@ -733,16 +832,20 @@ function Home(props) {
`${props.path}?page=${facilities?.current_page}`
)()
}
className='text-gray-400 font-semibold p-2 hover:underline active:underline focus:underline'>
className='text-gray-400 border border-gray-400 rounded font-semibold p-2 hover:underline active:underline focus:underline'>
{facilities?.current_page}
</a>
</li>

{facilities?.near_pages &&
facilities?.near_pages.map((page, i) => (
<li key={i} className='text-base text-gray-600'>

<a
href={
`
/public
${
(() =>
props.path.includes('?page') ?
props.path.replace(/\?page=\d+/, `?page=${page}`)
Expand All @@ -756,22 +859,24 @@ function Home(props) {
`${props.path}?page=${page}`

)()
}
`
}
className='text-gray-800 p-2 hover:underline active:underline focus:underline'>
{page}
</a>
</li>
))}
<li className='text-sm text-gray-400 flex'>
<DotsHorizontalIcon className='h-3' />
</li>


</ul>
)}
</div>

</div>



</div>
</MainLayout>

Expand Down