run build fixing
This commit is contained in:
parent
4a716dd637
commit
853ec99014
|
|
@ -1,141 +1,371 @@
|
||||||
"use client";
|
"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 { Button } from "@/components/ui/button";
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogClose,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { close, error, loading, successCallback } from "@/config/swal";
|
|
||||||
import {
|
import {
|
||||||
listData5Data,
|
Table,
|
||||||
listDataAllNonPagination,
|
TableBody,
|
||||||
mediaTrackingSave,
|
TableCell,
|
||||||
} from "@/service/media-tracking/media-tracking";
|
TableHead,
|
||||||
import { useEffect, useState } from "react";
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import {
|
||||||
|
ChevronDown,
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
Eye,
|
||||||
|
MoreVertical,
|
||||||
|
Search,
|
||||||
|
SquarePen,
|
||||||
|
Trash2,
|
||||||
|
TrendingDown,
|
||||||
|
TrendingUp,
|
||||||
|
UserIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuRadioGroup,
|
||||||
|
DropdownMenuRadioItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||||
|
import TablePagination from "@/components/table/table-pagination";
|
||||||
|
import columns from "./column";
|
||||||
|
import { listEnableCategory } from "@/service/content/content";
|
||||||
|
import { close, loading } from "@/config/swal";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import TrackingMediaModal from "./modal";
|
||||||
|
import { getMediaTracking } from "@/service/media-tracking/media-tracking";
|
||||||
|
|
||||||
export default function TrackingMediaModal(props: {
|
const NewsTable = () => {
|
||||||
triggerFetch: () => void;
|
const router = useRouter();
|
||||||
}) {
|
const asPath = usePathname();
|
||||||
const [content, setContent] = useState<any>([]);
|
const searchParams = useSearchParams();
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [showData, setShowData] = React.useState("10");
|
||||||
const [selectedId, setSelectedId] = useState(0);
|
const [categories, setCategories] = React.useState<any>();
|
||||||
useEffect(() => {
|
const [dataTable, setDataTable] = React.useState<any[]>([]);
|
||||||
initFecth();
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
const [showTable, setShowTable] = React.useState(false);
|
||||||
|
const [onSearch, setOnSearch] = React.useState("");
|
||||||
|
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<any>([]);
|
||||||
|
const [searchTitle, setSearchTitle] = React.useState<string>("");
|
||||||
|
const [statusFilter, setStatusFilter] = React.useState<number[]>([]);
|
||||||
|
const [page, setPage] = React.useState(1);
|
||||||
|
const [imageData, setImageData] = React.useState<any>();
|
||||||
|
const [totalData, setTotalData] = React.useState<number>(1);
|
||||||
|
const [totalPage, setTotalPage] = React.useState(1);
|
||||||
|
const [contentAll, setContentAll] = React.useState([]);
|
||||||
|
const [formatFilter, setFormatFilter] = React.useState<any>([]);
|
||||||
|
const [totalContent, setTotalContent] = React.useState();
|
||||||
|
const [search, setSearch] = React.useState<string>("");
|
||||||
|
const group = searchParams?.get("group");
|
||||||
|
const title = searchParams?.get("title");
|
||||||
|
const categorie = searchParams?.get("category");
|
||||||
|
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;
|
||||||
|
|
||||||
|
// async function doneTyping() {
|
||||||
|
// fetchData();
|
||||||
|
// }
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const pageFromUrl = searchParams?.get("page");
|
||||||
|
if (pageFromUrl) {
|
||||||
|
setPage(Number(pageFromUrl));
|
||||||
|
}
|
||||||
|
}, [searchParams]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
getCategories();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const initFecth = async () => {
|
React.useEffect(() => {
|
||||||
const response = await listData5Data();
|
getDataTable();
|
||||||
setContent(response?.data?.data.content);
|
}, [page, showData, search]);
|
||||||
};
|
|
||||||
|
|
||||||
const fecthAll = async (search?: string) => {
|
const getDataTable = async () => {
|
||||||
const response = await listDataAllNonPagination(search || inputValue);
|
const res = await getMediaTracking(page - 1, search, showData);
|
||||||
setContent(response?.data?.data.content);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const data = res?.data?.data;
|
||||||
const value = e.target.value;
|
const newData = data?.content;
|
||||||
const nowLength = value.split(" ").length;
|
|
||||||
const prevLength = inputValue.split(" ").length;
|
|
||||||
|
|
||||||
setInputValue(value);
|
newData.forEach((item: any, index: number) => {
|
||||||
|
item.no = (page - 1) * Number(showData) + index + 1;
|
||||||
if (value === "") {
|
|
||||||
initFecth();
|
|
||||||
setSelectedId(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (/\s/.test(value)) {
|
|
||||||
console.log("Terdapat spasi dalam input");
|
|
||||||
fecthAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nowLength !== prevLength) {
|
|
||||||
fecthAll();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const doSave = async () => {
|
|
||||||
loading();
|
|
||||||
const req = {
|
|
||||||
mediaUploadId: selectedId,
|
|
||||||
duration: 24,
|
|
||||||
scrapingPeriod: 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
const res = await mediaTrackingSave(req);
|
|
||||||
if (res?.error) {
|
|
||||||
error(res?.message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
close();
|
|
||||||
|
|
||||||
toast("Berhasil Menambahkan", {
|
|
||||||
description: "",
|
|
||||||
});
|
});
|
||||||
props.triggerFetch();
|
|
||||||
return false;
|
setDataTable(newData);
|
||||||
|
setTotalData(data?.totalElements);
|
||||||
|
setTotalPage(data?.totalPages);
|
||||||
|
setTotalContent(data.totalElements);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function getCategories() {
|
||||||
|
const category = await listEnableCategory("");
|
||||||
|
const resCategory = category?.data?.data?.content;
|
||||||
|
setCategories(resCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (categorie) {
|
||||||
|
setCategoryFilter(
|
||||||
|
categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie]
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"Kategori",
|
||||||
|
categorie,
|
||||||
|
categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [categorie]);
|
||||||
|
|
||||||
|
const handleCategoryFilter = (e: boolean, id: string) => {
|
||||||
|
let filter = [...categoryFilter];
|
||||||
|
|
||||||
|
if (e) {
|
||||||
|
filter = [...categoryFilter, String(id)];
|
||||||
|
} else {
|
||||||
|
filter.splice(categoryFilter.indexOf(id), 1);
|
||||||
|
}
|
||||||
|
console.log("checkbox filter", filter);
|
||||||
|
setCategoryFilter(filter);
|
||||||
|
router.push(`?category=${filter.join("&")}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanCheckbox = () => {
|
||||||
|
setCategoryFilter([]);
|
||||||
|
setFormatFilter([]);
|
||||||
|
router.push(`?category=&title=`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// async function getData() {
|
||||||
|
// if (asPath?.includes("/polda/") == true) {
|
||||||
|
// if (asPath?.split("/")[2] !== "[polda_name]") {
|
||||||
|
// const filter =
|
||||||
|
// categoryFilter?.length > 0
|
||||||
|
// ? categoryFilter?.sort().join(",")
|
||||||
|
// : categorie || "";
|
||||||
|
|
||||||
|
// const name = title == undefined ? "" : title;
|
||||||
|
// const format = formatFilter == undefined ? "" : formatFilter?.join(",");
|
||||||
|
// const filterGroup = group == undefined ? asPath.split("/")[2] : group;
|
||||||
|
// loading();
|
||||||
|
// const response = await listDataAll("", name, filter, "");
|
||||||
|
// close();
|
||||||
|
// // setGetTotalPage(response?.data?.data?.totalPages);
|
||||||
|
// // setContentImage(response?.data?.data?.content);
|
||||||
|
// // setTotalContent(response?.data?.data?.totalElements);
|
||||||
|
// const data = response?.data?.data;
|
||||||
|
// const contentData = data?.content;
|
||||||
|
// setImageData(contentData);
|
||||||
|
// setTotalData(data?.totalElements);
|
||||||
|
// setContentAll(response?.data?.data?.content);
|
||||||
|
// setTotalPage(data?.totalPages);
|
||||||
|
// setTotalContent(response?.data?.data?.totalElements);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSearch(e.target.value);
|
||||||
|
table.getColumn("judul")?.setFilterValue(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyUp = () => {
|
||||||
|
clearTimeout(typingTimer);
|
||||||
|
typingTimer = setTimeout(doneTyping, doneTypingInterval);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function doneTyping() {
|
||||||
|
if (searchTitle == "" || searchTitle == undefined) {
|
||||||
|
router.push("?title=");
|
||||||
|
} else {
|
||||||
|
router.push(`?title=${searchTitle}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleKeyDown = () => {
|
||||||
|
clearTimeout(typingTimer);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<div className="w-full overflow-x-auto bg-white p-4 rounded-sm space-y-3 border ">
|
||||||
<DialogTrigger asChild>
|
<div className="flex justify-between items-center">
|
||||||
<Button className="bg-blue-600" size="md">
|
<p className="text-xl font-medium text-default-900">
|
||||||
Tracking Berita
|
Tracking Berita hari ini!
|
||||||
</Button>
|
</p>
|
||||||
</DialogTrigger>
|
</div>
|
||||||
<DialogContent className="sm:max-w-md">
|
|
||||||
<DialogHeader>
|
<div className="flex flex-col sm:flex-row lg:flex-row justify-between sm:items-center md:items-center lg:items-center px-1">
|
||||||
<DialogTitle>Form Tracking Berita</DialogTitle>
|
{/* <TrackingMediaModal triggerFetch={() => getDataTable()} /> */}
|
||||||
</DialogHeader>
|
<div className=" flex flex-row items-center gap-3">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex items-center py-2">
|
||||||
{" "}
|
<div className="mx-3">
|
||||||
<Input
|
<DropdownMenu>
|
||||||
type="text"
|
<DropdownMenuTrigger asChild>
|
||||||
placeholder="Content"
|
<Button size="md" variant="outline">
|
||||||
value={inputValue}
|
1 - {showData} Data
|
||||||
onChange={handleInputChange}
|
</Button>
|
||||||
/>{" "}
|
</DropdownMenuTrigger>
|
||||||
<div className="w-full border rounded-sm text-xs p-2 flex flex-col max-h-[300px] overflow-auto">
|
<DropdownMenuContent className="w-56 text-sm">
|
||||||
{content.length > 0 &&
|
<DropdownMenuRadioGroup
|
||||||
content.map((item: any) => (
|
value={showData}
|
||||||
<a
|
onValueChange={setShowData}
|
||||||
key={item.id}
|
>
|
||||||
className={`cursor-pointer px-2 py-4 ${
|
<DropdownMenuRadioItem value="10">
|
||||||
selectedId === item.id
|
1 - 10 Data
|
||||||
? "font-bold bg-gray-200 rounded-sm"
|
</DropdownMenuRadioItem>
|
||||||
: "hover:bg-gray-100 hover:font-semibold"
|
<DropdownMenuRadioItem value="50">
|
||||||
}`}
|
1 - 50 Data
|
||||||
onClick={() => {
|
</DropdownMenuRadioItem>
|
||||||
setSelectedId(item.id);
|
<DropdownMenuRadioItem value="100">
|
||||||
setInputValue(item.title);
|
1 - 100 Data
|
||||||
fecthAll(item.title);
|
</DropdownMenuRadioItem>
|
||||||
}}
|
<DropdownMenuRadioItem value="250">
|
||||||
>
|
1 - 250 Data
|
||||||
{item.title}
|
</DropdownMenuRadioItem>
|
||||||
</a>
|
</DropdownMenuRadioGroup>
|
||||||
))}
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center py-4">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" className="ml-auto" size="md">
|
||||||
|
Columns <ChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
{table
|
||||||
|
.getAllColumns()
|
||||||
|
.filter((column) => column.getCanHide())
|
||||||
|
.map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem
|
||||||
|
key={column.id}
|
||||||
|
className="capitalize"
|
||||||
|
checked={column.getIsVisible()}
|
||||||
|
onCheckedChange={(value) =>
|
||||||
|
column.toggleVisibility(!!value)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* <DialogFooter className="sm:justify-start">
|
</div>
|
||||||
<DialogClose asChild>
|
<Table className="overflow-hidden">
|
||||||
<Button type="button">Close</Button>
|
<TableHeader>
|
||||||
</DialogClose>
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
</DialogFooter> */}
|
<TableRow key={headerGroup.id} className="bg-default-200">
|
||||||
<DialogFooter className="flex justify-end gap-2">
|
{headerGroup.headers.map((header) => (
|
||||||
<Button className="bg-blue-600 text-white" onClick={doSave}>
|
<TableHead key={header.id}>
|
||||||
Tracking Berita
|
{header.isPlaceholder
|
||||||
</Button>
|
? null
|
||||||
</DialogFooter>
|
: flexRender(
|
||||||
</DialogContent>
|
header.column.columnDef.header,
|
||||||
</Dialog>
|
header.getContext()
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
))}
|
||||||
|
</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())}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</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> */}
|
||||||
|
{/* </>
|
||||||
|
)} */}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default NewsTable;
|
||||||
|
|
@ -266,7 +266,7 @@ const NewsTable = () => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col sm:flex-row lg:flex-row justify-between sm:items-center md:items-center lg:items-center px-1">
|
<div className="flex flex-col sm:flex-row lg:flex-row justify-between sm:items-center md:items-center lg:items-center px-1">
|
||||||
<TrackingMediaModal triggerFetch={() => getDataTable()} />
|
{/* <TrackingMediaModal triggerFetch={() => getDataTable()} /> */}
|
||||||
<div className=" flex flex-row items-center gap-3">
|
<div className=" flex flex-row items-center gap-3">
|
||||||
<div className="flex items-center py-2">
|
<div className="flex items-center py-2">
|
||||||
<div className="mx-3">
|
<div className="mx-3">
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue