QUDO-365, QUDO-364, QUDO-362, QUDO-363

This commit is contained in:
Sabda Yagra 2025-08-26 23:13:48 +07:00
parent 8ba5499378
commit bbed0c29c1
3 changed files with 33 additions and 38 deletions

View File

@ -101,10 +101,8 @@ const useTableColumns = () => {
enableHiding: false,
cell: ({ row }) => {
const MySwal = withReactContent(Swal);
const levelNumber = Number(getCookiesDecrypt("ulne")); // 1 = Mabes, 2 = Polda
const calendarOwnerLevel = Number(row.original.assignedToLevel); // dari API
const calendarOwner = row.original.assignedTo; // ID unit Polda/Mabes dari API
const myUnit = getCookiesDecrypt("unitId"); // misal ID unit Polda login
const levelNumber = Number(getCookiesDecrypt("ulne"));
const userId = Number(getCookiesDecrypt("uie"));
async function doDelete(id: any) {
const response = await deleteCalendar(id);
@ -143,29 +141,6 @@ const useTableColumns = () => {
}
});
};
// === RULE AKSI ===
let canEdit = false;
let canDelete = false;
const canView = true;
if (levelNumber === 1) {
// Mabes -> bebas
canEdit = true;
canDelete = true;
} else if (levelNumber === 2) {
// Polda
if (calendarOwnerLevel === 1) {
// kalender Mabes -> hanya view
canEdit = false;
canDelete = false;
} else if (calendarOwnerLevel === 2 && calendarOwner === myUnit) {
// kalender polda sendiri -> bisa edit/delete
canEdit = true;
canDelete = true;
}
}
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
@ -178,7 +153,7 @@ const useTableColumns = () => {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="p-0" align="end">
{canView && (
<Link
href={`/contributor/schedule/calendar-polri/detail/${row.original.id}`}
>
@ -187,9 +162,9 @@ const useTableColumns = () => {
Detail
</DropdownMenuItem>
</Link>
)}
{canEdit && (
{row.original.createdById === userId && (
<Link
href={`/contributor/schedule/calendar-polri/update/${row.original.id}`}
>
@ -200,7 +175,7 @@ const useTableColumns = () => {
</Link>
)}
{canDelete && (
{row.original.createdById === userId && (
<DropdownMenuItem
onClick={() => handleDeleteCalendars(row.original.id)}
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
@ -214,7 +189,7 @@ const useTableColumns = () => {
);
},
},
// {
// id: "actions",
// accessorKey: "action",

View File

@ -27,7 +27,7 @@ import {
saveMediaBlastCampaign,
} from "@/service/broadcast/broadcast";
import { error } from "@/config/swal";
import { useRouter } from "@/i18n/routing";
import { Link, useRouter } from "@/i18n/routing";
import { useEffect, useRef, useState } from "react";
import { useParams } from "next/navigation";
@ -78,6 +78,11 @@ const FormSchema = z.object({
}),
});
interface Campaign {
id: string;
name: string;
}
export default function ContentBlast(props: { type: string }) {
const editor = useRef(null);
const id = useParams()?.id;
@ -85,7 +90,7 @@ export default function ContentBlast(props: { type: string }) {
const router = useRouter();
const { type } = props;
const [dataSelectCampaign, setDataSelectCampaign] = useState([]);
const [dataSelectCampaign, setDataSelectCampaign] = useState<Campaign[]>([]);
const [openModal, setOpenModal] = useState(false);
const form = useForm<z.infer<typeof FormSchema>>({
@ -295,9 +300,16 @@ export default function ContentBlast(props: { type: string }) {
Untuk melihat Email Terkirim silahkan cek menu Sent!
</div>
<DialogFooter className="flex justify-center">
<Button type="button" color="success">
Menu "Sent"
</Button>
<Link
href={`/admin/broadcast/campaign-list/detail/${
form.getValues("selected")[0]?.id
}`}
>
<Button type="button" color="success">
Menu "Sent"
</Button>
</Link>
<Button
type="button"
onClick={() => router.push("/admin/broadcast")}

View File

@ -95,11 +95,19 @@ export function CalendarPolriAddDetail() {
const details = response?.data?.data;
setDetail(details);
if (details) {
// if (details) {
// setDate({
// from: parseISO(details.startDate),
// to: parseISO(details.endDate),
// });
// }
if (details?.startDate && details?.endDate) {
setDate({
from: parseISO(details.startDate),
to: parseISO(details.endDate),
});
} else {
// atau biarkan kosong sesuai kebutuhan
}
if (details?.assignedTo) {