Merge branch 'dev-anang' of https://gitlab.com/hanifsalafi/mediahub_redesign
This commit is contained in:
commit
fc87dd7211
|
|
@ -1,8 +1,8 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
|
||||||
import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react";
|
import { Eye, MoreVertical, SquarePen, Trash2, Upload } from "lucide-react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn, getCookiesDecrypt } from "@/lib/utils";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
|
@ -13,6 +13,11 @@ import { Button } from "@/components/ui/button";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { Link } from "@/components/navigation";
|
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>[] = [
|
const columns: ColumnDef<any>[] = [
|
||||||
{
|
{
|
||||||
|
|
@ -73,7 +78,7 @@ const columns: ColumnDef<any>[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "targetParticipantTopLevel",
|
accessorKey: "targetParticipantTopLevel",
|
||||||
header: "Tag ",
|
header: "Target Participant ",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<span className="whitespace-nowrap">
|
<span className="whitespace-nowrap">
|
||||||
{row.getValue("targetParticipantTopLevel")}
|
{row.getValue("targetParticipantTopLevel")}
|
||||||
|
|
@ -81,29 +86,96 @@ const columns: ColumnDef<any>[] = [
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "isPublishForAll",
|
accessorKey: "isPublishForAll", // Bisa menggunakan ini untuk membaca default data
|
||||||
header: "Status",
|
header: "Status",
|
||||||
cell: ({ row }) => {
|
cell: ({
|
||||||
const isPublishForAll = row.getValue("isPublishForAll");
|
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 (
|
return (
|
||||||
<Badge
|
<Badge
|
||||||
className={`whitespace-nowrap px-2 py-1 rounded-full ${
|
className={`whitespace-nowrap px-2 py-1 rounded-full ${
|
||||||
isPublishForAll
|
isPending
|
||||||
? "bg-green-100 text-green-600" // Warna hijau untuk status "Publish"
|
? "bg-orange-100 text-orange-600" // Warna kuning untuk "Pending"
|
||||||
: "bg-orange-100 text-orange-600" // Warna kuning untuk status "Pending"
|
: "bg-green-100 text-green-600" // Warna hijau untuk "Publish"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{isPublishForAll ? "Publish" : "Pending"}
|
{isPending ? "Pending" : "Publish"}
|
||||||
</Badge>
|
</Badge>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
accessorKey: "action",
|
accessorKey: "action",
|
||||||
header: "Actions",
|
header: "Actions",
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
cell: ({ row }) => {
|
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 (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|
@ -116,6 +188,21 @@ const columns: ColumnDef<any>[] = [
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="p-0" align="end">
|
<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}`}>
|
<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">
|
<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" />
|
<Eye className="w-4 h-4 me-1.5" />
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import {
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from "@/components/ui/popover";
|
} from "@/components/ui/popover";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn, getCookiesDecrypt } from "@/lib/utils";
|
||||||
import { CalendarIcon, ChevronDown, ChevronUp } from "lucide-react";
|
import { CalendarIcon, ChevronDown, ChevronUp } from "lucide-react";
|
||||||
import { format, parseISO } from "date-fns";
|
import { format, parseISO } from "date-fns";
|
||||||
import { Calendar } from "@/components/ui/calendar";
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
|
|
@ -104,6 +104,9 @@ interface FileWithPreview extends File {
|
||||||
|
|
||||||
export default function FormContestDetail() {
|
export default function FormContestDetail() {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
|
const userRoleId = Number(getCookiesDecrypt("urie"));
|
||||||
|
const userLevelId = Number(getCookiesDecrypt("ulie"));
|
||||||
|
const userLevelNumber = Number(getCookiesDecrypt("ulne"));
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const editor = useRef(null);
|
const editor = useRef(null);
|
||||||
type ContestSchema = z.infer<typeof contestSchema>;
|
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",
|
id: "contest",
|
||||||
href: "/shared/contest",
|
href: "/shared/contest",
|
||||||
label: t("lomba"),
|
label: t("contest"),
|
||||||
active: pathname.includes("/contest"),
|
active: pathname.includes("/contest"),
|
||||||
icon: "ic:outline-emoji-events",
|
icon: "ic:outline-emoji-events",
|
||||||
submenus: [],
|
submenus: [],
|
||||||
|
|
@ -1783,7 +1783,7 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
{
|
{
|
||||||
id: "contest",
|
id: "contest",
|
||||||
href: "/shared/contest",
|
href: "/shared/contest",
|
||||||
label: t("lomba"),
|
label: t("contest"),
|
||||||
active: pathname.includes("/contest"),
|
active: pathname.includes("/contest"),
|
||||||
icon: "ic:outline-emoji-events",
|
icon: "ic:outline-emoji-events",
|
||||||
submenus: [],
|
submenus: [],
|
||||||
|
|
@ -1949,7 +1949,7 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
{
|
{
|
||||||
id: "contest",
|
id: "contest",
|
||||||
href: "/shared/contest",
|
href: "/shared/contest",
|
||||||
label: t("lomba"),
|
label: t("contest"),
|
||||||
active: pathname.includes("/contest"),
|
active: pathname.includes("/contest"),
|
||||||
icon: "ic:outline-emoji-events",
|
icon: "ic:outline-emoji-events",
|
||||||
submenus: [],
|
submenus: [],
|
||||||
|
|
@ -2177,7 +2177,7 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
{
|
{
|
||||||
id: "contest",
|
id: "contest",
|
||||||
href: "/shared/contest",
|
href: "/shared/contest",
|
||||||
label: t("lomba"),
|
label: t("contest"),
|
||||||
active: pathname.includes("/contest"),
|
active: pathname.includes("/contest"),
|
||||||
icon: "ic:outline-emoji-events",
|
icon: "ic:outline-emoji-events",
|
||||||
submenus: [],
|
submenus: [],
|
||||||
|
|
@ -2386,7 +2386,7 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
{
|
{
|
||||||
id: "contest",
|
id: "contest",
|
||||||
href: "/shared/contest",
|
href: "/shared/contest",
|
||||||
label: "Lomba",
|
label: "contest",
|
||||||
active: pathname.includes("/contest"),
|
active: pathname.includes("/contest"),
|
||||||
icon: "ic:outline-emoji-events",
|
icon: "ic:outline-emoji-events",
|
||||||
submenus: [],
|
submenus: [],
|
||||||
|
|
@ -2669,7 +2669,7 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
{
|
{
|
||||||
id: "contest",
|
id: "contest",
|
||||||
href: "/shared/contest",
|
href: "/shared/contest",
|
||||||
label: t("Lomba"),
|
label: t("contest"),
|
||||||
active: pathname.includes("/contest"),
|
active: pathname.includes("/contest"),
|
||||||
icon: "ic:outline-emoji-events",
|
icon: "ic:outline-emoji-events",
|
||||||
submenus: [],
|
submenus: [],
|
||||||
|
|
@ -2873,7 +2873,7 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
{
|
{
|
||||||
id: "contest",
|
id: "contest",
|
||||||
href: "/shared/contest",
|
href: "/shared/contest",
|
||||||
label: "Lomba",
|
label: t("contest"),
|
||||||
active: pathname.includes("/contest"),
|
active: pathname.includes("/contest"),
|
||||||
icon: "ic:outline-emoji-events",
|
icon: "ic:outline-emoji-events",
|
||||||
submenus: [],
|
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: "",
|
groupLabel: "",
|
||||||
id: "content-production",
|
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: "",
|
groupLabel: "",
|
||||||
id: "communication",
|
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: "",
|
groupLabel: "",
|
||||||
id: "settings",
|
id: "settings",
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@
|
||||||
"lockScreenThree": "Lock Screen Three",
|
"lockScreenThree": "Lock Screen Three",
|
||||||
"utility": "utility",
|
"utility": "utility",
|
||||||
"blankPage": "Blank Page",
|
"blankPage": "Blank Page",
|
||||||
"blog": "Blog",
|
"blog": "Indeks",
|
||||||
"invoice": "Invoice",
|
"invoice": "Invoice",
|
||||||
"pricing": "Pricing",
|
"pricing": "Pricing",
|
||||||
"profile": "Profile",
|
"profile": "Profile",
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,8 @@ export async function postCreateContest(data: any) {
|
||||||
const url = "contest";
|
const url = "contest";
|
||||||
return httpPostInterceptor(url, data);
|
return httpPostInterceptor(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function publishContest(id: any) {
|
||||||
|
const url = `contest/publish?id=${id}`;
|
||||||
|
return httpPostInterceptor(url);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue