feat:add menu sidebar polda, publish contest mabes and all
This commit is contained in:
parent
be7e34ee11
commit
fd8e011ce5
|
|
@ -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<any>[] = [
|
||||
{
|
||||
|
|
@ -73,7 +78,7 @@ const columns: ColumnDef<any>[] = [
|
|||
},
|
||||
{
|
||||
accessorKey: "targetParticipantTopLevel",
|
||||
header: "Tag ",
|
||||
header: "Target Participant ",
|
||||
cell: ({ row }) => (
|
||||
<span className="whitespace-nowrap">
|
||||
{row.getValue("targetParticipantTopLevel")}
|
||||
|
|
@ -81,29 +86,96 @@ const columns: ColumnDef<any>[] = [
|
|||
),
|
||||
},
|
||||
{
|
||||
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 (
|
||||
<Badge
|
||||
className={`whitespace-nowrap px-2 py-1 rounded-full ${
|
||||
isPublishForAll
|
||||
? "bg-green-100 text-green-600" // Warna hijau untuk status "Publish"
|
||||
: "bg-orange-100 text-orange-600" // Warna kuning untuk status "Pending"
|
||||
isPending
|
||||
? "bg-orange-100 text-orange-600" // Warna kuning untuk "Pending"
|
||||
: "bg-green-100 text-green-600" // Warna hijau untuk "Publish"
|
||||
}`}
|
||||
>
|
||||
{isPublishForAll ? "Publish" : "Pending"}
|
||||
{isPending ? "Pending" : "Publish"}
|
||||
</Badge>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
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 (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
|
@ -116,6 +188,21 @@ const columns: ColumnDef<any>[] = [
|
|||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="p-0" align="end">
|
||||
{((userRoleId == 11 || userRoleId == 12) &&
|
||||
row?.original?.isPublishForMabes != true) ||
|
||||
(userRoleId == 3 &&
|
||||
userLevelNumber == 1 &&
|
||||
row?.original?.isPublishForAll != true) ? (
|
||||
<DropdownMenuItem
|
||||
className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none"
|
||||
onClick={() => handlePublishContest(row.original.id)}
|
||||
>
|
||||
<Upload className="w-4 h-4 me-1.5" />
|
||||
Publish
|
||||
</DropdownMenuItem>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
<Link href={`/shared/contest/detail/${row.original.id}`}>
|
||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||
<Eye className="w-4 h-4 me-1.5" />
|
||||
|
|
|
|||
|
|
@ -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<typeof contestSchema>;
|
||||
|
|
|
|||
72
lib/menus.ts
72
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",
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@
|
|||
"lockScreenThree": "Lock Screen Three",
|
||||
"utility": "utility",
|
||||
"blankPage": "Blank Page",
|
||||
"blog": "Blog",
|
||||
"blog": "Indeks",
|
||||
"invoice": "Invoice",
|
||||
"pricing": "Pricing",
|
||||
"profile": "Profile",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue