fix: redirect /in and double //
This commit is contained in:
parent
c71532cdd5
commit
15a395ccd2
|
|
@ -0,0 +1,422 @@
|
|||
import * as React from "react";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
|
||||
import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react";
|
||||
import { cn, getCookiesDecrypt } 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 { format } from "date-fns";
|
||||
import { Link } from "@/components/navigation";
|
||||
import { deleteMedia } from "@/service/content/content";
|
||||
import Swal from "sweetalert2";
|
||||
import withReactContent from "sweetalert2-react-content";
|
||||
import { error } from "@/lib/swal";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "@/i18n/routing";
|
||||
|
||||
const useTableColumns = () => {
|
||||
const t = useTranslations("Table");
|
||||
const MySwal = withReactContent(Swal);
|
||||
const userLevelId = getCookiesDecrypt("ulie");
|
||||
|
||||
const columns: ColumnDef<any>[] = [
|
||||
{
|
||||
accessorKey: "no",
|
||||
header: t("no", { defaultValue: "No" }),
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-5">
|
||||
<div className="flex-1 text-start">
|
||||
<h4 className="text-sm font-medium text-default-600 whitespace-nowrap mb-1">
|
||||
{row.getValue("no")}
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "title",
|
||||
header: t("title", { defaultValue: "Title" }),
|
||||
cell: ({ row }: { row: { getValue: (key: string) => string } }) => {
|
||||
const title: string = row.getValue("title");
|
||||
return (
|
||||
<span className="whitespace-nowrap">
|
||||
{title.length > 50 ? `${title.slice(0, 30)}...` : title}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "categoryName",
|
||||
header: t("category-name", { defaultValue: "Category Name" }),
|
||||
cell: ({ row }) => (
|
||||
<span className="whitespace-nowrap">
|
||||
{row.getValue("categoryName")}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "createdAt",
|
||||
header: t("upload-date", { defaultValue: "Upload Date" }),
|
||||
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 <span className="whitespace-nowrap">{formattedDate}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "creatorName",
|
||||
header: t("creator-group", { defaultValue: "Creator Group" }),
|
||||
cell: ({ row }) => (
|
||||
<span className="whitespace-nowrap">{row.getValue("creatorName")}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "creatorGroupLevelName",
|
||||
header: t("source", { defaultValue: "Source" }),
|
||||
cell: ({ row }) => (
|
||||
<span className="whitespace-nowrap">
|
||||
{row.getValue("creatorGroupLevelName")}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "publishedOn",
|
||||
header: t("published", { defaultValue: "Published" }),
|
||||
cell: ({ row }) => {
|
||||
const isPublish = row.original.isPublish;
|
||||
const isPublishOnPolda = row.original.isPublishOnPolda;
|
||||
const creatorGroupParentLevelId =
|
||||
row.original.creatorGroupParentLevelId;
|
||||
|
||||
let displayText = "-";
|
||||
if (isPublish && !isPublishOnPolda) {
|
||||
displayText = "Mabes";
|
||||
} else if (isPublish && isPublishOnPolda) {
|
||||
if (Number(creatorGroupParentLevelId) == 761) {
|
||||
displayText = "Mabes & Satker";
|
||||
} else {
|
||||
displayText = "Mabes & Polda";
|
||||
}
|
||||
} else if (!isPublish && isPublishOnPolda) {
|
||||
if (Number(creatorGroupParentLevelId) == 761) {
|
||||
displayText = "Satker";
|
||||
} else {
|
||||
displayText = "Polda";
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="text-center whitespace-nowrap" title={displayText}>
|
||||
{displayText}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
accessorKey: "statusName",
|
||||
header: "Status",
|
||||
cell: ({ row }) => {
|
||||
const statusColors: Record<string, string> = {
|
||||
diterima: "bg-green-100 text-green-600",
|
||||
"menunggu review": "bg-orange-100 text-orange-600",
|
||||
};
|
||||
|
||||
const colors = [
|
||||
"bg-orange-100 text-orange-600",
|
||||
"bg-orange-100 text-orange-600",
|
||||
"bg-green-100 text-green-600",
|
||||
"bg-blue-100 text-blue-600",
|
||||
"bg-red-200 text-red-600",
|
||||
];
|
||||
|
||||
const status =
|
||||
Number(row.original?.statusId) == 2 &&
|
||||
row.original?.reviewedAtLevel !== null &&
|
||||
!row.original?.reviewedAtLevel?.includes(`:${userLevelId}:`) &&
|
||||
Number(row.original?.creatorGroupLevelId) != Number(userLevelId)
|
||||
? "1"
|
||||
: row.original?.statusId;
|
||||
const statusStyles =
|
||||
colors[Number(status)] || "bg-red-200 text-red-600";
|
||||
// const statusStyles = statusColors[status] || "bg-red-200 text-red-600";
|
||||
|
||||
return (
|
||||
<Badge
|
||||
className={cn(
|
||||
"rounded-full px-5 w-full whitespace-nowrap",
|
||||
statusStyles
|
||||
)}
|
||||
>
|
||||
{(Number(row.original?.statusId) == 2 &&
|
||||
!row.original?.reviewedAtLevel !== null &&
|
||||
!row.original?.reviewedAtLevel?.includes(
|
||||
`:${Number(userLevelId)}:`
|
||||
) &&
|
||||
Number(row.original?.creatorGroupLevelId) !=
|
||||
Number(userLevelId)) ||
|
||||
(Number(row.original?.statusId) == 1 &&
|
||||
Number(row.original?.needApprovalFromLevel) ==
|
||||
Number(userLevelId))
|
||||
? "Menunggu Review"
|
||||
: row.original?.statusName}{" "}
|
||||
</Badge>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
id: "actions",
|
||||
accessorKey: "action",
|
||||
header: t("action", { defaultValue: "Action" }),
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const router = useRouter();
|
||||
const MySwal = withReactContent(Swal);
|
||||
|
||||
async function doDelete(id: any) {
|
||||
const data = { id };
|
||||
const response = await deleteMedia(data);
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const handleDeleteMedia = (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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||
const userId = getCookiesDecrypt("uie");
|
||||
const userLevelId = getCookiesDecrypt("ulie");
|
||||
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||
|
||||
React.useEffect(() => {
|
||||
if (userLevelId !== undefined && roleId !== undefined) {
|
||||
setIsMabesApprover(
|
||||
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||
);
|
||||
}
|
||||
}, [userLevelId, roleId]);
|
||||
|
||||
const canEdit =
|
||||
Number(row.original.uploadedById) === Number(userId) ||
|
||||
isMabesApprover ||
|
||||
roleId === 14;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
size="icon"
|
||||
className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
||||
>
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreVertical className="h-4 w-4 text-default-800" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="p-0" align="end">
|
||||
<Link
|
||||
href={`/contributor/content/satker/detail/${row.original.id}`}
|
||||
>
|
||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||
<Eye className="w-4 h-4 me-1.5" />
|
||||
View
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
|
||||
{canEdit && (
|
||||
<Link
|
||||
href={`/contributor/content/satker/update/${row.original.id}`}
|
||||
>
|
||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||
<SquarePen className="w-4 h-4 me-1.5" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDeleteMedia(row.original.id)}
|
||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 me-1.5" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
},
|
||||
// {
|
||||
// id: "actions",
|
||||
// accessorKey: "action",
|
||||
// header: t("action", { defaultValue: "Action" }),
|
||||
// enableHiding: false,
|
||||
// cell: ({ row }) => {
|
||||
// const MySwal = withReactContent(Swal);
|
||||
|
||||
// async function doDelete(id: any) {
|
||||
// // loading();
|
||||
// const data = {
|
||||
// id,
|
||||
// };
|
||||
|
||||
// const response = await deleteMedia(data);
|
||||
|
||||
// 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();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// const handleDeleteMedia = (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);
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
// const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||
// const userId = getCookiesDecrypt("uie");
|
||||
// const userLevelId = getCookiesDecrypt("ulie");
|
||||
// const roleId = getCookiesDecrypt("urie");
|
||||
|
||||
// React.useEffect(() => {
|
||||
// if (userLevelId !== undefined && roleId !== undefined) {
|
||||
// setIsMabesApprover(
|
||||
// Number(userLevelId) == 216 && Number(roleId) == 3
|
||||
// );
|
||||
// }
|
||||
// }, [userLevelId, roleId]);
|
||||
|
||||
// return (
|
||||
// <DropdownMenu>
|
||||
// <DropdownMenuTrigger asChild>
|
||||
// <Button
|
||||
// size="icon"
|
||||
// className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
||||
// >
|
||||
// <span className="sr-only">Open menu</span>
|
||||
// <MoreVertical className="h-4 w-4 text-default-800" />
|
||||
// </Button>
|
||||
// </DropdownMenuTrigger>
|
||||
// <DropdownMenuContent className="p-0" align="end">
|
||||
// <Link
|
||||
// href={`/contributor/content/video/detail/${row.original.id}`}
|
||||
// >
|
||||
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||
// <Eye className="w-4 h-4 me-1.5" />
|
||||
// View
|
||||
// </DropdownMenuItem>
|
||||
// </Link>
|
||||
// {/* <Link
|
||||
// href={`/contributor/content/video/update/${row.original.id}`}
|
||||
// >
|
||||
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||
// <SquarePen className="w-4 h-4 me-1.5" />
|
||||
// Edit
|
||||
// </DropdownMenuItem>
|
||||
// </Link> */}
|
||||
// {(Number(row.original.uploadedById) === Number(userId) ||
|
||||
// isMabesApprover) && (
|
||||
// <Link
|
||||
// href={`/contributor/content/video/update/${row.original.id}`}
|
||||
// >
|
||||
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||
// <SquarePen className="w-4 h-4 me-1.5" />
|
||||
// Edit
|
||||
// </DropdownMenuItem>
|
||||
// </Link>
|
||||
// )}
|
||||
// <DropdownMenuItem
|
||||
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||
// >
|
||||
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||
// Delete
|
||||
// </DropdownMenuItem>
|
||||
// {/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
||||
// <DropdownMenuItem
|
||||
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||
// >
|
||||
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||
// Hapus
|
||||
// </DropdownMenuItem>
|
||||
// )} */}
|
||||
// </DropdownMenuContent>
|
||||
// </DropdownMenu>
|
||||
// );
|
||||
// },
|
||||
// },
|
||||
];
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
export default useTableColumns;
|
||||
|
|
@ -0,0 +1,579 @@
|
|||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import {
|
||||
ColumnFiltersState,
|
||||
PaginationState,
|
||||
SortingState,
|
||||
VisibilityState,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
getFilteredRowModel,
|
||||
getPaginationRowModel,
|
||||
getSortedRowModel,
|
||||
useReactTable,
|
||||
} from "@tanstack/react-table";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { ChevronDown, Search } from "lucide-react";
|
||||
import { getCookiesDecrypt } from "@/lib/utils";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { InputGroup, InputGroupText } from "@/components/ui/input-group";
|
||||
import TablePagination from "@/components/table/table-pagination";
|
||||
import { listDataAll, listDataSatker, listEnableCategory } from "@/service/content/content";
|
||||
import Swal from "sweetalert2";
|
||||
import withReactContent from "sweetalert2-react-content";
|
||||
import { format } from "date-fns";
|
||||
import useTableColumns from "./columns";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useRouter } from "@/i18n/routing";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
const TableSatker = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const MySwal = withReactContent(Swal);
|
||||
|
||||
const [dataTable, setDataTable] = React.useState<any[]>([]);
|
||||
const [totalData, setTotalData] = React.useState<number>(1);
|
||||
const [totalPage, setTotalPage] = React.useState(1);
|
||||
|
||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||
[]
|
||||
);
|
||||
const [columnVisibility, setColumnVisibility] =
|
||||
React.useState<VisibilityState>({});
|
||||
const [rowSelection, setRowSelection] = React.useState({});
|
||||
|
||||
const [showData, setShowData] = React.useState("10");
|
||||
const [page, setPage] = React.useState(1);
|
||||
const [search, setSearch] = React.useState("");
|
||||
|
||||
// gunakan ref untuk debounce search
|
||||
const searchTimeoutRef = React.useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
// === FILTER STATES ===
|
||||
const [categories, setCategories] = React.useState<any[]>([]);
|
||||
const [selectedCategories, setSelectedCategories] = React.useState<number[]>(
|
||||
[]
|
||||
);
|
||||
const [categoryFilter, setCategoryFilter] = React.useState<string>("");
|
||||
const [statusFilter, setStatusFilter] = React.useState<any[]>([]);
|
||||
const [startDate, setStartDate] = React.useState("");
|
||||
const [endDate, setEndDate] = React.useState("");
|
||||
const [filterByCreator, setFilterByCreator] = React.useState("");
|
||||
const [filterBySource, setFilterBySource] = React.useState("");
|
||||
const [filterByCreatorGroup, setFilterByCreatorGroup] = React.useState("");
|
||||
const [typeId, setTypeId] = React.useState<string>(""); // 1=image, 2=video, 3=text, 4=audio
|
||||
|
||||
const userLevelId = getCookiesDecrypt("ulie");
|
||||
const roleId = getCookiesDecrypt("urie");
|
||||
|
||||
const columns = useTableColumns();
|
||||
|
||||
const [pagination, setPagination] = React.useState<PaginationState>({
|
||||
pageIndex: 0,
|
||||
pageSize: Number(showData),
|
||||
});
|
||||
|
||||
const table = useReactTable({
|
||||
data: dataTable,
|
||||
columns,
|
||||
onSortingChange: setSorting,
|
||||
onColumnFiltersChange: setColumnFilters,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getPaginationRowModel: getPaginationRowModel(),
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
getFilteredRowModel: getFilteredRowModel(),
|
||||
onColumnVisibilityChange: setColumnVisibility,
|
||||
onRowSelectionChange: setRowSelection,
|
||||
onPaginationChange: setPagination,
|
||||
state: {
|
||||
sorting,
|
||||
columnFilters,
|
||||
columnVisibility,
|
||||
rowSelection,
|
||||
pagination,
|
||||
},
|
||||
});
|
||||
|
||||
// Sync page dari URL (?page=)
|
||||
React.useEffect(() => {
|
||||
const pageFromUrl = searchParams?.get("page");
|
||||
if (pageFromUrl) setPage(Number(pageFromUrl));
|
||||
}, [searchParams]);
|
||||
|
||||
// Ambil kategori sekali di awal
|
||||
React.useEffect(() => {
|
||||
getCategories();
|
||||
}, []);
|
||||
|
||||
// Fetch data ketika filter/pagination berubah
|
||||
React.useEffect(() => {
|
||||
fetchData();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
categoryFilter,
|
||||
statusFilter,
|
||||
startDate,
|
||||
endDate,
|
||||
showData,
|
||||
page,
|
||||
typeId,
|
||||
filterByCreatorGroup,
|
||||
]);
|
||||
|
||||
async function getCategories() {
|
||||
try {
|
||||
// ini mengikuti kode awal, type "2" (misal: kategori video)
|
||||
const category = await listEnableCategory("2");
|
||||
const resCategory = category?.data?.data?.content;
|
||||
setCategories(resCategory || []);
|
||||
} catch (error) {
|
||||
console.error("Error fetching categories:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchData(showLoader = false, customSearch?: string) {
|
||||
const formattedStartDate = startDate
|
||||
? format(new Date(startDate), "yyyy-MM-dd")
|
||||
: "";
|
||||
const formattedEndDate = endDate
|
||||
? format(new Date(endDate), "yyyy-MM-dd")
|
||||
: "";
|
||||
|
||||
try {
|
||||
if (showLoader) {
|
||||
MySwal.fire({
|
||||
title: "Memuat data...",
|
||||
html: "Mohon tunggu sebentar",
|
||||
allowOutsideClick: false,
|
||||
didOpen: () => MySwal.showLoading(),
|
||||
});
|
||||
}
|
||||
|
||||
const isForSelf = Number(roleId) === 4;
|
||||
const isApproval = !isForSelf;
|
||||
|
||||
const res = await listDataSatker(
|
||||
isForSelf,
|
||||
isApproval,
|
||||
page - 1, // page (0-based)
|
||||
parseInt(showData) || 10, // limit
|
||||
search, // search (kalau diperlukan di backend)
|
||||
typeId, // typeId: 1=image, 2=video, 3=text, 4=audio
|
||||
statusFilter?.join(","), // statusId
|
||||
statusFilter?.join(",")?.includes("1") ? userLevelId : "",
|
||||
filterByCreator,
|
||||
filterBySource,
|
||||
formattedStartDate,
|
||||
formattedEndDate,
|
||||
customSearch ?? search // title
|
||||
);
|
||||
|
||||
const data = res?.data?.data;
|
||||
const contentData = data?.content || [];
|
||||
const newData = contentData.map((item: any, index: number) => ({
|
||||
...item,
|
||||
no: (page - 1) * Number(showData) + index + 1,
|
||||
}));
|
||||
|
||||
setDataTable([...newData]);
|
||||
setTotalData(data?.totalElements || 0);
|
||||
setTotalPage(data?.totalPages || 1);
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
} finally {
|
||||
MySwal.close();
|
||||
}
|
||||
}
|
||||
|
||||
// === HANDLERS ===
|
||||
const handleCheckboxChange = (categoryId: number) => {
|
||||
setSelectedCategories((prev) =>
|
||||
prev.includes(categoryId)
|
||||
? prev.filter((id) => id !== categoryId)
|
||||
: [...prev, categoryId]
|
||||
);
|
||||
|
||||
setCategoryFilter((prev) => {
|
||||
const updated = prev.split(",").filter(Boolean).map(Number);
|
||||
const newList = updated.includes(categoryId)
|
||||
? updated.filter((id) => id !== categoryId)
|
||||
: [...updated, categoryId];
|
||||
return newList.join(",");
|
||||
});
|
||||
};
|
||||
|
||||
function handleStatusCheckboxChange(value: any) {
|
||||
setStatusFilter((prev: any) =>
|
||||
prev.includes(value)
|
||||
? prev.filter((status: any) => status !== value)
|
||||
: [...prev, value]
|
||||
);
|
||||
}
|
||||
|
||||
// Search dengan debounce 2 detik
|
||||
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = e.target.value;
|
||||
setSearch(value);
|
||||
|
||||
if (searchTimeoutRef.current) {
|
||||
clearTimeout(searchTimeoutRef.current);
|
||||
}
|
||||
|
||||
searchTimeoutRef.current = setTimeout(() => {
|
||||
// setiap kali search, reset ke page 1
|
||||
setPage(1);
|
||||
fetchData(true, value);
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
const handleSearchFilterByCreator = (
|
||||
e: React.ChangeEvent<HTMLInputElement>
|
||||
) => {
|
||||
const value = e.target.value;
|
||||
setFilterByCreator(value);
|
||||
setPage(1);
|
||||
fetchData(true);
|
||||
};
|
||||
|
||||
const handleSearchFilterBySource = (
|
||||
e: React.ChangeEvent<HTMLInputElement>
|
||||
) => {
|
||||
const value = e.target.value;
|
||||
setFilterBySource(value);
|
||||
setPage(1);
|
||||
fetchData(true);
|
||||
};
|
||||
|
||||
// 🧹 Reset semua filter
|
||||
const handleResetFilters = () => {
|
||||
setSelectedCategories([]);
|
||||
setCategoryFilter("");
|
||||
setStatusFilter([]);
|
||||
setStartDate("");
|
||||
setEndDate("");
|
||||
setFilterByCreator("");
|
||||
setFilterBySource("");
|
||||
setFilterByCreatorGroup("");
|
||||
setTypeId("");
|
||||
setPage(1);
|
||||
fetchData(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<div className="flex flex-col md:flex-row md:justify-between items-center md:px-5">
|
||||
{/* 🔍 Search bar */}
|
||||
<div className="w-full md:w-[200px] lg:w-[300px] px-2">
|
||||
<InputGroup merged>
|
||||
<InputGroupText className="bg-transparent dark:border-secondary dark:group-focus-within:border-secondary">
|
||||
<Search className="h-6 w-6 dark:text-white" />
|
||||
</InputGroupText>
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Cari Judul..."
|
||||
className="bg-transparent dark:border-secondary dark:placeholder-white/80 dark:focus:border-secondary dark:text-white text-[16px]"
|
||||
value={search}
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</InputGroup>
|
||||
</div>
|
||||
|
||||
{/* Filter & Columns & ShowData */}
|
||||
<div className="flex flex-wrap items-center gap-3 mt-2 md:mt-0">
|
||||
{/* Show Data Dropdown */}
|
||||
<div className="mx-3">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button size="md" variant="outline">
|
||||
{showData} Data
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56 text-sm">
|
||||
<DropdownMenuRadioGroup
|
||||
value={showData}
|
||||
onValueChange={(value) => {
|
||||
setShowData(value);
|
||||
setPagination((prev) => ({
|
||||
...prev,
|
||||
pageSize: Number(value),
|
||||
pageIndex: 0,
|
||||
}));
|
||||
setPage(1);
|
||||
}}
|
||||
>
|
||||
<DropdownMenuRadioItem value="10">
|
||||
10 Data
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="50">
|
||||
50 Data
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="100">
|
||||
100 Data
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="250">
|
||||
250 Data
|
||||
</DropdownMenuRadioItem>
|
||||
</DropdownMenuRadioGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
{/* Jenis Konten (typeId) */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="md">
|
||||
Jenis Konten <ChevronDown />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56 text-sm">
|
||||
<DropdownMenuRadioGroup
|
||||
value={typeId}
|
||||
onValueChange={(value) => {
|
||||
setTypeId(value);
|
||||
setPage(1);
|
||||
fetchData(true);
|
||||
}}
|
||||
>
|
||||
<DropdownMenuRadioItem value="">
|
||||
Semua Jenis
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="1">
|
||||
Gambar / Image
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="2">
|
||||
Video
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="3">
|
||||
Teks / Artikel
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="4">
|
||||
Audio
|
||||
</DropdownMenuRadioItem>
|
||||
</DropdownMenuRadioGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Filter Dropdown */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="md">
|
||||
Filter <ChevronDown />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
className="w-64 h-[380px] overflow-y-auto"
|
||||
>
|
||||
{/* 🧹 Reset All Button */}
|
||||
<div className="flex justify-end px-3 pt-2 pb-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-xs text-gray-700 hover:bg-red-200 dark:text-white"
|
||||
onClick={handleResetFilters}
|
||||
>
|
||||
Reset Semua Filter
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Label className="ml-2">Kategori</Label>
|
||||
{categories.length > 0 ? (
|
||||
categories.map((category) => (
|
||||
<div
|
||||
key={category.id}
|
||||
className="flex items-center px-4 py-1"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`category-${category.id}`}
|
||||
className="mr-2"
|
||||
checked={selectedCategories.includes(category.id)}
|
||||
onChange={() => handleCheckboxChange(category.id)}
|
||||
/>
|
||||
<label
|
||||
htmlFor={`category-${category.id}`}
|
||||
className="text-sm"
|
||||
>
|
||||
{category.name}
|
||||
</label>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<p className="text-sm text-gray-500 px-4 py-2">
|
||||
Tidak ada kategori.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="mx-2 my-1">
|
||||
<Label>Tanggal Awal</Label>
|
||||
<Input
|
||||
type="date"
|
||||
value={startDate}
|
||||
onChange={(e) => {
|
||||
setStartDate(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="mx-2 my-1">
|
||||
<Label>Tanggal Akhir</Label>
|
||||
<Input
|
||||
type="date"
|
||||
value={endDate}
|
||||
onChange={(e) => {
|
||||
setEndDate(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mx-2 my-1">
|
||||
<Label>Kreator</Label>
|
||||
<Input
|
||||
placeholder="Nama kreator..."
|
||||
value={filterByCreator}
|
||||
onChange={handleSearchFilterByCreator}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mx-2 my-1">
|
||||
<Label>Sumber</Label>
|
||||
<Input
|
||||
placeholder="Nama sumber..."
|
||||
value={filterBySource}
|
||||
onChange={handleSearchFilterBySource}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Label className="ml-2 mt-2">Status</Label>
|
||||
{[1, 2, 3, 4].map((id) => {
|
||||
const label =
|
||||
id === 1
|
||||
? "Menunggu Review"
|
||||
: id === 2
|
||||
? "Diterima"
|
||||
: id === 3
|
||||
? "Minta Update"
|
||||
: "Ditolak";
|
||||
return (
|
||||
<div key={id} className="flex items-center px-4 py-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`status-${id}`}
|
||||
className="mr-2"
|
||||
checked={statusFilter.includes(id)}
|
||||
onChange={() => handleStatusCheckboxChange(id)}
|
||||
/>
|
||||
<label htmlFor={`status-${id}`} className="text-sm">
|
||||
{label}
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Columns Toggle */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="md">
|
||||
Columns <ChevronDown />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{table
|
||||
.getAllColumns()
|
||||
.filter((column) => column.getCanHide())
|
||||
.map((column) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={column.id}
|
||||
className="capitalize"
|
||||
checked={column.getIsVisible()}
|
||||
onCheckedChange={(value) =>
|
||||
column.toggleVisibility(!!value)
|
||||
}
|
||||
>
|
||||
{column.id}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* === TABLE === */}
|
||||
<Table className="overflow-hidden mt-3">
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id} className="bg-default-200">
|
||||
{headerGroup.headers.map((header) => (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<TableRow
|
||||
key={row.id}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
className="h-[75px]"
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext()
|
||||
)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||
Tidak ada hasil ditemukan.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<TablePagination
|
||||
table={table}
|
||||
totalData={totalData}
|
||||
totalPage={totalPage}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableSatker;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import FormVideo from "@/components/form/content/video-form";
|
||||
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||
|
||||
const VideoCreatePage = async () => {
|
||||
return (
|
||||
<div>
|
||||
<SiteBreadcrumb />
|
||||
<div className="space-y-4">
|
||||
<FormVideo />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoCreatePage;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||
import FormImageDetail from "@/components/form/content/image-detail-form";
|
||||
import FormVideoDetail from "@/components/form/content/video-detail-form";
|
||||
|
||||
const VideoDetailPage = async () => {
|
||||
return (
|
||||
<div>
|
||||
<SiteBreadcrumb />
|
||||
<div className="space-y-4">
|
||||
<FormVideoDetail />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoDetailPage;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { Metadata } from "next";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Media Hub | POLRI",
|
||||
description: "Media Hub merupakan situs resmi milik Divisi Humas Polri di mana di dalamnya berisi konten-konten yang dapat diakses secara gratis oleh Internal Polri, Jurnalis, Masyarakat Umum, dan KSP.",
|
||||
};
|
||||
const Layout = ({ children }: { children: React.ReactNode }) => {
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default Layout;
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
"use client";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||
import TableImage from "./components/table-satker";
|
||||
import { UploadIcon } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Icon } from "@iconify/react/dist/iconify.js";
|
||||
import TableVideo from "./components/table-satker";
|
||||
import { Link } from "@/components/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
const ReactTableVideoPage = () => {
|
||||
const t = useTranslations("AnalyticsDashboard");
|
||||
return (
|
||||
<div>
|
||||
<SiteBreadcrumb />
|
||||
<div className="space-y-4">
|
||||
<Card className="py-4 px-3">
|
||||
<div className="flex flex-wrap justify-between items-center px-5">
|
||||
<div className="flex flex-row items-center text-xl font-medium text-default-900 gap-2">
|
||||
<div>
|
||||
<Icon icon="icon-park-outline:check-one" />
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span className="text-red-500">{t("average", { defaultValue: "Average" })} :0</span>
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
{t("Hasil_unggah_disetujui_hari_ini", { defaultValue: "Hasil Unggah Disetujui Hari Ini" })}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-row items-center text-xl font-medium text-default-900 gap-2">
|
||||
<div>
|
||||
<Icon icon="material-symbols:settings-backup-restore-rounded" />
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span className="text-red-500">{t("average", { defaultValue: "Average" })} :0</span>
|
||||
</p>
|
||||
<p className="text-sm">{t("Hasil_unggah_direvisi_hari_ini", { defaultValue: "Hasil Unggah Direvisi Hari Ini" })}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-row items-center text-xl font-medium text-default-900 gap-2">
|
||||
<div>
|
||||
<Icon icon="healthicons:no-outline" />
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span className="text-red-500">{t("average", { defaultValue: "Average" })} :0</span>
|
||||
</p>
|
||||
<p className="text-sm">{t("Hasil_unggah_ditolak_hari_ini", { defaultValue: "Hasil Unggah Ditolak Hari Ini" })}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="border-b border-solid border-default-200 mb-6">
|
||||
<CardTitle>
|
||||
<div className="flex items-center">
|
||||
<div className="flex-1 text-xl font-medium text-default-900">
|
||||
{t("video", { defaultValue: "Video" })}
|
||||
</div>
|
||||
<div className="flex-none">
|
||||
<Link href={"/contributor/content/video/create"}>
|
||||
<Button color="primary" className="text-white">
|
||||
<UploadIcon size={18} className="mr-2" />
|
||||
{t("create-video", { defaultValue: "Create Video" })}
|
||||
</Button>
|
||||
</Link>
|
||||
{/* <Button color="primary" className="text-white ml-3">
|
||||
<UploadIcon />
|
||||
Unggah Video Dengan AI
|
||||
</Button> */}
|
||||
</div>
|
||||
</div>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<TableVideo />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ReactTableVideoPage;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||
import FormImageDetail from "@/components/form/content/image-detail-form";
|
||||
import FormImageUpdate from "@/components/form/content/image-update-form";
|
||||
import FormVideoUpdate from "@/components/form/content/video-update-form";
|
||||
import FormVideoSeo from "@/components/form/content/video-update-seo";
|
||||
|
||||
const VideoUpdatePage = async () => {
|
||||
return (
|
||||
<div>
|
||||
<SiteBreadcrumb />
|
||||
<div className="space-y-4">
|
||||
<FormVideoSeo />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoUpdatePage;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||
import FormImageDetail from "@/components/form/content/image-detail-form";
|
||||
import FormImageUpdate from "@/components/form/content/image-update-form";
|
||||
import FormVideoUpdate from "@/components/form/content/video-update-form";
|
||||
|
||||
const VideoUpdatePage = async () => {
|
||||
return (
|
||||
<div>
|
||||
<SiteBreadcrumb />
|
||||
<div className="space-y-4">
|
||||
<FormVideoUpdate />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoUpdatePage;
|
||||
|
|
@ -99,7 +99,7 @@ const Navbar = () => {
|
|||
? `/polda/${poldaName}`
|
||||
: satkerName
|
||||
? `/satker/${satkerName}`
|
||||
: "/";
|
||||
: "";
|
||||
|
||||
let menu = "";
|
||||
|
||||
|
|
@ -205,6 +205,21 @@ const Navbar = () => {
|
|||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!pathname) return;
|
||||
|
||||
if (
|
||||
pathname.startsWith("/_next") ||
|
||||
pathname.startsWith("/api") ||
|
||||
pathname.includes("favicon")
|
||||
)
|
||||
return;
|
||||
|
||||
if (!pathname.startsWith("/in")) {
|
||||
router.replace("/in");
|
||||
}
|
||||
}, [pathname]);
|
||||
|
||||
return (
|
||||
<div className="bg-[#f7f7f7] dark:bg-black shadow-md sticky top-0 z-50">
|
||||
<div className="flex items-center justify-between px-4 lg:px-16 py-2 gap-3">
|
||||
|
|
|
|||
14
lib/menus.ts
14
lib/menus.ts
|
|
@ -4321,13 +4321,13 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
|||
icon: "heroicons:arrow-trending-up",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
href: "/admin/settings/banner",
|
||||
label: "Banner",
|
||||
active: pathname === "/admin/settings/banner",
|
||||
icon: "heroicons:arrow-trending-up",
|
||||
children: [],
|
||||
},
|
||||
// {
|
||||
// href: "/admin/settings/banner",
|
||||
// label: "Banner",
|
||||
// active: pathname === "/admin/settings/banner",
|
||||
// icon: "heroicons:arrow-trending-up",
|
||||
// children: [],
|
||||
// },
|
||||
// {
|
||||
// href: "/admin/settings/feedback",
|
||||
// label: "Feedback",
|
||||
|
|
|
|||
|
|
@ -1,29 +1,65 @@
|
|||
import createMiddleware from "next-intl/middleware";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { locales } from "@/config";
|
||||
import { routing } from "./i18n/routing";
|
||||
|
||||
// export default async function middleware(request: NextRequest) {
|
||||
// // Step 1: Use the incoming request (example)
|
||||
// const defaultLocale = "in";
|
||||
// // const defaultLocale = request.headers.get("dashcode-locale") || "in";
|
||||
const intlMiddleware = createMiddleware(routing);
|
||||
|
||||
// // Step 2: Create and call the next-intl middleware (example)
|
||||
// const handleI18nRouting = createMiddleware({
|
||||
// locales: ["in", "en"],
|
||||
// defaultLocale: "in",
|
||||
// });
|
||||
// const response = handleI18nRouting(request);
|
||||
export default function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
// // Step 3: Alter the response (example)
|
||||
// response.headers.set("dashcode-locale", defaultLocale);
|
||||
// Abaikan asset & API
|
||||
if (
|
||||
pathname.startsWith("/api") ||
|
||||
pathname.startsWith("/_next") ||
|
||||
pathname.startsWith("/favicon") ||
|
||||
pathname.startsWith("/assets")
|
||||
) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
// return response;
|
||||
// }
|
||||
// Jika sudah mengandung /in → pakai next-intl
|
||||
if (pathname.startsWith("/in")) {
|
||||
return intlMiddleware(request);
|
||||
}
|
||||
|
||||
export default createMiddleware(routing);
|
||||
// Jika TIDAK mengandung /in → selalu tambahkan /in
|
||||
// Contoh:
|
||||
// /image/detail/... → /in/image/detail/...
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = `/in${pathname}`;
|
||||
return NextResponse.redirect(url);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
// Match only internationalized pathnames
|
||||
matcher: ["/", "/(in|en)/:path*"],
|
||||
matcher: ["/((?!_next|api|favicon.ico|assets).*)"],
|
||||
};
|
||||
|
||||
// import createMiddleware from "next-intl/middleware";
|
||||
// import { NextRequest, NextResponse } from "next/server";
|
||||
// import { locales } from "@/config";
|
||||
// import { routing } from "./i18n/routing";
|
||||
|
||||
// // export default async function middleware(request: NextRequest) {
|
||||
// // // Step 1: Use the incoming request (example)
|
||||
// // const defaultLocale = "in";
|
||||
// // // const defaultLocale = request.headers.get("dashcode-locale") || "in";
|
||||
|
||||
// // // Step 2: Create and call the next-intl middleware (example)
|
||||
// // const handleI18nRouting = createMiddleware({
|
||||
// // locales: ["in", "en"],
|
||||
// // defaultLocale: "in",
|
||||
// // });
|
||||
// // const response = handleI18nRouting(request);
|
||||
|
||||
// // // Step 3: Alter the response (example)
|
||||
// // response.headers.set("dashcode-locale", defaultLocale);
|
||||
|
||||
// // return response;
|
||||
// // }
|
||||
|
||||
// export default createMiddleware(routing);
|
||||
|
||||
// export const config = {
|
||||
// // Match only internationalized pathnames
|
||||
// matcher: ["/", "/(in|en)/:path*"],
|
||||
// };
|
||||
|
|
|
|||
|
|
@ -46,6 +46,39 @@ export async function listDataAll(
|
|||
);
|
||||
}
|
||||
|
||||
export async function listDataSatker(
|
||||
isForSelf: any,
|
||||
isApproval: any,
|
||||
page: any,
|
||||
limit: any,
|
||||
search: any,
|
||||
typeId: any,
|
||||
statusFilter: any,
|
||||
needApprovalFromLevel: any,
|
||||
creator: any,
|
||||
source: any,
|
||||
startDate: any,
|
||||
endDate: any,
|
||||
title: string = ""
|
||||
) {
|
||||
return await httpGetInterceptor(
|
||||
`media/list?enablePage=1&sortBy=createdAt&sort=desc&isAllSatker=1` +
|
||||
`&size=${limit}` +
|
||||
`&page=${page}` +
|
||||
`&isForSelf=${isForSelf}` +
|
||||
`&isApproval=${isApproval}` +
|
||||
`&typeId=${typeId || ""}` +
|
||||
`&statusId=${statusFilter || ""}` +
|
||||
`&needApprovalFromLevel=${needApprovalFromLevel || ""}` +
|
||||
`&creator=${encodeURIComponent(creator || "")}` +
|
||||
`&source=${encodeURIComponent(source || "")}` +
|
||||
`&startDate=${startDate || ""}` +
|
||||
`&endDate=${endDate || ""}` +
|
||||
`&title=${encodeURIComponent(title || search || "")}`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export async function listDataImage(
|
||||
size: any = "",
|
||||
page: any = "",
|
||||
|
|
|
|||
Loading…
Reference in New Issue