"use client"; import SiteBreadcrumb from "@/components/site-breadcrumb"; import { Button } from "@/components/ui/button"; import { Calendar } from "@/components/ui/calendar"; import { Input } from "@/components/ui/input"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Link, useRouter } from "@/i18n/routing"; import { CalendarIcon } from "lucide-react"; import React, { useEffect, useRef, useState } from "react"; import { cn } from "@/lib/utils"; import { format } from "date-fns"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { error } from "@/config/swal"; import { getOnlyDate } from "@/utils/globals"; import { getMonthlyPlanList, savePlanning, } from "@/service/agenda-setting/agenda-setting"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import dynamic from "next/dynamic"; const FormSchema = z.object({ week: z.object({ from: z.date({ required_error: "Start date (from) is required", }), to: z.date({ required_error: "End date (to) is required", }), }), title: z.string({ required_error: "Required", }), detail: z.string({ required_error: "Required", }), parentId: z.string({ required_error: "Required", }), }); const CustomEditor = dynamic( () => { return import("@/components/editor/custom-editor"); }, { ssr: false } ); export default function CreateMonthly() { const MySwal = withReactContent(Swal); const router = useRouter(); const form = useForm>({ resolver: zodResolver(FormSchema), defaultValues: { detail: "", }, }); const [monthlyList, setMonthlyList] = useState(); const editor = useRef(null); const onSubmit = async (data: z.infer) => { if (form.getValues("detail") == "") { form.setError("detail", { type: "manual", message: "Required", }); } else { MySwal.fire({ title: "Simpan Data", text: "Apakah Anda yakin ingin menyimpan data ini?", icon: "warning", showCancelButton: true, cancelButtonColor: "#d33", confirmButtonColor: "#3085d6", confirmButtonText: "Simpan", }).then((result) => { if (result.isConfirmed) { save(data); } }); } }; const save = async (data: z.infer) => { const reqData = { planningTypeId: 2, title: data.title, time: "2", description: data.detail, username: "", date: `${getOnlyDate(data.week.from)} - ${getOnlyDate(data.week.to)}`, status: "Open", parentId: Number(data.parentId), }; console.log("req", reqData); const response = await savePlanning(reqData); close(); if (response?.error) { error(response?.message); return false; } MySwal.fire({ title: "Sukses", icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: "OK", }).then((result) => { if (result.isConfirmed) { router.push("/curator/task-plan/medsos-mediahub"); } }); }; useEffect(() => { getMonthlyPlanning(); }, []); async function getMonthlyPlanning() { const res = await getMonthlyPlanList(new Date().getDate(), 2); if (res?.data !== null) { const rawUser = res?.data?.data; const optionArr = rawUser.map((option: any) => ({ id: option.id, label: option.title, value: String(option.id), })); console.log("ssss", optionArr); setMonthlyList(optionArr); } } return (
Bulanan
Mingguan
Harian

Perencanaan MediaHub Mingguan

( Judul Perencanaan )} /> ( Pilih Tanggal )} /> ( Perencanaan Bulanan )} /> ( Detail Perencanaan )} />
); }