diff --git a/app/(dashboard)/(main)/page.tsx b/app/(dashboard)/(main)/page.tsx index cdc017d..0660a71 100644 --- a/app/(dashboard)/(main)/page.tsx +++ b/app/(dashboard)/(main)/page.tsx @@ -42,6 +42,7 @@ export default async function DashboardPage() { const alreadyCheckin = todayPresence.history.length > 0 const alreadyCheckout = (alreadyCheckin && todayPresence.history[0].presence_checkout) || todayPresence.history.length === 0 + // console.log(dataDashboard) return ( <>
diff --git a/app/(dashboard)/components/ApprovalLeaveSick.tsx b/app/(dashboard)/components/ApprovalLeaveSick.tsx index a69fb29..8079e72 100644 --- a/app/(dashboard)/components/ApprovalLeaveSick.tsx +++ b/app/(dashboard)/components/ApprovalLeaveSick.tsx @@ -15,6 +15,8 @@ import PageLoading from '@/components/loader/PageLoading'; import { useRouter } from 'next/navigation'; import { toast } from 'sonner'; import FallbackAvatar from '@/components/loader/FallbackAvatar'; +import { useFetchPOSTWithAxios } from '@/lib/axios/useFetch'; +import Link from 'next/link'; const ViewAvatar = lazy(() => import('@/components/ViewAvatar')); const Avatar = lazy(() => import('@/components/ViewAvatar').then(mod => ({ default: mod.Avatar }))); @@ -34,6 +36,7 @@ const ApprovalLeaveSick: FC = ({ data, className }) => { const [showConfirm, setShowConfirm] = useState(false) const [isApproval, setIsApproval] = useState(false) const [dataPresence, setDataPresence] = useState(null) + const [mentionsTo, setMentionsTo] = useState([]) const [presenceId, setPresenceId] = useState(0) const [dataFilter, setDataFilter] = useState([]) const [search, setSearch] = useState('') @@ -42,6 +45,8 @@ const ApprovalLeaveSick: FC = ({ data, className }) => { const axios = useAxiosAuth() const router = useRouter() + const { data: TLList } = useFetchPOSTWithAxios(['/user/position'], { position_code: 'P02' }) + useEffect(() => { let newData = [...data.list] if (!search) { @@ -71,6 +76,19 @@ const ApprovalLeaveSick: FC = ({ data, className }) => { const { data: res } = await axios.get('/application-form/approval/info/' + presenceId) // console.log(res.data) setDataPresence(res.data) + const dataTL = TLList || [] + + const nameDictionary = dataTL.reduce((acc: any, user: any) => { + acc[user.id] = user.fullname; + return acc; + }, {}); + + const result = res.data.cc.map((id: any) => ({ + id: id, + fullname: nameDictionary[id] ?? null + })); + + setMentionsTo(result) setShowDialog(true) } catch (error: any) { toast.error(`Fail to fetch presence`, { @@ -102,7 +120,7 @@ const ApprovalLeaveSick: FC = ({ data, className }) => { } } - console.log(dataPresence) + // console.log(TLList, dataPresence) // console.log(dataFilter) return ( <> @@ -220,7 +238,13 @@ const ApprovalLeaveSick: FC = ({ data, className }) => {

Mentions to

-

{dataPresence.cc.length > 0 ? dataPresence.cc.join(', ') : '-'}

+ {dataPresence.cc && dataPresence.cc.length > 0 ? + mentionsTo.map((item: any, key: number) => + @{item?.fullname || item?.id} + ) + : + '-' + }
@@ -236,9 +260,10 @@ const ApprovalLeaveSick: FC = ({ data, className }) => { - + } - {showConfirm && + { + showConfirm && diff --git a/app/(dashboard)/profile/components/EditProfile.tsx b/app/(dashboard)/profile/components/EditProfile.tsx index 171218e..16c4dda 100644 --- a/app/(dashboard)/profile/components/EditProfile.tsx +++ b/app/(dashboard)/profile/components/EditProfile.tsx @@ -36,7 +36,7 @@ const EditProfile: FC = ({ data }) => { useEffect(() => { if (data) { form.setFieldsValue(data) - if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday)) + if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday).format('YYYY-MM-DD')) } else { form.resetFields() } diff --git a/lib/axios/useFetch.tsx b/lib/axios/useFetch.tsx index 3f98ae1..5b74983 100644 --- a/lib/axios/useFetch.tsx +++ b/lib/axios/useFetch.tsx @@ -40,4 +40,24 @@ export function useFetchWithAxios(url: string | null, options?: SWRConfiguration error, mutate } +} + +export function useFetchPOSTWithAxios(endpointKey: [string, ...any[]] | null, payload: any = {}, options?: SWRConfiguration) { + const axios = useAxiosAuth(); + + const fetcher = ([url, ..._]: [string, ...any[]]) => + axios.post(url, payload).then(res => res.data); + + const { data, error, isLoading, mutate } = useSWR( + endpointKey, // Keep it as an array for SWR to track + fetcher, + options + ); + + return { + data: data?.data, + isLoading, + error, + mutate + }; } \ No newline at end of file