feat: add en language in filter section
This commit is contained in:
commit
308d07d1ff
|
|
@ -0,0 +1,110 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
|
||||||
|
import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react";
|
||||||
|
import { cn } 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 {
|
||||||
|
formatDateToIndonesian,
|
||||||
|
getOnlyDate,
|
||||||
|
htmlToString,
|
||||||
|
} from "@/utils/globals";
|
||||||
|
import { Link, useRouter } from "@/i18n/routing";
|
||||||
|
import {
|
||||||
|
Accordion,
|
||||||
|
AccordionContent,
|
||||||
|
AccordionItem,
|
||||||
|
AccordionTrigger,
|
||||||
|
} from "@/components/ui/accordion";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Collapsible, CollapsibleContent } from "@/components/ui/collapsible";
|
||||||
|
import StatusToogle from "./status-toogle";
|
||||||
|
import StaticToogle from "./static-toogle";
|
||||||
|
|
||||||
|
const columns: ColumnDef<any>[] = [
|
||||||
|
// {
|
||||||
|
// accessorKey: "no",
|
||||||
|
// header: "No",
|
||||||
|
// cell: ({ row }) => <span>{row.getValue("no")}</span>,
|
||||||
|
// },
|
||||||
|
|
||||||
|
{
|
||||||
|
accessorKey: "title",
|
||||||
|
header: "Judul",
|
||||||
|
cell: ({ row }) => <span>{row.getValue("title")}</span>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "categoryName",
|
||||||
|
header: "Kategori",
|
||||||
|
cell: ({ row }) => <span>{row.getValue("categoryName")}</span>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Tanggal Unggah",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span>{formatDateToIndonesian(row.getValue("createdAt"))}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "static",
|
||||||
|
header: "Static Banner",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<StaticToogle
|
||||||
|
id={row.original.id}
|
||||||
|
initChecked={row.original.staticPage}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "statusName",
|
||||||
|
header: "Status Banner",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<StatusToogle id={row.original.id} initChecked={row.original.isBanner} />
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
accessorKey: "action",
|
||||||
|
header: "Actions",
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
||||||
|
>
|
||||||
|
<MoreVertical className="h-4 w-4 text-default-800" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent className="p-0" align="end">
|
||||||
|
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
<Link
|
||||||
|
href={`/contributor/content/image/detail/${row.original.id}`}
|
||||||
|
>
|
||||||
|
Detail
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default columns;
|
||||||
|
|
@ -0,0 +1,166 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
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 { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
|
import { close, loading } from "@/config/swal";
|
||||||
|
import { Link, useRouter } from "@/i18n/routing";
|
||||||
|
import columns from "./banner-column";
|
||||||
|
import { listBanner, listStaticBanner } from "@/service/settings/settings";
|
||||||
|
|
||||||
|
const BannerListTable = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const [showData, setShowData] = React.useState("10");
|
||||||
|
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
const [columnVisibility, setColumnVisibility] =
|
||||||
|
React.useState<VisibilityState>({});
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({});
|
||||||
|
const [pagination, setPagination] = React.useState<PaginationState>({
|
||||||
|
pageIndex: 0,
|
||||||
|
pageSize: Number(showData),
|
||||||
|
});
|
||||||
|
const [getData, setGetData] = React.useState<any>([]);
|
||||||
|
const dataChange = searchParams?.get("dataChange");
|
||||||
|
|
||||||
|
const [page, setPage] = React.useState(1);
|
||||||
|
const [totalPage, setTotalPage] = React.useState(1);
|
||||||
|
const table = useReactTable({
|
||||||
|
data: getData,
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const pageFromUrl = searchParams?.get("page");
|
||||||
|
if (pageFromUrl) {
|
||||||
|
setPage(Number(pageFromUrl));
|
||||||
|
}
|
||||||
|
}, [searchParams]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (dataChange) {
|
||||||
|
router.push("/admin/settings/banner");
|
||||||
|
}
|
||||||
|
getListBanner();
|
||||||
|
}, [dataChange]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
getListBanner();
|
||||||
|
// getListStaticBanner();
|
||||||
|
}, [page, showData]);
|
||||||
|
|
||||||
|
async function getListBanner() {
|
||||||
|
loading();
|
||||||
|
let temp: any;
|
||||||
|
|
||||||
|
const response = await listBanner();
|
||||||
|
temp = response?.data?.data;
|
||||||
|
const response2 = await listStaticBanner();
|
||||||
|
console.log("sadadddd", response2?.data?.data.length);
|
||||||
|
for (let i = 0; i < response2?.data?.data.length; i++) {
|
||||||
|
for (let j = 0; j < temp.length; j++) {
|
||||||
|
console.log("temp", j, temp[j].id);
|
||||||
|
if (response2?.data?.data[i].mediaUploadId === temp[j].id) {
|
||||||
|
temp[j].staticPage = true;
|
||||||
|
} else {
|
||||||
|
temp[j].staticPage = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("tesmasdasdasdasd", temp);
|
||||||
|
setGetData(temp);
|
||||||
|
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Table className="overflow-hidden mt-10">
|
||||||
|
<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">
|
||||||
|
No results.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BannerListTable;
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
|
||||||
|
import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react";
|
||||||
|
import { cn } 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 {
|
||||||
|
formatDateToIndonesian,
|
||||||
|
getOnlyDate,
|
||||||
|
htmlToString,
|
||||||
|
} from "@/utils/globals";
|
||||||
|
import { Link, useRouter } from "@/i18n/routing";
|
||||||
|
import {
|
||||||
|
Accordion,
|
||||||
|
AccordionContent,
|
||||||
|
AccordionItem,
|
||||||
|
AccordionTrigger,
|
||||||
|
} from "@/components/ui/accordion";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Collapsible, CollapsibleContent } from "@/components/ui/collapsible";
|
||||||
|
import { setBanner } from "@/service/settings/settings";
|
||||||
|
import { error } from "@/config/swal";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
|
||||||
|
const columns: ColumnDef<any>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "no",
|
||||||
|
header: "No",
|
||||||
|
cell: ({ row }) => <span>{row.getValue("no")}</span>,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
accessorKey: "title",
|
||||||
|
header: "Judul",
|
||||||
|
cell: ({ row }) => <span>{row.getValue("title")}</span>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "categoryName",
|
||||||
|
header: "Kategori",
|
||||||
|
cell: ({ row }) => <span>{row.getValue("categoryName")}</span>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Tanggal Unggah",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span>{formatDateToIndonesian(row.getValue("createdAt"))}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
accessorKey: "statusName",
|
||||||
|
header: "Status",
|
||||||
|
cell: ({ row }) => <span>{row.getValue("statusName")}</span>,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
accessorKey: "action",
|
||||||
|
header: "Actions",
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
const handleBanner = async (id: number) => {
|
||||||
|
const response = setBanner(id, true);
|
||||||
|
toast({
|
||||||
|
title: "Success",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
||||||
|
>
|
||||||
|
<MoreVertical className="h-4 w-4 text-default-800" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent className="p-0" align="end">
|
||||||
|
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
<Link
|
||||||
|
href={`/contributor/content/image/detail/${row.original.id}`}
|
||||||
|
>
|
||||||
|
Detail
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
<a onClick={() => handleBanner(row.original.id)}>
|
||||||
|
Jadikan Banner
|
||||||
|
</a>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default columns;
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { useRouter } from "@/i18n/routing";
|
||||||
|
import { setStaticBanner } from "@/service/settings/settings";
|
||||||
|
|
||||||
|
export default function StaticToogle(props: {
|
||||||
|
id: number;
|
||||||
|
initChecked: boolean;
|
||||||
|
}) {
|
||||||
|
const { id, initChecked } = props;
|
||||||
|
const { toast } = useToast();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const changeStaticBanner = async (id: number) => {
|
||||||
|
const response = await setStaticBanner(id);
|
||||||
|
|
||||||
|
if (response?.error) {
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: response?.message,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: "Success ",
|
||||||
|
});
|
||||||
|
router.push("/admin/settings/banner?dataChange=true");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Switch
|
||||||
|
id="static-toogle"
|
||||||
|
checked={initChecked}
|
||||||
|
onCheckedChange={(e) => {
|
||||||
|
changeStaticBanner(id);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { useRouter } from "@/i18n/routing";
|
||||||
|
import { setBanner } from "@/service/settings/settings";
|
||||||
|
|
||||||
|
export default function StatusToogle(props: {
|
||||||
|
id: number;
|
||||||
|
initChecked: boolean;
|
||||||
|
}) {
|
||||||
|
const { id, initChecked } = props;
|
||||||
|
const { toast } = useToast();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const disableBanner = async () => {
|
||||||
|
const response = await setBanner(id, false);
|
||||||
|
|
||||||
|
if (response?.error) {
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: response?.message,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: "Success ",
|
||||||
|
});
|
||||||
|
router.push("/admin/settings/banner?dataChange=true");
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Switch
|
||||||
|
id="status-toogle"
|
||||||
|
checked={initChecked}
|
||||||
|
onCheckedChange={() => disableBanner()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,393 @@
|
||||||
|
"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";
|
||||||
|
|
||||||
|
const ContentListTable = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
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 [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);
|
||||||
|
typingTimer = setTimeout(doneTyping, doneTypingInterval);
|
||||||
|
};
|
||||||
|
|
||||||
|
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,
|
||||||
|
"",
|
||||||
|
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="flex justify-between ">
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
placeholder="Search"
|
||||||
|
onKeyUp={handleKeyUp}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
className="max-w-[300px]"
|
||||||
|
/>
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button size="md" variant="outline">
|
||||||
|
1 - {showData} Data
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent className="w-56 text-sm">
|
||||||
|
<DropdownMenuRadioGroup
|
||||||
|
value={showData}
|
||||||
|
onValueChange={setShowData}
|
||||||
|
>
|
||||||
|
<DropdownMenuRadioItem value="10">
|
||||||
|
1 - 10 Data
|
||||||
|
</DropdownMenuRadioItem>
|
||||||
|
<DropdownMenuRadioItem value="20">
|
||||||
|
1 - 20 Data
|
||||||
|
</DropdownMenuRadioItem>
|
||||||
|
<DropdownMenuRadioItem value="25">
|
||||||
|
1 - 25 Data
|
||||||
|
</DropdownMenuRadioItem>
|
||||||
|
<DropdownMenuRadioItem value="50">
|
||||||
|
1 - 50 Data
|
||||||
|
</DropdownMenuRadioItem>
|
||||||
|
</DropdownMenuRadioGroup>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button size="md" variant="outline">
|
||||||
|
Filter
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-80 ">
|
||||||
|
<div className="flex flex-col gap-2 px-2">
|
||||||
|
<div className="flex justify-between text-sm">
|
||||||
|
<p>Filter</p>
|
||||||
|
<a
|
||||||
|
onClick={() => fetchData()}
|
||||||
|
className="cursor-pointer text-primary"
|
||||||
|
>
|
||||||
|
Simpan
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1 overflow-auto max-h-[300px] text-xs custom-scrollbar-table">
|
||||||
|
<p>Kategory</p>
|
||||||
|
{categories?.map((category: any) => (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id={category.id}
|
||||||
|
checked={categoryFilter.includes(category.id)}
|
||||||
|
onCheckedChange={(e) =>
|
||||||
|
handleChange("category", category.id, Boolean(e))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor={category.id}
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
{category.name}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<p className="mt-3">Status</p>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="accepted"
|
||||||
|
checked={statusFilter.includes(1)}
|
||||||
|
onCheckedChange={(e) =>
|
||||||
|
handleChange("status", 1, Boolean(e))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor="accepted"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Menunggu Review
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="accepted"
|
||||||
|
checked={statusFilter.includes(2)}
|
||||||
|
onCheckedChange={(e) =>
|
||||||
|
handleChange("status", 2, Boolean(e))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor="accepted"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Diterima
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="accepted"
|
||||||
|
checked={statusFilter.includes(3)}
|
||||||
|
onCheckedChange={(e) =>
|
||||||
|
handleChange("status", 3, Boolean(e))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor="accepted"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Minta Update{" "}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="accepted"
|
||||||
|
checked={statusFilter.includes(4)}
|
||||||
|
onCheckedChange={(e) =>
|
||||||
|
handleChange("status", 4, Boolean(e))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor="accepted"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Ditolak
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Table className="overflow-hidden">
|
||||||
|
<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">
|
||||||
|
No results.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
<TablePagination
|
||||||
|
table={table}
|
||||||
|
totalData={totalData}
|
||||||
|
totalPage={totalPage}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ContentListTable;
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
"use client";
|
||||||
|
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||||
|
import ContentListTable from "./component/table";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
import BannerListTable from "./component/banner-table";
|
||||||
|
|
||||||
|
export default function AdminBanner() {
|
||||||
|
const [selectedTab, setSelectedTab] = useState("content");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<SiteBreadcrumb />
|
||||||
|
<div className="w-full overflow-x-auto bg-white p-4 rounded-sm space-y-3">
|
||||||
|
<div className="flex justify-between">
|
||||||
|
{selectedTab === "content"
|
||||||
|
? "Daftar List Media"
|
||||||
|
: "Table List Banner"}
|
||||||
|
|
||||||
|
<div className="flex flex-row text-sm">
|
||||||
|
<a
|
||||||
|
onClick={() => setSelectedTab("content")}
|
||||||
|
className={`px-3 py-2 cursor-pointer ${
|
||||||
|
selectedTab === "content" ? "bg-primary text-white" : ""
|
||||||
|
} `}
|
||||||
|
>
|
||||||
|
Kontent
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
onClick={() => setSelectedTab("banner")}
|
||||||
|
className={`px-3 py-2 cursor-pointer ${
|
||||||
|
selectedTab === "banner" ? "bg-primary text-white" : ""
|
||||||
|
} `}
|
||||||
|
>
|
||||||
|
Banner
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{selectedTab === "content" ? <ContentListTable /> : <BannerListTable />}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -92,42 +92,6 @@ const columns: ColumnDef<any>[] = [
|
||||||
router.push("/admin/settings/category?dataChange=true");
|
router.push("/admin/settings/category?dataChange=true");
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
// <Popover>
|
|
||||||
// <PopoverTrigger>
|
|
||||||
// <Button
|
|
||||||
// size="icon"
|
|
||||||
// className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
|
||||||
// >
|
|
||||||
// <MoreVertical className="h-4 w-4 text-default-800" />
|
|
||||||
// </Button>
|
|
||||||
// </PopoverTrigger>
|
|
||||||
// <PopoverContent className="w-40">
|
|
||||||
// <div className="flex flex-col">
|
|
||||||
// <EditCategoryModal />
|
|
||||||
// <a onClick={() => categoryDelete(row.original.id)}>Delete</a>
|
|
||||||
// </div>
|
|
||||||
// </PopoverContent>
|
|
||||||
// </Popover>
|
|
||||||
|
|
||||||
// <DropdownMenu>
|
|
||||||
// <DropdownMenuTrigger asChild>
|
|
||||||
// <Button
|
|
||||||
// size="icon"
|
|
||||||
// className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
|
||||||
// >
|
|
||||||
// <MoreVertical className="h-4 w-4 text-default-800" />
|
|
||||||
// </Button>
|
|
||||||
// </DropdownMenuTrigger>
|
|
||||||
// <DropdownMenuContent className="p-0" align="end">
|
|
||||||
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
|
||||||
// <EditCategoryModal />
|
|
||||||
// </DropdownMenuItem>
|
|
||||||
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
|
||||||
// <a onClick={() => categoryDelete(row.original.id)}>Delete</a>
|
|
||||||
// </DropdownMenuItem>
|
|
||||||
// </DropdownMenuContent>
|
|
||||||
// </DropdownMenu>
|
|
||||||
|
|
||||||
<Menubar className="border-none">
|
<Menubar className="border-none">
|
||||||
<MenubarMenu>
|
<MenubarMenu>
|
||||||
<MenubarTrigger>
|
<MenubarTrigger>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,123 @@
|
||||||
|
"use client";
|
||||||
|
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form";
|
||||||
|
import { close, error, loading } from "@/config/swal";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import JoditEditor from "jodit-react";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
import { getPrivacy, savePrivacy } from "@/service/settings/settings";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
|
const FormSchema = z.object({
|
||||||
|
title: z.string({
|
||||||
|
required_error: "Required",
|
||||||
|
}),
|
||||||
|
description: z.string({
|
||||||
|
required_error: "Required",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function AdminPrivacyPolicy() {
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
const editor = useRef(null);
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getPrivacyData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function getPrivacyData() {
|
||||||
|
const response = await getPrivacy("1");
|
||||||
|
console.log(response?.data?.data);
|
||||||
|
form.setValue("title", response?.data?.data?.title);
|
||||||
|
form.setValue("description", response?.data?.data?.htmlContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSubmit = async (data: z.infer<typeof FormSchema>) => {
|
||||||
|
const req = {
|
||||||
|
id: 1,
|
||||||
|
title: data.title,
|
||||||
|
htmlContent: data.description,
|
||||||
|
isActive: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await savePrivacy(req);
|
||||||
|
if (response?.error) {
|
||||||
|
error(response?.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
toast({
|
||||||
|
title: "Berhasil Simpan",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SiteBreadcrumb />
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
onSubmit={form.handleSubmit(onSubmit)}
|
||||||
|
className="space-y-3 bg-white rounded-sm p-4"
|
||||||
|
>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Judul</FormLabel>
|
||||||
|
<Input
|
||||||
|
value={field.value}
|
||||||
|
placeholder="Masukkan Judul"
|
||||||
|
onChange={field.onChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Konten</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<JoditEditor
|
||||||
|
ref={editor}
|
||||||
|
value={field.value}
|
||||||
|
config={{
|
||||||
|
height: 400, // Tinggi editor dalam piksel
|
||||||
|
}}
|
||||||
|
className="dark:text-black"
|
||||||
|
onChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<Button color="primary" type="submit">
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
// "use client";
|
// "use client";
|
||||||
import React, { useState, useEffect } from "react";
|
import React, {
|
||||||
|
useState,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
Fragment,
|
||||||
|
} from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -32,7 +37,7 @@ import {
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { error, loading } from "@/lib/swal";
|
import { error, loading, success } from "@/lib/swal";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
|
|
@ -42,12 +47,18 @@ import { saveAgendaSettings } from "@/service/agenda-setting/agenda-setting";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { getUserLevelForAssignments } from "@/service/task";
|
import { getUserLevelForAssignments } from "@/service/task";
|
||||||
import { AudioRecorder } from "react-audio-voice-recorder";
|
import { AudioRecorder } from "react-audio-voice-recorder";
|
||||||
|
import FileUploader from "@/components/form/shared/file-uploader";
|
||||||
|
import { Upload } from "tus-js-client";
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
title: z.string().min(3, { message: "Required" }),
|
title: z.string().min(3, { message: "Required" }),
|
||||||
description: z.string().min(3, { message: "Required" }),
|
description: z.string().min(3, { message: "Required" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface FileWithPreview extends File {
|
||||||
|
preview: string;
|
||||||
|
}
|
||||||
|
|
||||||
const EventModal = ({
|
const EventModal = ({
|
||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
|
|
@ -64,7 +75,7 @@ const EventModal = ({
|
||||||
const [startDate, setStartDate] = useState<Date>(new Date());
|
const [startDate, setStartDate] = useState<Date>(new Date());
|
||||||
const [endDate, setEndDate] = useState<Date>(new Date());
|
const [endDate, setEndDate] = useState<Date>(new Date());
|
||||||
const [isPending, startTransition] = React.useTransition();
|
const [isPending, startTransition] = React.useTransition();
|
||||||
const [calendarProps, setCalendarProps] = React.useState<any>(
|
const [agendaType, setAgendaType] = React.useState<any>(
|
||||||
categories[0].value
|
categories[0].value
|
||||||
);
|
);
|
||||||
const [listDest, setListDest] = useState([]);
|
const [listDest, setListDest] = useState([]);
|
||||||
|
|
@ -78,6 +89,14 @@ const EventModal = ({
|
||||||
const [audioFile, setAudioFile] = useState<File | null>(null);
|
const [audioFile, setAudioFile] = useState<File | null>(null);
|
||||||
const [isRecording, setIsRecording] = useState(false);
|
const [isRecording, setIsRecording] = useState(false);
|
||||||
const [timer, setTimer] = useState<number>(120);
|
const [timer, setTimer] = useState<number>(120);
|
||||||
|
const [imageFiles, setImageFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [videoFiles, setVideoFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [textFiles, setTextFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [audioFiles, setAudioFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [isImageUploadFinish, setIsImageUploadFinish] = useState(false);
|
||||||
|
const [isVideoUploadFinish, setIsVideoUploadFinish] = useState(false);
|
||||||
|
const [isTextUploadFinish, setIsTextUploadFinish] = useState(false);
|
||||||
|
const [isAudioUploadFinish, setIsAudioUploadFinish] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
|
|
@ -96,8 +115,17 @@ const EventModal = ({
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await getUserLevelForAssignments();
|
const response = await getUserLevelForAssignments();
|
||||||
setListDest(response?.data?.data.list);
|
const levelList = response?.data?.data.list;
|
||||||
const initialExpandedState = response?.data?.data.list.reduce(
|
let listFiltered = [];
|
||||||
|
if (agendaType == "polda") {
|
||||||
|
listFiltered = levelList.filter((level: any) => level.name != 'SATKER POLRI');
|
||||||
|
} else if (agendaType == "polres") {
|
||||||
|
listFiltered = levelList.filter((level: any) => level.name != 'SATKER POLRI');
|
||||||
|
} else if (agendaType == "satker") {
|
||||||
|
listFiltered = levelList.filter((level: any) => level.name == 'SATKER POLRI');
|
||||||
|
}
|
||||||
|
setListDest(listFiltered);
|
||||||
|
const initialExpandedState = listFiltered.reduce(
|
||||||
(acc: any, polda: any) => {
|
(acc: any, polda: any) => {
|
||||||
acc[polda.id] = false;
|
acc[polda.id] = false;
|
||||||
return acc;
|
return acc;
|
||||||
|
|
@ -105,7 +133,6 @@ const EventModal = ({
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
setExpandedPolda(initialExpandedState);
|
setExpandedPolda(initialExpandedState);
|
||||||
console.log("polres", initialExpandedState);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching Polda/Polres data:", error);
|
console.error("Error fetching Polda/Polres data:", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -113,7 +140,8 @@ const EventModal = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchPoldaPolres();
|
fetchPoldaPolres();
|
||||||
}, []);
|
console.log("Event", event);
|
||||||
|
}, [agendaType]);
|
||||||
|
|
||||||
const handleCheckboxChange = (levelId: number) => {
|
const handleCheckboxChange = (levelId: number) => {
|
||||||
setCheckedLevels((prev) => {
|
setCheckedLevels((prev) => {
|
||||||
|
|
@ -128,18 +156,15 @@ const EventModal = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const save = async (data: any) => {
|
const save = async (data: any) => {
|
||||||
if (!audioFile) return;
|
// const formData = new FormData();
|
||||||
|
// formData.append("voiceNote", audioFile);
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("voiceNote", audioFile);
|
|
||||||
|
|
||||||
const reqData = {
|
const reqData = {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
agendaType: calendarProps,
|
agendaType: agendaType,
|
||||||
startDate: format(startDate, "yyyy-MM-dd"),
|
startDate: format(startDate, "yyyy-MM-dd"),
|
||||||
endDate: format(endDate, "yyyy-MM-dd"),
|
endDate: format(endDate, "yyyy-MM-dd"),
|
||||||
voiceNote: formData,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Submitted Data:", reqData);
|
console.log("Submitted Data:", reqData);
|
||||||
|
|
@ -150,20 +175,70 @@ const EventModal = ({
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cookies.set("AgendaSetting", response?.data?.data.id, {
|
const id = response?.data?.data.id;
|
||||||
expires: 1,
|
|
||||||
|
if (imageFiles?.length == 0) {
|
||||||
|
setIsImageUploadFinish(true);
|
||||||
|
}
|
||||||
|
imageFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"1",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (videoFiles?.length == 0) {
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
}
|
||||||
|
videoFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"2",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (textFiles?.length == 0) {
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
}
|
||||||
|
textFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"3",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (audioFiles?.length == 0) {
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
audioFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"4",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Optional: Use Swal for success feedback
|
// Optional: Use Swal for success feedback
|
||||||
MySwal.fire({
|
// MySwal.fire({
|
||||||
title: "Sukses",
|
// title: "Sukses",
|
||||||
text: "Data berhasil disimpan.",
|
// text: "Data berhasil disimpan.",
|
||||||
icon: "success",
|
// icon: "success",
|
||||||
confirmButtonColor: "#3085d6",
|
// confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
// confirmButtonText: "OK",
|
||||||
}).then(() => {
|
// }).then(() => {
|
||||||
router.push("en/contributor/agenda-setting");
|
// router.push("en/contributor/agenda-setting");
|
||||||
});
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = (data: any) => {
|
const onSubmit = (data: any) => {
|
||||||
|
|
@ -179,7 +254,7 @@ const EventModal = ({
|
||||||
setStartDate(event?.event?.start);
|
setStartDate(event?.event?.start);
|
||||||
setEndDate(event?.event?.end);
|
setEndDate(event?.event?.end);
|
||||||
const eventCalendar = event?.event?.extendedProps?.calendar;
|
const eventCalendar = event?.event?.extendedProps?.calendar;
|
||||||
setCalendarProps(eventCalendar || categories[0].value);
|
setAgendaType(eventCalendar || categories[0].value);
|
||||||
}
|
}
|
||||||
setValue("title", event?.event?.title || "");
|
setValue("title", event?.event?.title || "");
|
||||||
setValue("description", event?.event?.description || "");
|
setValue("description", event?.event?.description || "");
|
||||||
|
|
@ -197,6 +272,7 @@ const EventModal = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleExpand = (poldaId: any) => {
|
const toggleExpand = (poldaId: any) => {
|
||||||
|
console.log("Toogle : ", expandedPolda);
|
||||||
setExpandedPolda((prev: any) => ({
|
setExpandedPolda((prev: any) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[poldaId]: !prev[poldaId],
|
[poldaId]: !prev[poldaId],
|
||||||
|
|
@ -248,6 +324,89 @@ const EventModal = ({
|
||||||
audioElements.forEach((audio) => audio.remove());
|
audioElements.forEach((audio) => audio.remove());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function uploadResumableFile(
|
||||||
|
idx: number,
|
||||||
|
id: string,
|
||||||
|
file: any,
|
||||||
|
fileTypeId: string,
|
||||||
|
duration: string
|
||||||
|
) {
|
||||||
|
console.log(idx, id, file, fileTypeId, duration);
|
||||||
|
|
||||||
|
// const placements = getPlacement(file.placements);
|
||||||
|
// console.log("Placementttt: : ", placements);
|
||||||
|
|
||||||
|
const upload = new Upload(file, {
|
||||||
|
endpoint: `${process.env.NEXT_PUBLIC_API}/agenda-settings/file/upload`,
|
||||||
|
retryDelays: [0, 3000, 6000, 12_000, 24_000],
|
||||||
|
chunkSize: 20_000,
|
||||||
|
metadata: {
|
||||||
|
agendaSettingId: id,
|
||||||
|
filename: file.name,
|
||||||
|
filetype: file.type,
|
||||||
|
fileTypeId: fileTypeId,
|
||||||
|
duration: "",
|
||||||
|
isWatermark: "true", // hardcode
|
||||||
|
},
|
||||||
|
onError: async (e: any) => {
|
||||||
|
console.log("Error upload :", e);
|
||||||
|
error(e);
|
||||||
|
},
|
||||||
|
onChunkComplete: (
|
||||||
|
chunkSize: any,
|
||||||
|
bytesAccepted: any,
|
||||||
|
bytesTotal: any
|
||||||
|
) => {
|
||||||
|
const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100);
|
||||||
|
// progressInfo[idx].percentage = uploadPersen;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// console.log(counterUpdateProgress);
|
||||||
|
// setProgressList(progressInfo);
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
},
|
||||||
|
onSuccess: async () => {
|
||||||
|
// uploadPersen = 100;
|
||||||
|
// progressInfo[idx].percentage = 100;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
successTodo();
|
||||||
|
if (fileTypeId == '1'){
|
||||||
|
setIsImageUploadFinish(true);
|
||||||
|
} else if (fileTypeId == '2'){
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
} if (fileTypeId == '3'){
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
} if (fileTypeId == '4'){
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
upload.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
successTodo();
|
||||||
|
}, [isImageUploadFinish, isVideoUploadFinish, isAudioUploadFinish, isTextUploadFinish])
|
||||||
|
|
||||||
|
function successTodo() {
|
||||||
|
if (isImageUploadFinish && isVideoUploadFinish && isAudioUploadFinish && isTextUploadFinish) {
|
||||||
|
successSubmit("/in/contributor/agenda-setting");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const successSubmit = (redirect: string) => {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Sukses",
|
||||||
|
text: "Data berhasil disimpan.",
|
||||||
|
icon: "success",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
}).then(() => {
|
||||||
|
router.push(redirect);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DeleteConfirmationDialog
|
<DeleteConfirmationDialog
|
||||||
|
|
@ -263,7 +422,7 @@ const EventModal = ({
|
||||||
>
|
>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
{event ? "Edit Agenda Setting" : "Create Agenda Setting"}{" "}
|
{event?.length > 1 ? "Edit Agenda Setting" : "Create Agenda Setting"}{" "}
|
||||||
{event?.title}
|
{event?.title}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
@ -366,14 +525,14 @@ const EventModal = ({
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="calendarProps">Jenis Agenda </Label>
|
<Label htmlFor="agendaType">Jenis Agenda </Label>
|
||||||
<Controller
|
<Controller
|
||||||
name="calendarProps"
|
name="agendaType"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Select
|
<Select
|
||||||
value={calendarProps}
|
value={agendaType}
|
||||||
onValueChange={(data) => setCalendarProps(data)}
|
onValueChange={(data) => setAgendaType(data)}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Label" />
|
<SelectValue placeholder="Label" />
|
||||||
|
|
@ -392,12 +551,12 @@ const EventModal = ({
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{calendarProps === "polda" && (
|
{(agendaType === "polda" || agendaType === "polres" || agendaType === "satker" )&& (
|
||||||
<div>
|
<div>
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button variant="soft" size="sm" color="primary">
|
<Button variant="soft" size="sm" color="primary">
|
||||||
[Kustom]
|
[Pilih {agendaType}]
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent className="sm:max-w-[425px] md:max-w-[500px] lg:max-w-[1500px]">
|
<DialogContent className="sm:max-w-[425px] md:max-w-[500px] lg:max-w-[1500px]">
|
||||||
|
|
@ -429,7 +588,7 @@ const EventModal = ({
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</Label>
|
</Label>
|
||||||
{expandedPolda[polda.id] && (
|
{(agendaType == "polres" || agendaType == "satker") && expandedPolda[polda.id] && (
|
||||||
<div className="ml-6 mt-2">
|
<div className="ml-6 mt-2">
|
||||||
<Label className="block">
|
<Label className="block">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
|
@ -506,29 +665,36 @@ const EventModal = ({
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div>
|
<div>
|
||||||
<Label>Video</Label>
|
<Label>Video</Label>
|
||||||
<Input
|
<FileUploader
|
||||||
type="file"
|
accept={{
|
||||||
accept="video/*"
|
"mp4/*": [],
|
||||||
multiple
|
"mov/*": [],
|
||||||
{...register("attachments.video")}
|
}}
|
||||||
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .mp4 atau .mov."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Foto</Label>
|
<Label>Foto</Label>
|
||||||
<Input
|
<FileUploader
|
||||||
type="file"
|
accept={{
|
||||||
accept="image/*"
|
"image/*": [],
|
||||||
multiple
|
}}
|
||||||
{...register("attachments.photo")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .png, .jpg, atau .jpeg."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Teks</Label>
|
<Label>Teks</Label>
|
||||||
<Input
|
<FileUploader
|
||||||
type="file"
|
accept={{
|
||||||
accept="text/plain"
|
"pdf/*": [],
|
||||||
multiple
|
}}
|
||||||
{...register("attachments.text")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .pdf."
|
||||||
|
onDrop={(files) => setTextFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -542,6 +708,16 @@ const EventModal = ({
|
||||||
downloadOnSavePress={true}
|
downloadOnSavePress={true}
|
||||||
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">
|
||||||
|
|
@ -568,15 +744,15 @@ const EventModal = ({
|
||||||
{isPending ? (
|
{isPending ? (
|
||||||
<>
|
<>
|
||||||
<Loader2 className="me-2 h-4 w-4 animate-spin" />
|
<Loader2 className="me-2 h-4 w-4 animate-spin" />
|
||||||
{event ? "Updating..." : "Adding..."}
|
{event?.length > 1 ? "Updating..." : "Adding..."}
|
||||||
</>
|
</>
|
||||||
) : event ? (
|
) : event?.length > 1 ? (
|
||||||
"Update Agenda Setting"
|
"Update Agenda Setting"
|
||||||
) : (
|
) : (
|
||||||
"Simpan Agenda Setting"
|
"Simpan Agenda Setting"
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
{event && (
|
{event?.length > 1 && (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
color="destructive"
|
color="destructive"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
import { Link } from "@/components/navigation";
|
||||||
|
|
||||||
const columns: ColumnDef<any>[] = [
|
const columns: ColumnDef<any>[] = [
|
||||||
{
|
{
|
||||||
|
|
@ -99,25 +100,32 @@ const columns: ColumnDef<any>[] = [
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "isDone",
|
accessorKey: "statusName",
|
||||||
header: "Status",
|
header: "Status",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const isDone = row.getValue<boolean>("isDone");
|
const statusColors: Record<string, string> = {
|
||||||
|
diterima: "bg-green-100 text-green-600",
|
||||||
|
"menunggu review": "bg-orange-100 text-orange-600",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mengambil `statusName` dari data API
|
||||||
|
const status = row.getValue("statusName") as string;
|
||||||
|
const statusName = status?.toLocaleLowerCase(); // Ubah ke huruf kecil
|
||||||
|
|
||||||
|
// Gunakan `statusName` untuk pencocokan
|
||||||
|
const statusStyles =
|
||||||
|
statusColors[statusName] || "bg-gray-100 text-gray-600";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Badge
|
||||||
<Button
|
className={cn(
|
||||||
size="sm"
|
"rounded-full px-5 w-full whitespace-nowrap",
|
||||||
color="success"
|
statusStyles
|
||||||
variant="outline"
|
)}
|
||||||
className={` btn btn-sm ${
|
>
|
||||||
isDone ? "btn-outline-success" : "btn-outline-primary"
|
{status} {/* Tetap tampilkan nilai asli */}
|
||||||
} pill-btn ml-1`}
|
</Badge>
|
||||||
>
|
|
||||||
{isDone ? "Selesai" : "Aktif"}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -139,12 +147,18 @@ const columns: ColumnDef<any>[] = [
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="p-0" align="end">
|
<DropdownMenuContent className="p-0" align="end">
|
||||||
<a href="/contributor/task/detail/[id]">
|
<Link href={`/contributor/content/audio/detail/${row.original.id}`}>
|
||||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
<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" />
|
<Eye className="w-4 h-4 me-1.5" />
|
||||||
View
|
View
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</a>
|
</Link>
|
||||||
|
<Link href={`/contributor/content/Audio/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 className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none">
|
<DropdownMenuItem 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" />
|
<Trash2 className="w-4 h-4 me-1.5" />
|
||||||
Delete
|
Delete
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import SiteBreadcrumb from "@/components/site-breadcrumb";
|
||||||
|
import FormImageDetail from "@/components/form/content/image-detail-form";
|
||||||
|
import FormAudioDetail from "@/components/form/content/audio-detail-form";
|
||||||
|
|
||||||
|
const AudioDetailPage = async () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<SiteBreadcrumb />
|
||||||
|
<div className="space-y-4">
|
||||||
|
<FormAudioDetail />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AudioDetailPage;
|
||||||
|
|
@ -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 FormAudioUpdate from "@/components/form/content/audio-update-form";
|
||||||
|
|
||||||
|
const AudioUpdatePage = async () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<SiteBreadcrumb />
|
||||||
|
<div className="space-y-4">
|
||||||
|
<FormAudioUpdate />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AudioUpdatePage;
|
||||||
|
|
@ -100,7 +100,6 @@ const columns: ColumnDef<any>[] = [
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "statusName",
|
accessorKey: "statusName",
|
||||||
header: "Status",
|
header: "Status",
|
||||||
|
|
|
||||||
|
|
@ -102,23 +102,31 @@ const columns: ColumnDef<any>[] = [
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "isDone",
|
accessorKey: "statusName",
|
||||||
header: "Status",
|
header: "Status",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const isDone = row.getValue<boolean>("isDone");
|
const statusColors: Record<string, string> = {
|
||||||
|
diterima: "bg-green-100 text-green-600",
|
||||||
|
"menunggu review": "bg-orange-100 text-orange-600",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mengambil `statusName` dari data API
|
||||||
|
const status = row.getValue("statusName") as string;
|
||||||
|
const statusName = status?.toLocaleLowerCase(); // Ubah ke huruf kecil
|
||||||
|
|
||||||
|
// Gunakan `statusName` untuk pencocokan
|
||||||
|
const statusStyles =
|
||||||
|
statusColors[statusName] || "bg-gray-100 text-gray-600";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Badge
|
||||||
<Button
|
className={cn(
|
||||||
size="sm"
|
"rounded-full px-5 w-full whitespace-nowrap",
|
||||||
color="success"
|
statusStyles
|
||||||
variant="outline"
|
)}
|
||||||
className={` btn btn-sm ${
|
>
|
||||||
isDone ? "btn-outline-success" : "btn-outline-primary"
|
{status} {/* Tetap tampilkan nilai asli */}
|
||||||
} pill-btn ml-1`}
|
</Badge>
|
||||||
>
|
|
||||||
{isDone ? "Selesai" : "Aktif"}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -102,23 +102,31 @@ const columns: ColumnDef<any>[] = [
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "isDone",
|
accessorKey: "statusName",
|
||||||
header: "Status",
|
header: "Status",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const isDone = row.getValue<boolean>("isDone");
|
const statusColors: Record<string, string> = {
|
||||||
|
diterima: "bg-green-100 text-green-600",
|
||||||
|
"menunggu review": "bg-orange-100 text-orange-600",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mengambil `statusName` dari data API
|
||||||
|
const status = row.getValue("statusName") as string;
|
||||||
|
const statusName = status?.toLocaleLowerCase(); // Ubah ke huruf kecil
|
||||||
|
|
||||||
|
// Gunakan `statusName` untuk pencocokan
|
||||||
|
const statusStyles =
|
||||||
|
statusColors[statusName] || "bg-gray-100 text-gray-600";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Badge
|
||||||
<Button
|
className={cn(
|
||||||
size="sm"
|
"rounded-full px-5 w-full whitespace-nowrap",
|
||||||
color="success"
|
statusStyles
|
||||||
variant="outline"
|
)}
|
||||||
className={` btn btn-sm ${
|
>
|
||||||
isDone ? "btn-outline-success" : "btn-outline-primary"
|
{status} {/* Tetap tampilkan nilai asli */}
|
||||||
} pill-btn ml-1`}
|
</Badge>
|
||||||
>
|
|
||||||
{isDone ? "Selesai" : "Aktif"}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,752 @@
|
||||||
|
"use client";
|
||||||
|
import React, { ChangeEvent, useEffect, useRef, useState } from "react";
|
||||||
|
import { useForm, Controller } from "react-hook-form";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Card } from "@/components/ui/card";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import * as z from "zod";
|
||||||
|
import Swal from "sweetalert2";
|
||||||
|
import withReactContent from "sweetalert2-react-content";
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
||||||
|
import JoditEditor from "jodit-react";
|
||||||
|
import { register } from "module";
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
|
import Cookies from "js-cookie";
|
||||||
|
import {
|
||||||
|
createMedia,
|
||||||
|
getTagsBySubCategoryId,
|
||||||
|
listEnableCategory,
|
||||||
|
rejectFiles,
|
||||||
|
submitApproval,
|
||||||
|
} from "@/service/content/content";
|
||||||
|
import { detailMedia } from "@/service/curated-content/curated-content";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { MailIcon } from "lucide-react";
|
||||||
|
import { Swiper, SwiperSlide } from "swiper/react";
|
||||||
|
import "swiper/css";
|
||||||
|
import "swiper/css/free-mode";
|
||||||
|
import "swiper/css/navigation";
|
||||||
|
import "swiper/css/pagination";
|
||||||
|
import "swiper/css/thumbs";
|
||||||
|
import "swiper/css";
|
||||||
|
import "swiper/css/navigation";
|
||||||
|
import { FreeMode, Navigation, Pagination, Thumbs } from "swiper/modules";
|
||||||
|
import {
|
||||||
|
DialogHeader,
|
||||||
|
DialogFooter,
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { loading } from "@/config/swal";
|
||||||
|
import { getCookiesDecrypt } from "@/lib/utils";
|
||||||
|
import { Icon } from "@iconify/react/dist/iconify.js";
|
||||||
|
import { error } from "@/lib/swal";
|
||||||
|
|
||||||
|
const imageSchema = z.object({
|
||||||
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
description: z
|
||||||
|
.string()
|
||||||
|
.min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
|
||||||
|
creatorName: z.string().min(1, { message: "Creator diperlukan" }),
|
||||||
|
// tags: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Category = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type FileType = {
|
||||||
|
id: number;
|
||||||
|
url: string;
|
||||||
|
thumbnailFileUrl: string;
|
||||||
|
fileName: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Detail = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
slug: string;
|
||||||
|
category: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
categoryName: string;
|
||||||
|
creatorName: string;
|
||||||
|
thumbnailLink: string;
|
||||||
|
tags: string;
|
||||||
|
statusName: string;
|
||||||
|
isPublish: boolean;
|
||||||
|
needApprovalFromLevel: number;
|
||||||
|
files: FileType[];
|
||||||
|
uploadedById: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function FormAudioDetail() {
|
||||||
|
const MySwal = withReactContent(Swal);
|
||||||
|
const router = useRouter();
|
||||||
|
const userId = getCookiesDecrypt("uie");
|
||||||
|
const userLevelId = getCookiesDecrypt("ulie");
|
||||||
|
const roleId = getCookiesDecrypt("urie");
|
||||||
|
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const { id } = useParams() as { id: string };
|
||||||
|
console.log(id);
|
||||||
|
const editor = useRef(null);
|
||||||
|
type ImageSchema = z.infer<typeof imageSchema>;
|
||||||
|
|
||||||
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||||
|
const taskId = Cookies.get("taskId");
|
||||||
|
const scheduleId = Cookies.get("scheduleId");
|
||||||
|
const scheduleType = Cookies.get("scheduleType");
|
||||||
|
const [status, setStatus] = useState("");
|
||||||
|
const [categories, setCategories] = useState<Category[]>([]);
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||||
|
const [tags, setTags] = useState<any[]>([]);
|
||||||
|
const [detail, setDetail] = useState<any>();
|
||||||
|
const [refresh, setRefresh] = useState(false);
|
||||||
|
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
||||||
|
const [description, setDescription] = useState("");
|
||||||
|
const [main, setMain] = useState<any>([]);
|
||||||
|
const [detailThumb, setDetailThumb] = useState<any>([]);
|
||||||
|
const [thumbsSwiper, setThumbsSwiper] = useState<any>(null);
|
||||||
|
|
||||||
|
const [selectedTarget, setSelectedTarget] = useState("");
|
||||||
|
const [files, setFiles] = useState<FileType[]>([]);
|
||||||
|
const [rejectedFiles, setRejectedFiles] = useState<number[]>([]);
|
||||||
|
const [isMabesApprover, setIsMabesApprover] = useState(false);
|
||||||
|
|
||||||
|
let fileTypeId = "4";
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
setValue,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm<ImageSchema>({
|
||||||
|
resolver: zodResolver(imageSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
// const handleKeyDown = (e: any) => {
|
||||||
|
// const newTag = e.target.value.trim(); // Ambil nilai input
|
||||||
|
// if (e.key === "Enter" && newTag) {
|
||||||
|
// e.preventDefault(); // Hentikan submit form
|
||||||
|
// if (!tags.includes(newTag)) {
|
||||||
|
// setTags((prevTags) => [...prevTags, newTag]); // Tambah tag baru
|
||||||
|
// setValue("tags", ""); // Kosongkan input
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
userLevelId != undefined &&
|
||||||
|
roleId != undefined &&
|
||||||
|
userLevelId == "216" &&
|
||||||
|
roleId == "3"
|
||||||
|
) {
|
||||||
|
setIsMabesApprover(true);
|
||||||
|
}
|
||||||
|
}, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
const handleCheckboxChange = (id: number) => {
|
||||||
|
setSelectedPublishers((prev) =>
|
||||||
|
prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function initState() {
|
||||||
|
getCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
initState();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getCategories = async () => {
|
||||||
|
try {
|
||||||
|
const category = await listEnableCategory(fileTypeId);
|
||||||
|
const resCategory: Category[] = category.data.data.content;
|
||||||
|
|
||||||
|
setCategories(resCategory);
|
||||||
|
console.log("data category", resCategory);
|
||||||
|
|
||||||
|
if (scheduleId && scheduleType === "3") {
|
||||||
|
const findCategory = resCategory.find((o) =>
|
||||||
|
o.name.toLowerCase().includes("pers rilis")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (findCategory) {
|
||||||
|
// setValue("categoryId", findCategory.id);
|
||||||
|
setSelectedCategory(findCategory.id); // Set the selected category
|
||||||
|
const response = await getTagsBySubCategoryId(findCategory.id);
|
||||||
|
setTags(response?.data.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch categories:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function initState() {
|
||||||
|
if (id) {
|
||||||
|
const response = await detailMedia(id);
|
||||||
|
const details = response.data?.data;
|
||||||
|
console.log("detail", details);
|
||||||
|
setFiles(details?.files);
|
||||||
|
setDetail(details);
|
||||||
|
setMain({
|
||||||
|
type: details?.fileType.name,
|
||||||
|
url: details?.files[0]?.url,
|
||||||
|
names: details?.files[0]?.fileName,
|
||||||
|
format: details?.files[0]?.format,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (details.publishedForObject) {
|
||||||
|
const publisherIds = details.publishedForObject.map(
|
||||||
|
(obj: any) => obj.id
|
||||||
|
);
|
||||||
|
setSelectedPublishers(publisherIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
const matchingCategory = categories.find(
|
||||||
|
(category) => category.id === details.categoryId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matchingCategory) {
|
||||||
|
setSelectedTarget(matchingCategory.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedTarget(details.categoryId); // Untuk dropdown
|
||||||
|
|
||||||
|
const filesData = details.files || [];
|
||||||
|
const fileUrls = filesData.map((file: { thumbnailFileUrl: string }) =>
|
||||||
|
file.thumbnailFileUrl ? file.thumbnailFileUrl : "default-image.jpg"
|
||||||
|
);
|
||||||
|
setDetailThumb(fileUrls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initState();
|
||||||
|
}, [refresh, setValue]);
|
||||||
|
|
||||||
|
const actionApproval = (e: string) => {
|
||||||
|
setStatus(e);
|
||||||
|
setModalOpen(true);
|
||||||
|
setDescription("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const submit = async () => {
|
||||||
|
if (
|
||||||
|
(description?.length > 1 && Number(status) == 3) ||
|
||||||
|
Number(status) == 2 ||
|
||||||
|
Number(status) == 4
|
||||||
|
) {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Simpan Approval",
|
||||||
|
text: "",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
cancelButtonColor: "#d33",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "Simpan",
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const data = {
|
||||||
|
mediaUploadId: id,
|
||||||
|
statusId: status,
|
||||||
|
message: description,
|
||||||
|
files: [],
|
||||||
|
// files: isMabesApprover ? getPlacement() : [],
|
||||||
|
};
|
||||||
|
|
||||||
|
loading();
|
||||||
|
const response = await submitApproval(data);
|
||||||
|
|
||||||
|
if (response?.error) {
|
||||||
|
error(response.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataReject = {
|
||||||
|
listFiles: rejectedFiles,
|
||||||
|
};
|
||||||
|
|
||||||
|
const resReject = await rejectFiles(dataReject);
|
||||||
|
|
||||||
|
if (resReject?.error) {
|
||||||
|
error(resReject.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
close();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDeleteFileApproval(id: number) {
|
||||||
|
const selectedFiles = files.filter((file) => file.id != id);
|
||||||
|
setFiles(selectedFiles);
|
||||||
|
const rejects = rejectedFiles;
|
||||||
|
rejects.push(id);
|
||||||
|
setRejectedFiles(rejects);
|
||||||
|
}
|
||||||
|
const handleMain = (
|
||||||
|
type: string,
|
||||||
|
url: string,
|
||||||
|
names: string,
|
||||||
|
format: string
|
||||||
|
) => {
|
||||||
|
console.log("Test 3 :", type, url, names, format);
|
||||||
|
setMain({
|
||||||
|
type,
|
||||||
|
url,
|
||||||
|
names,
|
||||||
|
format,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitApprovalSuccesss = () => {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Sukses",
|
||||||
|
text: "Data berhasil disimpan.",
|
||||||
|
icon: "success",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
}).then(() => {
|
||||||
|
router.push("/in/contributor/content/image");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form>
|
||||||
|
{detail !== undefined ? (
|
||||||
|
<div className="flex lg:flex-row gap-10">
|
||||||
|
<Card className="w-full lg:w-8/12">
|
||||||
|
<div className="px-6 py-6">
|
||||||
|
<p className="text-lg font-semibold mb-3">Form Konten Foto</p>
|
||||||
|
<div className="gap-5 mb-5">
|
||||||
|
{/* Input Title */}
|
||||||
|
<div className="space-y-2 py-3">
|
||||||
|
<Label>Judul</Label>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
size="md"
|
||||||
|
type="text"
|
||||||
|
value={detail?.title}
|
||||||
|
onChange={field.onChange}
|
||||||
|
placeholder="Enter Title"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.title?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.title.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="py-3 w-full">
|
||||||
|
<Label>Kategori</Label>
|
||||||
|
<Select
|
||||||
|
value={detail?.category.name} // Nilai default berdasarkan detail
|
||||||
|
onValueChange={(id) => {
|
||||||
|
console.log("Selected Category:", id);
|
||||||
|
setSelectedTarget(id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger size="md">
|
||||||
|
<SelectValue placeholder="Pilih" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{categories.map((category) => (
|
||||||
|
<SelectItem key={category.id} value={category.name}>
|
||||||
|
{category.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="py-3">
|
||||||
|
<Label>Deskripsi</Label>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="description"
|
||||||
|
render={({ field: { onChange, value } }) => (
|
||||||
|
<JoditEditor
|
||||||
|
ref={editor}
|
||||||
|
value={detail?.description}
|
||||||
|
onChange={onChange}
|
||||||
|
className="dark:text-black"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.description?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.description.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Label className="text-xl text-black">File Media</Label>
|
||||||
|
<div className="w-full ">
|
||||||
|
<Swiper
|
||||||
|
thumbs={{ swiper: thumbsSwiper }}
|
||||||
|
modules={[FreeMode, Navigation, Thumbs]}
|
||||||
|
navigation={false}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
{detailThumb?.map((data: any) => (
|
||||||
|
<SwiperSlide key={data.id}>
|
||||||
|
<img
|
||||||
|
className="object-fill h-full w-full rounded-md"
|
||||||
|
src={data}
|
||||||
|
alt={` ${data.id}`}
|
||||||
|
/>
|
||||||
|
</SwiperSlide>
|
||||||
|
))}
|
||||||
|
</Swiper>
|
||||||
|
<div className=" mt-2 ">
|
||||||
|
<Swiper
|
||||||
|
onSwiper={setThumbsSwiper}
|
||||||
|
slidesPerView={6}
|
||||||
|
spaceBetween={8}
|
||||||
|
pagination={{
|
||||||
|
clickable: true,
|
||||||
|
}}
|
||||||
|
modules={[Pagination, Thumbs]}
|
||||||
|
// className="mySwiper2"
|
||||||
|
>
|
||||||
|
{detailThumb?.map((data: any) => (
|
||||||
|
<SwiperSlide key={data.id}>
|
||||||
|
<img
|
||||||
|
className="object-cover h-[60px] w-[80px]"
|
||||||
|
src={data}
|
||||||
|
alt={` ${data.id}`}
|
||||||
|
/>
|
||||||
|
</SwiperSlide>
|
||||||
|
))}
|
||||||
|
</Swiper>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
<div className="w-4/12">
|
||||||
|
<Card className=" h-[800px]">
|
||||||
|
<div className="px-3 py-3">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Kreator</Label>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="creatorName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
size="md"
|
||||||
|
type="text"
|
||||||
|
value={detail?.creatorName}
|
||||||
|
onChange={field.onChange}
|
||||||
|
placeholder="Enter Title"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.creatorName?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.creatorName.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="px-3 py-3">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Tag</Label>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{detail?.tags
|
||||||
|
?.split(",")
|
||||||
|
.map((tag: string, index: number) => (
|
||||||
|
<Badge
|
||||||
|
key={index}
|
||||||
|
className="border rounded-md px-2 py-2"
|
||||||
|
>
|
||||||
|
{tag.trim()}
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="px-3 py-3">
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<Label>Target Publish</Label>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="5"
|
||||||
|
checked={selectedPublishers.includes(5)}
|
||||||
|
onChange={() => handleCheckboxChange(5)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="5">UMUM</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="6"
|
||||||
|
checked={selectedPublishers.includes(6)}
|
||||||
|
onChange={() => handleCheckboxChange(6)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="6">JOURNALIS</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="7"
|
||||||
|
checked={selectedPublishers.includes(7)}
|
||||||
|
onChange={() => handleCheckboxChange(7)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="7">POLRI</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="8"
|
||||||
|
checked={selectedPublishers.includes(8)}
|
||||||
|
onChange={() => handleCheckboxChange(8)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="8">KSP</Label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="px-3 py-3 flex flex-row items-center text-blue-500 gap-2 text-sm">
|
||||||
|
<MailIcon />
|
||||||
|
<p className="">Kotak Saran (0)</p>
|
||||||
|
</div>
|
||||||
|
<div className="px-3 py-3 border mx-3">
|
||||||
|
<p>Keterangan:</p>
|
||||||
|
<p className="text-sm text-slate-400">{detail?.statusName}</p>
|
||||||
|
</div>
|
||||||
|
{/* {detail?.isPublish == false ? (
|
||||||
|
<div className="p-3">
|
||||||
|
<Button className="bg-blue-600">Publish</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)} */}
|
||||||
|
{Number(detail?.needApprovalFromLevel) == Number(userLevelId) ? (
|
||||||
|
Number(detail?.uploadedById) == Number(userId) ? (
|
||||||
|
""
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col gap-2 p-3">
|
||||||
|
<Button
|
||||||
|
onClick={() => actionApproval("2")}
|
||||||
|
color="primary"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:check" className="mr-3" /> Setujui
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => actionApproval("3")}
|
||||||
|
className="bg-orange-400 hover:bg-orange-300"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:comment-o" className="mr-3" /> Revisi
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => actionApproval("4")}
|
||||||
|
color="destructive"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:times" className="mr-3" />
|
||||||
|
Tolak
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
|
||||||
|
<DialogContent size="md">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Berikan Komentar</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
{status == "2"
|
||||||
|
? files?.map((file) => (
|
||||||
|
<div
|
||||||
|
key={file.id}
|
||||||
|
className="flex flex-row gap-2 items-center"
|
||||||
|
>
|
||||||
|
<img src={file.url} className="w-[200px]" />
|
||||||
|
<div className="flex flex-col gap-2 w-full">
|
||||||
|
<div className="flex justify-between text-sm">
|
||||||
|
{file.fileName}
|
||||||
|
<a>
|
||||||
|
<Icon icon="humbleicons:times" color="red" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox id="terms" />
|
||||||
|
<label
|
||||||
|
htmlFor="terms"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Semua
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox id="terms" />
|
||||||
|
<label
|
||||||
|
htmlFor="terms"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Nasional
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox id="terms" />
|
||||||
|
<label
|
||||||
|
htmlFor="terms"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Wilayah
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox id="terms" />
|
||||||
|
<label
|
||||||
|
htmlFor="terms"
|
||||||
|
className="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
>
|
||||||
|
Internasional
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
: ""}
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<Textarea
|
||||||
|
placeholder="Type your message here."
|
||||||
|
value={description}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{status == "3" || status == "4" ? (
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<Badge
|
||||||
|
color={
|
||||||
|
description === "Kualitas media kurang baik"
|
||||||
|
? "primary"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={() =>
|
||||||
|
setDescription("Kualitas media kurang baik")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Kualitas media kurang baik
|
||||||
|
</Badge>
|
||||||
|
|
||||||
|
<Badge
|
||||||
|
color={
|
||||||
|
description === "Deskripsi kurang lengkap"
|
||||||
|
? "primary"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={() =>
|
||||||
|
setDescription("Deskripsi kurang lengkap")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Deskripsi kurang lengkap
|
||||||
|
</Badge>
|
||||||
|
<Badge
|
||||||
|
color={
|
||||||
|
description === "Judul kurang tepat"
|
||||||
|
? "primary"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={() => setDescription("Judul kurang tepat")}
|
||||||
|
>
|
||||||
|
Judul kurang tepat
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<Badge
|
||||||
|
color={
|
||||||
|
description === "Konten sangat bagus"
|
||||||
|
? "primary"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={() => setDescription("Konten sangat bagus")}
|
||||||
|
>
|
||||||
|
Konten sangat bagus
|
||||||
|
</Badge>
|
||||||
|
<Badge
|
||||||
|
color={
|
||||||
|
description === "Konten menarik"
|
||||||
|
? "primary"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={() => setDescription("Konten menarik")}
|
||||||
|
>
|
||||||
|
Konten menarik
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
color="primary"
|
||||||
|
onClick={submitApprovalSuccesss}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
color="destructive"
|
||||||
|
onClick={() => setModalOpen(false)}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -509,7 +509,7 @@ export default function FormAudio() {
|
||||||
setIsStartUpload(false);
|
setIsStartUpload(false);
|
||||||
// hideProgress();
|
// hideProgress();
|
||||||
Cookies.remove("idCreate");
|
Cookies.remove("idCreate");
|
||||||
successSubmit("/in/contributor/content/audio/");
|
successSubmit("/in/contributor/content/audio");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,430 @@
|
||||||
|
"use client";
|
||||||
|
import React, { ChangeEvent, useEffect, useRef, useState } from "react";
|
||||||
|
import { useForm, Controller } from "react-hook-form";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Card } from "@/components/ui/card";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import * as z from "zod";
|
||||||
|
import Swal from "sweetalert2";
|
||||||
|
import withReactContent from "sweetalert2-react-content";
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
||||||
|
import JoditEditor from "jodit-react";
|
||||||
|
import { register } from "module";
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
|
import Cookies from "js-cookie";
|
||||||
|
import {
|
||||||
|
createMedia,
|
||||||
|
getTagsBySubCategoryId,
|
||||||
|
listEnableCategory,
|
||||||
|
} from "@/service/content/content";
|
||||||
|
import { detailMedia } from "@/service/curated-content/curated-content";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { MailIcon } from "lucide-react";
|
||||||
|
|
||||||
|
const imageSchema = z.object({
|
||||||
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
description: z
|
||||||
|
.string()
|
||||||
|
.min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
|
||||||
|
creatorName: z.string().min(1, { message: "Creator diperlukan" }),
|
||||||
|
// tags: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Category = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Detail = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
slug: string;
|
||||||
|
categoryId: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
creatorName: string;
|
||||||
|
categoryName: string;
|
||||||
|
thumbnailLink: string;
|
||||||
|
tags: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function FormAudioUpdate() {
|
||||||
|
const MySwal = withReactContent(Swal);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const { id } = useParams() as { id: string };
|
||||||
|
console.log(id);
|
||||||
|
const editor = useRef(null);
|
||||||
|
type ImageSchema = z.infer<typeof imageSchema>;
|
||||||
|
|
||||||
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||||
|
const taskId = Cookies.get("taskId");
|
||||||
|
const scheduleId = Cookies.get("scheduleId");
|
||||||
|
const scheduleType = Cookies.get("scheduleType");
|
||||||
|
|
||||||
|
const [categories, setCategories] = useState<Category[]>([]);
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||||
|
const [tags, setTags] = useState<any[]>([]);
|
||||||
|
const [detail, setDetail] = useState<Detail>();
|
||||||
|
const [refresh, setRefresh] = useState(false);
|
||||||
|
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
||||||
|
|
||||||
|
const [selectedTarget, setSelectedTarget] = useState("");
|
||||||
|
const [unitSelection, setUnitSelection] = useState({
|
||||||
|
allUnit: false,
|
||||||
|
mabes: false,
|
||||||
|
polda: false,
|
||||||
|
polres: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
let fileTypeId = "4";
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
setValue,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm<ImageSchema>({
|
||||||
|
resolver: zodResolver(imageSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
// const handleKeyDown = (e: any) => {
|
||||||
|
// const newTag = e.target.value.trim(); // Ambil nilai input
|
||||||
|
// if (e.key === "Enter" && newTag) {
|
||||||
|
// e.preventDefault(); // Hentikan submit form
|
||||||
|
// if (!tags.includes(newTag)) {
|
||||||
|
// setTags((prevTags) => [...prevTags, newTag]); // Tambah tag baru
|
||||||
|
// setValue("tags", ""); // Kosongkan input
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
const handleRemoveTag = (index: any) => {
|
||||||
|
setTags((prevTags) => prevTags.filter((_, i) => i !== index));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
if (event.target.files) {
|
||||||
|
const files = Array.from(event.target.files);
|
||||||
|
setSelectedFiles((prevImages: any) => [...prevImages, ...files]);
|
||||||
|
console.log("DATAFILE::", selectedFiles);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveImage = (index: number) => {
|
||||||
|
setSelectedFiles((prevImages) => prevImages.filter((_, i) => i !== index));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCheckboxChange = (id: number) => {
|
||||||
|
setSelectedPublishers((prev) =>
|
||||||
|
prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function initState() {
|
||||||
|
getCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
initState();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getCategories = async () => {
|
||||||
|
try {
|
||||||
|
const category = await listEnableCategory(fileTypeId);
|
||||||
|
const resCategory: Category[] = category.data.data.content;
|
||||||
|
|
||||||
|
setCategories(resCategory);
|
||||||
|
console.log("data category", resCategory);
|
||||||
|
|
||||||
|
if (scheduleId && scheduleType === "3") {
|
||||||
|
const findCategory = resCategory.find((o) =>
|
||||||
|
o.name.toLowerCase().includes("pers rilis")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (findCategory) {
|
||||||
|
// setValue("categoryId", findCategory.id);
|
||||||
|
setSelectedCategory(findCategory.id); // Set the selected category
|
||||||
|
const response = await getTagsBySubCategoryId(findCategory.id);
|
||||||
|
setTags(response?.data.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch categories:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function initState() {
|
||||||
|
if (id) {
|
||||||
|
const response = await detailMedia(id);
|
||||||
|
const details = response.data?.data;
|
||||||
|
|
||||||
|
setDetail(details);
|
||||||
|
|
||||||
|
if (details.publishedForObject) {
|
||||||
|
const publisherIds = details.publishedForObject.map(
|
||||||
|
(obj: any) => obj.id
|
||||||
|
);
|
||||||
|
setSelectedPublishers(publisherIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
const matchingCategory = categories.find(
|
||||||
|
(category) => category.id === details.categoryId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matchingCategory) {
|
||||||
|
setSelectedTarget(matchingCategory.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedTarget(details.categoryId); // Untuk dropdown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initState();
|
||||||
|
}, [refresh, setValue]);
|
||||||
|
|
||||||
|
const save = async (data: ImageSchema) => {
|
||||||
|
const requestData = {
|
||||||
|
...data,
|
||||||
|
id: detail?.id,
|
||||||
|
title: data.title,
|
||||||
|
description: data.description,
|
||||||
|
htmlDescription: data.description,
|
||||||
|
fileTypeId,
|
||||||
|
categoryId: selectedTarget,
|
||||||
|
subCategoryId: selectedTarget,
|
||||||
|
uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
||||||
|
statusId: "1",
|
||||||
|
publishedFor: "6",
|
||||||
|
creatorName: data.creatorName,
|
||||||
|
tags: "siap",
|
||||||
|
isYoutube: false,
|
||||||
|
isInternationalMedia: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await createMedia(requestData);
|
||||||
|
console.log("Form Data Submitted:", requestData);
|
||||||
|
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Sukses",
|
||||||
|
text: "Data berhasil disimpan.",
|
||||||
|
icon: "success",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
}).then(() => {
|
||||||
|
router.push("/en/contributor/content/audio");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = (data: ImageSchema) => {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Simpan Data",
|
||||||
|
text: "Apakah Anda yakin ingin menyimpan data ini?",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
cancelButtonColor: "#d33",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "Simpan",
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
save(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
{detail !== undefined ? (
|
||||||
|
<div className="flex lg:flex-row gap-10">
|
||||||
|
<Card className="w-full lg:w-8/12">
|
||||||
|
<div className="px-6 py-6">
|
||||||
|
<p className="text-lg font-semibold mb-3">Form Konten Foto</p>
|
||||||
|
<div className="gap-5 mb-5">
|
||||||
|
{/* Input Title */}
|
||||||
|
<div className="space-y-2 py-3">
|
||||||
|
<Label>Judul</Label>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
size="md"
|
||||||
|
type="text"
|
||||||
|
defaultValue={detail?.title}
|
||||||
|
onChange={field.onChange}
|
||||||
|
placeholder="Enter Title"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.title?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.title.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="py-3 w-full">
|
||||||
|
<Label>Kategori</Label>
|
||||||
|
<Select
|
||||||
|
defaultValue={detail?.categoryId.name} // Nilai default berdasarkan detail
|
||||||
|
onValueChange={(id) => {
|
||||||
|
console.log("Selected Category:", id);
|
||||||
|
setSelectedTarget(id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger size="md">
|
||||||
|
<SelectValue placeholder="Pilih" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{categories.map((category) => (
|
||||||
|
<SelectItem key={category.id} value={category.id}>
|
||||||
|
{category.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="py-3">
|
||||||
|
<Label>Deskripsi</Label>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="description"
|
||||||
|
render={({ field: { onChange, value } }) => (
|
||||||
|
<JoditEditor
|
||||||
|
ref={editor}
|
||||||
|
value={detail?.description}
|
||||||
|
onChange={onChange}
|
||||||
|
className="dark:text-black"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.description?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.description.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
<div className="w-4/12">
|
||||||
|
<Card className=" h-[800px]">
|
||||||
|
<div className="px-3 py-3">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Kreator</Label>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="creatorName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
size="md"
|
||||||
|
type="text"
|
||||||
|
defaultValue={detail?.creatorName}
|
||||||
|
onChange={field.onChange}
|
||||||
|
placeholder="Enter Title"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.creatorName?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.creatorName.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="px-3 py-3">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Tag</Label>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{detail?.tags?.split(",").map((tag, index) => (
|
||||||
|
<Badge
|
||||||
|
key={index}
|
||||||
|
className="border rounded-md px-2 py-2"
|
||||||
|
>
|
||||||
|
{tag.trim()}
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="px-3 py-3">
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<Label>Target Publish</Label>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="5"
|
||||||
|
checked={selectedPublishers.includes(5)}
|
||||||
|
onChange={() => handleCheckboxChange(5)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="5">UMUM</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="6"
|
||||||
|
checked={selectedPublishers.includes(6)}
|
||||||
|
onChange={() => handleCheckboxChange(6)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="6">JOURNALIS</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="7"
|
||||||
|
checked={selectedPublishers.includes(7)}
|
||||||
|
onChange={() => handleCheckboxChange(7)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="7">POLRI</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="8"
|
||||||
|
checked={selectedPublishers.includes(8)}
|
||||||
|
onChange={() => handleCheckboxChange(8)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="8">KSP</Label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="px-3 py-3 flex flex-row items-center text-blue-500 gap-2 text-sm">
|
||||||
|
<MailIcon />
|
||||||
|
<p className="">Kotak Saran (0)</p>
|
||||||
|
</div>
|
||||||
|
<div className="px-3 py-3">
|
||||||
|
<p>Keterangan:</p>
|
||||||
|
{/* <p>{detail?.status}</p> */}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
<div className="flex flex-row justify-end gap-3">
|
||||||
|
<div className="mt-4">
|
||||||
|
<Button type="submit" color="primary">
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4">
|
||||||
|
<Button type="submit" color="primary" variant="outline">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -922,7 +922,10 @@ export default function FormImage() {
|
||||||
// onChange={onChange}
|
// onChange={onChange}
|
||||||
// className="dark:text-black"
|
// className="dark:text-black"
|
||||||
// />
|
// />
|
||||||
<CustomEditor onChange={onChange} />
|
<CustomEditor
|
||||||
|
onChange={onChange}
|
||||||
|
initialData={articleBody || value}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
{errors.description?.message && (
|
{errors.description?.message && (
|
||||||
|
|
|
||||||
|
|
@ -336,7 +336,7 @@ export default function FormTeksDetail() {
|
||||||
confirmButtonColor: "#3085d6",
|
confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
confirmButtonText: "OK",
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
router.push("/in/contributor/content/image");
|
router.push("/in/contributor/content/teks");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -346,7 +346,9 @@ export default function FormTeksDetail() {
|
||||||
<div className="flex lg:flex-row gap-10">
|
<div className="flex lg:flex-row gap-10">
|
||||||
<Card className="w-full lg:w-8/12">
|
<Card className="w-full lg:w-8/12">
|
||||||
<div className="px-6 py-6">
|
<div className="px-6 py-6">
|
||||||
<p className="text-lg font-semibold mb-3">Form Konten Foto</p>
|
<p className="text-lg font-semibold mb-3">
|
||||||
|
Form detail Konten Teks
|
||||||
|
</p>
|
||||||
<div className="gap-5 mb-5">
|
<div className="gap-5 mb-5">
|
||||||
{/* Input Title */}
|
{/* Input Title */}
|
||||||
<div className="space-y-2 py-3">
|
<div className="space-y-2 py-3">
|
||||||
|
|
|
||||||
|
|
@ -509,7 +509,7 @@ export default function FormTeks() {
|
||||||
setIsStartUpload(false);
|
setIsStartUpload(false);
|
||||||
// hideProgress();
|
// hideProgress();
|
||||||
Cookies.remove("idCreate");
|
Cookies.remove("idCreate");
|
||||||
successSubmit("/in/contributor/content/image/");
|
successSubmit("/in/contributor/content/teks");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ export default function FormTeksUpdate() {
|
||||||
confirmButtonColor: "#3085d6",
|
confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
confirmButtonText: "OK",
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
router.push("/en/contributor/content/image");
|
router.push("/en/contributor/content/teks");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -251,7 +251,9 @@ export default function FormTeksUpdate() {
|
||||||
<div className="flex lg:flex-row gap-10">
|
<div className="flex lg:flex-row gap-10">
|
||||||
<Card className="w-full lg:w-8/12">
|
<Card className="w-full lg:w-8/12">
|
||||||
<div className="px-6 py-6">
|
<div className="px-6 py-6">
|
||||||
<p className="text-lg font-semibold mb-3">Form Konten Foto</p>
|
<p className="text-lg font-semibold mb-3">
|
||||||
|
Form Update Konten Teks
|
||||||
|
</p>
|
||||||
<div className="gap-5 mb-5">
|
<div className="gap-5 mb-5">
|
||||||
{/* Input Title */}
|
{/* Input Title */}
|
||||||
<div className="space-y-2 py-3">
|
<div className="space-y-2 py-3">
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ export default function FormVideoDetail() {
|
||||||
confirmButtonColor: "#3085d6",
|
confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
confirmButtonText: "OK",
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
router.push("/in/contributor/content/image");
|
router.push("/in/contributor/content/video");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -347,7 +347,9 @@ export default function FormVideoDetail() {
|
||||||
<div className="flex lg:flex-row gap-10">
|
<div className="flex lg:flex-row gap-10">
|
||||||
<Card className="w-full lg:w-8/12">
|
<Card className="w-full lg:w-8/12">
|
||||||
<div className="px-6 py-6">
|
<div className="px-6 py-6">
|
||||||
<p className="text-lg font-semibold mb-3">Form Konten Foto</p>
|
<p className="text-lg font-semibold mb-3">
|
||||||
|
Form Detail Konten Video
|
||||||
|
</p>
|
||||||
<div className="gap-5 mb-5">
|
<div className="gap-5 mb-5">
|
||||||
{/* Input Title */}
|
{/* Input Title */}
|
||||||
<div className="space-y-2 py-3">
|
<div className="space-y-2 py-3">
|
||||||
|
|
|
||||||
|
|
@ -522,7 +522,7 @@ export default function FormVideo() {
|
||||||
setIsStartUpload(false);
|
setIsStartUpload(false);
|
||||||
// hideProgress();
|
// hideProgress();
|
||||||
Cookies.remove("idCreate");
|
Cookies.remove("idCreate");
|
||||||
successSubmit("/in/contributor/content/image/");
|
successSubmit("/in/contributor/content/video");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,7 @@ export default function FormVideoUpdate() {
|
||||||
confirmButtonColor: "#3085d6",
|
confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
confirmButtonText: "OK",
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
router.push("/en/contributor/content/image");
|
router.push("/en/contributor/content/video");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -268,7 +268,9 @@ export default function FormVideoUpdate() {
|
||||||
<div className="flex lg:flex-row gap-10">
|
<div className="flex lg:flex-row gap-10">
|
||||||
<Card className="w-full lg:w-8/12">
|
<Card className="w-full lg:w-8/12">
|
||||||
<div className="px-6 py-6">
|
<div className="px-6 py-6">
|
||||||
<p className="text-lg font-semibold mb-3">Form Konten Foto</p>
|
<p className="text-lg font-semibold mb-3">
|
||||||
|
Form Update Konten Video
|
||||||
|
</p>
|
||||||
<div className="gap-5 mb-5">
|
<div className="gap-5 mb-5">
|
||||||
{/* Input Title */}
|
{/* Input Title */}
|
||||||
<div className="space-y-2 py-3">
|
<div className="space-y-2 py-3">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
"use client";
|
||||||
|
import { Fragment, useState } from "react";
|
||||||
|
import { Icon } from "@iconify/react";
|
||||||
|
import { Accept, useDropzone } from "react-dropzone";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { CloudUpload } from "lucide-react";
|
||||||
|
|
||||||
|
interface FileWithPreview extends File {
|
||||||
|
preview: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FileUploaderProps {
|
||||||
|
onDrop: (files: FileWithPreview[]) => void;
|
||||||
|
accept: Accept;
|
||||||
|
maxSize: number;
|
||||||
|
label: string;
|
||||||
|
className?: string;
|
||||||
|
isMultiple?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FileUploader = ({ onDrop, accept, maxSize, label, className = "", isMultiple = true }: FileUploaderProps) => {
|
||||||
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
|
||||||
|
const { getRootProps, getInputProps } = useDropzone({
|
||||||
|
accept,
|
||||||
|
maxSize: maxSize * 1024 * 1024,
|
||||||
|
onDrop: (acceptedFiles) => {
|
||||||
|
const mappedFiles = acceptedFiles.map((file) => Object.assign(file));
|
||||||
|
setFiles((prevFiles) => [...prevFiles, ...mappedFiles]);
|
||||||
|
onDrop(mappedFiles);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const renderFilePreview = (file: FileWithPreview) => {
|
||||||
|
if (file.type.startsWith("image")) {
|
||||||
|
return (
|
||||||
|
<Image
|
||||||
|
width={48}
|
||||||
|
height={48}
|
||||||
|
alt={file.name}
|
||||||
|
src={URL.createObjectURL(file)}
|
||||||
|
className=" rounded border p-0.5"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return <Icon icon="tabler:file-description" />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveFile = (file: FileWithPreview) => {
|
||||||
|
const uploadedFiles = files;
|
||||||
|
const filtered = uploadedFiles.filter((i) => i.name !== file.name);
|
||||||
|
setFiles([...filtered]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveAllFiles = () => {
|
||||||
|
setFiles([]);
|
||||||
|
onDrop([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fileList = files.map((file) => (
|
||||||
|
<div
|
||||||
|
key={file.name}
|
||||||
|
className=" flex justify-between border px-3.5 py-3 my-6 rounded-md"
|
||||||
|
>
|
||||||
|
<div className="flex gap-3 items-center">
|
||||||
|
<div className="file-preview">{renderFilePreview(file)}</div>
|
||||||
|
<div>
|
||||||
|
<div className=" text-sm text-card-foreground">{file.name}</div>
|
||||||
|
<div className=" text-xs font-light text-muted-foreground">
|
||||||
|
{Math.round(file.size / 100) / 10 > 1000 ? (
|
||||||
|
<>{(Math.round(file.size / 100) / 10000).toFixed(1)}</>
|
||||||
|
) : (
|
||||||
|
<>{(Math.round(file.size / 100) / 10).toFixed(1)}</>
|
||||||
|
)}
|
||||||
|
{" kb"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
color="destructive"
|
||||||
|
variant="outline"
|
||||||
|
className=" border-none rounded-full"
|
||||||
|
onClick={() => handleRemoveFile(file)}
|
||||||
|
>
|
||||||
|
<Icon icon="tabler:x" className=" h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<div {...getRootProps({ className: "dropzone" })} className={className}>
|
||||||
|
<input {...getInputProps()} />
|
||||||
|
<div className=" w-full text-center border-dashed border border-default-200 dark:border-default-300 rounded-md py-[52px] flex items-center flex-col">
|
||||||
|
<CloudUpload className="text-default-300 w-10 h-10" />
|
||||||
|
<h4 className=" text-2xl font-medium mb-1 mt-3 text-card-foreground/80">
|
||||||
|
{/* Drop files here or click to upload. */}
|
||||||
|
Tarik file disini atau klik untuk upload.
|
||||||
|
</h4>
|
||||||
|
<div className=" text-xs text-muted-foreground">
|
||||||
|
( {label}
|
||||||
|
Ukuran maksimal {maxSize} MB.)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{files.length ? (
|
||||||
|
<Fragment>
|
||||||
|
<div>{fileList}</div>
|
||||||
|
<div className=" flex justify-between gap-2">
|
||||||
|
<Button
|
||||||
|
color="destructive"
|
||||||
|
onClick={handleRemoveAllFiles}
|
||||||
|
>
|
||||||
|
Remove All
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Fragment>
|
||||||
|
) : null}
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default FileUploader;
|
||||||
|
|
@ -34,6 +34,9 @@ import {
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { ChevronDown, ChevronUp } from "lucide-react";
|
import { ChevronDown, ChevronUp } from "lucide-react";
|
||||||
import { AudioRecorder } from "react-audio-voice-recorder";
|
import { AudioRecorder } from "react-audio-voice-recorder";
|
||||||
|
import FileUploader from "@/components/form/shared/file-uploader";
|
||||||
|
import { Upload } from "tus-js-client";
|
||||||
|
import { error } from "@/config/swal";
|
||||||
|
|
||||||
const taskSchema = z.object({
|
const taskSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -42,6 +45,10 @@ const taskSchema = z.object({
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface FileWithPreview extends File {
|
||||||
|
preview: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type taskDetail = {
|
export type taskDetail = {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -96,6 +103,15 @@ export default function FormTask() {
|
||||||
const [isRecording, setIsRecording] = useState(false);
|
const [isRecording, setIsRecording] = useState(false);
|
||||||
const [timer, setTimer] = useState<number>(120);
|
const [timer, setTimer] = useState<number>(120);
|
||||||
|
|
||||||
|
const [imageFiles, setImageFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [videoFiles, setVideoFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [textFiles, setTextFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [audioFiles, setAudioFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [isImageUploadFinish, setIsImageUploadFinish] = useState(false);
|
||||||
|
const [isVideoUploadFinish, setIsVideoUploadFinish] = useState(false);
|
||||||
|
const [isTextUploadFinish, setIsTextUploadFinish] = useState(false);
|
||||||
|
const [isAudioUploadFinish, setIsAudioUploadFinish] = useState(false);
|
||||||
|
|
||||||
const [platformTypeVisible, setPlatformTypeVisible] = useState(false);
|
const [platformTypeVisible, setPlatformTypeVisible] = useState(false);
|
||||||
const [unitSelection, setUnitSelection] = useState({
|
const [unitSelection, setUnitSelection] = useState({
|
||||||
allUnit: false,
|
allUnit: false,
|
||||||
|
|
@ -222,15 +238,69 @@ export default function FormTask() {
|
||||||
console.log("Form Data Submitted:", requestData);
|
console.log("Form Data Submitted:", requestData);
|
||||||
console.log("response", response);
|
console.log("response", response);
|
||||||
|
|
||||||
MySwal.fire({
|
const id = response?.data?.data.id;
|
||||||
title: "Sukses",
|
|
||||||
text: "Data berhasil disimpan.",
|
if (imageFiles?.length == 0) {
|
||||||
icon: "success",
|
setIsImageUploadFinish(true);
|
||||||
confirmButtonColor: "#3085d6",
|
}
|
||||||
confirmButtonText: "OK",
|
imageFiles?.map(async (item: any, index: number) => {
|
||||||
}).then(() => {
|
await uploadResumableFile(
|
||||||
router.push("/en/contributor/task");
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"1",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (videoFiles?.length == 0) {
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
}
|
||||||
|
videoFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"2",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (textFiles?.length == 0) {
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
}
|
||||||
|
textFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"3",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (audioFiles?.length == 0) {
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
audioFiles?.map(async (item: any, index: number) => {
|
||||||
|
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) => {
|
||||||
|
|
@ -301,6 +371,90 @@ export default function FormTask() {
|
||||||
audioElements.forEach((audio) => audio.remove());
|
audioElements.forEach((audio) => audio.remove());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function uploadResumableFile(
|
||||||
|
idx: number,
|
||||||
|
id: string,
|
||||||
|
file: any,
|
||||||
|
fileTypeId: string,
|
||||||
|
duration: string
|
||||||
|
) {
|
||||||
|
console.log(idx, id, file, fileTypeId, duration);
|
||||||
|
|
||||||
|
// const placements = getPlacement(file.placements);
|
||||||
|
// console.log("Placementttt: : ", placements);
|
||||||
|
|
||||||
|
const upload = new Upload(file, {
|
||||||
|
endpoint: `${process.env.NEXT_PUBLIC_API}/assignment/file/upload`,
|
||||||
|
retryDelays: [0, 3000, 6000, 12_000, 24_000],
|
||||||
|
chunkSize: 20_000,
|
||||||
|
metadata: {
|
||||||
|
assignmentid: id,
|
||||||
|
filename: file.name,
|
||||||
|
filetype: file.type,
|
||||||
|
fileTypeId: fileTypeId,
|
||||||
|
duration: "",
|
||||||
|
isWatermark: "true", // hardcode
|
||||||
|
},
|
||||||
|
onError: async (e: any) => {
|
||||||
|
console.log("Error upload :", e);
|
||||||
|
error(e);
|
||||||
|
},
|
||||||
|
onChunkComplete: (
|
||||||
|
chunkSize: any,
|
||||||
|
bytesAccepted: any,
|
||||||
|
bytesTotal: any
|
||||||
|
) => {
|
||||||
|
const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100);
|
||||||
|
// progressInfo[idx].percentage = uploadPersen;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// console.log(counterUpdateProgress);
|
||||||
|
// setProgressList(progressInfo);
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
},
|
||||||
|
onSuccess: async () => {
|
||||||
|
// uploadPersen = 100;
|
||||||
|
// progressInfo[idx].percentage = 100;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
successTodo();
|
||||||
|
if (fileTypeId == '1'){
|
||||||
|
setIsImageUploadFinish(true);
|
||||||
|
} else if (fileTypeId == '2'){
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
} if (fileTypeId == '3'){
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
} if (fileTypeId == '4'){
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
upload.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
successTodo();
|
||||||
|
}, [isImageUploadFinish, isVideoUploadFinish, isAudioUploadFinish, isTextUploadFinish])
|
||||||
|
|
||||||
|
function successTodo() {
|
||||||
|
if (isImageUploadFinish && isVideoUploadFinish && isAudioUploadFinish && isTextUploadFinish) {
|
||||||
|
successSubmit("/in/contributor/agenda-setting");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const successSubmit = (redirect: string) => {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Sukses",
|
||||||
|
text: "Data berhasil disimpan.",
|
||||||
|
icon: "success",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
}).then(() => {
|
||||||
|
router.push(redirect);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<div className="px-6 py-6">
|
<div className="px-6 py-6">
|
||||||
|
|
@ -550,34 +704,41 @@ export default function FormTask() {
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5 mt-5">
|
||||||
<Label htmlFor="attachments">Lampiran</Label>
|
<Label htmlFor="attachments">Lampiran</Label>
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div>
|
<div>
|
||||||
<Label>Video</Label>
|
<Label>Video</Label>
|
||||||
<Input
|
<FileUploader
|
||||||
type="file"
|
accept={{
|
||||||
accept="video/*"
|
"mp4/*": [],
|
||||||
multiple
|
"mov/*": [],
|
||||||
// {...register("attachments.video")}
|
}}
|
||||||
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .mp4 atau .mov."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Foto</Label>
|
<Label>Foto</Label>
|
||||||
<Input
|
<FileUploader
|
||||||
type="file"
|
accept={{
|
||||||
accept="image/*"
|
"image/*": [],
|
||||||
multiple
|
}}
|
||||||
// {...register("attachments.photo")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .png, .jpg, atau .jpeg."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Teks</Label>
|
<Label>Teks</Label>
|
||||||
<Input
|
<FileUploader
|
||||||
type="file"
|
accept={{
|
||||||
accept="text/plain"
|
"pdf/*": [],
|
||||||
multiple
|
}}
|
||||||
// {...register("attachments.text")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .pdf."
|
||||||
|
onDrop={(files) => setTextFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -591,6 +752,16 @@ export default function FormTask() {
|
||||||
downloadOnSavePress={true}
|
downloadOnSavePress={true}
|
||||||
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">
|
||||||
|
|
@ -605,7 +776,9 @@ export default function FormTask() {
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{isRecording && <p>Recording... {timer} seconds remaining</p>}{" "}
|
{isRecording && (
|
||||||
|
<p>Recording... {timer} seconds remaining</p>
|
||||||
|
)}{" "}
|
||||||
{/* Display remaining time */}
|
{/* Display remaining time */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,6 +3,7 @@ import axiosInterceptorInstance from "./axios-interceptor-instance";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
export async function httpGetInterceptor(pathUrl: any) {
|
export async function httpGetInterceptor(pathUrl: any) {
|
||||||
|
const pathname = window.location.pathname;
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
.get(pathUrl)
|
.get(pathUrl)
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
|
|
@ -17,7 +18,9 @@ export async function httpGetInterceptor(pathUrl: any) {
|
||||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
Object.keys(Cookies.get()).forEach((cookieName) => {
|
||||||
Cookies.remove(cookieName);
|
Cookies.remove(cookieName);
|
||||||
});
|
});
|
||||||
// window.location.href = "/";
|
if (pathname?.includes("/contributor/") || pathname?.includes("/admin/") || pathname?.includes("/supervisor/")) {
|
||||||
|
window.location.href = "/";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
|
|
||||||
|
|
@ -28,3 +28,33 @@ export async function postCategory(data: any) {
|
||||||
const url = "media/categories";
|
const url = "media/categories";
|
||||||
return httpPostInterceptor(url, data);
|
return httpPostInterceptor(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getPrivacy(id: string) {
|
||||||
|
const url = `general/privacy-policy/${id}`;
|
||||||
|
return httpGetInterceptor(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function savePrivacy(data: any) {
|
||||||
|
const url = "general/privacy-policy/save";
|
||||||
|
return httpPostInterceptor(url, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listBanner() {
|
||||||
|
const url = "media/banner";
|
||||||
|
return httpGetInterceptor(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listStaticBanner() {
|
||||||
|
const url = "media/static-banner";
|
||||||
|
return httpGetInterceptor(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setStaticBanner(id: number) {
|
||||||
|
const url = `media/static-banner?id=${id}`;
|
||||||
|
return httpPostInterceptor(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setBanner(id: number, status: boolean) {
|
||||||
|
const url = `media/banner?id=${id}&status=${status}`;
|
||||||
|
return httpPostInterceptor(url);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
case `uname` in
|
case `uname` in
|
||||||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -x "$basedir/node" ]; then
|
if [ -x "$basedir/node" ]; then
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
case `uname` in
|
case `uname` in
|
||||||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -x "$basedir/node" ]; then
|
if [ -x "$basedir/node" ]; then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue