diff --git a/app/[locale]/(protected)/blog/table-blog/blog-table.tsx b/app/[locale]/(protected)/blog/table-blog/blog-table.tsx index b7ea563b..9a0426a8 100644 --- a/app/[locale]/(protected)/blog/table-blog/blog-table.tsx +++ b/app/[locale]/(protected)/blog/table-blog/blog-table.tsx @@ -46,17 +46,33 @@ import { } from "@/components/ui/dropdown-menu"; export type CompanyData = { + no: number; title: string; category: string; - date: string; - tag: string; - status: string; + createdAt: string; + tags: string; + statusName: string; }; import { data } from "./data"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; +import { listTask } from "@/service/ppid-categories-services"; +import { paginationBlog } from "@/service/blog/blog"; export const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => ( +
+
+

+ {row.getValue("no")} +

+
+
+ ), + }, { accessorKey: "title", header: "Judul", @@ -71,33 +87,33 @@ export const columns: ColumnDef[] = [ ), }, { - accessorKey: "category", + accessorKey: "categoryName", header: "Kategori ", cell: ({ row }) => ( - {row.getValue("category")} + {row.getValue("categoryName")} ), }, { - accessorKey: "date", + accessorKey: "createdAt", header: "Tanggal Unggah ", cell: ({ row }) => ( - {row.getValue("date")} + {row.getValue("createdAt")} ), }, { - accessorKey: "tag", + accessorKey: "tags", header: "Tag ", cell: ({ row }) => ( - {row.getValue("tag")} + {row.getValue("tags")} ), }, { - accessorKey: "status", + accessorKey: "statusName", header: "Status", cell: ({ row }) => { return ( - {row.getValue("status")} + {row.getValue("statusName")} ); }, @@ -140,6 +156,7 @@ export const columns: ColumnDef[] = [ ]; const BlogTable = () => { + const [blogTable, setBlogTable] = React.useState([]); const [sorting, setSorting] = React.useState([]); const [columnFilters, setColumnFilters] = React.useState( [] @@ -148,12 +165,15 @@ const BlogTable = () => { React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); const [pagination, setPagination] = React.useState({ - pageIndex: 0, - pageSize: 6, + pageIndex: 0, // Halaman pertama + pageSize: 10, // Jumlah baris per halaman }); + const [page, setPage] = React.useState(1); // Halaman aktif + const [totalPage, setTotalPage] = React.useState(1); // Total halaman + const [limit, setLimit] = React.useState(10); const table = useReactTable({ - data, + data: blogTable, columns, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, @@ -173,6 +193,30 @@ const BlogTable = () => { }, }); + React.useEffect(() => { + initState(); + }, [page, limit]); + + async function initState() { + try { + const res = await paginationBlog(limit, page); + const data = res.data.data.content.map((item: any, index: number) => ({ + no: (page - 1) * limit + index + 1, // Hitung nomor urut + title: item.title, + categoryName: item.categoryName, + tags: item.tags, + assignmentType: item.assignmentType?.name || "-", + createdAt: item.createdAt, + statusName: item.statusName, + })); + + setBlogTable(data); + setTotalPage(res.data.totalPages); // Total halaman + } catch (error) { + console.error("Error fetching tasks:", error); + } + } + return (
diff --git a/app/[locale]/(protected)/content/image/create/page.tsx b/app/[locale]/(protected)/content/image/create/page.tsx new file mode 100644 index 00000000..6b169ce1 --- /dev/null +++ b/app/[locale]/(protected)/content/image/create/page.tsx @@ -0,0 +1,17 @@ +import { Card, CardContent } from "@/components/ui/card"; +import SiteBreadcrumb from "@/components/site-breadcrumb"; +import FormTask from "@/components/form/task/task-form"; +import FormImage from "@/components/form/content/create-form"; + +const ImageCreatePage = async () => { + return ( +
+ +
+ +
+
+ ); +}; + +export default ImageCreatePage; diff --git a/app/[locale]/(protected)/content/image/page.tsx b/app/[locale]/(protected)/content/image/page.tsx index 070ef5d1..bbbd5df8 100644 --- a/app/[locale]/(protected)/content/image/page.tsx +++ b/app/[locale]/(protected)/content/image/page.tsx @@ -5,6 +5,7 @@ import TableImage from "./table-image"; import { Newspaper, NewspaperIcon, UploadIcon } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Icon } from "@iconify/react/dist/iconify.js"; +import { Link } from "@/components/navigation"; const ReactTableImagePage = () => { return ( @@ -54,10 +55,12 @@ const ReactTableImagePage = () => { Konten Foto
- + + + +
+ ); + }, + }, + { + id: "actions", + accessorKey: "action", + header: "Actions", + enableHiding: false, + cell: ({ row }) => { + return ( + + + + + + + + + View + + + + + Delete + + + + ); + }, + }, +]; const TableImage = () => { + const [imageTable, setImageTable] = React.useState([]); const [sorting, setSorting] = React.useState([]); const [columnFilters, setColumnFilters] = React.useState( [] @@ -35,9 +205,29 @@ const TableImage = () => { const [columnVisibility, setColumnVisibility] = React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); + const [pagination, setPagination] = React.useState({ + pageIndex: 0, // Halaman pertama + pageSize: 10, // Jumlah baris per halaman + }); + const [page, setPage] = React.useState(1); // Halaman aktif + const [totalPage, setTotalPage] = React.useState(1); // Total halaman + const [limit, setLimit] = React.useState(10); // Jumlah baris per halaman + const [search, setSearch] = React.useState(title); + const userId = getCookiesDecrypt("uie"); + const userLevelId = getCookiesDecrypt("ulie"); + + const [categories, setCategories] = React.useState(); + const [categoryFilter, setCategoryFilter] = React.useState([]); + const [statusFilter, setStatusFilter] = React.useState([]); + const [startDateString, setStartDateString] = React.useState(""); + const [endDateString, setEndDateString] = React.useState(""); + const [filterByCreator, setFilterByCreator] = React.useState(""); + const [filterBySource, setFilterBySource] = React.useState(""); + + const roleId = getCookiesDecrypt("urie"); const table = useReactTable({ - data, + data: imageTable, columns, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, @@ -55,6 +245,48 @@ const TableImage = () => { }, }); + React.useEffect(() => { + initState(); + }, [page, limit]); + + async function initState() { + try { + const isForSelf = Number(roleId) == 4; + const res = await listDataImage( + limit, + page, + isForSelf, + !isForSelf, + categoryFilter?.sort().join(","), + statusFilter?.sort().join(",").includes("1") + ? "1,2" + : statusFilter?.sort().join(","), + statusFilter?.sort().join(",").includes("1") ? userLevelId : "", + filterByCreator, + filterBySource, + startDateString, + endDateString + ); + const data = res.data.data.content.map((item: any, index: number) => ({ + no: (page - 1) * limit + index + 1, // Hitung nomor urut + title: item.title, + categoryName: item.categoryName, + creatorGroup: item.creatorGroup, + assignmentType: item.assignmentType?.name || "-", + createdAt: item.createdAt, + isDone: item.isDone, + publishedOn: item.publishedOn, + isPublish: item.isPublish, + isPublishOnPolda: item.isPublishOnPolda, + })); + + setImageTable(data); + setTotalPage(res.data.totalPages); // Total halaman + } catch (error) { + console.error("Error fetching tasks:", error); + } + } + return (
@@ -72,22 +304,20 @@ const TableImage = () => {
- +
{table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => { - return ( - - {header.isPlaceholder - ? null - : flexRender( - header.column.columnDef.header, - header.getContext() - )} - - ); - })} + + {headerGroup.headers.map((header) => ( + + {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext() + )} + + ))} ))} @@ -97,6 +327,7 @@ const TableImage = () => { {row.getVisibleCells().map((cell) => ( @@ -114,7 +345,41 @@ const TableImage = () => { )}
- +
+ + {table.getPageOptions().map((page, pageIndex) => ( + + ))} + +
); }; diff --git a/app/[locale]/(protected)/planning/mediahub/table-mediahub/mediahub-table.tsx b/app/[locale]/(protected)/planning/mediahub/table-mediahub/mediahub-table.tsx index 1ba02331..506ea04d 100644 --- a/app/[locale]/(protected)/planning/mediahub/table-mediahub/mediahub-table.tsx +++ b/app/[locale]/(protected)/planning/mediahub/table-mediahub/mediahub-table.tsx @@ -46,15 +46,32 @@ import { } from "@/components/ui/dropdown-menu"; export type CompanyData = { + no: number; title: string; date: string; - status: string; + isActive: boolean; }; import { data } from "./data"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; +import { listTask } from "@/service/ppid-categories-services"; +import page from "../page"; +import { getPlanningSentPagination } from "@/service/planning/planning"; export const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => ( +
+
+

+ {row.getValue("no")} +

+
+
+ ), + }, { accessorKey: "title", header: "Judul", @@ -69,20 +86,26 @@ export const columns: ColumnDef[] = [ ), }, { - accessorKey: "date", + accessorKey: "createdAt", header: "Tanggal Unggah ", cell: ({ row }) => ( - {row.getValue("date")} + {row.getValue("createdAt")} ), }, { - accessorKey: "status", + accessorKey: "isActive", header: "Status", cell: ({ row }) => { + const isActive = row.getValue("isActive"); + console.log("isActive value:", isActive); // TypeScript type is inferred correctly return ( - - {row.getValue("status")} - +
+ {isActive ? ( + Terkirim + ) : ( + Belum Terkirim + )} +
); }, }, @@ -124,6 +147,7 @@ export const columns: ColumnDef[] = [ ]; const MediahubTable = () => { + const [mediahubTable, setMediahubTable] = React.useState([]); const [sorting, setSorting] = React.useState([]); const [columnFilters, setColumnFilters] = React.useState( [] @@ -132,12 +156,16 @@ const MediahubTable = () => { React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); const [pagination, setPagination] = React.useState({ - pageIndex: 0, - pageSize: 6, + pageIndex: 0, // Halaman pertama + pageSize: 10, // Jumlah baris per halaman }); + const [page, setPage] = React.useState(1); // Halaman aktif + const [totalPage, setTotalPage] = React.useState(1); // Total halaman + const [limit, setLimit] = React.useState(10); // Jumlah baris per halaman + // const [search, setSearch] = React.useState(title); const table = useReactTable({ - data, + data: mediahubTable, columns, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, @@ -157,6 +185,27 @@ const MediahubTable = () => { }, }); + React.useEffect(() => { + initState(); + }, [page, limit]); + + async function initState() { + try { + const res = await getPlanningSentPagination(limit, page, 1); + const data = res.data.data.content.map((item: any, index: number) => ({ + no: (page - 1) * limit + index + 1, // Hitung nomor urut + title: item.title, + createdAt: item.createdAt, + isActive: item.isActive === true, + })); + + setMediahubTable(data); + setTotalPage(res.data.totalPages); // Total halaman + } catch (error) { + console.error("Error fetching tasks:", error); + } + } + return (
diff --git a/app/[locale]/(protected)/planning/medsos-mediahub/table-medsos/medsos-table.tsx b/app/[locale]/(protected)/planning/medsos-mediahub/table-medsos/medsos-table.tsx index c6dbda3d..89e53e08 100644 --- a/app/[locale]/(protected)/planning/medsos-mediahub/table-medsos/medsos-table.tsx +++ b/app/[locale]/(protected)/planning/medsos-mediahub/table-medsos/medsos-table.tsx @@ -46,15 +46,32 @@ import { } from "@/components/ui/dropdown-menu"; export type CompanyData = { + no: number; title: string; date: string; - status: string; + isActive: boolean; }; import { data } from "./data"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; +import { listTask } from "@/service/ppid-categories-services"; +import page from "../page"; +import { getPlanningSentPagination } from "@/service/planning/planning"; export const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => ( +
+
+

+ {row.getValue("no")} +

+
+
+ ), + }, { accessorKey: "title", header: "Judul", @@ -69,20 +86,26 @@ export const columns: ColumnDef[] = [ ), }, { - accessorKey: "date", + accessorKey: "createdAt", header: "Tanggal Unggah ", cell: ({ row }) => ( - {row.getValue("date")} + {row.getValue("createdAt")} ), }, { - accessorKey: "status", + accessorKey: "isActive", header: "Status", cell: ({ row }) => { + const isActive = row.getValue("isActive"); + console.log("isActive value:", isActive); // TypeScript type is inferred correctly return ( - - {row.getValue("status")} - +
+ {isActive ? ( + Terkirim + ) : ( + Belum Terkirim + )} +
); }, }, @@ -124,6 +147,7 @@ export const columns: ColumnDef[] = [ ]; const MedsosTable = () => { + const [mediahubTable, setMediahubTable] = React.useState([]); const [sorting, setSorting] = React.useState([]); const [columnFilters, setColumnFilters] = React.useState( [] @@ -132,12 +156,16 @@ const MedsosTable = () => { React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); const [pagination, setPagination] = React.useState({ - pageIndex: 0, - pageSize: 6, + pageIndex: 0, // Halaman pertama + pageSize: 10, // Jumlah baris per halaman }); + const [page, setPage] = React.useState(1); // Halaman aktif + const [totalPage, setTotalPage] = React.useState(1); // Total halaman + const [limit, setLimit] = React.useState(10); // Jumlah baris per halaman + // const [search, setSearch] = React.useState(title); const table = useReactTable({ - data, + data: mediahubTable, columns, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, @@ -157,6 +185,27 @@ const MedsosTable = () => { }, }); + React.useEffect(() => { + initState(); + }, [page, limit]); + + async function initState() { + try { + const res = await getPlanningSentPagination(limit, page, 2); + const data = res.data.data.content.map((item: any, index: number) => ({ + no: (page - 1) * limit + index + 1, // Hitung nomor urut + title: item.title, + createdAt: item.createdAt, + isActive: item.isActive === true, + })); + + setMediahubTable(data); + setTotalPage(res.data.totalPages); // Total halaman + } catch (error) { + console.error("Error fetching tasks:", error); + } + } + return (
diff --git a/app/[locale]/(protected)/task/table-task/data.ts b/app/[locale]/(protected)/task/table-task/data.ts deleted file mode 100644 index 93d38fe7..00000000 --- a/app/[locale]/(protected)/task/table-task/data.ts +++ /dev/null @@ -1,106 +0,0 @@ -export const data = [ - { - title: "Giat Pimpinan", - code: "PNMH-1287", - status: "paid", - date: "$231.26", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Liputan Kegiatan", - code: "PNMH-1287", - status: "due", - date: "$432.81", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Giat Pimpinan", - code: "PNMH-1287", - status: "due", - date: "$437.65", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Pers Rilis", - code: "PNMH-1287", - status: "canceled", - date: "$387.55", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Giat Pimpinan", - code: "PNMH-1287", - status: "canceled", - date: "$489.80", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Liputan Kegiatan", - code: "PNMH-1287", - status: "canceled", - date: "$421.45", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Pers Rilis", - code: "PNMH-1287", - status: "canceled", - date: "$207.61", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Giat Pimpinan", - code: "PNMH-1287", - status: "paid", - date: "$392.86", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Pers Rilis", - code: "PNMH-1287", - status: "paid", - date: "$162.87", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Giat Pimpinan", - code: "PNMH-1287", - status: "paid", - date: "$268.58", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Liputan Kegiatan", - code: "PNMH-1287", - status: "paid", - date: "$369.19", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Liputan Kegiatan", - code: "PNMH-1287", - status: "paid", - date: "$420.87", - category: "amplifikasi", - typeTask: "Mediahub", - }, - { - title: "Giat Pimpinan", - code: "PNMH-1287", - status: "paid", - date: "$420.26", - category: "amplifikasi", - typeTask: "Mediahub", - }, -]; diff --git a/app/[locale]/(protected)/task/table-task/task-table.tsx b/app/[locale]/(protected)/task/table-task/task-table.tsx index 3a3644a2..b5a7ddee 100644 --- a/app/[locale]/(protected)/task/table-task/task-table.tsx +++ b/app/[locale]/(protected)/task/table-task/task-table.tsx @@ -37,7 +37,6 @@ import { TrendingDown, TrendingUp, } from "lucide-react"; -import { cn } from "@/lib/utils"; import { DropdownMenu, DropdownMenuContent, @@ -45,20 +44,38 @@ import { DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; -export type CompanyData = { - title: string; - code: string; - typeTask: string; - category: string; - date: string; - status: string; -}; -import { data } from "./data"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; import { Link } from "@/components/navigation"; +import { listTask } from "@/service/ppid-categories-services"; +import { title } from "process"; +import search from "../../app/chat/components/search"; +import { format } from "date-fns"; + +export type CompanyData = { + no: number; + title: string; + uniqueCode: string; + assignmentMainType: string; + assignmentType: string; + createdAt: string; + isDone: string; +}; export const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => ( +
+
+

+ {row.getValue("no")} +

+
+
+ ), + }, { accessorKey: "title", header: "Judul", @@ -73,47 +90,65 @@ export const columns: ColumnDef[] = [ ), }, { - accessorKey: "code", + accessorKey: "uniqueCode", header: "Kode ", cell: ({ row }) => ( - {row.getValue("code")} + {row.getValue("uniqueCode")} ), }, { - accessorKey: "typeTask", - header: "Kode ", + accessorKey: "assignmentMainType", + header: "Tipe Tugas ", cell: ({ row }) => ( - {row.getValue("typeTask")} + + {row.getValue("assignmentMainType")} + ), }, { - accessorKey: "category", + accessorKey: "assignmentType", header: "Jenis Tugas ", cell: ({ row }) => ( - {row.getValue("category")} + + {row.getValue("assignmentType")} + ), }, { - accessorKey: "date", - header: "Tanggal Unggah ", - cell: ({ row }) => ( - {row.getValue("date")} - ), + accessorKey: "createdAt", + header: "Tanggal Unggah", + cell: ({ row }) => { + const createdAt = row.getValue("createdAt") as + | string + | number + | undefined; + + const formattedDate = + createdAt && !isNaN(new Date(createdAt).getTime()) + ? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss") + : "-"; + return {formattedDate}; + }, }, + { - accessorKey: "status", + accessorKey: "isDone", header: "Status", cell: ({ row }) => { - const statusColors: Record = { - paid: "bg-success/20 text-success", - due: "bg-warning/20 text-warning", - canceled: "bg-destructive/20 text-destructive", - }; - const status = row.getValue("status"); + const isDone = row.getValue("isDone"); return ( - - {status} - +
+ +
); }, }, @@ -154,6 +189,7 @@ export const columns: ColumnDef[] = [ const TaskTable = () => { const [sorting, setSorting] = React.useState([]); + const [taskTable, setTaskTable] = React.useState([]); const [columnFilters, setColumnFilters] = React.useState( [] ); @@ -161,31 +197,55 @@ const TaskTable = () => { React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); const [pagination, setPagination] = React.useState({ - pageIndex: 0, - pageSize: 6, + pageIndex: 0, // Halaman pertama + pageSize: 10, // Jumlah baris per halaman }); + const [page, setPage] = React.useState(1); // Halaman aktif + const [totalPage, setTotalPage] = React.useState(1); // Total halaman + const [limit, setLimit] = React.useState(10); // Jumlah baris per halaman + const [search, setSearch] = React.useState(title); const table = useReactTable({ - data, + data: taskTable, columns, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, + onPaginationChange: setPagination, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), - onColumnVisibilityChange: setColumnVisibility, - onRowSelectionChange: setRowSelection, - onPaginationChange: setPagination, state: { sorting, columnFilters, - columnVisibility, - rowSelection, pagination, }, }); + React.useEffect(() => { + initState(); + }, [page, limit]); + + async function initState() { + try { + const res = await listTask(limit, page); + const data = res.data.data.content.map((item: any, index: number) => ({ + no: (page - 1) * limit + index + 1, // Hitung nomor urut + title: item.title, + uniqueCode: item.uniqueCode || "-", + assignmentMainType: item.assignmentMainType?.name || "-", + assignmentType: item.assignmentType?.name || "-", + createdAt: item.createdAt, + isDone: item.isDone, + })); + + setTaskTable(data); + setTotalPage(res.data.totalPages); // Total halaman + } catch (error) { + console.error("Error fetching tasks:", error); + } + } + return (
diff --git a/components/form/content/create-form.tsx b/components/form/content/create-form.tsx new file mode 100644 index 00000000..3b695882 --- /dev/null +++ b/components/form/content/create-form.tsx @@ -0,0 +1,381 @@ +"use client"; +import React, { ChangeEvent, useRef, useState } from "react"; +import { useForm, Controller } from "react-hook-form"; +import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; +import { Label } from "@/components/ui/label"; +import { Card } from "@/components/ui/card"; +import { zodResolver } from "@hookform/resolvers/zod"; +import * as z from "zod"; +import Swal from "sweetalert2"; +import withReactContent from "sweetalert2-react-content"; +import { useRouter } from "next/navigation"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Checkbox } from "@/components/ui/checkbox"; +import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; +import JoditEditor from "jodit-react"; +import { register } from "module"; +import { Switch } from "@/components/ui/switch"; + +const taskSchema = z.object({ + title: z.string().min(1, { message: "Judul diperlukan" }), + naration: z.string().min(2, { + message: "Narasi Penugasan harus lebih dari 2 karakter.", + }), + creator: z.string().min(1, { message: "Judul diperlukan" }), + tags: z.string().min(1, { message: "Judul diperlukan" }), +}); + +export default function FormImage() { + const MySwal = withReactContent(Swal); + const router = useRouter(); + const editor = useRef(null); + type TaskSchema = z.infer; + const [tags, setTags] = useState([]); + const [selectedFiles, setSelectedFiles] = useState([]); + + // State for various form fields + const [output, setOutput] = useState({ + all: false, + video: false, + audio: false, + image: false, + text: false, + }); + + const [assignmentType, setAssignmentType] = useState("mediahub"); + const [assignmentCategory, setAssignmentCategory] = useState("publication"); + + const [selectedTarget, setSelectedTarget] = useState("all"); + const [unitSelection, setUnitSelection] = useState({ + allUnit: false, + mabes: false, + polda: false, + polres: false, + }); + + const { + control, + handleSubmit, + setValue, + formState: { errors }, + } = useForm({ + resolver: zodResolver(taskSchema), + }); + + const handleKeyDown = (e: any) => { + const newTag = e.target.value.trim(); // Ambil nilai input + if (e.key === "Enter" && newTag) { + e.preventDefault(); // Hentikan submit form + if (!tags.includes(newTag)) { + setTags((prevTags) => [...prevTags, newTag]); // Tambah tag baru + setValue("tags", ""); // Kosongkan input + } + } + }; + + const handleRemoveTag = (index: any) => { + setTags((prevTags) => prevTags.filter((_, i) => i !== index)); + }; + + const handleImageChange = (event: ChangeEvent) => { + if (event.target.files) { + const files = Array.from(event.target.files); + setSelectedFiles((prevImages: any) => [...prevImages, ...files]); + console.log("DATAFILE::", selectedFiles); + } + }; + + const handleRemoveImage = (index: number) => { + setSelectedFiles((prevImages) => prevImages.filter((_, i) => i !== index)); + }; + + const save = async (data: TaskSchema) => { + const requestData = { + ...data, + output, + assignmentType, + assignmentCategory, + target: selectedTarget, + unitSelection, + }; + + console.log("Form Data Submitted:", requestData); + + MySwal.fire({ + title: "Sukses", + text: "Data berhasil disimpan.", + icon: "success", + confirmButtonColor: "#3085d6", + confirmButtonText: "OK", + }).then(() => { + router.push("/en/content/image"); + }); + }; + + const onSubmit = (data: TaskSchema) => { + 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); + } + }); + }; + + return ( +
+
+ +
+

Form Konten Foto

+
+ {/* Input Title */} +
+ + ( + + )} + /> + {errors.title?.message && ( +

{errors.title.message}

+ )} +
+
+
+ + +
+
+
+ + ( + + )} + /> + {errors.naration?.message && ( +

+ {errors.naration.message} +

+ )} +
+
+ +
+ +
+
+ +
+ +
+
+ {selectedFiles?.length > 0 ? ( +
+
+ {selectedFiles.map((image, index) => ( +
+ Pratinjau Gambar + +
+ ))} +
+
+ ) : ( + "" + )} +
+
+ + {/* Submit Button */} +
+
+
+ +
+
+ + ( + + )} + /> + {errors.creator?.message && ( +

+ {errors.creator.message} +

+ )} +
+
+
+ + ( + + )} + /> +
+ {tags.length === 0 && "Please add at least one tag."} +
+
+ {tags.map((tag, index) => ( +
+ {tag} + +
+ ))} +
+
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+ ); +} diff --git a/config/api.ts b/config/api.ts index 19badfd3..1e2317f1 100644 --- a/config/api.ts +++ b/config/api.ts @@ -124,22 +124,24 @@ export async function getAPIInterceptor(url: any) { }; } -export async function postAPIInterceptor(url: any, data: any) { +// Fungsi postAPIInterceptor +export async function postAPIInterceptor(url: string, data: any) { const response = await axiosInterceptor .post(url, data) .catch((error) => error.response); - if (response?.status == 401) { + + if (response?.status === 401) { Object.keys(Cookies.get()).forEach((cookieName) => { Cookies.remove(cookieName); }); window.location.href = "/"; - } else if (response?.status > 300 && response?.status != 401) { + } else if (response?.status > 300 && response?.status !== 401) { return { error: true, message: response?.data?.message, data: null, }; - } else if (response?.data.success) { + } else if (response?.data?.success) { return { error: false, message: "success", @@ -149,11 +151,17 @@ export async function postAPIInterceptor(url: any, data: any) { return { error: true, - message: response?.data.message, + message: response?.data?.message, data: null, }; } +// Fungsi createTask +export async function createTask(data: any) { + const url = "assignment"; + return postAPIInterceptor(url, data); // Perbaikan: Memisahkan parameter url dan data +} + export async function deleteAPIInterceptor(url: any, data: any) { const response = await axiosInterceptor .delete(url, { data }) diff --git a/lib/menus.ts b/lib/menus.ts index 9f4d6940..881d1242 100644 --- a/lib/menus.ts +++ b/lib/menus.ts @@ -36,7 +36,7 @@ export function getMenuList(pathname: string, t: any): Group[] { menus: [ { id: "dashboard", - href: "/dashboard/tabs", + href: "/dashboard", label: t("dashboard"), active: pathname.includes("/dashboard"), icon: "material-symbols:dashboard", diff --git a/lib/utils.ts b/lib/utils.ts index 542c545b..c1d41a7c 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -1,8 +1,10 @@ -import { type ClassValue, clsx } from "clsx" -import { twMerge } from "tailwind-merge" +import { type ClassValue, clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; +import Cookies from "js-cookie"; +import CryptoJS from "crypto-js"; export function cn(...inputs: ClassValue[]) { - return twMerge(clsx(inputs)) + return twMerge(clsx(inputs)); } export const hexToRGB = (hex: any, alpha?: number): any => { @@ -15,4 +17,51 @@ export const hexToRGB = (hex: any, alpha?: number): any => { } else { return `rgb(${r}, ${g}, ${b})`; } -}; \ No newline at end of file +}; + +export function checkAuthorization(page: any) { + const roleId = getCookiesDecrypt("urie"); + const levelNumber = getCookiesDecrypt("ulne"); + if ( + (Number(roleId) !== 3 && + Number(roleId) !== 4 && + Number(roleId) !== 11 && + Number(roleId) !== 12 && + Number(roleId) !== 2) || + roleId == undefined + ) { + console.log("Wrong Authentication"); + window.location.href = "/"; + } else if (page == "admin" && Number(levelNumber) !== 1) { + console.log("Wrong Authentication Admin"); + window.location.href = "/"; + } +} + +export function checkLoginSession() { + const userId = getCookiesDecrypt("uie"); + const jwt = Cookies.get("access_token"); + const data = { + userId, + jwt, + }; + // doCheckSession(data); +} + +export function getCookiesDecrypt(param: any) { + const cookiesEncrypt = Cookies.get(param); + try { + if (cookiesEncrypt != undefined) { + const output = CryptoJS.AES.decrypt( + cookiesEncrypt.toString(), + `${param}_EncryptKey@mediahub` + ).toString(CryptoJS.enc.Utf8); + if (output.startsWith('"')) { + return output.slice(1, -1); + } + return output; + } + } catch (e) { + console.log("Error", cookiesEncrypt); + } +} diff --git a/package-lock.json b/package-lock.json index 1b934d68..46dd08ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,7 @@ "@south-paw/react-vector-maps": "^3.2.0", "@tanstack/react-table": "^8.19.2", "@types/cleave.js": "^1.4.12", + "@types/crypto-js": "^4.2.2", "@types/js-cookie": "^3.0.6", "@types/qs": "^6.9.17", "@types/react-syntax-highlighter": "^15.5.13", @@ -66,6 +67,7 @@ "clsx": "^2.1.1", "cmdk": "^1.0.0", "cookie": "^1.0.2", + "crypto-js": "^4.2.0", "date-fns": "^3.6.0", "dayjs": "^1.11.11", "embla-carousel-autoplay": "^8.1.3", @@ -1082,6 +1084,126 @@ "glob": "10.3.10" } }, + "node_modules/@next/swc-darwin-arm64": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.3.tgz", + "integrity": "sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", + "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", + "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", + "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.3.tgz", + "integrity": "sha512-ENPiNnBNDInBLyUU5ii8PMQh+4XLr4pG51tOp6aJ9xqFQ2iRI6IH0Ds2yJkAzNV1CfyagcyzPfROMViS2wOZ9w==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.3.tgz", + "integrity": "sha512-BTAbq0LnCbF5MtoM7I/9UeUu/8ZBY0i8SFjUMCbPDOLv+un67e2JgyN4pmgfXBwy/I+RHu8q+k+MCkDN6P9ViQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", + "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", + "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@next/swc-win32-x64-msvc": { "version": "14.2.3", "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.3.tgz", @@ -2780,6 +2902,11 @@ "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", "integrity": "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==" }, + "node_modules/@types/crypto-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", + "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==" + }, "node_modules/@types/d3-array": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/@types/d3-array/-/d3-array-3.2.1.tgz", @@ -4022,6 +4149,11 @@ "node": ">= 8" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/cssesc": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", @@ -13382,126 +13514,6 @@ "type": "github", "url": "https://github.com/sponsors/wooorm" } - }, - "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.3.tgz", - "integrity": "sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-darwin-x64": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", - "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", - "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", - "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.3.tgz", - "integrity": "sha512-ENPiNnBNDInBLyUU5ii8PMQh+4XLr4pG51tOp6aJ9xqFQ2iRI6IH0Ds2yJkAzNV1CfyagcyzPfROMViS2wOZ9w==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.3.tgz", - "integrity": "sha512-BTAbq0LnCbF5MtoM7I/9UeUu/8ZBY0i8SFjUMCbPDOLv+un67e2JgyN4pmgfXBwy/I+RHu8q+k+MCkDN6P9ViQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", - "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", - "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } } } } diff --git a/package.json b/package.json index 2a6c72b1..b80a2d6a 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@south-paw/react-vector-maps": "^3.2.0", "@tanstack/react-table": "^8.19.2", "@types/cleave.js": "^1.4.12", + "@types/crypto-js": "^4.2.2", "@types/js-cookie": "^3.0.6", "@types/qs": "^6.9.17", "@types/react-syntax-highlighter": "^15.5.13", @@ -67,6 +68,7 @@ "clsx": "^2.1.1", "cmdk": "^1.0.0", "cookie": "^1.0.2", + "crypto-js": "^4.2.0", "date-fns": "^3.6.0", "dayjs": "^1.11.11", "embla-carousel-autoplay": "^8.1.3", diff --git a/service/blog/blog.ts b/service/blog/blog.ts new file mode 100644 index 00000000..85f9bc16 --- /dev/null +++ b/service/blog/blog.ts @@ -0,0 +1,8 @@ +import { title } from "process"; +import { httpGetInterceptor } from "../http-config/http-interceptor-service"; + +export async function paginationBlog(size: number, page: number) { + return await httpGetInterceptor( + `blog/pagination?enablePage=1&page=${page}&size=${size}` + ); +} diff --git a/service/content/content-image.ts b/service/content/content-image.ts new file mode 100644 index 00000000..93f1f6b6 --- /dev/null +++ b/service/content/content-image.ts @@ -0,0 +1,19 @@ +import { httpGetInterceptor } from "../http-config/http-interceptor-service"; + +export async function listDataImage( + page: any, + limit: any, + isForSelf: any, + isApproval: any, + categoryFilter: any, + statusFilter: any, + needApprovalFromLevel: any, + creator: any, + source: any, + startDate: any, + endDate: any +) { + return await httpGetInterceptor( + `media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=1&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}` + ); +} diff --git a/service/http-config/axios-base-instance.ts b/service/http-config/axios-base-instance.ts new file mode 100644 index 00000000..c1c8fb83 --- /dev/null +++ b/service/http-config/axios-base-instance.ts @@ -0,0 +1,12 @@ +import axios from "axios"; + +const baseURL = "https://netidhub.com/api/"; + +const axiosBaseInstance = axios.create({ + baseURL, + headers: { + "content-type": "application/json", + }, +}); + +export default axiosBaseInstance; diff --git a/service/http-config/axios-interceptor-instance.ts b/service/http-config/axios-interceptor-instance.ts new file mode 100644 index 00000000..09b7b146 --- /dev/null +++ b/service/http-config/axios-interceptor-instance.ts @@ -0,0 +1,56 @@ +import axios from "axios"; +import Cookies from "js-cookie"; +import { login } from "../login-services"; + +const baseURL = "https://netidhub.com/api/"; + +const refreshToken = Cookies.get("refresh_token"); + +const axiosInterceptorInstance = axios.create({ + baseURL, + headers: { + "content-type": "application/json", + }, +}); + +// Request interceptor +axiosInterceptorInstance.interceptors.request.use( + (config) => { + console.log("Config interceptor : ", config); + const accessToken = Cookies.get("access_token"); + if (accessToken) { + if (config.headers) + config.headers.Authorization = "Bearer " + accessToken; + } + return config; + }, + (error) => { + return Promise.reject(error); + } +); + +// Response interceptor +axiosInterceptorInstance.interceptors.response.use( + (response) => { + return response; + }, + async function (error) { + const originalRequest = error.config; + if (error.response.status === 401 && !originalRequest._retry) { + originalRequest._retry = true; + const data = { + refreshToken: refreshToken, + }; + const res = await login(data); + if (res.data?.data?.access_token) { + Cookies.set("access_token", res.data.data.access_token); + Cookies.set("refresh_token", res.data.data.refresh_token); + return axiosInterceptorInstance(originalRequest); + } + } + + return Promise.reject(error); + } +); + +export default axiosInterceptorInstance; diff --git a/service/http-config/http-base-service.ts b/service/http-config/http-base-service.ts new file mode 100644 index 00000000..3af62f08 --- /dev/null +++ b/service/http-config/http-base-service.ts @@ -0,0 +1,70 @@ +import axiosBaseInstance from "./axios-base-instance"; + +export async function httpPost(pathUrl: any, headers: any, data?: any) { + const response = await axiosBaseInstance + .post(pathUrl, data, { headers }) + .catch(function (error: any) { + console.log(error); + return error.response; + }); + console.log("Response base svc : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + +export async function httpGet(pathUrl: any, headers: any) { + const response = await axiosBaseInstance + .get(pathUrl, { headers }) + .catch(function (error: any) { + console.log(error); + return error.response; + }); + console.log("Response base svc : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + +export async function httpPut(pathUrl: any, headers: any, data?: any) { + const response = await axiosBaseInstance + .put(pathUrl, data, { headers }) + .catch(function (error: any) { + console.log(error); + return error.response; + }); + console.log("Response base svc : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} \ No newline at end of file diff --git a/service/http-config/http-interceptor-service.ts b/service/http-config/http-interceptor-service.ts new file mode 100644 index 00000000..1e990160 --- /dev/null +++ b/service/http-config/http-interceptor-service.ts @@ -0,0 +1,129 @@ +import { useRouter } from "next/navigation"; +import axiosInterceptorInstance from "./axios-interceptor-instance"; +import Cookies from "js-cookie"; + +export async function httpGetInterceptor(pathUrl: any) { + const response = await axiosInterceptorInstance + .get(pathUrl) + .catch((error) => error.response); + console.log("Response interceptor : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else if (response?.status == 401) { + Cookies.set("is_logout", "true"); + window.location.href = "/"; + return { + error: true, + }; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + +export async function httpPostInterceptor( + pathUrl: any, + data: any, + headers?: any +) { + const response = await axiosInterceptorInstance + .post(pathUrl, data) + .catch((error) => error.response); + console.log("Response interceptor : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else if (response?.status == 401) { + Cookies.set("is_logout", "true"); + window.location.href = "/"; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + +export async function httpPutInterceptor( + pathUrl: any, + data: any, + headers?: any +) { + const response = await axiosInterceptorInstance + .put(pathUrl, data, { headers }) + .catch((error) => error.response); + console.log("Response interceptor : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else if (response?.status == 401) { + Cookies.set("is_logout", "true"); + window.location.href = "/"; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + +export async function httpDeleteInterceptor(pathUrl: any) { + const response = await axiosInterceptorInstance + .delete(pathUrl) + .catch((error) => error.response); + console.log("Response interceptor : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else if (response?.status == 401) { + Cookies.set("is_logout", "true"); + window.location.href = "/"; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + +export async function httpGetInterceptorWithToken(pathUrl: any, headers?: any) { + const response = await axiosInterceptorInstance + .get(pathUrl, headers) + .catch((error) => error.response); + console.log("Response interceptor : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else if (response?.status == 401) { + Cookies.set("is_logout", "true"); + window.location.href = "/"; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} diff --git a/service/login-services.ts b/service/login-services.ts new file mode 100644 index 00000000..cd000b52 --- /dev/null +++ b/service/login-services.ts @@ -0,0 +1,17 @@ +import { httpGet, httpPost } from "./http-config/http-base-service"; +import { httpGetInterceptor, httpGetInterceptorWithToken } from "./http-config/http-interceptor-service"; + + +export async function login(data: any) { + const pathUrl = `users/login`; + const headers = { + "content-type": "application/json", + }; + return await httpPost(pathUrl, headers, data); +} + +export async function userInfo(token: any) { + const pathUrl = `users/info`; + return await httpGetInterceptorWithToken(pathUrl, token); +} + diff --git a/service/media.ts b/service/media.ts deleted file mode 100644 index 7d6ea790..00000000 --- a/service/media.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { - deleteAPIInterceptor, - getAPI, - getAPIInterceptor, - postAPIInterceptor, -} from "../config/api"; - -export async function listDataMedia( - page: any, - limit: any, - search: any, - categoryFilter: any, - statusFilter: any -) { - const name = search || ""; - const url = `media/list?isForAdmin=true&title=${name}&enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=1&categoryId=${categoryFilter}&statusId=${statusFilter}`; - return getAPIInterceptor({ url }); -} - -export async function listDataVideo( - isForSelf: any, - isApproval: any, - page: any, - limit: any, - search: any, - categoryFilter: any, - statusFilter: any, - needApprovalFromLevel: any, - creator: any, - source: any, - startDate: any, - endDate: any -) { - const name = search || ""; - const url = `media/list?title=${name}&enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=2&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}`; - return getAPIInterceptor({ url }); -} - -export async function listDataImage( - isForSelf: any, - isApproval: any, - page: any, - limit: any, - search: any, - categoryFilter: any, - statusFilter: any, - needApprovalFromLevel: any, - creator: any, - source: any, - startDate: any, - endDate: any -) { - const name = search || ""; - const url = `media/list?title=${name}&enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=1&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}`; - return getAPIInterceptor({ url }); -} - -export async function listDataAll( - isForSelf: any, - isApproval: any, - page: any, - limit: any, - search: any, - fileTypeFilter: any, - statusFilter: any, - startDate: any, - endDate: any, - needApprovalFromLevel: any -) { - const name = search || ""; - const url = `media/list?title=${name}&enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&isForSelf=${isForSelf}&isApproval=${isApproval}&typeId=${fileTypeFilter}&statusId=${statusFilter}&startDate=${ - startDate == undefined ? "" : startDate - }&endDate=${ - endDate == undefined ? "" : endDate - }&needApprovalFromLevel=${needApprovalFromLevel}`; - return getAPIInterceptor({ url }); -} diff --git a/service/planning/planning.ts b/service/planning/planning.ts new file mode 100644 index 00000000..8f1cde59 --- /dev/null +++ b/service/planning/planning.ts @@ -0,0 +1,11 @@ +import { httpGetInterceptor } from "../http-config/http-interceptor-service"; + +export async function getPlanningSentPagination( + size: number, + page: number, + typeId: number +) { + return await httpGetInterceptor( + `planning/pagination/sent?enablePage=1&size=${size}&page=${page}&typeId=${typeId}` + ); +} diff --git a/service/ppid-categories-services.ts b/service/ppid-categories-services.ts new file mode 100644 index 00000000..5af976a0 --- /dev/null +++ b/service/ppid-categories-services.ts @@ -0,0 +1,147 @@ +import { httpGet, httpPost } from "./http-config/http-base-service"; +import { + httpDeleteInterceptor, + httpGetInterceptor, + httpPostInterceptor, + httpPutInterceptor, +} from "./http-config/http-interceptor-service"; + +export async function getPublicListPpidData(categoryId: number) { + const headers = { + "content-type": "application/json", + }; + return await httpGet(`/ppid-datas?categoryId=${categoryId}`, headers); +} + +export async function getListCategories(size: number, page: number) { + return await httpGetInterceptor( + `/ppid-data-categories?page=${page}&size=${size}&isOnlyTop=true` + ); +} + +export async function listTask(size: number, page: number) { + return await httpGetInterceptor(`assignment/list?size=${size}&page=${page}`); +} + +export async function updateCategoryPosition(category: any) { + const pathUrl = `/ppid-data-categories/position`; + return await httpPostInterceptor(pathUrl, category); +} + +export async function getListSubCategories( + size: number, + page: number, + parentId: number +) { + const headers = { + "content-type": "application/json", + }; + return await httpGetInterceptor( + `/ppid-data-categories?page=${page}&size=${size}&parentId=${parentId}` + ); +} + +export async function getPublicListCategoriesByParentId( + id: any, + limit: number, + levelGroup?: string +) { + const headers = { + "content-type": "application/json", + }; + return await httpGet( + `/ppid-data-categories?parentId=${id}&isPpidDataIncluded=true&sort=asc&sortBy=position&limit=${limit}${ + levelGroup ? `&levelGroup=${levelGroup}` : "" + }`, + headers + ); +} + +export async function getListCategoriesByParentId( + id: any, + limit: number, + levelGroup?: string +) { + const headers = { + "content-type": "application/json", + }; + return await httpGetInterceptor( + `/ppid-data-categories?parentId=${id}&isPpidDataIncluded=true&sort=asc&sortBy=position&limit=${limit}${ + levelGroup ? `&levelGroup=${levelGroup}` : "" + }` + ); +} + +export async function getListCategoriesById(id: any) { + const headers = { + "content-type": "application/json", + }; + return await httpGetInterceptor(`/ppid-data-categories/${id}`); +} + +export async function getListCategoriesBySlug(slug: any) { + const headers = { + "content-type": "application/json", + }; + return await httpGetInterceptor(`/ppid-data-categories/slug/${slug}`); +} + +export async function getPublicListCategoriesBySlug(slug: any) { + const headers = { + "content-type": "application/json", + }; + return await httpGet(`/ppid-data-categories/slug/${slug}`, headers); +} + +export async function getList(categoryId: number) { + const headers = { + "content-type": "application/json", + }; + return await httpGetInterceptor(`/ppid-datas?categoryId=1`); +} + +export async function createArticle(data: any) { + const pathUrl = `/articles`; + return await httpPostInterceptor(pathUrl, data); +} + +export async function createPublicCategory(request: any) { + const pathUrl = `/ppid-data-categories`; + return await httpPostInterceptor(pathUrl, request); +} + +export async function uploadPublicThumbnail(id: number, data: any) { + const headers = { + "Content-Type": "multipart/form-data", + }; + const pathUrl = `ppid-data-categories/thumbnail/${id}`; + return await httpPost(pathUrl, headers, data); +} + +export async function getPublicCategoryById(id: any) { + const headers = { + "content-type": "application/json", + }; + return await httpGetInterceptor(`/ppid-data-categories/${id}`); +} + +export async function updatePublicCategory(id: any, request: any) { + const headers = { + "content-type": "application/json", + }; + return await httpPutInterceptor(`/ppid-data-categories/${id}`, request); +} + +export async function deletePublicCategory(id: any) { + const headers = { + "content-type": "application/json", + }; + return await httpDeleteInterceptor(`/ppid-data-categories/${id}`); +} + +export async function getParentCategories() { + const headers = { + "content-type": "application/json", + }; + return await httpGet(`ppid-data-categories?isOnlyTop=true`, headers); +} diff --git a/service/task.ts b/service/task.ts new file mode 100644 index 00000000..28d4c863 --- /dev/null +++ b/service/task.ts @@ -0,0 +1,80 @@ +import { + deleteAPIInterceptor, + getAPIInterceptor, + postAPIInterceptor, +} from "../config/api"; + +export async function listTask(page: any, limit: any) { + const url = `assignment/list?enablePage=1&size=${limit}&page=${page}`; + return getAPIInterceptor({ url }); +} + +export async function getTask(id: any) { + const url = `/assignment?id=${id}`; + return getAPIInterceptor({ url }); +} + +export async function createTask(data: any) { + const url = "assignment"; + return postAPIInterceptor(url, data); // Perbaikan: Memisahkan parameter url dan data +} + +export async function forwardTask(data: any) { + const url = "assignment/forward"; + return postAPIInterceptor(url, data); +} + +export async function finishTask(id: any) { + const url = `assignment/finish?id=${id}`; + return postAPIInterceptor(url, id); +} + +export async function deleteTask(id: any) { + const url = `assignment?id=${id}`; + return deleteAPIInterceptor(url, id); +} + +export async function getUserLevelForAssignments() { + const url = "/users/user-levels/assignment"; + return getAPIInterceptor({ url }); +} + +export async function getAssignmentResponseList(id: any) { + const url = `assignment/response?assignmentId=${id}`; + return getAPIInterceptor({ url }); +} + +export async function createAssignmentResponse(data: any) { + const url = "assignment/response"; + return postAPIInterceptor(url, data); +} + +export async function deleteAssignmentResponse(id: any) { + const url = `assignment/response?id=${id}`; + return deleteAPIInterceptor(url, id); +} + +export async function getAcceptance(id: any, isAccept: any) { + const url = `assignment/acceptance?id=${id}&isAccept=${isAccept}`; + return getAPIInterceptor({ url }); +} + +export async function acceptAssignment(id: any, isAccept: any) { + const url = `assignment/acceptance?id=${id}`; + return postAPIInterceptor(url, id); +} + +export async function postFinishAcceptance(id: any) { + const url = `assignment/finish-acceptance?id=${id}`; + return postAPIInterceptor(url, id); +} + +export async function getAcceptanceAssignmentStatus(id: any) { + const url = `assignment/acceptance/status?id=${id}`; + return getAPIInterceptor({ url }); +} + +export async function getListAttachment(assignmentId: any, isForCreator: any) { + const url = `media/list?&enablePage=0&assignmentId=${assignmentId}&isForAdmin=${isForCreator}`; + return getAPIInterceptor({ url }); +}