2025-02-11 05:54:31 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import * as React from "react";
|
|
|
|
|
import {
|
|
|
|
|
ColumnDef,
|
|
|
|
|
ColumnFiltersState,
|
|
|
|
|
PaginationState,
|
|
|
|
|
SortingState,
|
|
|
|
|
VisibilityState,
|
|
|
|
|
flexRender,
|
|
|
|
|
getCoreRowModel,
|
|
|
|
|
getFilteredRowModel,
|
|
|
|
|
getPaginationRowModel,
|
|
|
|
|
getSortedRowModel,
|
|
|
|
|
useReactTable,
|
|
|
|
|
} from "@tanstack/react-table";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "@/components/ui/table";
|
|
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
|
|
|
import {
|
|
|
|
|
ChevronLeft,
|
|
|
|
|
ChevronRight,
|
|
|
|
|
Eye,
|
|
|
|
|
MoreVertical,
|
|
|
|
|
Search,
|
|
|
|
|
SquarePen,
|
|
|
|
|
Trash2,
|
|
|
|
|
TrendingDown,
|
|
|
|
|
TrendingUp,
|
|
|
|
|
UserIcon,
|
|
|
|
|
} from "lucide-react";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuRadioGroup,
|
|
|
|
|
DropdownMenuRadioItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { InputGroup, InputGroupText } from "@/components/ui/input-group";
|
|
|
|
|
import { paginationBlog } from "@/service/blog/blog";
|
|
|
|
|
import { ticketingPagination } from "@/service/ticketing/ticketing";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
|
|
|
import TablePagination from "@/components/table/table-pagination";
|
|
|
|
|
import columns from "./column";
|
|
|
|
|
import { getPlanningPagination } from "@/service/agenda-setting/agenda-setting";
|
|
|
|
|
import {
|
|
|
|
|
Popover,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverTrigger,
|
|
|
|
|
} from "@/components/ui/popover";
|
|
|
|
|
import { listDataMedia } from "@/service/broadcast/broadcast";
|
|
|
|
|
import { listEnableCategory } from "@/service/content/content";
|
|
|
|
|
import { Checkbox } from "@/components/ui/checkbox";
|
|
|
|
|
import { close, loading } from "@/config/swal";
|
|
|
|
|
import { Link } from "@/i18n/routing";
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
2025-05-08 10:02:54 +00:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogTrigger,
|
|
|
|
|
} from "@/components/ui/dialog";
|
|
|
|
|
import { link } from "fs";
|
2025-02-11 05:54:31 +00:00
|
|
|
|
|
|
|
|
const NewsTable = () => {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
|
const [search, setSearch] = React.useState("");
|
|
|
|
|
const [showData, setShowData] = React.useState("10");
|
|
|
|
|
const [categories, setCategories] = React.useState<any>();
|
|
|
|
|
const [dataTable, setDataTable] = React.useState<any[]>([]);
|
|
|
|
|
const [totalData, setTotalData] = React.useState<number>(1);
|
|
|
|
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
|
|
|
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
|
|
|
|
[]
|
|
|
|
|
);
|
|
|
|
|
const [showTable, setShowTable] = React.useState(false);
|
2025-05-08 10:02:54 +00:00
|
|
|
const [link, setLink] = React.useState("");
|
2025-02-11 05:54:31 +00:00
|
|
|
const [columnVisibility, setColumnVisibility] =
|
|
|
|
|
React.useState<VisibilityState>({});
|
|
|
|
|
const [rowSelection, setRowSelection] = React.useState({});
|
|
|
|
|
const [pagination, setPagination] = React.useState<PaginationState>({
|
|
|
|
|
pageIndex: 0,
|
|
|
|
|
pageSize: Number(showData),
|
|
|
|
|
});
|
|
|
|
|
const [categoryFilter, setCategoryFilter] = React.useState<number[]>([]);
|
|
|
|
|
const [statusFilter, setStatusFilter] = React.useState<number[]>([]);
|
|
|
|
|
const [page, setPage] = React.useState(1);
|
|
|
|
|
const [totalPage, setTotalPage] = React.useState(1);
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let typingTimer: any;
|
|
|
|
|
const doneTypingInterval = 1500;
|
|
|
|
|
|
|
|
|
|
// const handleKeyUp = () => {
|
|
|
|
|
// clearTimeout(typingTimer);
|
|
|
|
|
// typingTimer = setTimeout(doneTyping, doneTypingInterval);
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = () => {
|
|
|
|
|
clearTimeout(typingTimer);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// async function doneTyping() {
|
|
|
|
|
// fetchData();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
const pageFromUrl = searchParams?.get("page");
|
|
|
|
|
if (pageFromUrl) {
|
|
|
|
|
setPage(Number(pageFromUrl));
|
|
|
|
|
}
|
|
|
|
|
}, [searchParams]);
|
|
|
|
|
|
|
|
|
|
// React.useEffect(() => {
|
|
|
|
|
// fetchData();
|
|
|
|
|
// setPagination({
|
|
|
|
|
// pageIndex: 0,
|
|
|
|
|
// pageSize: Number(showData),
|
|
|
|
|
// });
|
|
|
|
|
// }, [page, showData]);
|
|
|
|
|
|
|
|
|
|
// async function fetchData() {
|
|
|
|
|
// try {
|
|
|
|
|
// loading();
|
|
|
|
|
// const res = await listDataMedia(
|
|
|
|
|
// page - 1,
|
|
|
|
|
// showData,
|
|
|
|
|
// search,
|
|
|
|
|
// categoryFilter?.sort().join(","),
|
|
|
|
|
// statusFilter?.sort().join(",")
|
|
|
|
|
// );
|
|
|
|
|
// const data = res?.data?.data;
|
|
|
|
|
// const contentData = data?.content;
|
|
|
|
|
// contentData.forEach((item: any, index: number) => {
|
|
|
|
|
// item.no = (page - 1) * Number(showData) + index + 1;
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// console.log("contentData : ", data);
|
|
|
|
|
|
|
|
|
|
// setDataTable(contentData);
|
|
|
|
|
// setTotalData(data?.totalElements);
|
|
|
|
|
// setTotalPage(data?.totalPages);
|
|
|
|
|
// close();
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.error("Error fetching tasks:", error);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
getCategories();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
async function getCategories() {
|
|
|
|
|
const category = await listEnableCategory("");
|
|
|
|
|
const resCategory = category?.data?.data?.content;
|
|
|
|
|
setCategories(resCategory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleChange = (type: string, id: number, checked: boolean) => {
|
|
|
|
|
if (type === "category") {
|
|
|
|
|
if (checked) {
|
|
|
|
|
const temp: number[] = [...categoryFilter];
|
|
|
|
|
temp.push(id);
|
|
|
|
|
setCategoryFilter(temp);
|
|
|
|
|
} else {
|
|
|
|
|
const temp = categoryFilter.filter((a) => a !== id);
|
|
|
|
|
setCategoryFilter(temp);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (checked) {
|
|
|
|
|
const temp: number[] = [...statusFilter];
|
|
|
|
|
temp.push(id);
|
|
|
|
|
setStatusFilter(temp);
|
|
|
|
|
} else {
|
|
|
|
|
const temp = statusFilter.filter((a) => a !== id);
|
|
|
|
|
setStatusFilter(temp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="w-full overflow-x-auto bg-white p-4 rounded-sm space-y-3 border">
|
2025-05-08 10:02:54 +00:00
|
|
|
<div className="flex justify-between items-center">
|
2025-02-11 05:54:31 +00:00
|
|
|
<p className="text-xl font-medium text-default-900">
|
|
|
|
|
Tracking Berita hari ini!
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2025-05-08 10:02:54 +00:00
|
|
|
<Dialog>
|
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
|
<Button className="bg-blue-600" size="md">
|
2025-02-11 05:54:31 +00:00
|
|
|
Tracking Berita
|
|
|
|
|
</Button>
|
2025-05-08 10:02:54 +00:00
|
|
|
</DialogTrigger>
|
|
|
|
|
<DialogContent className="sm:max-w-md">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>Form Tracking Berita</DialogTitle>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
<div className="grid gap-4 py-4">
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label htmlFor="link" className="text-sm font-medium">
|
|
|
|
|
Masukkan Link <span className="text-red-500">*</span>
|
|
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
id="link"
|
|
|
|
|
placeholder="Masukkan Link disini!"
|
|
|
|
|
value={link}
|
|
|
|
|
onChange={(e) => setLink(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-sm text-muted-foreground mt-1">
|
|
|
|
|
Sisa Kuota Harian: 5 Kata Kunci
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<DialogFooter className="flex justify-end gap-2">
|
|
|
|
|
<Button variant="outline">Batal</Button>
|
|
|
|
|
<Button className="bg-blue-600 text-white">Tracking Berita</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
<Table className="overflow-hidden mt-4">
|
|
|
|
|
<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>
|
2025-02-11 05:54:31 +00:00
|
|
|
))}
|
2025-05-08 10:02:54 +00:00
|
|
|
</TableRow>
|
|
|
|
|
))}
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{table.getRowModel().rows?.length ? (
|
|
|
|
|
table.getRowModel().rows.map((row) => (
|
|
|
|
|
<TableRow key={row.id} className="h-[75px]">
|
|
|
|
|
{row.getVisibleCells().map((cell) => (
|
|
|
|
|
<TableCell key={cell.id}>
|
|
|
|
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
2025-02-11 05:54:31 +00:00
|
|
|
</TableCell>
|
2025-05-08 10:02:54 +00:00
|
|
|
))}
|
|
|
|
|
</TableRow>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
|
|
|
|
No results.
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
<TablePagination
|
|
|
|
|
table={table}
|
|
|
|
|
totalData={totalData}
|
|
|
|
|
totalPage={totalPage}
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex justify-end mt-4">
|
|
|
|
|
<Button
|
|
|
|
|
color="primary"
|
|
|
|
|
size="md"
|
|
|
|
|
className="text-sm mr-3"
|
|
|
|
|
onClick={() => setShowTable(false)}
|
|
|
|
|
>
|
|
|
|
|
Tracking Berita Baru
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{/* </>
|
|
|
|
|
)} */}
|
2025-02-11 05:54:31 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default NewsTable;
|