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

41 lines
1.4 KiB
TypeScript

'use client'
import { FC, useEffect, useState } from 'react';
import { IHistory } from '../history/components/type';
import { CardContent } from '@/components/ui/card';
import dayjs from 'dayjs';
type Props = {
history: IHistory[]
};
const LastPresence: FC<Props> = ({ history }) => {
const [latestPresenceCheckout, setLatestPresenceCheckout] = useState<any>(null)
const [latestPresenceCheckIn, setLatestPresenceCheckIn] = useState<any>(null)
useEffect(() => {
if (history && history.length > 0) {
for (let i = 0; i < history.length; i++) {
if (history[i].presence_checkout) {
setLatestPresenceCheckIn(history[i].presence_checkout?.working_hours_start || null)
setLatestPresenceCheckout(history[i].presence_checkout?.working_hours_end || null)
break
}
}
}
}, [history])
return (
<>
<CardContent>
<div className="text-2xl font-bold">{latestPresenceCheckout ? dayjs(latestPresenceCheckIn).format('HH:mm a') + ' - ' + dayjs(latestPresenceCheckout).format('HH:mm a') : '--:-- - --:--'} </div>
<p className="text-xs text-muted-foreground">
your last presence at {latestPresenceCheckIn ? dayjs(latestPresenceCheckIn).format('MMM DD, YYYY') : ''}
</p>
</CardContent>
</>
);
}
export default LastPresence;