Files
hats-app/app/(dashboard)/components/FooterV2.tsx
T
2025-12-19 13:57:55 +07:00

84 lines
3.6 KiB
TypeScript

'use client'
import { FC, useEffect, useState } from 'react';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import { useSession } from 'next-auth/react';
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
type Props = {};
const FooterV2: FC<Props> = () => {
const [lastPresence, setLastPresence] = useState<any>(null)
const pathname = usePathname()
const router = useRouter()
const { data: session } = useSession()
const axios = useAxiosAuth()
useEffect(() => {
async function fetchLastPresence() {
axios.post('/presence/last-status/today', { nik: session?.user.detail.nik })
.then(res => {
setLastPresence(res.data.data)
}).catch((err) => console.log(err))
}
fetchLastPresence()
}, [pathname])
const getMenuActiveStyle = (path: string) => {
if (pathname?.startsWith(path) && (pathname !== '' && pathname !== '/') && (path !== '' && path !== '/')) {
return 'text-his font-semibold'
} else {
if (path === pathname) {
return 'text-his font-semibold'
}
}
return ''
}
return (
<footer className="fixed sm:hidden flex-col bottom-5 z-10 backdrop-blur-lg px-6 shadow-sm w-full">
<div className="w-full dark:bg-zinc-50 bg-zinc-900 rounded-full grid grid-cols-5 px-2 py-4 text-xs font-medium text-muted-foreground relative">
<Link prefetch href={'/'} onClick={() => router.push('/')}
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/')}`}
>
<i className='ti ti-home-stats icon text-2xl'></i>
<p>Home</p>
</Link>
<Link prefetch href={'/history'} onClick={() => router.push('/')}
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/history')}`}
>
<i className='ti ti-history-toggle icon text-2xl'></i>
<p>History</p>
</Link>
<div className={`absolute top-[18px] left-1/2 flex flex-col items-center ${getMenuActiveStyle('/presence-v2')}`} style={{ transform: 'translate(-50%, -50%)' }}>
<Link prefetch href={!lastPresence?.is_checkin ? '/presence-v2' : lastPresence?.device_code === "11001" ? '' : '/presence-v2?checkout=true'} className='w-16 h-16 p-0.5 rounded-full bg-zinc-950 dark:bg-zinc-50 flex justify-center items-center' >
<div className='h-full w-full bg-his rounded-full flex justify-center items-center text-white'>
<i className='ti ti-face-id icon text-3xl'></i>
</div>
</Link>
<p className='mt-0.5'>Presence</p>
</div>
<div></div>
<Link prefetch href={'/task'} onClick={() => router.push('/')}
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/task')}`}
>
<i className='ti ti-checklist icon text-2xl'></i>
<p>Task</p>
</Link>
<Link prefetch href={'/profile'} onClick={() => router.push('/')}
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/profile')}`}
>
<i className='ti ti-user-circle icon icon text-2xl'></i>
<p>Profile</p>
</Link>
</div>
</footer>
);
}
export default FooterV2;