diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/schedule/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/schedule/page.tsx index 578b19b3..6330d0c9 100644 --- a/app/[locale]/(public)/(polda)/polda/[polda_name]/schedule/page.tsx +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/schedule/page.tsx @@ -1,19 +1,52 @@ "use client"; import { Button } from "@/components/ui/button"; import { Calendar } from "@/components/ui/calendar"; -import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; -import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { + Popover, + PopoverArrow, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; import { CalendarIcon } from "lucide-react"; import React, { useEffect, useState } from "react"; import { format } from "date-fns"; -import { cn } from "@/lib/utils"; +import { cn, getCookiesDecrypt } from "@/lib/utils"; import { Checkbox } from "@/components/ui/checkbox"; import { Icon } from "@iconify/react/dist/iconify.js"; -import { detailSchedule, listSchedule, listScheduleNextPublic, listSchedulePrevPublic, listScheduleTodayPublic } from "@/service/schedule/schedule"; -import { useRouter } from "@/i18n/routing"; -import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"; -import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"; +import { + detailSchedule, + listSchedule, + listScheduleNextPublic, + listSchedulePrevPublic, + listScheduleTodayPublic, + searchSchedules, +} from "@/service/schedule/schedule"; +import { usePathname, useRouter } from "@/i18n/routing"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import { Input } from "@/components/ui/input"; +import { getUserLevelForAssignments } from "@/service/task"; +import { useParams } from "next/navigation"; const timeList = [ { @@ -116,18 +149,44 @@ const timeList = [ const Schedule = (props: any) => { const router = useRouter(); + const asPath = usePathname(); const [startDate, setStartDate] = useState(new Date()); const [dateAWeek, setDateAWeek] = useState([]); - const [scheduleSearch, setScheduleSearch] = useState(); const [todayList, setTodayList] = useState([]); const [prevdayList, setPrevdayList] = useState([]); const [nextdayList, setNextdayList] = useState([]); - const [isOpen, setIsOpen] = React.useState(false); const [schedules, setSchedules] = useState([]); const [openDialog, setOpenDialog] = useState(false); const [detail, setDetail] = useState(); const [content, setContent] = useState(); const { id } = props; + const t = useTranslations("LandingPage"); + const [search, setSearch] = useState(); + const [scheduleSearch, setScheduleSearch] = useState(); + let typingTimer: any; + const doneTypingInterval = 1500; + const [regionFilter, setRegionFilter] = useState([]); + const [regionName, setRegionName] = useState([]); + const isPolda = asPath.includes("/polda"); + const userId = getCookiesDecrypt("uie"); + + async function doneTyping() { + if (search?.length > 2) { + const resSchedule = await searchSchedules(search); + setScheduleSearch(resSchedule.data?.data); + } else { + setScheduleSearch([]); + } + } + + const handleKeyUp = () => { + clearTimeout(typingTimer); + typingTimer = setTimeout(doneTyping, doneTypingInterval); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; useEffect(() => { async function getDataSchedule() { @@ -141,26 +200,32 @@ const Schedule = (props: any) => { useEffect(() => { async function initState() { - getDataByDate(); - // const group = isPolda ? asPath.split("/")[2] : regionFilter?.join(","); - const resSchedule = await listSchedule(); + const group = isPolda ? asPath.split("/")[2] : regionFilter?.join(","); + const resSchedule = await listSchedule(group); setSchedules(resSchedule.data?.data); console.log(resSchedule); setDateAWeek(dateList); + getDataByDate(); // let today = new Date(); + // if (!dateList.includes(today.getDate())){ + // changeNextWeek(); + // } + console.log("GROUP", group); } initState(); }, []); async function getDataByDate() { - const resToday = await listScheduleTodayPublic(); + const group = isPolda ? asPath.split("/")[2] : regionFilter?.join(","); + const resToday = await listScheduleTodayPublic(group as string); const today = resToday.data?.data; + setTodayList(today); - const resNext = await listScheduleNextPublic(); + const resNext = await listScheduleNextPublic(group as string); const next = resNext.data?.data; setNextdayList(next); - const resPrev = await listSchedulePrevPublic(); + const resPrev = await listSchedulePrevPublic(group as string); const prev = resPrev.data?.data; setPrevdayList(prev); @@ -200,13 +265,21 @@ const Schedule = (props: any) => { function getLastWeek(today: Date | undefined) { if (today) { - return new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7); + return new Date( + today.getFullYear(), + today.getMonth(), + today.getDate() - 7 + ); } } function getNextWeek(today: Date | undefined) { if (today) { - return new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7); + return new Date( + today.getFullYear(), + today.getMonth(), + today.getDate() + 7 + ); } } @@ -279,14 +352,49 @@ const Schedule = (props: any) => { setOpenDialog(true); }; + const handleRegionFilter = (e: any) => { + let regions = [...regionFilter]; + + if (e.target.checked) { + regions = [...regionFilter, e.target.value]; + } else { + regions.splice(regionFilter.indexOf(e.target.value), 1); + } + + console.log(regions); + setRegionFilter(regions); + }; + + const goLogin = () => { + router.push("/auth"); + }; + + const deleteFilterhandler = (filterId: any) => { + console.log("hapus", filterId); + const deletedReg = regionName.filter((list: any) => list.id !== filterId); + const filtered = regionFilter.filter((list: any) => list !== filterId); + + setRegionName(deletedReg); + setRegionFilter(filtered); + }; + function setItemSchedule(id: string, date: string) { - const itemFound: any = schedules?.filter((s: any) => s.dateInRange.includes(date) && s.timeIndex.split(",").includes(id)); + const itemFound: any = schedules?.filter( + (s: any) => + s.dateInRange.includes(date) && s.timeIndex.split(",").includes(id) + ); if (itemFound?.length > 0) { if (itemFound?.length == 1) { return ( { getItem(itemFound[0]); }} @@ -294,7 +402,14 @@ const Schedule = (props: any) => {

{itemFound[0]?.title}

- {itemFound[0].isYoutube == true ?

LIVE

: ""} + {itemFound[0].isYoutube == true ? ( +
+
+ LIVE +
+ ) : ( + "" + )} {/*

{itemFound[0].address}

*/}
); @@ -306,10 +421,12 @@ const Schedule = (props: any) => { return (

- {`${itemFound?.length} Jadwal Bersamaan`} + {t(`${itemFound?.length}simultaneousSchedule`)}

- Lihat Jadwal + + {t("viewSchedule")} + {itemFound?.map((list: any) => ( {

{list.title}

- {list.isYoutube == true ?

LIVE

: ""} + {list.isYoutube == true ? ( +
+
+ LIVE +
+ ) : ( + "" + )} {/*

{list.address}

*/}
))}
-
+
); } @@ -337,140 +464,165 @@ const Schedule = (props: any) => { return ( <> {/* Awal Komponen Kiri */} -
- - - - - - { - handleChangeDate(e); - }} - initialFocus - /> - - - -
- - - - - - - Filter - - - - - - - -
-
Filter
- -
-
-
-

Region Filter

-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
- -

POLDA METRO JAYA

-
-
-
-
-
+
+
+ + + + + + { + handleChangeDate(e); + }} + initialFocus + /> + +
-
-
+
+
-
- +
+
- + - - - - - - -
Time Table + {t("timeTable", { defaultValue: "Time Table" })} + - changePrevWeek()} className="cursor-pointer h-fit self-center bottom-0"> - - + changePrevWeek()} + className="cursor-pointer h-fit self-center bottom-0" + > + + + {/* {" "} */}
-

{dateAWeek[0]?.split("-")[2]}

-

Monday

+

+ {dateAWeek[0]?.split("-")[2]} +

+

{t("monday", { defaultValue: "Monday" })}

-
{dateAWeek[1]?.split("-")[2]}
Tuesday +
+
+ {dateAWeek[1]?.split("-")[2]} +
+ {t("tuesday", { defaultValue: "Tuesday" })}
-
{dateAWeek[2]?.split("-")[2]}
Wednesday +
+
+ {dateAWeek[2]?.split("-")[2]} +
+ {t("wednesday", { defaultValue: "Wednesday" })}
-
{dateAWeek[3]?.split("-")[2]}
Thursday +
+
+ {dateAWeek[3]?.split("-")[2]} +
+ {t("thursday", { defaultValue: "Thursday" })}
-
{dateAWeek[4]?.split("-")[2]}
Friday +
+
+ {dateAWeek[4]?.split("-")[2]} +
+ {t("friday", { defaultValue: "Friday" })}
-
{dateAWeek[5]?.split("-")[2]}
Saturday +
+
+ {dateAWeek[5]?.split("-")[2]} +
+ {t("saturday", { defaultValue: "Saturday" })}
changeNextWeek()} className={`text-center border cursor-pointer border-r-0 border-gray-100 dark:border-gray-700 py-6 min-w-[100px] ${ - new Date().toISOString().slice(0, 10) == dateAWeek[6] ? "bg-[#BE0106] text-white rounded-lg" : "" + new Date().toISOString().slice(0, 10) == + dateAWeek[6] + ? "bg-[#BE0106] text-white rounded-lg" + : "" }`} >
-

{dateAWeek[6]?.split("-")[2]}

-

Sunday

+

+ {dateAWeek[6]?.split("-")[2]} +

+

{t("sunday", { defaultValue: "Sunday" })}

{/* @@ -478,10 +630,21 @@ const Schedule = (props: any) => { */}
- changeNextWeek()} className="cursor-pointer"> - - + + changeNextWeek()} + className="cursor-pointer" + > + + @@ -490,16 +653,34 @@ const Schedule = (props: any) => { {timeList.map((times) => (
- {times.time} - + + {times.time} + + {setItemSchedule(times.id, dateList[0])} - {setItemSchedule(times.id, dateList[1])} - {setItemSchedule(times.id, dateList[2])} - {setItemSchedule(times.id, dateList[3])} - {setItemSchedule(times.id, dateList[4])} - {setItemSchedule(times.id, dateList[5])} - + + {setItemSchedule(times.id, dateList[1])} + + + {setItemSchedule(times.id, dateList[2])} + + + {setItemSchedule(times.id, dateList[3])} + + + {setItemSchedule(times.id, dateList[4])} + + + {setItemSchedule(times.id, dateList[5])} + + {setItemSchedule(times.id, dateList[6])}
@@ -511,15 +692,32 @@ const Schedule = (props: any) => { - {/* Component Kanan */} -
+ {/* komponen Kanan */} +
- + setSearch(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + placeholder={t("titleSchedule", { + defaultValue: "Title Schedule", + })} + className="pl-8 pr-4 py-1 w-full border rounded-full text-sm focus:outline-none" + /> - + - + @@ -557,12 +755,20 @@ const Schedule = (props: any) => { ))} */} + - Jadwal Hari ini + + {t("todaySchedule", { defaultValue: "Today Schedule" })} + {todayList?.map((list: any) => ( - -
{new Date(list.startDate).getDate()}
+ +
+ {new Date(list.startDate).getDate()} +

{list?.title}

@@ -570,10 +776,10 @@ const Schedule = (props: any) => { {list?.startTime} - {list?.endTime} WIB

- + {list?.address}

-

Pembicara :

+

{t("speaker", { defaultValue: "Speaker" })}

{list?.speakerTitle} {list?.speakerName} @@ -584,10 +790,17 @@ const Schedule = (props: any) => { - Jadwal Sebelumnya + + {t("previousSchedule", { defaultValue: "Previous Schedule" })} + {prevdayList?.map((list: any) => ( - -

{new Date(list.startDate).getDate()}
+ +
+ {new Date(list.startDate).getDate()} +

{list?.title}

@@ -595,10 +808,10 @@ const Schedule = (props: any) => { {list?.startTime} - {list?.endTime} WIB

- + {list?.address}

-

Pembicara :

+

{t("speaker", { defaultValue: "Speaker" })}

{list?.speakerTitle} {list?.speakerName} @@ -609,10 +822,17 @@ const Schedule = (props: any) => { - Jadwal Selanjutnya + + {t("nextSchedule", { defaultValue: "Next Schedule" })} + {nextdayList?.map((list: any) => ( - -

{new Date(list.startDate).getDate()}
+ +
+ {new Date(list.startDate).getDate()} +

{list?.title}

@@ -620,10 +840,10 @@ const Schedule = (props: any) => { {list?.startTime} - {list?.endTime} WIB

- + {list?.address}

-

Pembicara :

+

{t("speaker", { defaultValue: "Speaker" })}

{list?.speakerTitle} {list?.speakerName} @@ -703,37 +923,71 @@ const Schedule = (props: any) => {

- - - - -

JADWAL / {detail?.isYoutube == true ? "LIVE STREAMING" : "DETAIL"}

+ + + + +

+ {t("timeTable1")} + {detail?.isYoutube == true ? "LIVE STREAMING" : "DETAIL"} +

{detail?.title}

-
- + +

- {detail?.date} {detail?.startTime} - {detail?.endTime} {detail?.timezone ? detail.timezone : "WIB"} + {detail?.startDate} {detail?.startTime} - {detail?.endTime}{" "} + {detail?.timezone ? detail.timezone : "WIB"}

-
- -

- + + +

+ {detail?.address}

-
- + +

{detail?.speakerTitle || ""} {detail?.speakerName || ""}{" "}

-
-
- - Close - -
-
+ + + {detail?.isYoutube == true ? ( + userId == null ? ( +
+ ) : ( +
+