From 56514ef878324693d96596ab2ae60e121797a95b Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Tue, 4 Feb 2025 14:22:51 +0700 Subject: [PATCH] feat: update filter in agenda settings --- .../agenda-setting/calender-view.tsx | 2 +- .../contributor/agenda-setting/data.ts | 1 - .../agenda-setting/event-modal.tsx | 2 +- .../contributor/agenda-setting/page.tsx | 48 +++++++++++++++---- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx b/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx index 6713b9c8..9169de8f 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx +++ b/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx @@ -609,7 +609,7 @@ const CalendarView = ({ categories }: CalendarViewProps) => { if (selectedCategory?.length === categories?.length) { setSelectedCategory([]); } else { - setSelectedCategory(categories.map((c) => c.value)); + setSelectedCategory(categories?.map((c) => c.value)); } }} /> diff --git a/app/[locale]/(protected)/contributor/agenda-setting/data.ts b/app/[locale]/(protected)/contributor/agenda-setting/data.ts index fddde01a..3cab4af9 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/data.ts +++ b/app/[locale]/(protected)/contributor/agenda-setting/data.ts @@ -125,7 +125,6 @@ export const categories = [ { label: "Polda", value: "polda", - className: "data-[state=checked]:bg-blue-400 data-[state=checked]:ring-blue-400", }, diff --git a/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx b/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx index 94bbf18e..27def02c 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx +++ b/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx @@ -382,7 +382,7 @@ const EventModal = ({ setStartDate(event?.event?.start); setEndDate(event?.event?.end); const eventCalendar = event?.event?.extendedProps?.calendar; - setAgendaType(eventCalendar || categories[0].value); + setAgendaType(eventCalendar || categories?.length > 0 && categories[0].value); } setValue("title", event?.event?.title || ""); setValue("description", event?.event?.description || ""); diff --git a/app/[locale]/(protected)/contributor/agenda-setting/page.tsx b/app/[locale]/(protected)/contributor/agenda-setting/page.tsx index a9235b2d..4f88d946 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/page.tsx +++ b/app/[locale]/(protected)/contributor/agenda-setting/page.tsx @@ -1,17 +1,49 @@ +"use client" + import { getEvents, getCategories } from "./utils"; import { calendarEvents, Category } from "./data"; import CalendarView from "./calender-view"; +import { getCookiesDecrypt } from "@/lib/utils"; +import { useEffect, useState } from "react"; +import { CalendarCategory } from "./data"; + +const CalenderPage = () => { + + const [categories, setCategories] = useState([]); + const userLevelNumber = Number(getCookiesDecrypt("ulne")) || 0; + const userLevelId = Number(getCookiesDecrypt("ulie")) || 0; + const userParentLevelId = Number(getCookiesDecrypt("uplie")) || 0; + + useEffect(() => { + initData(); + + async function initData() { + const events = await getEvents(); + const categories = await getCategories(); + let valueShowed : string[] = []; + if (userLevelNumber == 1) { + valueShowed = ['mabes', 'polda', 'polres', 'satker', 'international']; + } else if (userLevelNumber == 2 && userLevelId != 761) { + valueShowed = ['polda', 'polres']; + } else if ((userLevelNumber == 2 && userLevelId == 761) || (userLevelNumber == 3 && userParentLevelId == 761)) { + valueShowed = ['satker']; + } else if (userLevelNumber == 3 && userParentLevelId != 761) { + valueShowed = ['polres']; + } + + const formattedCategories = categories.filter((category: Category) => valueShowed.includes(category.value)) + .map((category: Category) => ({ + ...category, + activeClass: "", + })); + console.log(formattedCategories); + setCategories(formattedCategories); + } + }, []); -const CalenderPage = async () => { - const events = await getEvents(); - const categories = await getCategories(); - const formattedCategories = categories.map((category: Category) => ({ - ...category, - activeClass: "", - })); return (
- + {categories && }
); };