From c314be8cc81da6c8c65b2d74a7d463794009a069 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 13 Jan 2025 16:50:23 +0700 Subject: [PATCH] feat:faq fixing, tickting table fixing --- .../supervisor/faq/components/column.tsx | 117 +++++---- .../supervisor/faq/components/create.tsx | 202 +++++++++++++++ .../supervisor/faq/components/edit.tsx | 237 ++++++++++++++++++ .../supervisor/faq/components/table.tsx | 123 ++++----- .../(protected)/supervisor/faq/page.tsx | 31 +-- .../ticketing/components/columns.tsx | 41 ++- .../supervisor/ticketing/components/table.tsx | 107 +++++--- .../(protected)/supervisor/ticketing/page.tsx | 39 +-- .../management-user-internal-table.tsx | 15 -- 9 files changed, 669 insertions(+), 243 deletions(-) create mode 100644 app/[locale]/(protected)/supervisor/faq/components/create.tsx create mode 100644 app/[locale]/(protected)/supervisor/faq/components/edit.tsx diff --git a/app/[locale]/(protected)/supervisor/faq/components/column.tsx b/app/[locale]/(protected)/supervisor/faq/components/column.tsx index ee7f653b..42fb7831 100644 --- a/app/[locale]/(protected)/supervisor/faq/components/column.tsx +++ b/app/[locale]/(protected)/supervisor/faq/components/column.tsx @@ -1,76 +1,101 @@ - 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, -} from "lucide-react"; -import { cn } from "@/lib/utils"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuTrigger, - DropdownMenuItem, -} from "@/components/ui/dropdown-menu"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; +import { Link, useRouter } from "@/i18n/routing"; +import { error } from "@/config/swal"; +import { deleteCategory, deleteDataFAQ } from "@/service/settings/settings"; +import { useToast } from "@/components/ui/use-toast"; + +import { + Menubar, + MenubarContent, + MenubarMenu, + MenubarTrigger, +} from "@/components/ui/menubar"; +import { htmlToString } from "@/utils/globals"; +import EditSpvFAQModal from "./edit"; + const columns: ColumnDef[] = [ { accessorKey: "no", header: "No", cell: ({ row }) => {row.getValue("no")}, }, + { accessorKey: "question", - header: "Question", - cell: ({ row }) => {row.getValue("question")}, + header: "Pertanyaan", + cell: ({ row }) => ( + + {htmlToString(row.getValue("question"))} + + ), }, { accessorKey: "answer", header: "Answer", - cell: ({ row }) => {row.getValue("answer")}, + cell: ({ row }) => ( + + {htmlToString(row.getValue("answer"))} + + ), }, + { id: "actions", accessorKey: "action", header: "Actions", enableHiding: false, cell: ({ row }) => { + const router = useRouter(); + const { toast } = useToast(); + + const faqDelete = async (id: string) => { + const response = await deleteDataFAQ(id); + console.log(response); + if (response?.error) { + error(response.message); + return false; + } + toast({ + title: "Sukses", + description: "Berhasil Delete", + }); + router.push("/supervisor/faq?dataChange=true"); + }; return ( - - - - - - - - View - - - - Edit - - - - Delete - - - + + + + + + + + + + + faqDelete(row.original.id)} + className="hover:underline cursor-pointer hover:text-destructive" + > + Delete + + + + ); }, }, ]; -export default columns; \ No newline at end of file +export default columns; diff --git a/app/[locale]/(protected)/supervisor/faq/components/create.tsx b/app/[locale]/(protected)/supervisor/faq/components/create.tsx new file mode 100644 index 00000000..a5af317c --- /dev/null +++ b/app/[locale]/(protected)/supervisor/faq/components/create.tsx @@ -0,0 +1,202 @@ +"use client"; + +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { z } from "zod"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { useRouter } from "@/i18n/routing"; + +import { + getUserRoles, + postCategory, + postDataFAQ, +} from "@/service/settings/settings"; +import { useState } from "react"; +import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; +import { Textarea } from "@/components/ui/textarea"; +import { close, error, loading } from "@/config/swal"; +import { useToast } from "@/components/ui/use-toast"; +import { stringify } from "querystring"; + +const FormSchema = z.object({ + answer: z.string({ + required_error: "Required", + }), + question: z.string({ + required_error: "Required", + }), + publishTo: z.string({ + required_error: "Required", + }), + + // publishTo: z.array(z.string()).refine((value) => value.some((item) => item), { + // message: "Required", + // }), +}); + +const publishToList = [ + { + id: "mabes", + name: "Nasional", + }, + { + id: "polda", + name: "Polda", + }, + { + id: "satker", + name: "Satker", + }, + { + id: "internasional", + name: "Internasional", + }, +]; + +export default function CreateSpvFAQModal() { + const router = useRouter(); + const { toast } = useToast(); + + const [isOpen, setIsOpen] = useState(false); + + const form = useForm>({ + resolver: zodResolver(FormSchema), + defaultValues: { publishTo: "wilayah" }, + }); + + const target = form.watch("publishTo"); + const isAllTargetChecked = publishToList.every((item) => + target?.includes(item.id) + ); + + const onSubmit = async (data: z.infer) => { + const request = { + question: data.question, + answer: data.answer, + isInternational: data.publishTo === "wilayah" ? false : true, + isActive: true, + }; + + const response = await postDataFAQ(request); + close(); + if (response?.error) { + toast({ title: stringify(response.message), variant: "destructive" }); + return false; + } + toast({ + title: "Succes", + description: "FAQ berhasil dibuat", + }); + router.push("/supervisor/faq?dataChange=true"); + setIsOpen(false); + }; + + return ( + + + + + + + Tambah FAQ + +
+ + ( + + Wilayah Publish + + + + + + + Wilayah + + + + + + + Internasional + + + + + + + )} + /> + + ( + + Pertanyaan + +