diff --git a/app/[locale]/(protected)/contributor/schedule/live-report/component/columns.tsx b/app/[locale]/(protected)/contributor/schedule/live-report/component/columns.tsx index 1a3a3ae3..329d7e6a 100644 --- a/app/[locale]/(protected)/contributor/schedule/live-report/component/columns.tsx +++ b/app/[locale]/(protected)/contributor/schedule/live-report/component/columns.tsx @@ -13,8 +13,12 @@ import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Link } from "@/components/navigation"; import { useTranslations } from "next-intl"; +import withReactContent from "sweetalert2-react-content"; +import Swal from "sweetalert2"; +import { deleteSchedule } from "@/service/schedule/schedule"; +import { error } from "@/config/swal"; -const useTableColumns = () => { +const useTableColumns = (props: { selectedTypeSchedule: string }) => { const t = useTranslations("Table"); // Panggil di dalam hook const columns: ColumnDef[] = [ @@ -138,6 +142,33 @@ const useTableColumns = () => { header: t("action"), enableHiding: false, cell: ({ row }) => { + const MySwal = withReactContent(Swal); + + async function doDelete(id: any) { + // loading(); + + const response = await deleteSchedule(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(); + } + }); + } + return ( @@ -151,7 +182,7 @@ const useTableColumns = () => { @@ -159,14 +190,17 @@ const useTableColumns = () => { Edit - + doDelete(row.original.id)} + className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + > Delete diff --git a/app/[locale]/(protected)/contributor/schedule/live-report/component/live-report-table.tsx b/app/[locale]/(protected)/contributor/schedule/live-report/component/live-report-table.tsx index cbe89c77..73e5c839 100644 --- a/app/[locale]/(protected)/contributor/schedule/live-report/component/live-report-table.tsx +++ b/app/[locale]/(protected)/contributor/schedule/live-report/component/live-report-table.tsx @@ -91,7 +91,7 @@ const LiveReportTable = () => { const [search, setSearch] = React.useState(""); const [statusFilter, setStatusFilter] = React.useState([]); const [selectedType, setSelectedType] = React.useState("1"); - const columns = useTableColumns(); + const columns = useTableColumns({ selectedTypeSchedule: selectedType }); const table = useReactTable({ data: dataTable, columns, @@ -197,11 +197,11 @@ const LiveReportTable = () => { /> -
-
+
+
- @@ -226,12 +226,12 @@ const LiveReportTable = () => {
-
+
-
+
- @@ -287,10 +291,14 @@ const LiveReportTable = () => {
-
+
- diff --git a/app/[locale]/(protected)/contributor/schedule/live-report/detail/[id]/page.tsx b/app/[locale]/(protected)/contributor/schedule/live-report/detail/[id]/page.tsx index 273f3b55..95dbefb2 100644 --- a/app/[locale]/(protected)/contributor/schedule/live-report/detail/[id]/page.tsx +++ b/app/[locale]/(protected)/contributor/schedule/live-report/detail/[id]/page.tsx @@ -1,11 +1,5 @@ "use client"; -import { Card, CardContent } from "@/components/ui/card"; import SiteBreadcrumb from "@/components/site-breadcrumb"; -import FormTask from "@/components/form/task/task-form"; -import FormPressConference from "@/components/form/schedule/press-conference-form"; -import FormDetailPressConference from "@/components/form/schedule/press-conference-detail-form"; -import { useParams } from "next/navigation"; -import { id } from "date-fns/locale"; import FormDetailLiveReport from "@/components/form/schedule/live-report-detail-form"; const LiveReportDetailPage = () => { diff --git a/app/[locale]/(protected)/contributor/schedule/live-report/update/[id]/page.tsx b/app/[locale]/(protected)/contributor/schedule/live-report/update/[id]/page.tsx index 109a315f..b62ec487 100644 --- a/app/[locale]/(protected)/contributor/schedule/live-report/update/[id]/page.tsx +++ b/app/[locale]/(protected)/contributor/schedule/live-report/update/[id]/page.tsx @@ -1,12 +1,5 @@ "use client"; -import { Card, CardContent } from "@/components/ui/card"; import SiteBreadcrumb from "@/components/site-breadcrumb"; -import FormTask from "@/components/form/task/task-form"; -import FormPressConference from "@/components/form/schedule/press-conference-form"; -import FormDetailPressConference from "@/components/form/schedule/press-conference-detail-form"; -import { useParams } from "next/navigation"; -import { id } from "date-fns/locale"; -import FormUpdatePressConference from "@/components/form/schedule/press-conference-update-form"; import FormUpdateLiveReport from "@/components/form/schedule/live-report-update-form"; const LiveReportUpdatePage = () => { diff --git a/components/form/schedule/live-report-detail-form.tsx b/components/form/schedule/live-report-detail-form.tsx index 2bd4d714..025342d8 100644 --- a/components/form/schedule/live-report-detail-form.tsx +++ b/components/form/schedule/live-report-detail-form.tsx @@ -16,7 +16,7 @@ import { PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; -import { cn } from "@/lib/utils"; +import { cn, getCookiesDecrypt } from "@/lib/utils"; import { CalendarIcon, Clock1, Locate, MapPin, User2 } from "lucide-react"; import { Calendar } from "@/components/ui/calendar"; import { addDays, format, parseISO, setDate } from "date-fns"; @@ -32,6 +32,7 @@ import { detailSchedule, listScheduleNext, listScheduleToday, + postApprovalSchedule, postSchedule, } from "@/service/schedule/schedule"; import { @@ -42,6 +43,18 @@ import { } from "@/components/ui/accordion"; import { formatDateToIndonesian } from "@/utils/globals"; import { formatDate } from "@fullcalendar/core/index.js"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { useTranslations } from "next-intl"; +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Badge } from "@/components/ui/badge"; +import { close } from "@/config/swal"; +import { Checkbox } from "@/components/ui/checkbox"; const taskSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -58,14 +71,23 @@ interface Detail { speakerName: string; addressLat: number; addressLong: number; + isYoutube: boolean; + youtubeUrl: string; + needApprovalFrom: number; + uploadedById: number; } export default function FormDetailLiveReport() { const { id } = useParams() as { id: string }; - console.log(id); const router = useRouter(); - const [isLiveStreamingEnabled, setIsLiveStreamingEnabled] = useState(false); type TaskSchema = z.infer; + + const userId = getCookiesDecrypt("uie"); + const userLevelId = getCookiesDecrypt("ulie"); + const roleId = getCookiesDecrypt("urie"); + const userLevelNumber = getCookiesDecrypt("ulne"); + + console.log("cookie", userId, userLevelId, roleId, userLevelNumber); const [startTime, setStartTime] = useState("08:00"); const [endTime, setEndTime] = useState("09:00"); const [date, setDate] = useState(); @@ -75,6 +97,12 @@ export default function FormDetailLiveReport() { const [detail, setDetail] = useState(); const [refresh, setRefresh] = useState(false); + const t = useTranslations("Form"); + + const [status, setStatus] = useState(""); + const [description, setDescription] = useState(""); + const [modalOpen, setModalOpen] = useState(false); + const { control, handleSubmit, @@ -82,9 +110,6 @@ export default function FormDetailLiveReport() { formState: { errors }, } = useForm({ resolver: zodResolver(taskSchema), - defaultValues: { - location: "", - }, }); async function getDataByDate() { @@ -98,27 +123,30 @@ export default function FormDetailLiveReport() { } useEffect(() => { - async function initState() { - if (id) { - const response = await detailSchedule(id); - const details = response?.data?.data; - - setDetail(details); - if (details) { - setDate({ - from: parseISO(details.startDate), - to: parseISO(details.endDate), - }); - } - if (details) { - setStartTime(details.startTime); - setEndTime(details.endTime); - } - getDataByDate(); - } - } initState(); - }, [refresh, setValue]); + }, [refresh]); + + async function initState() { + if (id) { + loading(); + const response = await detailSchedule(id); + close(); + const details = response?.data?.data; + + setDetail(details); + if (details) { + setDate({ + from: parseISO(details.startDate), + to: parseISO(details.endDate), + }); + } + if (details) { + setStartTime(details.startTime); + setEndTime(details.endTime); + } + getDataByDate(); + } + } const handleStartTime = (e: React.ChangeEvent) => { setStartTime(e.target.value); @@ -128,6 +156,75 @@ export default function FormDetailLiveReport() { setEndTime(e.target.value); }; + const actionApproval = (e: string) => { + setStatus(e); + setDescription(""); + setModalOpen(true); + }; + + const submit = async () => { + if ( + description?.length > 1 && + (Number(status) == 3 || Number(status) == 2 || Number(status) == 4) + ) { + save(); + } + }; + + 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([]); + + const setupPlacement = (placement: string, checked: boolean) => { + let temp = [...schedulePlacements]; + if (checked) { + if (placement === "all") { + temp = ["all", "mabes", "polda", "international"]; + } else { + const now = temp; + now.push(placement); + if (now.length === 3 && !now.includes("all")) { + now.push("all"); + } + temp = now; + } + } else { + if (placement === "all") { + temp = []; + } else { + const now = temp.filter((a) => a !== placement); + console.log("now", now); + temp = now; + if (now.length === 3 && now.includes("all")) { + const newData = now.filter((b) => b !== "all"); + temp = newData; + } + } + } + + console.log("temp"); + setSchedulePlacements(temp); + }; + return (
@@ -157,39 +254,24 @@ export default function FormDetailLiveReport() {
-

Aktifkan fitur live streaming

+

Aktifkan fitur live streaming

- setIsLiveStreamingEnabled(checked) - } />
- {isLiveStreamingEnabled && ( + {detail.isYoutube && (
- ( - - )} + - {errors.title?.message && ( -

- {errors.title.message} -

- )}
)} @@ -332,12 +414,6 @@ export default function FormDetailLiveReport() { ) : ( "" )} - {/* Submit Button -
- -
*/}
@@ -349,13 +425,31 @@ export default function FormDetailLiveReport() { {todayList?.length > 0 ? ( -
    +
    {todayList.map((item: any, index) => ( -
  • - {item.name} -
  • +
    +
  • {item.title}
  • +

    + + {formatDate(item?.startDate)}- + {formatDate(item?.endDate)} +

    +

    + + {item?.startTime}-{item?.endTime} +

    +

    + + {item?.address} +

    +

    Disampaikan oleh:

    +

    + + {item?.speakerTitle} {item?.speakerName} +

    +
    ))} -
+
) : (

Tidak ada jadwal hari ini

)} @@ -373,26 +467,25 @@ export default function FormDetailLiveReport() { {nextDayList.map((item: any, index) => (
  • {item.title}
  • -

    +

    {formatDate(item?.startDate)}- {formatDate(item?.endDate)}

    -

    +

    {item?.startTime}-{item?.endTime}

    -

    - +

    + {item?.address}

    Disampaikan oleh:

    -

    - +

    + {item?.speakerTitle} {item?.speakerName}

    - //

    {item.startDate}

    ))}
    ) : ( @@ -401,7 +494,162 @@ export default function FormDetailLiveReport() { + + {Number(detail?.needApprovalFrom) == Number(userLevelId) && + Number(userLevelNumber) < 2 ? ( + Number(detail?.uploadedById) == Number(userId) ? ( + "" + ) : ( +
    + + + +
    + ) + ) : ( + "" + )} + + + + + {t("leave-comment")} + +
    +

    + {" "} + Status:{" "} + + {status === "2" + ? "Disetujui" + : status === "3" + ? "Revisi" + : "Ditolak"} + +

    + {status === "2" && ( +
    +
    + setupPlacement("all", Boolean(e))} + /> + +
    +
    + setupPlacement("mabes", Boolean(e))} + /> + +
    +
    + setupPlacement("polda", Boolean(e))} + /> + +
    + +
    + + setupPlacement("international", Boolean(e)) + } + /> + +
    +
    + )} +

    Deskripsi:

    +
    +