fix: schedule live report
This commit is contained in:
parent
c99e1a5c7d
commit
78d1fc0d93
|
|
@ -75,6 +75,7 @@ interface Detail {
|
||||||
youtubeUrl: string;
|
youtubeUrl: string;
|
||||||
needApprovalFrom: number;
|
needApprovalFrom: number;
|
||||||
uploadedById: number;
|
uploadedById: number;
|
||||||
|
statusId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FormDetailLiveReport() {
|
export default function FormDetailLiveReport() {
|
||||||
|
|
@ -176,21 +177,68 @@ export default function FormDetailLiveReport() {
|
||||||
statusId: Number(status),
|
statusId: Number(status),
|
||||||
message: description,
|
message: description,
|
||||||
isPublish: status === "2",
|
isPublish: status === "2",
|
||||||
placements: schedulePlacements?.filter((val) => val != "all")?.join(","),
|
placements: schedulePlacements?.filter((val) => val !== "all")?.join(","),
|
||||||
};
|
};
|
||||||
|
|
||||||
loading();
|
loading();
|
||||||
const response = await postApprovalSchedule(data);
|
const response = await postApprovalSchedule(data);
|
||||||
close();
|
close();
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
|
|
||||||
if (response?.error) {
|
if (response?.error) {
|
||||||
error(response?.message);
|
error(response?.message || "Gagal menyimpan data");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
initState();
|
|
||||||
return false;
|
// ✅ update UI lokal (optimistic)
|
||||||
|
setDetail((prev) =>
|
||||||
|
prev
|
||||||
|
? {
|
||||||
|
...prev,
|
||||||
|
statusId: Number(status),
|
||||||
|
}
|
||||||
|
: prev,
|
||||||
|
);
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
icon: "success",
|
||||||
|
title: "Berhasil",
|
||||||
|
text:
|
||||||
|
status === "2"
|
||||||
|
? "Jadwal berhasil disetujui"
|
||||||
|
: status === "3"
|
||||||
|
? "Jadwal dikembalikan untuk revisi"
|
||||||
|
: "Jadwal berhasil ditolak",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
router.push("/contributor/schedule/live-report");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async function save() {
|
||||||
|
// const data = {
|
||||||
|
// scheduleId: Number(id),
|
||||||
|
// statusId: Number(status),
|
||||||
|
// message: description,
|
||||||
|
// isPublish: status === "2",
|
||||||
|
// placements: schedulePlacements?.filter((val) => val != "all")?.join(","),
|
||||||
|
// };
|
||||||
|
|
||||||
|
// loading();
|
||||||
|
// const response = await postApprovalSchedule(data);
|
||||||
|
// close();
|
||||||
|
// setModalOpen(false);
|
||||||
|
|
||||||
|
// if (response?.error) {
|
||||||
|
// error(response?.message);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// initState();
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
const [schedulePlacements, setSchedulePlacements] = useState<string[]>([]);
|
const [schedulePlacements, setSchedulePlacements] = useState<string[]>([]);
|
||||||
|
|
||||||
const setupPlacement = (placement: string, checked: boolean) => {
|
const setupPlacement = (placement: string, checked: boolean) => {
|
||||||
|
|
@ -224,6 +272,15 @@ export default function FormDetailLiveReport() {
|
||||||
setSchedulePlacements(temp);
|
setSchedulePlacements(temp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isCreator = Number(detail?.uploadedById) === Number(userId);
|
||||||
|
|
||||||
|
const isApprover =
|
||||||
|
Number(detail?.needApprovalFrom) === Number(userLevelId) &&
|
||||||
|
Number(userLevelNumber) < 2;
|
||||||
|
|
||||||
|
const isAlreadyProcessed =
|
||||||
|
detail?.statusId === 2 || detail?.statusId === 3 || detail?.statusId === 4;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col lg:flex-row gap-2">
|
<div className="flex flex-col lg:flex-row gap-2">
|
||||||
<Card className="w-full lg:w-9/12">
|
<Card className="w-full lg:w-9/12">
|
||||||
|
|
@ -284,7 +341,7 @@ export default function FormDetailLiveReport() {
|
||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-[280px] lg:w-[250px] justify-start text-left font-normal px-0 md:px-0 lg:px-4",
|
"w-[280px] lg:w-[250px] justify-start text-left font-normal px-0 md:px-0 lg:px-4",
|
||||||
!date && "text-muted-foreground"
|
!date && "text-muted-foreground",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<CalendarIcon size={15} className="mr-3" />
|
<CalendarIcon size={15} className="mr-3" />
|
||||||
|
|
@ -494,7 +551,38 @@ export default function FormDetailLiveReport() {
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
{Number(detail?.needApprovalFrom) == Number(userLevelId) &&
|
{(isApprover || isCreator) && !isAlreadyProcessed && (
|
||||||
|
<div className="flex flex-col gap-2 p-3">
|
||||||
|
<Button
|
||||||
|
onClick={() => actionApproval("2")}
|
||||||
|
color="primary"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:check" className="mr-3" />
|
||||||
|
{t("accept", { defaultValue: "Accept" })}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() => actionApproval("3")}
|
||||||
|
className="bg-orange-400 hover:bg-orange-300"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:comment-o" className="mr-3" />
|
||||||
|
{t("revision", { defaultValue: "Revision" })}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() => actionApproval("4")}
|
||||||
|
color="destructive"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:times" className="mr-3" />
|
||||||
|
{t("reject", { defaultValue: "Reject" })}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* {Number(detail?.needApprovalFrom) == Number(userLevelId) &&
|
||||||
Number(userLevelNumber) < 2 ? (
|
Number(userLevelNumber) < 2 ? (
|
||||||
Number(detail?.uploadedById) == Number(userId) ? (
|
Number(detail?.uploadedById) == Number(userId) ? (
|
||||||
""
|
""
|
||||||
|
|
@ -527,13 +615,15 @@ export default function FormDetailLiveReport() {
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
)}
|
)} */}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
|
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
|
||||||
<DialogContent className="overflow-y-auto">
|
<DialogContent className="overflow-y-auto">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>{t("leave-comment", { defaultValue: "Leave Comment" })}</DialogTitle>
|
<DialogTitle>
|
||||||
|
{t("leave-comment", { defaultValue: "Leave Comment" })}
|
||||||
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="flex flex-col gap-1 text-sm">
|
<div className="flex flex-col gap-1 text-sm">
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -544,15 +634,15 @@ export default function FormDetailLiveReport() {
|
||||||
status === "2"
|
status === "2"
|
||||||
? "text-primary"
|
? "text-primary"
|
||||||
: status === "3"
|
: status === "3"
|
||||||
? "text-warning"
|
? "text-warning"
|
||||||
: "text-destructive"
|
: "text-destructive"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{status === "2"
|
{status === "2"
|
||||||
? "Disetujui"
|
? "Disetujui"
|
||||||
: status === "3"
|
: status === "3"
|
||||||
? "Revisi"
|
? "Revisi"
|
||||||
: "Ditolak"}
|
: "Ditolak"}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
{status === "2" && (
|
{status === "2" && (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue