2025-05-19 01:24:48 +00:00
|
|
|
"use client";
|
2024-12-10 18:04:03 +00:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
Accordion,
|
|
|
|
|
AccordionContent,
|
|
|
|
|
AccordionItem,
|
|
|
|
|
AccordionTrigger,
|
|
|
|
|
} from "@/components/ui/accordion";
|
2025-05-19 01:24:48 +00:00
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
|
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
2024-12-07 19:53:34 +00:00
|
|
|
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
2025-05-19 01:24:48 +00:00
|
|
|
import {
|
|
|
|
|
deleteKnowledgeBase,
|
|
|
|
|
getKnowledgeBaseCategoryList,
|
|
|
|
|
getKnowledgeBaseList,
|
|
|
|
|
} from "@/service/master/knowledge-base";
|
2024-12-10 18:04:03 +00:00
|
|
|
import React from "react";
|
2025-05-19 01:24:48 +00:00
|
|
|
import { Plus, Trash, Trash2 } from "lucide-react";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
2024-12-31 08:14:22 +00:00
|
|
|
import CreateCategory from "./create-category";
|
2025-05-19 01:24:48 +00:00
|
|
|
import withReactContent from "sweetalert2-react-content";
|
|
|
|
|
import Swal from "sweetalert2";
|
|
|
|
|
import { deleteMedia } from "@/service/content/content";
|
|
|
|
|
import { error } from "@/lib/swal";
|
2024-12-10 18:04:03 +00:00
|
|
|
|
|
|
|
|
const KnowledgeBase = () => {
|
2025-05-19 01:24:48 +00:00
|
|
|
const MySwal = withReactContent(Swal);
|
2024-12-10 18:04:03 +00:00
|
|
|
const [categories, setCategories] = React.useState<any>([]);
|
|
|
|
|
const [questions, setQuestions] = React.useState<any>([]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
fetchCategoryList();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
async function fetchCategoryList() {
|
|
|
|
|
const response = await getKnowledgeBaseCategoryList();
|
2025-01-05 00:44:55 +00:00
|
|
|
const data = response?.data?.data;
|
2024-12-10 18:04:03 +00:00
|
|
|
if (data) {
|
|
|
|
|
setCategories(data);
|
2025-05-19 01:24:48 +00:00
|
|
|
fetchQuestions(data[0]?.id);
|
2024-12-10 18:04:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fetchQuestions = async (id: number) => {
|
|
|
|
|
const response = await getKnowledgeBaseList(id);
|
2025-01-05 00:44:55 +00:00
|
|
|
const data = response?.data?.data;
|
2024-12-10 18:04:03 +00:00
|
|
|
if (data) {
|
|
|
|
|
setQuestions(data);
|
|
|
|
|
}
|
2025-05-19 01:24:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function doDelete(id: any) {
|
|
|
|
|
// loading();
|
|
|
|
|
const data = {
|
|
|
|
|
id,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await deleteKnowledgeBase(id);
|
|
|
|
|
|
|
|
|
|
if (response?.error) {
|
|
|
|
|
error(response.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
success();
|
2024-12-10 18:04:03 +00:00
|
|
|
}
|
2024-12-07 19:53:34 +00:00
|
|
|
|
2025-05-19 01:24:48 +00:00
|
|
|
function success() {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Sukses",
|
|
|
|
|
icon: "success",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "OK",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDeleteKnowlagde = (id: any) => {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Hapus Data",
|
|
|
|
|
text: "",
|
|
|
|
|
icon: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
cancelButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonColor: "#d33",
|
|
|
|
|
confirmButtonText: "Hapus",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
doDelete(id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-07 19:53:34 +00:00
|
|
|
return (
|
2025-05-19 01:24:48 +00:00
|
|
|
<div>
|
|
|
|
|
<SiteBreadcrumb />
|
|
|
|
|
<Tabs defaultValue={`category-0`}>
|
|
|
|
|
<div className="grid grid-cols-12 gap-6">
|
|
|
|
|
<Card className="lg:col-span-3 md:col-span-5 col-span-12 h-max">
|
|
|
|
|
<CardContent className=" p-6">
|
|
|
|
|
<TabsList className="md:flex-col gap-2 flex-wrap md:items-start justify-start">
|
|
|
|
|
<CreateCategory onSuccess={fetchCategoryList} />
|
|
|
|
|
{categories?.map((category: any, index: number) => (
|
|
|
|
|
<TabsTrigger
|
|
|
|
|
key={index}
|
|
|
|
|
value={`category-${index}`}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
fetchQuestions(category?.id);
|
|
|
|
|
}}
|
|
|
|
|
className="group data-[state=active]:bg-secondary data-[state=active]:text-default rounded-md px-6 py-3 w-full justify-between flex items-center"
|
|
|
|
|
>
|
|
|
|
|
{category?.name}
|
|
|
|
|
<div
|
|
|
|
|
className="right-2 top-2 hidden group-hover:inline-flex"
|
|
|
|
|
// onClick={() => deleteCategory(category?.id)}
|
|
|
|
|
>
|
|
|
|
|
<Trash size={20} className="text-red-500" />
|
|
|
|
|
</div>
|
|
|
|
|
</TabsTrigger>
|
|
|
|
|
))}
|
|
|
|
|
</TabsList>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
<div className="lg:col-span-9 md:col-span-7 col-span-12 mt-4 lg:mt-0">
|
|
|
|
|
{categories?.map((cateogry: any, index: number) => (
|
|
|
|
|
<TabsContent
|
|
|
|
|
key={index}
|
|
|
|
|
value={`category-${index}`}
|
|
|
|
|
className="mt-0"
|
|
|
|
|
>
|
|
|
|
|
<Accordion type="single" collapsible className="w-full">
|
|
|
|
|
{questions?.map((question: any) => (
|
|
|
|
|
<AccordionItem
|
|
|
|
|
key={question.id}
|
|
|
|
|
className="dark:bg-secondary bg-white"
|
|
|
|
|
value={question.id}
|
|
|
|
|
>
|
|
|
|
|
<AccordionTrigger className="flex items-center justify-between gap-4 dark:bg-secondary bg-white data-[state=open]:bg-default-200 data-[state=active]:text-default">
|
|
|
|
|
<div className="flex items-center justify-between w-full gap-4">
|
|
|
|
|
<span
|
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
|
__html: question.question,
|
|
|
|
|
}}
|
|
|
|
|
className="text-left"
|
|
|
|
|
/>
|
|
|
|
|
<Trash
|
|
|
|
|
size={20}
|
|
|
|
|
className="text-red-500 hover:cursor-pointer"
|
|
|
|
|
onClick={() => handleDeleteKnowlagde(question.id)}
|
|
|
|
|
/>
|
2025-01-01 14:10:58 +00:00
|
|
|
</div>
|
2025-05-19 01:24:48 +00:00
|
|
|
</AccordionTrigger>
|
|
|
|
|
<AccordionContent className="dark:bg-secondary bg-white">
|
|
|
|
|
{question.answer}
|
|
|
|
|
</AccordionContent>
|
|
|
|
|
</AccordionItem>
|
2024-12-10 18:04:03 +00:00
|
|
|
))}
|
2025-05-19 01:24:48 +00:00
|
|
|
</Accordion>
|
|
|
|
|
{questions?.length > 0 && (
|
|
|
|
|
<div className="flex gap-3">
|
|
|
|
|
<Button fullWidth size="md" variant="outline">
|
|
|
|
|
<Plus className="w-6 h-6 me-1.5" />
|
|
|
|
|
Import
|
|
|
|
|
</Button>
|
|
|
|
|
<Button fullWidth size="md">
|
|
|
|
|
<Plus className="w-6 h-6 me-1.5" />
|
|
|
|
|
Add Question
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</TabsContent>
|
|
|
|
|
))}
|
2024-12-07 19:53:34 +00:00
|
|
|
</div>
|
2025-05-19 01:24:48 +00:00
|
|
|
</div>
|
|
|
|
|
</Tabs>
|
|
|
|
|
</div>
|
2024-12-07 19:53:34 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-10 18:04:03 +00:00
|
|
|
export default KnowledgeBase;
|