feat:fix penugasan,filter content,update content

This commit is contained in:
Anang Yusman 2025-01-16 20:52:59 +08:00
parent 9c78c2a2e2
commit 95860da6d6
14 changed files with 985 additions and 290 deletions

View File

@ -68,17 +68,19 @@ const columns: ColumnDef<any>[] = [
}, },
}, },
{ {
accessorKey: "creatorGroup", accessorKey: "creatorName",
header: "Creator Group", header: "Creator Group",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorGroup")}</span> <span className="whitespace-nowrap">{row.getValue("creatorName")}</span>
), ),
}, },
{ {
accessorKey: "creatorName", accessorKey: "creatorGroupLevelName",
header: "Sumber", header: "Sumber",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorName")}</span> <span className="whitespace-nowrap">
{row.getValue("creatorGroupLevelName")}
</span>
), ),
}, },
{ {

View File

@ -26,6 +26,7 @@ import {
} from "@/components/ui/table"; } from "@/components/ui/table";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { import {
ChevronDown,
ChevronLeft, ChevronLeft,
ChevronRight, ChevronRight,
Eye, Eye,
@ -39,6 +40,7 @@ import {
import { cn, getCookiesDecrypt } from "@/lib/utils"; import { cn, getCookiesDecrypt } from "@/lib/utils";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuItem,
DropdownMenuTrigger, DropdownMenuTrigger,
@ -55,7 +57,10 @@ import {
listDataAudio, listDataAudio,
listDataImage, listDataImage,
listDataVideo, listDataVideo,
listEnableCategory,
} from "@/service/content/content"; } from "@/service/content/content";
import { Label } from "@/components/ui/label";
import { format } from "date-fns";
const TableAudio = () => { const TableAudio = () => {
const router = useRouter(); const router = useRouter();
@ -81,13 +86,17 @@ const TableAudio = () => {
const userId = getCookiesDecrypt("uie"); const userId = getCookiesDecrypt("uie");
const userLevelId = getCookiesDecrypt("ulie"); const userLevelId = getCookiesDecrypt("ulie");
const [categories, setCategories] = React.useState(); const [categories, setCategories] = React.useState<any[]>([]);
const [categoryFilter, setCategoryFilter] = React.useState([]); const [selectedCategories, setSelectedCategories] = React.useState<number[]>(
[]
);
const [categoryFilter, setCategoryFilter] = React.useState<string>("");
const [statusFilter, setStatusFilter] = React.useState([]); const [statusFilter, setStatusFilter] = React.useState([]);
const [startDateString, setStartDateString] = React.useState(""); const [startDate, setStartDate] = React.useState("");
const [endDateString, setEndDateString] = React.useState(""); const [endDate, setEndDate] = React.useState("");
const [filterByCreator, setFilterByCreator] = React.useState(""); const [filterByCreator, setFilterByCreator] = React.useState("");
const [filterBySource, setFilterBySource] = React.useState(""); const [filterBySource, setFilterBySource] = React.useState("");
const [filterByCreatorGroup, setFilterByCreatorGroup] = React.useState("");
const roleId = getCookiesDecrypt("urie"); const roleId = getCookiesDecrypt("urie");
@ -121,35 +130,69 @@ const TableAudio = () => {
React.useEffect(() => { React.useEffect(() => {
fetchData(); fetchData();
}, [page, limit, search]); getCategories();
}, [categoryFilter, page, limit, search, startDate, endDate]);
async function getCategories() {
const category = await listEnableCategory("4");
const resCategory = category?.data?.data?.content;
setCategories(resCategory || []);
}
// Fungsi menangani perubahan checkbox
const handleCheckboxChange = (categoryId: number) => {
setSelectedCategories(
(prev: any) =>
prev.includes(categoryId)
? prev.filter((id: any) => id !== categoryId) // Hapus jika sudah dipilih
: [...prev, categoryId] // Tambahkan jika belum dipilih
);
// Perbarui filter kategori
setCategoryFilter((prev) => {
const updatedCategories = prev.split(",").filter(Boolean).map(Number);
const newCategories = updatedCategories.includes(categoryId)
? updatedCategories.filter((id) => id !== categoryId)
: [...updatedCategories, categoryId];
return newCategories.join(",");
});
};
async function fetchData() { async function fetchData() {
const formattedStartDate = startDate
? format(new Date(startDate), "yyyy-MM-dd")
: "";
const formattedEndDate = endDate
? format(new Date(endDate), "yyyy-MM-dd")
: "";
try { try {
const isForSelf = Number(roleId) == 4; const isForSelf = Number(roleId) === 4;
const res = await listDataAudio( const res = await listDataAudio(
limit, limit,
page - 1, page - 1,
isForSelf, isForSelf,
!isForSelf, !isForSelf,
categoryFilter?.sort().join(","), categoryFilter,
statusFilter?.sort().join(",").includes("1") statusFilter?.sort().join(",").includes("1")
? "1,2" ? "1,2"
: statusFilter?.sort().join(","), : statusFilter?.sort().join(","),
statusFilter?.sort().join(",").includes("1") ? userLevelId : "", statusFilter?.sort().join(",").includes("1") ? userLevelId : "",
filterByCreator, filterByCreator,
filterBySource, filterBySource,
startDateString, formattedStartDate, // Pastikan format sesuai
endDateString, formattedEndDate, // Pastikan format sesuai
search search,
filterByCreatorGroup
); );
const data = res?.data?.data; const data = res?.data?.data;
const contentData = data?.content; const contentData = data?.content;
contentData.forEach((item: any, index: number) => { contentData.forEach((item: any, index: number) => {
item.no = (page - 1) * limit + index + 1; item.no = (page - 1) * limit + index + 1;
}); });
console.log("contentData : ", contentData);
setDataTable(contentData); setDataTable(contentData);
setTotalData(data?.totalElements); setTotalData(data?.totalElements);
setTotalPage(data?.totalPages); setTotalPage(data?.totalPages);
@ -157,11 +200,28 @@ const TableAudio = () => {
console.error("Error fetching tasks:", error); console.error("Error fetching tasks:", error);
} }
} }
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => { const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearch(e.target.value); // Perbarui state search setSearch(e.target.value); // Perbarui state search
table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel
}; };
const handleSearchFilterBySource = (
e: React.ChangeEvent<HTMLInputElement>
) => {
const value = e.target.value;
setFilterBySource(value); // Perbarui state filter
fetchData(); // Panggil ulang data dengan filter baru
};
const handleSearchFilterByCreator = (
e: React.ChangeEvent<HTMLInputElement>
) => {
const value = e.target.value;
setFilterByCreator(value); // Perbarui state filter
fetchData(); // Panggil ulang data dengan filter baru
};
return ( return (
<div className="w-full overflow-x-auto"> <div className="w-full overflow-x-auto">
<div className="flex justify-between items-center px-5"> <div className="flex justify-between items-center px-5">
@ -179,17 +239,139 @@ const TableAudio = () => {
/> />
</InputGroup> </InputGroup>
</div> </div>
<div className="flex-none"> <div className="flex flex-row items-center gap-3">
<Input <div className="flex items-center py-4">
placeholder="Filter Status..." <DropdownMenu>
value={ <DropdownMenuTrigger asChild>
(table.getColumn("status")?.getFilterValue() as string) ?? "" <Button variant="outline" className="ml-auto" size="md">
} Filter <ChevronDown />
onChange={(event: React.ChangeEvent<HTMLInputElement>) => </Button>
table.getColumn("status")?.setFilterValue(event.target.value) </DropdownMenuTrigger>
} <DropdownMenuContent
className="max-w-sm " align="end"
/> className="w-64 h-[200px] overflow-y-auto"
>
<div className="flex flex-row justify-between my-1 mx-1">
<p>Filter</p>
{/* <p
className="text-blue-600 cursor-pointer"
onClick={fetchData}
>
Simpan
</p> */}
</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">
No categories found.
</p>
)}
<div className="mx-2 my-1">
<Label>Tanggal Awal</Label>
<Input
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Tanggal Akhir</Label>
<Input
type="date"
value={endDate}
onChange={(e) => setEndDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Kreator</Label>
<Input
placeholder="Filter Status..."
value={filterByCreator}
onChange={handleSearchFilterByCreator}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Sumber</Label>
<Input
placeholder="Filter Status..."
value={filterBySource}
onChange={handleSearchFilterBySource}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Status</Label>
<Input
placeholder="Filter Status..."
value={
(table
.getColumn("statusName")
?.getFilterValue() as string) ?? ""
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
table
.getColumn("statusName")
?.setFilterValue(event.target.value)
}
className="max-w-sm "
/>
</div>
</DropdownMenuContent>
</DropdownMenu>
</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> </div>
<Table className="overflow-hidden mt-3"> <Table className="overflow-hidden mt-3">

View File

@ -72,17 +72,19 @@ const columns: ColumnDef<any>[] = [
}, },
}, },
{ {
accessorKey: "creatorGroup", accessorKey: "creatorName",
header: "Creator Group", header: "Creator Group",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorGroup")}</span> <span className="whitespace-nowrap">{row.getValue("creatorName")}</span>
), ),
}, },
{ {
accessorKey: "creatorName", accessorKey: "creatorGroupLevelName",
header: "Sumber", header: "Sumber",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorName")}</span> <span className="whitespace-nowrap">
{row.getValue("creatorGroupLevelName")}
</span>
), ),
}, },
{ {

View File

@ -53,13 +53,19 @@ import { Badge } from "@/components/ui/badge";
import { useRouter, useSearchParams } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
import TablePagination from "@/components/table/table-pagination"; import TablePagination from "@/components/table/table-pagination";
import columns from "./columns"; import columns from "./columns";
import { deleteMedia, listDataImage } from "@/service/content/content"; import {
deleteMedia,
listDataImage,
listEnableCategory,
} from "@/service/content/content";
import { loading } from "@/config/swal"; import { loading } from "@/config/swal";
import { toast } from "sonner"; import { toast } from "sonner";
import Swal from "sweetalert2"; import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content"; import withReactContent from "sweetalert2-react-content";
import { error } from "@/lib/swal"; import { error } from "@/lib/swal";
import { Label } from "@/components/ui/label";
import { format } from "date-fns";
const TableImage = () => { const TableImage = () => {
const router = useRouter(); const router = useRouter();
@ -85,13 +91,17 @@ const TableImage = () => {
const userId = getCookiesDecrypt("uie"); const userId = getCookiesDecrypt("uie");
const userLevelId = getCookiesDecrypt("ulie"); const userLevelId = getCookiesDecrypt("ulie");
const [categories, setCategories] = React.useState(); const [categories, setCategories] = React.useState<any[]>([]);
const [categoryFilter, setCategoryFilter] = React.useState([]); const [selectedCategories, setSelectedCategories] = React.useState<number[]>(
[]
);
const [categoryFilter, setCategoryFilter] = React.useState<string>("");
const [statusFilter, setStatusFilter] = React.useState([]); const [statusFilter, setStatusFilter] = React.useState([]);
const [startDateString, setStartDateString] = React.useState(""); const [startDate, setStartDate] = React.useState("");
const [endDateString, setEndDateString] = React.useState(""); const [endDate, setEndDate] = React.useState("");
const [filterByCreator, setFilterByCreator] = React.useState(""); const [filterByCreator, setFilterByCreator] = React.useState("");
const [filterBySource, setFilterBySource] = React.useState(""); const [filterBySource, setFilterBySource] = React.useState("");
const [filterByCreatorGroup, setFilterByCreatorGroup] = React.useState("");
const roleId = getCookiesDecrypt("urie"); const roleId = getCookiesDecrypt("urie");
@ -124,36 +134,71 @@ const TableImage = () => {
}, [searchParams]); }, [searchParams]);
React.useEffect(() => { React.useEffect(() => {
// Panggil fetchData saat filter kategori berubah
fetchData(); fetchData();
}, [page, limit, search]); getCategories();
}, [categoryFilter, page, limit, search, startDate, endDate]);
async function getCategories() {
const category = await listEnableCategory("1");
const resCategory = category?.data?.data?.content;
setCategories(resCategory || []);
}
// Fungsi menangani perubahan checkbox
const handleCheckboxChange = (categoryId: number) => {
setSelectedCategories(
(prev: any) =>
prev.includes(categoryId)
? prev.filter((id: any) => id !== categoryId) // Hapus jika sudah dipilih
: [...prev, categoryId] // Tambahkan jika belum dipilih
);
// Perbarui filter kategori
setCategoryFilter((prev) => {
const updatedCategories = prev.split(",").filter(Boolean).map(Number);
const newCategories = updatedCategories.includes(categoryId)
? updatedCategories.filter((id) => id !== categoryId)
: [...updatedCategories, categoryId];
return newCategories.join(",");
});
};
async function fetchData() { async function fetchData() {
const formattedStartDate = startDate
? format(new Date(startDate), "yyyy-MM-dd")
: "";
const formattedEndDate = endDate
? format(new Date(endDate), "yyyy-MM-dd")
: "";
try { try {
const isForSelf = Number(roleId) == 4; const isForSelf = Number(roleId) === 4;
const res = await listDataImage( const res = await listDataImage(
limit, limit,
page - 1, page - 1,
isForSelf, isForSelf,
!isForSelf, !isForSelf,
categoryFilter?.sort().join(","), categoryFilter,
statusFilter?.sort().join(",").includes("1") statusFilter?.sort().join(",").includes("1")
? "1,2" ? "1,2"
: statusFilter?.sort().join(","), : statusFilter?.sort().join(","),
statusFilter?.sort().join(",").includes("1") ? userLevelId : "", statusFilter?.sort().join(",").includes("1") ? userLevelId : "",
filterByCreator, filterByCreator,
filterBySource, filterBySource,
startDateString, formattedStartDate, // Pastikan format sesuai
endDateString, formattedEndDate, // Pastikan format sesuai
search search,
filterByCreatorGroup
); );
const data = res?.data?.data; const data = res?.data?.data;
const contentData = data?.content; const contentData = data?.content;
contentData.forEach((item: any, index: number) => { contentData.forEach((item: any, index: number) => {
item.no = (page - 1) * limit + index + 1; item.no = (page - 1) * limit + index + 1;
}); });
console.log("contentData : ", contentData);
setDataTable(contentData); setDataTable(contentData);
setTotalData(data?.totalElements); setTotalData(data?.totalElements);
setTotalPage(data?.totalPages); setTotalPage(data?.totalPages);
@ -167,36 +212,21 @@ const TableImage = () => {
table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel
}; };
// async function doDelete(id: any) { const handleSearchFilterBySource = (
// loading(); e: React.ChangeEvent<HTMLInputElement>
// const data = { ) => {
// id, const value = e.target.value;
// }; setFilterBySource(value); // Perbarui state filter
fetchData(); // Panggil ulang data dengan filter baru
};
// const response = await deleteMedia(data); const handleSearchFilterByCreator = (
e: React.ChangeEvent<HTMLInputElement>
// if (response?.error) { ) => {
// error(response.message); const value = e.target.value;
// return false; setFilterByCreator(value); // Perbarui state filter
// } fetchData(); // Panggil ulang data dengan filter baru
};
// fetchData();
// toast.success("Konten berhasil dihapus");
// }
// const handleDeleteMedia = (id: any) => {
// MySwal.fire({
// title: "Apakah anda ingin menghapus konten?",
// showCancelButton: true,
// confirmButtonColor: "#dc3545",
// confirmButtonText: "Iya",
// cancelButtonText: "Tidak",
// }).then((result: any) => {
// if (result.isConfirmed) {
// doDelete(id);
// }
// });
// };
return ( return (
<div className="w-full overflow-x-auto"> <div className="w-full overflow-x-auto">
@ -216,16 +246,110 @@ const TableImage = () => {
</InputGroup> </InputGroup>
</div> </div>
<div className="flex flex-row items-center gap-3"> <div className="flex flex-row items-center gap-3">
<Input <div className="flex items-center py-4">
placeholder="Filter Status..." <DropdownMenu>
value={ <DropdownMenuTrigger asChild>
(table.getColumn("status")?.getFilterValue() as string) ?? "" <Button variant="outline" className="ml-auto" size="md">
} Filter <ChevronDown />
onChange={(event: React.ChangeEvent<HTMLInputElement>) => </Button>
table.getColumn("status")?.setFilterValue(event.target.value) </DropdownMenuTrigger>
} <DropdownMenuContent
className="max-w-sm " align="end"
/> className="w-64 h-[200px] overflow-y-auto"
>
<div className="flex flex-row justify-between my-1 mx-1">
<p>Filter</p>
{/* <p
className="text-blue-600 cursor-pointer"
onClick={fetchData}
>
Simpan
</p> */}
</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">
No categories found.
</p>
)}
<div className="mx-2 my-1">
<Label>Tanggal Awal</Label>
<Input
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Tanggal Akhir</Label>
<Input
type="date"
value={endDate}
onChange={(e) => setEndDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Kreator</Label>
<Input
placeholder="Filter Status..."
value={filterByCreator}
onChange={handleSearchFilterByCreator}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Sumber</Label>
<Input
placeholder="Filter Status..."
value={filterBySource}
onChange={handleSearchFilterBySource}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Status</Label>
<Input
placeholder="Filter Status..."
value={
(table
.getColumn("statusName")
?.getFilterValue() as string) ?? ""
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
table
.getColumn("statusName")
?.setFilterValue(event.target.value)
}
className="max-w-sm "
/>
</div>
</DropdownMenuContent>
</DropdownMenu>
</div>
<div className="flex items-center py-4"> <div className="flex items-center py-4">
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>

View File

@ -77,7 +77,7 @@ const columns: ColumnDef<any>[] = [
<div> <div>
<Button <Button
size="sm" size="sm"
color={isPublish ? "success" : "warning"} // Hijau untuk diterima, oranye untuk menunggu review color={isPublish ? "success" : "warning"}
variant="outline" variant="outline"
className={`btn btn-sm ${ className={`btn btn-sm ${
isPublish ? "btn-outline-success" : "btn-outline-warning" isPublish ? "btn-outline-success" : "btn-outline-warning"

View File

@ -170,10 +170,10 @@ const TableSPIT = () => {
<Input <Input
placeholder="Filter Status..." placeholder="Filter Status..."
value={ value={
(table.getColumn("status")?.getFilterValue() as string) ?? "" (table.getColumn("isPublish")?.getFilterValue() as string) ?? ""
} }
onChange={(event: React.ChangeEvent<HTMLInputElement>) => onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
table.getColumn("status")?.setFilterValue(event.target.value) table.getColumn("isPublish")?.setFilterValue(event.target.value)
} }
className="max-w-sm " className="max-w-sm "
/> />

View File

@ -68,17 +68,19 @@ const columns: ColumnDef<any>[] = [
}, },
}, },
{ {
accessorKey: "creatorGroup", accessorKey: "creatorName",
header: "Creator Group", header: "Creator Group",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorGroup")}</span> <span className="whitespace-nowrap">{row.getValue("creatorName")}</span>
), ),
}, },
{ {
accessorKey: "creatorName", accessorKey: "creatorGroupLevelName",
header: "Sumber", header: "Sumber",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorName")}</span> <span className="whitespace-nowrap">
{row.getValue("creatorGroupLevelName")}
</span>
), ),
}, },
{ {

View File

@ -26,6 +26,7 @@ import {
} from "@/components/ui/table"; } from "@/components/ui/table";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { import {
ChevronDown,
ChevronLeft, ChevronLeft,
ChevronRight, ChevronRight,
Eye, Eye,
@ -39,6 +40,7 @@ import {
import { cn, getCookiesDecrypt } from "@/lib/utils"; import { cn, getCookiesDecrypt } from "@/lib/utils";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuItem,
DropdownMenuTrigger, DropdownMenuTrigger,
@ -51,7 +53,13 @@ import { Badge } from "@/components/ui/badge";
import { useRouter, useSearchParams } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
import TablePagination from "@/components/table/table-pagination"; import TablePagination from "@/components/table/table-pagination";
import columns from "./columns"; import columns from "./columns";
import { listDataImage, listDataTeks } from "@/service/content/content"; import {
listDataImage,
listDataTeks,
listEnableCategory,
} from "@/service/content/content";
import { Label } from "@/components/ui/label";
import { format } from "date-fns";
const TableTeks = () => { const TableTeks = () => {
const router = useRouter(); const router = useRouter();
@ -77,13 +85,17 @@ const TableTeks = () => {
const userId = getCookiesDecrypt("uie"); const userId = getCookiesDecrypt("uie");
const userLevelId = getCookiesDecrypt("ulie"); const userLevelId = getCookiesDecrypt("ulie");
const [categories, setCategories] = React.useState(); const [categories, setCategories] = React.useState<any[]>([]);
const [categoryFilter, setCategoryFilter] = React.useState([]); const [selectedCategories, setSelectedCategories] = React.useState<number[]>(
[]
);
const [categoryFilter, setCategoryFilter] = React.useState<string>("");
const [statusFilter, setStatusFilter] = React.useState([]); const [statusFilter, setStatusFilter] = React.useState([]);
const [startDateString, setStartDateString] = React.useState(""); const [startDate, setStartDate] = React.useState("");
const [endDateString, setEndDateString] = React.useState(""); const [endDate, setEndDate] = React.useState("");
const [filterByCreator, setFilterByCreator] = React.useState(""); const [filterByCreator, setFilterByCreator] = React.useState("");
const [filterBySource, setFilterBySource] = React.useState(""); const [filterBySource, setFilterBySource] = React.useState("");
const [filterByCreatorGroup, setFilterByCreatorGroup] = React.useState("");
const roleId = getCookiesDecrypt("urie"); const roleId = getCookiesDecrypt("urie");
@ -117,35 +129,69 @@ const TableTeks = () => {
React.useEffect(() => { React.useEffect(() => {
fetchData(); fetchData();
}, [page, limit, search]); getCategories();
}, [categoryFilter, page, limit, search, startDate, endDate]);
async function getCategories() {
const category = await listEnableCategory("3");
const resCategory = category?.data?.data?.content;
setCategories(resCategory || []);
}
// Fungsi menangani perubahan checkbox
const handleCheckboxChange = (categoryId: number) => {
setSelectedCategories(
(prev: any) =>
prev.includes(categoryId)
? prev.filter((id: any) => id !== categoryId) // Hapus jika sudah dipilih
: [...prev, categoryId] // Tambahkan jika belum dipilih
);
// Perbarui filter kategori
setCategoryFilter((prev) => {
const updatedCategories = prev.split(",").filter(Boolean).map(Number);
const newCategories = updatedCategories.includes(categoryId)
? updatedCategories.filter((id) => id !== categoryId)
: [...updatedCategories, categoryId];
return newCategories.join(",");
});
};
async function fetchData() { async function fetchData() {
const formattedStartDate = startDate
? format(new Date(startDate), "yyyy-MM-dd")
: "";
const formattedEndDate = endDate
? format(new Date(endDate), "yyyy-MM-dd")
: "";
try { try {
const isForSelf = Number(roleId) == 4; const isForSelf = Number(roleId) === 4;
const res = await listDataTeks( const res = await listDataTeks(
limit, limit,
page - 1, page - 1,
isForSelf, isForSelf,
!isForSelf, !isForSelf,
categoryFilter?.sort().join(","), categoryFilter,
statusFilter?.sort().join(",").includes("1") statusFilter?.sort().join(",").includes("1")
? "1,2" ? "1,2"
: statusFilter?.sort().join(","), : statusFilter?.sort().join(","),
statusFilter?.sort().join(",").includes("1") ? userLevelId : "", statusFilter?.sort().join(",").includes("1") ? userLevelId : "",
filterByCreator, filterByCreator,
filterBySource, filterBySource,
startDateString, formattedStartDate, // Pastikan format sesuai
endDateString, formattedEndDate, // Pastikan format sesuai
search search,
filterByCreatorGroup
); );
const data = res?.data?.data; const data = res?.data?.data;
const contentData = data?.content; const contentData = data?.content;
contentData.forEach((item: any, index: number) => { contentData.forEach((item: any, index: number) => {
item.no = (page - 1) * limit + index + 1; item.no = (page - 1) * limit + index + 1;
}); });
console.log("contentData : ", contentData);
setDataTable(contentData); setDataTable(contentData);
setTotalData(data?.totalElements); setTotalData(data?.totalElements);
setTotalPage(data?.totalPages); setTotalPage(data?.totalPages);
@ -159,6 +205,22 @@ const TableTeks = () => {
table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel
}; };
const handleSearchFilterBySource = (
e: React.ChangeEvent<HTMLInputElement>
) => {
const value = e.target.value;
setFilterBySource(value); // Perbarui state filter
fetchData(); // Panggil ulang data dengan filter baru
};
const handleSearchFilterByCreator = (
e: React.ChangeEvent<HTMLInputElement>
) => {
const value = e.target.value;
setFilterByCreator(value); // Perbarui state filter
fetchData(); // Panggil ulang data dengan filter baru
};
return ( return (
<div className="w-full overflow-x-auto"> <div className="w-full overflow-x-auto">
<div className="flex justify-between items-center px-5"> <div className="flex justify-between items-center px-5">
@ -176,17 +238,139 @@ const TableTeks = () => {
/> />
</InputGroup> </InputGroup>
</div> </div>
<div className="flex-none"> <div className="flex flex-row items-center gap-3">
<Input <div className="flex items-center py-4">
placeholder="Filter Status..." <DropdownMenu>
value={ <DropdownMenuTrigger asChild>
(table.getColumn("status")?.getFilterValue() as string) ?? "" <Button variant="outline" className="ml-auto" size="md">
} Filter <ChevronDown />
onChange={(event: React.ChangeEvent<HTMLInputElement>) => </Button>
table.getColumn("status")?.setFilterValue(event.target.value) </DropdownMenuTrigger>
} <DropdownMenuContent
className="max-w-sm " align="end"
/> className="w-64 h-[200px] overflow-y-auto"
>
<div className="flex flex-row justify-between my-1 mx-1">
<p>Filter</p>
{/* <p
className="text-blue-600 cursor-pointer"
onClick={fetchData}
>
Simpan
</p> */}
</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">
No categories found.
</p>
)}
<div className="mx-2 my-1">
<Label>Tanggal Awal</Label>
<Input
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Tanggal Akhir</Label>
<Input
type="date"
value={endDate}
onChange={(e) => setEndDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Kreator</Label>
<Input
placeholder="Filter Status..."
value={filterByCreator}
onChange={handleSearchFilterByCreator}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Sumber</Label>
<Input
placeholder="Filter Status..."
value={filterBySource}
onChange={handleSearchFilterBySource}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Status</Label>
<Input
placeholder="Filter Status..."
value={
(table
.getColumn("statusName")
?.getFilterValue() as string) ?? ""
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
table
.getColumn("statusName")
?.setFilterValue(event.target.value)
}
className="max-w-sm "
/>
</div>
</DropdownMenuContent>
</DropdownMenu>
</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> </div>
<Table className="overflow-hidden mt-3"> <Table className="overflow-hidden mt-3">

View File

@ -68,17 +68,19 @@ const columns: ColumnDef<any>[] = [
}, },
}, },
{ {
accessorKey: "creatorGroup", accessorKey: "creatorName",
header: "Creator Group", header: "Creator Group",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorGroup")}</span> <span className="whitespace-nowrap">{row.getValue("creatorName")}</span>
), ),
}, },
{ {
accessorKey: "creatorName", accessorKey: "creatorGroupLevelName",
header: "Sumber", header: "Sumber",
cell: ({ row }) => ( cell: ({ row }) => (
<span className="whitespace-nowrap">{row.getValue("creatorName")}</span> <span className="whitespace-nowrap">
{row.getValue("creatorGroupLevelName")}
</span>
), ),
}, },
{ {

View File

@ -26,6 +26,7 @@ import {
} from "@/components/ui/table"; } from "@/components/ui/table";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { import {
ChevronDown,
ChevronLeft, ChevronLeft,
ChevronRight, ChevronRight,
Eye, Eye,
@ -39,6 +40,7 @@ import {
import { cn, getCookiesDecrypt } from "@/lib/utils"; import { cn, getCookiesDecrypt } from "@/lib/utils";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuItem,
DropdownMenuTrigger, DropdownMenuTrigger,
@ -51,9 +53,15 @@ import { Badge } from "@/components/ui/badge";
import { useRouter, useSearchParams } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
import TablePagination from "@/components/table/table-pagination"; import TablePagination from "@/components/table/table-pagination";
import columns from "./columns"; import columns from "./columns";
import { listDataImage, listDataVideo } from "@/service/content/content"; import {
listDataImage,
listDataVideo,
listEnableCategory,
} from "@/service/content/content";
import { Label } from "@/components/ui/label";
import { format } from "date-fns";
const TableImage = () => { const TableVideo = () => {
const router = useRouter(); const router = useRouter();
const searchParams = useSearchParams(); const searchParams = useSearchParams();
@ -77,13 +85,17 @@ const TableImage = () => {
const userId = getCookiesDecrypt("uie"); const userId = getCookiesDecrypt("uie");
const userLevelId = getCookiesDecrypt("ulie"); const userLevelId = getCookiesDecrypt("ulie");
const [categories, setCategories] = React.useState(); const [categories, setCategories] = React.useState<any[]>([]);
const [categoryFilter, setCategoryFilter] = React.useState([]); const [selectedCategories, setSelectedCategories] = React.useState<number[]>(
[]
);
const [categoryFilter, setCategoryFilter] = React.useState<string>("");
const [statusFilter, setStatusFilter] = React.useState([]); const [statusFilter, setStatusFilter] = React.useState([]);
const [startDateString, setStartDateString] = React.useState(""); const [startDate, setStartDate] = React.useState("");
const [endDateString, setEndDateString] = React.useState(""); const [endDate, setEndDate] = React.useState("");
const [filterByCreator, setFilterByCreator] = React.useState(""); const [filterByCreator, setFilterByCreator] = React.useState("");
const [filterBySource, setFilterBySource] = React.useState(""); const [filterBySource, setFilterBySource] = React.useState("");
const [filterByCreatorGroup, setFilterByCreatorGroup] = React.useState("");
const roleId = getCookiesDecrypt("urie"); const roleId = getCookiesDecrypt("urie");
@ -117,35 +129,69 @@ const TableImage = () => {
React.useEffect(() => { React.useEffect(() => {
fetchData(); fetchData();
}, [page, limit, search]); getCategories();
}, [categoryFilter, page, limit, search, startDate, endDate]);
async function getCategories() {
const category = await listEnableCategory("2");
const resCategory = category?.data?.data?.content;
setCategories(resCategory || []);
}
// Fungsi menangani perubahan checkbox
const handleCheckboxChange = (categoryId: number) => {
setSelectedCategories(
(prev: any) =>
prev.includes(categoryId)
? prev.filter((id: any) => id !== categoryId) // Hapus jika sudah dipilih
: [...prev, categoryId] // Tambahkan jika belum dipilih
);
// Perbarui filter kategori
setCategoryFilter((prev) => {
const updatedCategories = prev.split(",").filter(Boolean).map(Number);
const newCategories = updatedCategories.includes(categoryId)
? updatedCategories.filter((id) => id !== categoryId)
: [...updatedCategories, categoryId];
return newCategories.join(",");
});
};
async function fetchData() { async function fetchData() {
const formattedStartDate = startDate
? format(new Date(startDate), "yyyy-MM-dd")
: "";
const formattedEndDate = endDate
? format(new Date(endDate), "yyyy-MM-dd")
: "";
try { try {
const isForSelf = Number(roleId) == 4; const isForSelf = Number(roleId) === 4;
const res = await listDataVideo( const res = await listDataVideo(
limit, limit,
page - 1, page - 1,
isForSelf, isForSelf,
!isForSelf, !isForSelf,
categoryFilter?.sort().join(","), categoryFilter,
statusFilter?.sort().join(",").includes("1") statusFilter?.sort().join(",").includes("1")
? "1,2" ? "1,2"
: statusFilter?.sort().join(","), : statusFilter?.sort().join(","),
statusFilter?.sort().join(",").includes("1") ? userLevelId : "", statusFilter?.sort().join(",").includes("1") ? userLevelId : "",
filterByCreator, filterByCreator,
filterBySource, filterBySource,
startDateString, formattedStartDate, // Pastikan format sesuai
endDateString, formattedEndDate, // Pastikan format sesuai
search search,
filterByCreatorGroup
); );
const data = res?.data?.data; const data = res?.data?.data;
const contentData = data?.content; const contentData = data?.content;
contentData.forEach((item: any, index: number) => { contentData.forEach((item: any, index: number) => {
item.no = (page - 1) * limit + index + 1; item.no = (page - 1) * limit + index + 1;
}); });
console.log("contentData : ", contentData);
setDataTable(contentData); setDataTable(contentData);
setTotalData(data?.totalElements); setTotalData(data?.totalElements);
setTotalPage(data?.totalPages); setTotalPage(data?.totalPages);
@ -159,6 +205,22 @@ const TableImage = () => {
table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel
}; };
const handleSearchFilterBySource = (
e: React.ChangeEvent<HTMLInputElement>
) => {
const value = e.target.value;
setFilterBySource(value); // Perbarui state filter
fetchData(); // Panggil ulang data dengan filter baru
};
const handleSearchFilterByCreator = (
e: React.ChangeEvent<HTMLInputElement>
) => {
const value = e.target.value;
setFilterByCreator(value); // Perbarui state filter
fetchData(); // Panggil ulang data dengan filter baru
};
return ( return (
<div className="w-full overflow-x-auto"> <div className="w-full overflow-x-auto">
<div className="flex justify-between items-center px-5"> <div className="flex justify-between items-center px-5">
@ -176,17 +238,140 @@ const TableImage = () => {
/> />
</InputGroup> </InputGroup>
</div> </div>
<div className="flex-none">
<Input <div className="flex flex-row items-center gap-3">
placeholder="Filter Status..." <div className="flex items-center py-4">
value={ <DropdownMenu>
(table.getColumn("status")?.getFilterValue() as string) ?? "" <DropdownMenuTrigger asChild>
} <Button variant="outline" className="ml-auto" size="md">
onChange={(event: React.ChangeEvent<HTMLInputElement>) => Filter <ChevronDown />
table.getColumn("status")?.setFilterValue(event.target.value) </Button>
} </DropdownMenuTrigger>
className="max-w-sm " <DropdownMenuContent
/> align="end"
className="w-64 h-[200px] overflow-y-auto"
>
<div className="flex flex-row justify-between my-1 mx-1">
<p>Filter</p>
{/* <p
className="text-blue-600 cursor-pointer"
onClick={fetchData}
>
Simpan
</p> */}
</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">
No categories found.
</p>
)}
<div className="mx-2 my-1">
<Label>Tanggal Awal</Label>
<Input
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Tanggal Akhir</Label>
<Input
type="date"
value={endDate}
onChange={(e) => setEndDate(e.target.value)}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Kreator</Label>
<Input
placeholder="Filter Status..."
value={filterByCreator}
onChange={handleSearchFilterByCreator}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Sumber</Label>
<Input
placeholder="Filter Status..."
value={filterBySource}
onChange={handleSearchFilterBySource}
className="max-w-sm"
/>
</div>
<div className="mx-2 my-1">
<Label>Status</Label>
<Input
placeholder="Filter Status..."
value={
(table
.getColumn("statusName")
?.getFilterValue() as string) ?? ""
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
table
.getColumn("statusName")
?.setFilterValue(event.target.value)
}
className="max-w-sm "
/>
</div>
</DropdownMenuContent>
</DropdownMenu>
</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> </div>
<Table className="overflow-hidden mt-3"> <Table className="overflow-hidden mt-3">
@ -239,4 +424,4 @@ const TableImage = () => {
); );
}; };
export default TableImage; export default TableVideo;

View File

@ -240,15 +240,27 @@ export default function FormTaskDetail() {
const [imageUploadedFiles, setImageUploadedFiles] = useState<FileUploaded[]>( const [imageUploadedFiles, setImageUploadedFiles] = useState<FileUploaded[]>(
[] []
); );
const [selectedImage, setSelectedImage] = useState<string | null>(
imageUploadedFiles?.[0]?.url || null
);
const [videoUploadedFiles, setVideoUploadedFiles] = useState<FileUploaded[]>( const [videoUploadedFiles, setVideoUploadedFiles] = useState<FileUploaded[]>(
[] []
); );
const [selectedVideo, setSelectedVideo] = useState<string | null>(
videoUploadedFiles?.[0]?.url || null
);
const [textUploadedFiles, setTextUploadedFiles] = useState<FileUploaded[]>( const [textUploadedFiles, setTextUploadedFiles] = useState<FileUploaded[]>(
[] []
); );
const [selectedText, setSelectedText] = useState<string | null>(
textUploadedFiles?.[0]?.url || null
);
const [audioUploadedFiles, setAudioUploadedFiles] = useState<FileUploaded[]>( const [audioUploadedFiles, setAudioUploadedFiles] = useState<FileUploaded[]>(
[] []
); );
const [selectedAudio, setSelectedAudio] = useState<string | null>(
audioUploadedFiles?.[0]?.url || null
);
const [platformTypeVisible, setPlatformTypeVisible] = useState(false); const [platformTypeVisible, setPlatformTypeVisible] = useState(false);
const [unitSelection, setUnitSelection] = useState({ const [unitSelection, setUnitSelection] = useState({
@ -358,10 +370,10 @@ export default function FormTaskDetail() {
if (detail?.fileTypeOutput) { if (detail?.fileTypeOutput) {
const outputSet = new Set(detail.fileTypeOutput.split(",").map(Number)); const outputSet = new Set(detail.fileTypeOutput.split(",").map(Number));
setTaskOutput({ setTaskOutput({
all: outputSet.has(0), all: outputSet.has(1),
video: outputSet.has(2), video: outputSet.has(2),
audio: outputSet.has(4), audio: outputSet.has(4),
image: outputSet.has(1), image: outputSet.has(3),
text: outputSet.has(5), text: outputSet.has(5),
}); });
} }
@ -1028,24 +1040,32 @@ export default function FormTaskDetail() {
<div className="space-y-3"> <div className="space-y-3">
<div> <div>
{videoUploadedFiles?.length > 0 && <Label>Video</Label>} {videoUploadedFiles?.length > 0 && <Label>Video</Label>}
{videoUploadedFiles?.map((file: any, index: number) => ( <div>
<div> {selectedVideo && (
<video <Card className="mt-2">
className="object-fill h-full w-full rounded-md" <video
src={file.url} className="object-fill h-full w-full rounded-md"
controls src={selectedVideo}
title={`Video ${file.id}`} // Mengganti alt dengan title controls
/> title={`Video`} // Mengganti alt dengan title
/>
</Card>
)}
{videoUploadedFiles?.map((file: any, index: number) => (
<div <div
key={index} key={index}
className=" flex justify-between border px-3.5 py-3 my-6 rounded-md" className="flex justify-between border px-3.5 py-3 my-6 rounded-md"
> >
<div className="flex gap-3 items-center"> <div
className="flex gap-3 items-center cursor-pointer"
onClick={() => setSelectedVideo(file.url)}
>
<div className="file-preview"> <div className="file-preview">
{renderFilePreview(file.url)} {renderFilePreview(file.url)}
</div> </div>
<div> <div>
<div className=" text-sm text-card-foreground"> <div className="text-sm text-card-foreground">
{file.fileName} {file.fileName}
</div> </div>
</div> </div>
@ -1055,36 +1075,42 @@ export default function FormTaskDetail() {
size="icon" size="icon"
color="destructive" color="destructive"
variant="outline" variant="outline"
className=" border-none rounded-full" className="border-none rounded-full"
onClick={() => handleRemoveFile(file)} onClick={() => handleRemoveFile(file)}
> >
<Icon icon="tabler:x" className=" h-5 w-5" /> <Icon icon="tabler:x" className="h-5 w-5" />
</Button> </Button>
</div> </div>
</div> ))}
))} </div>
</div> </div>
<div> <div>
{imageUploadedFiles?.length > 0 && <Label>Foto</Label>} {imageUploadedFiles?.length > 0 && <Label>Foto</Label>}
{imageUploadedFiles?.map((file: any, index: number) => ( <div>
<div> {selectedImage && (
<Card className="mt-2"> <Card className="mt-2">
<img <img
src={file.url} src={selectedImage}
alt="Thumbnail Gambar Utama" alt="Thumbnail Gambar Utama"
className="w-full h-auto rounded-md" className="w-full h-auto rounded-md"
/> />
</Card> </Card>
)}
{imageUploadedFiles?.map((file: any, index: number) => (
<div <div
key={index} key={index}
className=" flex justify-between border px-3.5 py-3 my-6 rounded-md" className="flex justify-between border px-3.5 py-3 my-6 rounded-md"
> >
<div className="flex gap-3 items-center"> <div
className="flex gap-3 items-center cursor-pointer"
onClick={() => setSelectedImage(file.url)}
>
<div className="file-preview"> <div className="file-preview">
{renderFilePreview(file.url)} {renderFilePreview(file.url)}
</div> </div>
<div> <div>
<div className=" text-sm text-card-foreground"> <div className="text-sm text-card-foreground">
{file.fileName} {file.fileName}
</div> </div>
</div> </div>
@ -1094,44 +1120,44 @@ export default function FormTaskDetail() {
size="icon" size="icon"
color="destructive" color="destructive"
variant="outline" variant="outline"
className=" border-none rounded-full" className="border-none rounded-full"
onClick={() => handleRemoveFile(file)} onClick={() => handleRemoveFile(file)}
> >
<Icon icon="tabler:x" className=" h-5 w-5" /> <Icon icon="tabler:x" className="h-5 w-5" />
</Button> </Button>
</div> </div>
</div> ))}
))} </div>
{/* <FileUploader
accept={{
"image/*": [],
}}
maxSize={100}
label="Upload file dengan format .png, .jpg, atau .jpeg."
onDrop={(files) => setImageFiles(files)}
/> */}
</div> </div>
<div> <div>
{textUploadedFiles?.length > 0 && <Label>Teks</Label>} {textUploadedFiles?.length > 0 && <Label>Teks</Label>}
{textUploadedFiles?.map((file: any, index: number) => ( <div>
<div> {selectedText && (
<iframe <Card className="mt-2">
className="w-full h-96 rounded-md" <iframe
src={`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent( className="w-full h-96 rounded-md"
file.url src={`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(
)}`} selectedText
title={file.fileName || "Document"} )}`}
/> title={"Document"}
/>
</Card>
)}
{textUploadedFiles?.map((file: any, index: number) => (
<div <div
key={index} key={index}
className=" flex justify-between border px-3.5 py-3 my-6 rounded-md" className="flex justify-between border px-3.5 py-3 my-6 rounded-md"
> >
<div className="flex gap-3 items-center"> <div
className="flex gap-3 items-center cursor-pointer"
onClick={() => setSelectedText(file.url)}
>
<div className="file-preview"> <div className="file-preview">
{renderFilePreview(file.url)} {renderFilePreview(file.url)}
</div> </div>
<div> <div>
<div className=" text-sm text-card-foreground"> <div className="text-sm text-card-foreground">
{file.fileName} {file.fileName}
</div> </div>
</div> </div>
@ -1141,69 +1167,68 @@ export default function FormTaskDetail() {
size="icon" size="icon"
color="destructive" color="destructive"
variant="outline" variant="outline"
className=" border-none rounded-full" className="border-none rounded-full"
onClick={() => handleRemoveFile(file)} onClick={() => handleRemoveFile(file)}
> >
<Icon icon="tabler:x" className=" h-5 w-5" /> <Icon icon="tabler:x" className="h-5 w-5" />
</Button> </Button>
</div> </div>
</div> ))}
))} </div>
{/* <FileUploader
accept={{
"pdf/*": [],
}}
maxSize={100}
label="Upload file dengan format .pdf."
onDrop={(files) => setTextFiles(files)}
/> */}
</div> </div>
<div> <div>
{audioUploadedFiles?.length > 0 && <Label>Audio</Label>} {audioUploadedFiles?.length > 0 && <Label>Audio</Label>}
{audioUploadedFiles?.map((file: any, index: number) => ( <div>
<div> {selectedAudio && (
<div key={file.id}> <Card className="mt-2">
<WavesurferPlayer <div key={selectedAudio}>
height={500} <WavesurferPlayer
waveColor="red" height={500}
url={file.url} waveColor="red"
onReady={onReady} url={selectedAudio}
onPlay={() => setIsPlaying(true)} onReady={onReady}
onPause={() => setIsPlaying(false)} onPlay={() => setIsPlaying(true)}
/> onPause={() => setIsPlaying(false)}
</div> />
<Button </div>
size="sm" <Button
type="button" size="sm"
onClick={onPlayPause} type="button"
disabled={isPlaying} onClick={onPlayPause}
className={`flex items-center gap-2 ${ disabled={isPlaying}
isPlaying className={`flex items-center gap-2 ${
? "bg-gray-300 cursor-not-allowed"
: "bg-primary text-white"
} p-2 rounded`}
>
{isPlaying ? "Pause" : "Play"}
<Icon
icon={
isPlaying isPlaying
? "carbon:pause-outline" ? "bg-gray-300 cursor-not-allowed"
: "famicons:play-sharp" : "bg-primary text-white"
} } p-2 rounded`}
className="h-5 w-5" >
/> {isPlaying ? "Pause" : "Play"}
</Button> <Icon
icon={
isPlaying
? "carbon:pause-outline"
: "famicons:play-sharp"
}
className="h-5 w-5"
/>
</Button>
</Card>
)}
{audioUploadedFiles?.map((file: any, index: number) => (
<div <div
key={index} key={index}
className=" flex justify-between border px-3.5 py-3 my-6 rounded-md" className="flex justify-between border px-3.5 py-3 my-6 rounded-md"
> >
<div className="flex gap-3 items-center"> <div
className="flex gap-3 items-center cursor-pointer"
onClick={() => setSelectedAudio(file.url)}
>
<div className="file-preview"> <div className="file-preview">
{renderFilePreview(file.url)} {renderFilePreview(file.url)}
</div> </div>
<div> <div>
<div className=" text-sm text-card-foreground"> <div className="text-sm text-card-foreground">
{file.fileName} {file.fileName}
</div> </div>
</div> </div>
@ -1213,14 +1238,15 @@ export default function FormTaskDetail() {
size="icon" size="icon"
color="destructive" color="destructive"
variant="outline" variant="outline"
className=" border-none rounded-full" className="border-none rounded-full"
onClick={() => handleRemoveFile(file)} onClick={() => handleRemoveFile(file)}
> >
<Icon icon="tabler:x" className=" h-5 w-5" /> <Icon icon="tabler:x" className="h-5 w-5" />
</Button> </Button>
</div> </div>
</div> ))}
))} </div>
{audioUploadedFiles?.length > 0 && ( {audioUploadedFiles?.length > 0 && (
<AudioRecorder <AudioRecorder
onRecordingComplete={addAudioElement} onRecordingComplete={addAudioElement}
@ -1232,16 +1258,6 @@ export default function FormTaskDetail() {
downloadFileExtension="webm" downloadFileExtension="webm"
/> />
)} )}
{/* <FileUploader
accept={{
"mp3/*": [],
"wav/*": [],
}}
maxSize={100}
label="Upload file dengan format .mp3 atau .wav."
onDrop={(files) => setAudioFiles(files)}
className="mt-2"
/> */}
</div> </div>
{audioFile && ( {audioFile && (
<div className="flex flex-row justify-between items-center"> <div className="flex flex-row justify-between items-center">
@ -1260,17 +1276,19 @@ export default function FormTaskDetail() {
{/* Display remaining time */} {/* Display remaining time */}
<div className="mt-4"> <div className="mt-4">
{urlInputs.map((url: any, index: any) => ( {urlInputs.map((url: any, index: any) => (
<div className="mt-4 flex flex-col" key={index}> <div
<Label htmlFor={`url-${index}`}>Link Berita</Label> key={url.id}
<Button className="flex items-center gap-2 mt-2"
size="sm" >
id={`url-${index}`} <input
className="bg-slate-400 text-white py-2 px-4 rounded mt-2 hover:bg-blue-600 text-start" type="url"
onClick={() => window.open(url, "_blank")} className="border rounded p-2 w-full"
disabled={!url} // Disable button if URL is empty value={url}
> // onChange={(e) =>
{url} // handleLinkChange(index, e.target.value)
</Button> // }
placeholder={`Masukkan link berita ${index + 1}`}
/>
</div> </div>
))} ))}
</div> </div>

View File

@ -246,10 +246,10 @@ export default function FormTaskEdit() {
if (detail?.fileTypeOutput) { if (detail?.fileTypeOutput) {
const outputSet = new Set(detail.fileTypeOutput.split(",").map(Number)); // Membagi string ke dalam array dan mengonversi ke nomor const outputSet = new Set(detail.fileTypeOutput.split(",").map(Number)); // Membagi string ke dalam array dan mengonversi ke nomor
setTaskOutput({ setTaskOutput({
all: outputSet.has(0), all: outputSet.has(1),
video: outputSet.has(2), video: outputSet.has(2),
audio: outputSet.has(4), audio: outputSet.has(4),
image: outputSet.has(1), image: outputSet.has(3),
text: outputSet.has(5), text: outputSet.has(5),
}); });
} }
@ -289,8 +289,8 @@ export default function FormTaskEdit() {
const fileTypeMapping = { const fileTypeMapping = {
all: "1", all: "1",
video: "2", video: "2",
audio: "3", audio: "4",
image: "4", image: "3",
text: "5", text: "5",
}; };
@ -580,9 +580,9 @@ export default function FormTaskEdit() {
}; };
const handleLinkChange = (index: number, value: string) => { const handleLinkChange = (index: number, value: string) => {
const updatedUrls = [...urlInputs]; const updatedLinks = [...links];
updatedUrls[index].attachmentUrl = value; updatedLinks[index] = value;
setUrlInputs(updatedUrls); setLinks(updatedLinks);
}; };
const handleAddLink = () => { const handleAddLink = () => {

View File

@ -188,8 +188,8 @@ export default function FormTask() {
const fileTypeMapping = { const fileTypeMapping = {
all: "1", all: "1",
video: "2", video: "2",
audio: "3", audio: "4",
image: "4", image: "3",
text: "5", text: "5",
}; };
@ -275,16 +275,6 @@ export default function FormTask() {
audioFiles?.map(async (item: any, index: number) => { audioFiles?.map(async (item: any, index: number) => {
await uploadResumableFile(index, String(id), item, "4", "0"); await uploadResumableFile(index, String(id), item, "4", "0");
}); });
// MySwal.fire({
// title: "Sukses",
// text: "Data berhasil disimpan.",
// icon: "success",
// confirmButtonColor: "#3085d6",
// confirmButtonText: "OK",
// }).then(() => {
// router.push("/en/contributor/task");
// });
}; };
const onSubmit = (data: TaskSchema) => { const onSubmit = (data: TaskSchema) => {

View File

@ -57,10 +57,11 @@ export async function listDataImage(
source: any, source: any,
startDate: any, startDate: any,
endDate: any, endDate: any,
title: string = "" title: string = "",
creatorGroup: string = ""
) { ) {
return await httpGetInterceptor( 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}&title=${title}` `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}&title=${title}&creatorGroupLevelName=${creatorGroup}`
); );
} }
@ -76,10 +77,11 @@ export async function listDataVideo(
source: any, source: any,
startDate: any, startDate: any,
endDate: any, endDate: any,
title: string = "" title: string = "",
creatorGroup: string = ""
) { ) {
return await httpGetInterceptor( return await httpGetInterceptor(
`media/list?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}&title=${title}` `media/list?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}&title=${title}&creatorGroupLevelName=${creatorGroup}`
); );
} }
@ -95,10 +97,11 @@ export async function listDataTeks(
source: any, source: any,
startDate: any, startDate: any,
endDate: any, endDate: any,
title: string = "" title: string = "",
creatorGroup: string = ""
) { ) {
return await httpGetInterceptor( return await httpGetInterceptor(
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=3&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}` `media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=3&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}&creatorGroupLevelName=${creatorGroup}`
); );
} }
@ -114,10 +117,11 @@ export async function listDataAudio(
source: any, source: any,
startDate: any, startDate: any,
endDate: any, endDate: any,
title: string = "" title: string = "",
creatorGroup: string = ""
) { ) {
return await httpGetInterceptor( return await httpGetInterceptor(
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=4&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}` `media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=4&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}&creatorGroupLevelName=${creatorGroup}`
); );
} }