diff --git a/app/[locale]/(protected)/shared/contest/components/columns.tsx b/app/[locale]/(protected)/shared/contest/components/columns.tsx index 505f5c4e..5db22073 100644 --- a/app/[locale]/(protected)/shared/contest/components/columns.tsx +++ b/app/[locale]/(protected)/shared/contest/components/columns.tsx @@ -1,8 +1,8 @@ import * as React from "react"; import { ColumnDef } from "@tanstack/react-table"; -import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react"; -import { cn } from "@/lib/utils"; +import { Eye, MoreVertical, SquarePen, Trash2, Upload } from "lucide-react"; +import { cn, getCookiesDecrypt } from "@/lib/utils"; import { DropdownMenu, DropdownMenuContent, @@ -13,6 +13,11 @@ import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { format } from "date-fns"; import { Link } from "@/components/navigation"; +import withReactContent from "sweetalert2-react-content"; +import Swal from "sweetalert2"; +import { error } from "@/lib/swal"; +import { deleteMedia } from "@/service/content/content"; +import { publishContest } from "@/service/contest/contest"; const columns: ColumnDef[] = [ { @@ -73,7 +78,7 @@ const columns: ColumnDef[] = [ }, { accessorKey: "targetParticipantTopLevel", - header: "Tag ", + header: "Target Participant ", cell: ({ row }) => ( {row.getValue("targetParticipantTopLevel")} @@ -81,29 +86,96 @@ const columns: ColumnDef[] = [ ), }, { - accessorKey: "isPublishForAll", + accessorKey: "isPublishForAll", // Bisa menggunakan ini untuk membaca default data header: "Status", - cell: ({ row }) => { - const isPublishForAll = row.getValue("isPublishForAll"); + cell: ({ + row, + }: { + row: { + original: { isPublishForAll?: boolean; isPublishForMabes?: boolean }; + }; + }) => { + const userRoleId: number = Number(getCookiesDecrypt("urie")); + const userLevelNumber: number = Number(getCookiesDecrypt("ulne")); + + // Mengambil data dari row.original agar lebih aman + const isPublishForAll: boolean = Boolean(row.original.isPublishForAll); + const isPublishForMabes: boolean = Boolean( + row.original.isPublishForMabes + ); + + // Logika status berdasarkan role dan data dari API + const isPending: boolean = + (userRoleId === 3 && userLevelNumber === 1 && !isPublishForAll) || // Role 3 dengan level 1 hanya publish jika isPublishForAll true + ((userRoleId === 11 || userRoleId === 12) && !isPublishForMabes); // Role 11 dan 12 hanya publish jika isPublishForMabes true + return ( - {isPublishForAll ? "Publish" : "Pending"} + {isPending ? "Pending" : "Publish"} ); }, }, + { id: "actions", accessorKey: "action", header: "Actions", enableHiding: false, cell: ({ row }) => { + const MySwal = withReactContent(Swal); + const userRoleId = Number(getCookiesDecrypt("urie")); + const userLevelId = Number(getCookiesDecrypt("ulie")); + const userLevelNumber = Number(getCookiesDecrypt("ulne")); + + async function doPublish(id: any) { + // loading(); + // const data = { + // id, + // }; + + const response = await publishContest(id); + + if (response?.error) { + error(response.message); + return false; + } + success(); + } + + function success() { + MySwal.fire({ + title: "Sukses", + icon: "success", + confirmButtonColor: "#3085d6", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + window.location.reload(); + } + }); + } + + const handlePublishContest = (id: any) => { + MySwal.fire({ + title: "Apakah anda ingin publish Lomba?", + showCancelButton: true, + cancelButtonColor: "#3085d6", + confirmButtonColor: "#d33", + confirmButtonText: "Ya", + cancelButtonText: "Tidak", + }).then((result) => { + if (result.isConfirmed) { + doPublish(id); + } + }); + }; return ( @@ -116,6 +188,21 @@ const columns: ColumnDef[] = [ + {((userRoleId == 11 || userRoleId == 12) && + row?.original?.isPublishForMabes != true) || + (userRoleId == 3 && + userLevelNumber == 1 && + row?.original?.isPublishForAll != true) ? ( + handlePublishContest(row.original.id)} + > + + Publish + + ) : ( + "" + )} diff --git a/components/form/contest/contest-detail-form.tsx b/components/form/contest/contest-detail-form.tsx index 723d7c1d..13a1e13b 100644 --- a/components/form/contest/contest-detail-form.tsx +++ b/components/form/contest/contest-detail-form.tsx @@ -32,7 +32,7 @@ import { PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; -import { cn } from "@/lib/utils"; +import { cn, getCookiesDecrypt } from "@/lib/utils"; import { CalendarIcon, ChevronDown, ChevronUp } from "lucide-react"; import { format, parseISO } from "date-fns"; import { Calendar } from "@/components/ui/calendar"; @@ -104,6 +104,9 @@ interface FileWithPreview extends File { export default function FormContestDetail() { const MySwal = withReactContent(Swal); + const userRoleId = Number(getCookiesDecrypt("urie")); + const userLevelId = Number(getCookiesDecrypt("ulie")); + const userLevelNumber = Number(getCookiesDecrypt("ulne")); const router = useRouter(); const editor = useRef(null); type ContestSchema = z.infer; diff --git a/lib/menus.ts b/lib/menus.ts index 9fcdcbab..dc045ee9 100644 --- a/lib/menus.ts +++ b/lib/menus.ts @@ -1599,7 +1599,7 @@ export function getMenuList(pathname: string, t: any): Group[] { { id: "contest", href: "/shared/contest", - label: t("lomba"), + label: t("contest"), active: pathname.includes("/contest"), icon: "ic:outline-emoji-events", submenus: [], @@ -1783,7 +1783,7 @@ export function getMenuList(pathname: string, t: any): Group[] { { id: "contest", href: "/shared/contest", - label: t("lomba"), + label: t("contest"), active: pathname.includes("/contest"), icon: "ic:outline-emoji-events", submenus: [], @@ -1949,7 +1949,7 @@ export function getMenuList(pathname: string, t: any): Group[] { { id: "contest", href: "/shared/contest", - label: t("lomba"), + label: t("contest"), active: pathname.includes("/contest"), icon: "ic:outline-emoji-events", submenus: [], @@ -2177,7 +2177,7 @@ export function getMenuList(pathname: string, t: any): Group[] { { id: "contest", href: "/shared/contest", - label: t("lomba"), + label: t("contest"), active: pathname.includes("/contest"), icon: "ic:outline-emoji-events", submenus: [], @@ -2386,7 +2386,7 @@ export function getMenuList(pathname: string, t: any): Group[] { { id: "contest", href: "/shared/contest", - label: "Lomba", + label: "contest", active: pathname.includes("/contest"), icon: "ic:outline-emoji-events", submenus: [], @@ -2669,7 +2669,7 @@ export function getMenuList(pathname: string, t: any): Group[] { { id: "contest", href: "/shared/contest", - label: t("Lomba"), + label: t("contest"), active: pathname.includes("/contest"), icon: "ic:outline-emoji-events", submenus: [], @@ -2873,7 +2873,7 @@ export function getMenuList(pathname: string, t: any): Group[] { { id: "contest", href: "/shared/contest", - label: "Lomba", + label: t("contest"), active: pathname.includes("/contest"), icon: "ic:outline-emoji-events", submenus: [], @@ -3017,7 +3017,20 @@ export function getMenuList(pathname: string, t: any): Group[] { }, ], }, - + { + groupLabel: "", + id: "management-user", + menus: [ + { + id: "management-user-menu", + href: "/admin/management-user", + label: "Management User", + active: pathname.includes("/management-user"), + icon: "clarity:users-solid", + submenus: [], + }, + ], + }, { groupLabel: "", id: "content-production", @@ -3060,6 +3073,35 @@ export function getMenuList(pathname: string, t: any): Group[] { }, ], }, + { + groupLabel: "", + id: "media-tracking", + menus: [ + { + id: "media-tracking", + href: "/curator/media-tracking", + label: t("media-tracking"), + active: pathname.includes("/media-tracking"), + icon: "material-symbols:map-search-outline", + submenus: [ + { + href: "/admin/media-tracking/media-online", + label: "Media Online", + active: pathname === "/media-tracking/media-online", + icon: "heroicons:arrow-trending-up", + children: [], + }, + { + href: "/admin/media-tracking/tb-news", + label: "Tracking Beritra Hari Ini", + active: pathname === "/media-tracking/news", + icon: "heroicons:arrow-trending-up", + children: [], + }, + ], + }, + ], + }, { groupLabel: "", id: "communication", @@ -3074,6 +3116,20 @@ export function getMenuList(pathname: string, t: any): Group[] { }, ], }, + { + groupLabel: "", + id: "experts", + menus: [ + { + id: "experts", + href: "/admin/add-experts", + label: t("add-experts"), + active: pathname.includes("/add-experts"), + icon: "majesticons:user", + submenus: [], + }, + ], + }, { groupLabel: "", id: "settings", diff --git a/messages/in.json b/messages/in.json index 58a49f04..ec095da5 100644 --- a/messages/in.json +++ b/messages/in.json @@ -211,7 +211,7 @@ "lockScreenThree": "Lock Screen Three", "utility": "utility", "blankPage": "Blank Page", - "blog": "Blog", + "blog": "Indeks", "invoice": "Invoice", "pricing": "Pricing", "profile": "Profile", diff --git a/service/contest/contest.ts b/service/contest/contest.ts index ba751b9d..de881fd4 100644 --- a/service/contest/contest.ts +++ b/service/contest/contest.ts @@ -27,3 +27,8 @@ export async function postCreateContest(data: any) { const url = "contest"; return httpPostInterceptor(url, data); } + +export async function publishContest(id: any) { + const url = `contest/publish?id=${id}`; + return httpPostInterceptor(url); +}