feat: add translate button in update content
This commit is contained in:
parent
20f7b19471
commit
c661f8bbd2
|
|
@ -18,6 +18,7 @@ import { deleteMedia } from "@/service/content/content";
|
||||||
import { error } from "@/lib/swal";
|
import { error } from "@/lib/swal";
|
||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
import { useRouter } from "@/i18n/routing";
|
||||||
|
|
||||||
const useTableColumns = () => {
|
const useTableColumns = () => {
|
||||||
const t = useTranslations("Table");
|
const t = useTranslations("Table");
|
||||||
|
|
@ -181,14 +182,11 @@ const useTableColumns = () => {
|
||||||
header: t("action", { defaultValue: "Action" }),
|
header: t("action", { defaultValue: "Action" }),
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
|
const router = useRouter();
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
async function doDelete(id: any) {
|
async function doDelete(id: any) {
|
||||||
// loading();
|
const data = { id };
|
||||||
const data = {
|
|
||||||
id,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await deleteMedia(data);
|
const response = await deleteMedia(data);
|
||||||
|
|
||||||
if (response?.error) {
|
if (response?.error) {
|
||||||
|
|
@ -230,16 +228,21 @@ const useTableColumns = () => {
|
||||||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||||
const userId = getCookiesDecrypt("uie");
|
const userId = getCookiesDecrypt("uie");
|
||||||
const userLevelId = getCookiesDecrypt("ulie");
|
const userLevelId = getCookiesDecrypt("ulie");
|
||||||
const roleId = getCookiesDecrypt("urie");
|
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (userLevelId !== undefined && roleId !== undefined) {
|
if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
setIsMabesApprover(
|
setIsMabesApprover(
|
||||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [userLevelId, roleId]);
|
}, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
const canEdit =
|
||||||
|
Number(row.original.uploadedById) === Number(userId) ||
|
||||||
|
isMabesApprover ||
|
||||||
|
roleId === 14;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|
@ -260,16 +263,8 @@ const useTableColumns = () => {
|
||||||
View
|
View
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
{/* <Link
|
|
||||||
href={`/contributor/content/audio/update/${row.original.id}`}
|
{canEdit && (
|
||||||
>
|
|
||||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
|
||||||
<SquarePen className="w-4 h-4 me-1.5" />
|
|
||||||
Edit
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</Link> */}
|
|
||||||
{(Number(row.original.uploadedById) === Number(userId) ||
|
|
||||||
isMabesApprover) && (
|
|
||||||
<Link
|
<Link
|
||||||
href={`/contributor/content/audio/update/${row.original.id}`}
|
href={`/contributor/content/audio/update/${row.original.id}`}
|
||||||
>
|
>
|
||||||
|
|
@ -279,6 +274,7 @@ const useTableColumns = () => {
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
|
@ -286,15 +282,6 @@ const useTableColumns = () => {
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
<Trash2 className="w-4 h-4 me-1.5" />
|
||||||
Delete
|
Delete
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
{/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
|
||||||
>
|
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
|
||||||
Hapus
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)} */}
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -186,11 +186,7 @@ const useTableColumns = () => {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
async function doDelete(id: any) {
|
async function doDelete(id: any) {
|
||||||
// loading();
|
const data = { id };
|
||||||
const data = {
|
|
||||||
id,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await deleteMedia(data);
|
const response = await deleteMedia(data);
|
||||||
|
|
||||||
if (response?.error) {
|
if (response?.error) {
|
||||||
|
|
@ -232,16 +228,21 @@ const useTableColumns = () => {
|
||||||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||||
const userId = getCookiesDecrypt("uie");
|
const userId = getCookiesDecrypt("uie");
|
||||||
const userLevelId = getCookiesDecrypt("ulie");
|
const userLevelId = getCookiesDecrypt("ulie");
|
||||||
const roleId = getCookiesDecrypt("urie");
|
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (userLevelId !== undefined && roleId !== undefined) {
|
if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
setIsMabesApprover(
|
setIsMabesApprover(
|
||||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [userLevelId, roleId]);
|
}, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
const canEdit =
|
||||||
|
Number(row.original.uploadedById) === Number(userId) ||
|
||||||
|
isMabesApprover ||
|
||||||
|
roleId === 14;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|
@ -262,16 +263,8 @@ const useTableColumns = () => {
|
||||||
View
|
View
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
{/* <Link
|
|
||||||
href={`/contributor/content/image/update/${row.original.id}`}
|
{canEdit && (
|
||||||
>
|
|
||||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
|
||||||
<SquarePen className="w-4 h-4 me-1.5" />
|
|
||||||
Edit
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</Link> */}
|
|
||||||
{(Number(row.original.uploadedById) === Number(userId) ||
|
|
||||||
isMabesApprover) && (
|
|
||||||
<Link
|
<Link
|
||||||
href={`/contributor/content/image/update/${row.original.id}`}
|
href={`/contributor/content/image/update/${row.original.id}`}
|
||||||
>
|
>
|
||||||
|
|
@ -281,6 +274,7 @@ const useTableColumns = () => {
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
|
@ -288,20 +282,138 @@ const useTableColumns = () => {
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
<Trash2 className="w-4 h-4 me-1.5" />
|
||||||
Delete
|
Delete
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
{/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
|
||||||
>
|
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
|
||||||
Hapus
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)} */}
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// {
|
||||||
|
// id: "actions",
|
||||||
|
// accessorKey: "action",
|
||||||
|
// header: t("action", { defaultValue: "Action" }),
|
||||||
|
// enableHiding: false,
|
||||||
|
// cell: ({ row }) => {
|
||||||
|
// const router = useRouter();
|
||||||
|
// const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
|
// async function doDelete(id: any) {
|
||||||
|
// // loading();
|
||||||
|
// const data = {
|
||||||
|
// id,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const response = await deleteMedia(data);
|
||||||
|
|
||||||
|
// if (response?.error) {
|
||||||
|
// error(response.message);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// success();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function success() {
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Sukses",
|
||||||
|
// icon: "success",
|
||||||
|
// confirmButtonColor: "#3085d6",
|
||||||
|
// confirmButtonText: "OK",
|
||||||
|
// }).then((result) => {
|
||||||
|
// if (result.isConfirmed) {
|
||||||
|
// window.location.reload();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const handleDeleteMedia = (id: any) => {
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Hapus Data",
|
||||||
|
// text: "",
|
||||||
|
// icon: "warning",
|
||||||
|
// showCancelButton: true,
|
||||||
|
// cancelButtonColor: "#3085d6",
|
||||||
|
// confirmButtonColor: "#d33",
|
||||||
|
// confirmButtonText: "Hapus",
|
||||||
|
// }).then((result) => {
|
||||||
|
// if (result.isConfirmed) {
|
||||||
|
// doDelete(id);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||||
|
// const userId = getCookiesDecrypt("uie");
|
||||||
|
// const userLevelId = getCookiesDecrypt("ulie");
|
||||||
|
// const roleId = getCookiesDecrypt("urie");
|
||||||
|
|
||||||
|
// React.useEffect(() => {
|
||||||
|
// if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
|
// setIsMabesApprover(
|
||||||
|
// Number(userLevelId) == 216 && Number(roleId) == 3
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <DropdownMenu>
|
||||||
|
// <DropdownMenuTrigger asChild>
|
||||||
|
// <Button
|
||||||
|
// size="icon"
|
||||||
|
// className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
||||||
|
// >
|
||||||
|
// <span className="sr-only">Open menu</span>
|
||||||
|
// <MoreVertical className="h-4 w-4 text-default-800" />
|
||||||
|
// </Button>
|
||||||
|
// </DropdownMenuTrigger>
|
||||||
|
// <DropdownMenuContent className="p-0" align="end">
|
||||||
|
// <Link
|
||||||
|
// href={`/contributor/content/image/detail/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <Eye className="w-4 h-4 me-1.5" />
|
||||||
|
// View
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link>
|
||||||
|
// {/* <Link
|
||||||
|
// href={`/contributor/content/image/update/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <SquarePen className="w-4 h-4 me-1.5" />
|
||||||
|
// Edit
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link> */}
|
||||||
|
// {(Number(row.original.uploadedById) === Number(userId) ||
|
||||||
|
// isMabesApprover) && (
|
||||||
|
// <Link
|
||||||
|
// href={`/contributor/content/image/update/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <SquarePen className="w-4 h-4 me-1.5" />
|
||||||
|
// Edit
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link>
|
||||||
|
// )}
|
||||||
|
// <DropdownMenuItem
|
||||||
|
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
|
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
// >
|
||||||
|
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||||
|
// Delete
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// {/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
||||||
|
// <DropdownMenuItem
|
||||||
|
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
|
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
// >
|
||||||
|
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||||
|
// Hapus
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// )} */}
|
||||||
|
// </DropdownMenuContent>
|
||||||
|
// </DropdownMenu>
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// },
|
||||||
];
|
];
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import { deleteMedia } from "@/service/content/content";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
import { useRouter } from "@/i18n/routing";
|
||||||
|
|
||||||
const useTableColumns = () => {
|
const useTableColumns = () => {
|
||||||
const t = useTranslations("Table");
|
const t = useTranslations("Table");
|
||||||
|
|
@ -176,20 +177,18 @@ const useTableColumns = () => {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
accessorKey: "action",
|
accessorKey: "action",
|
||||||
header: t("action", { defaultValue: "Action" }),
|
header: t("action", { defaultValue: "Action" }),
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
|
const router = useRouter();
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
async function doDelete(id: any) {
|
async function doDelete(id: any) {
|
||||||
// loading();
|
const data = { id };
|
||||||
const data = {
|
|
||||||
id,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await deleteMedia(data);
|
const response = await deleteMedia(data);
|
||||||
|
|
||||||
if (response?.error) {
|
if (response?.error) {
|
||||||
|
|
@ -231,16 +230,21 @@ const useTableColumns = () => {
|
||||||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||||
const userId = getCookiesDecrypt("uie");
|
const userId = getCookiesDecrypt("uie");
|
||||||
const userLevelId = getCookiesDecrypt("ulie");
|
const userLevelId = getCookiesDecrypt("ulie");
|
||||||
const roleId = getCookiesDecrypt("urie");
|
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (userLevelId !== undefined && roleId !== undefined) {
|
if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
setIsMabesApprover(
|
setIsMabesApprover(
|
||||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [userLevelId, roleId]);
|
}, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
const canEdit =
|
||||||
|
Number(row.original.uploadedById) === Number(userId) ||
|
||||||
|
isMabesApprover ||
|
||||||
|
roleId === 14;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|
@ -261,8 +265,8 @@ const useTableColumns = () => {
|
||||||
View
|
View
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
{(Number(row.original.uploadedById) === Number(userId) ||
|
|
||||||
isMabesApprover) && (
|
{canEdit && (
|
||||||
<Link
|
<Link
|
||||||
href={`/contributor/content/teks/update/${row.original.id}`}
|
href={`/contributor/content/teks/update/${row.original.id}`}
|
||||||
>
|
>
|
||||||
|
|
@ -272,14 +276,7 @@ const useTableColumns = () => {
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
{/* <Link
|
|
||||||
href={`/contributor/content/teks/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
|
<DropdownMenuItem
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
|
@ -287,20 +284,136 @@ const useTableColumns = () => {
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
<Trash2 className="w-4 h-4 me-1.5" />
|
||||||
Delete
|
Delete
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
{/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
|
||||||
>
|
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
|
||||||
Hapus
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)} */}
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// id: "actions",
|
||||||
|
// accessorKey: "action",
|
||||||
|
// header: t("action", { defaultValue: "Action" }),
|
||||||
|
// enableHiding: false,
|
||||||
|
// cell: ({ row }) => {
|
||||||
|
// const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
|
// async function doDelete(id: any) {
|
||||||
|
// // loading();
|
||||||
|
// const data = {
|
||||||
|
// id,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const response = await deleteMedia(data);
|
||||||
|
|
||||||
|
// if (response?.error) {
|
||||||
|
// error(response.message);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// success();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function success() {
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Sukses",
|
||||||
|
// icon: "success",
|
||||||
|
// confirmButtonColor: "#3085d6",
|
||||||
|
// confirmButtonText: "OK",
|
||||||
|
// }).then((result) => {
|
||||||
|
// if (result.isConfirmed) {
|
||||||
|
// window.location.reload();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const handleDeleteMedia = (id: any) => {
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Hapus Data",
|
||||||
|
// text: "",
|
||||||
|
// icon: "warning",
|
||||||
|
// showCancelButton: true,
|
||||||
|
// cancelButtonColor: "#3085d6",
|
||||||
|
// confirmButtonColor: "#d33",
|
||||||
|
// confirmButtonText: "Hapus",
|
||||||
|
// }).then((result) => {
|
||||||
|
// if (result.isConfirmed) {
|
||||||
|
// doDelete(id);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||||
|
// const userId = getCookiesDecrypt("uie");
|
||||||
|
// const userLevelId = getCookiesDecrypt("ulie");
|
||||||
|
// const roleId = getCookiesDecrypt("urie");
|
||||||
|
|
||||||
|
// React.useEffect(() => {
|
||||||
|
// if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
|
// setIsMabesApprover(
|
||||||
|
// Number(userLevelId) == 216 && Number(roleId) == 3
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <DropdownMenu>
|
||||||
|
// <DropdownMenuTrigger asChild>
|
||||||
|
// <Button
|
||||||
|
// size="icon"
|
||||||
|
// className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
||||||
|
// >
|
||||||
|
// <span className="sr-only">Open menu</span>
|
||||||
|
// <MoreVertical className="h-4 w-4 text-default-800" />
|
||||||
|
// </Button>
|
||||||
|
// </DropdownMenuTrigger>
|
||||||
|
// <DropdownMenuContent className="p-0" align="end">
|
||||||
|
// <Link
|
||||||
|
// href={`/contributor/content/teks/detail/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <Eye className="w-4 h-4 me-1.5" />
|
||||||
|
// View
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link>
|
||||||
|
// {(Number(row.original.uploadedById) === Number(userId) ||
|
||||||
|
// isMabesApprover) && (
|
||||||
|
// <Link
|
||||||
|
// href={`/contributor/content/teks/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>
|
||||||
|
// )}
|
||||||
|
// {/* <Link
|
||||||
|
// href={`/contributor/content/teks/update/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <SquarePen className="w-4 h-4 me-1.5" />
|
||||||
|
// Edit
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link> */}
|
||||||
|
// <DropdownMenuItem
|
||||||
|
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
|
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
// >
|
||||||
|
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||||
|
// Delete
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// {/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
||||||
|
// <DropdownMenuItem
|
||||||
|
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
|
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
// >
|
||||||
|
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||||
|
// Hapus
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// )} */}
|
||||||
|
// </DropdownMenuContent>
|
||||||
|
// </DropdownMenu>
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// },
|
||||||
];
|
];
|
||||||
return columns;
|
return columns;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import Swal from "sweetalert2";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
import { error } from "@/lib/swal";
|
import { error } from "@/lib/swal";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
import { useRouter } from "@/i18n/routing";
|
||||||
|
|
||||||
const useTableColumns = () => {
|
const useTableColumns = () => {
|
||||||
const t = useTranslations("Table");
|
const t = useTranslations("Table");
|
||||||
|
|
@ -176,20 +177,18 @@ const useTableColumns = () => {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
accessorKey: "action",
|
accessorKey: "action",
|
||||||
header: t("action", { defaultValue: "Action" }),
|
header: t("action", { defaultValue: "Action" }),
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
|
const router = useRouter();
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
async function doDelete(id: any) {
|
async function doDelete(id: any) {
|
||||||
// loading();
|
const data = { id };
|
||||||
const data = {
|
|
||||||
id,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await deleteMedia(data);
|
const response = await deleteMedia(data);
|
||||||
|
|
||||||
if (response?.error) {
|
if (response?.error) {
|
||||||
|
|
@ -231,16 +230,21 @@ const useTableColumns = () => {
|
||||||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||||
const userId = getCookiesDecrypt("uie");
|
const userId = getCookiesDecrypt("uie");
|
||||||
const userLevelId = getCookiesDecrypt("ulie");
|
const userLevelId = getCookiesDecrypt("ulie");
|
||||||
const roleId = getCookiesDecrypt("urie");
|
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (userLevelId !== undefined && roleId !== undefined) {
|
if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
setIsMabesApprover(
|
setIsMabesApprover(
|
||||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [userLevelId, roleId]);
|
}, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
const canEdit =
|
||||||
|
Number(row.original.uploadedById) === Number(userId) ||
|
||||||
|
isMabesApprover ||
|
||||||
|
roleId === 14;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|
@ -261,16 +265,8 @@ const useTableColumns = () => {
|
||||||
View
|
View
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
{/* <Link
|
|
||||||
href={`/contributor/content/video/update/${row.original.id}`}
|
{canEdit && (
|
||||||
>
|
|
||||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
|
||||||
<SquarePen className="w-4 h-4 me-1.5" />
|
|
||||||
Edit
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</Link> */}
|
|
||||||
{(Number(row.original.uploadedById) === Number(userId) ||
|
|
||||||
isMabesApprover) && (
|
|
||||||
<Link
|
<Link
|
||||||
href={`/contributor/content/video/update/${row.original.id}`}
|
href={`/contributor/content/video/update/${row.original.id}`}
|
||||||
>
|
>
|
||||||
|
|
@ -280,6 +276,7 @@ const useTableColumns = () => {
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
|
@ -287,20 +284,136 @@ const useTableColumns = () => {
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
<Trash2 className="w-4 h-4 me-1.5" />
|
||||||
Delete
|
Delete
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
{/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
|
||||||
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
|
||||||
>
|
|
||||||
<Trash2 className="w-4 h-4 me-1.5" />
|
|
||||||
Hapus
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)} */}
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// id: "actions",
|
||||||
|
// accessorKey: "action",
|
||||||
|
// header: t("action", { defaultValue: "Action" }),
|
||||||
|
// enableHiding: false,
|
||||||
|
// cell: ({ row }) => {
|
||||||
|
// const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
|
// async function doDelete(id: any) {
|
||||||
|
// // loading();
|
||||||
|
// const data = {
|
||||||
|
// id,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const response = await deleteMedia(data);
|
||||||
|
|
||||||
|
// if (response?.error) {
|
||||||
|
// error(response.message);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// success();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function success() {
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Sukses",
|
||||||
|
// icon: "success",
|
||||||
|
// confirmButtonColor: "#3085d6",
|
||||||
|
// confirmButtonText: "OK",
|
||||||
|
// }).then((result) => {
|
||||||
|
// if (result.isConfirmed) {
|
||||||
|
// window.location.reload();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const handleDeleteMedia = (id: any) => {
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Hapus Data",
|
||||||
|
// text: "",
|
||||||
|
// icon: "warning",
|
||||||
|
// showCancelButton: true,
|
||||||
|
// cancelButtonColor: "#3085d6",
|
||||||
|
// confirmButtonColor: "#d33",
|
||||||
|
// confirmButtonText: "Hapus",
|
||||||
|
// }).then((result) => {
|
||||||
|
// if (result.isConfirmed) {
|
||||||
|
// doDelete(id);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||||
|
// const userId = getCookiesDecrypt("uie");
|
||||||
|
// const userLevelId = getCookiesDecrypt("ulie");
|
||||||
|
// const roleId = getCookiesDecrypt("urie");
|
||||||
|
|
||||||
|
// React.useEffect(() => {
|
||||||
|
// if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
|
// setIsMabesApprover(
|
||||||
|
// Number(userLevelId) == 216 && Number(roleId) == 3
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <DropdownMenu>
|
||||||
|
// <DropdownMenuTrigger asChild>
|
||||||
|
// <Button
|
||||||
|
// size="icon"
|
||||||
|
// className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
||||||
|
// >
|
||||||
|
// <span className="sr-only">Open menu</span>
|
||||||
|
// <MoreVertical className="h-4 w-4 text-default-800" />
|
||||||
|
// </Button>
|
||||||
|
// </DropdownMenuTrigger>
|
||||||
|
// <DropdownMenuContent className="p-0" align="end">
|
||||||
|
// <Link
|
||||||
|
// href={`/contributor/content/video/detail/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <Eye className="w-4 h-4 me-1.5" />
|
||||||
|
// View
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link>
|
||||||
|
// {/* <Link
|
||||||
|
// href={`/contributor/content/video/update/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <SquarePen className="w-4 h-4 me-1.5" />
|
||||||
|
// Edit
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link> */}
|
||||||
|
// {(Number(row.original.uploadedById) === Number(userId) ||
|
||||||
|
// isMabesApprover) && (
|
||||||
|
// <Link
|
||||||
|
// href={`/contributor/content/video/update/${row.original.id}`}
|
||||||
|
// >
|
||||||
|
// <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||||
|
// <SquarePen className="w-4 h-4 me-1.5" />
|
||||||
|
// Edit
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// </Link>
|
||||||
|
// )}
|
||||||
|
// <DropdownMenuItem
|
||||||
|
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
|
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
// >
|
||||||
|
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||||
|
// Delete
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// {/* {(row.original.uploadedById === userId || isMabesApprover) && (
|
||||||
|
// <DropdownMenuItem
|
||||||
|
// onClick={() => handleDeleteMedia(row.original.id)}
|
||||||
|
// className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
||||||
|
// >
|
||||||
|
// <Trash2 className="w-4 h-4 me-1.5" />
|
||||||
|
// Hapus
|
||||||
|
// </DropdownMenuItem>
|
||||||
|
// )} */}
|
||||||
|
// </DropdownMenuContent>
|
||||||
|
// </DropdownMenu>
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// },
|
||||||
];
|
];
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
|
|
|
||||||
|
|
@ -523,15 +523,120 @@ export default function FormAudio() {
|
||||||
}
|
}
|
||||||
}, [articleBody, setValue]);
|
}, [articleBody, setValue]);
|
||||||
|
|
||||||
|
// const save = async (data: AudioSchema) => {
|
||||||
|
// loading();
|
||||||
|
// const finalTags = tags.join(", ");
|
||||||
|
// const finalTitle = isSwitchOn ? title : data.title;
|
||||||
|
// const finalDescription = isSwitchOn
|
||||||
|
// ? data.description
|
||||||
|
// : selectedFileType === "rewrite"
|
||||||
|
// ? data.rewriteDescription
|
||||||
|
// : data.descriptionOri;
|
||||||
|
// if (!finalDescription?.trim()) {
|
||||||
|
// MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let requestData: {
|
||||||
|
// title: string;
|
||||||
|
// description: string;
|
||||||
|
// htmlDescription: string;
|
||||||
|
// fileTypeId: string;
|
||||||
|
// categoryId: any;
|
||||||
|
// subCategoryId: any;
|
||||||
|
// uploadedBy: string;
|
||||||
|
// statusId: string;
|
||||||
|
// publishedFor: string;
|
||||||
|
// creatorName: string;
|
||||||
|
// tags: string;
|
||||||
|
// isYoutube: boolean;
|
||||||
|
// isInternationalMedia: boolean;
|
||||||
|
// attachFromScheduleId?: number;
|
||||||
|
// } = {
|
||||||
|
// ...data,
|
||||||
|
// title: finalTitle,
|
||||||
|
// description: htmlToString(finalDescription),
|
||||||
|
// htmlDescription: finalDescription,
|
||||||
|
// fileTypeId,
|
||||||
|
// categoryId: selectedCategory,
|
||||||
|
// subCategoryId: selectedCategory,
|
||||||
|
// uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
||||||
|
// statusId: "1",
|
||||||
|
// publishedFor: publishedFor.join(","),
|
||||||
|
// creatorName: data.creatorName,
|
||||||
|
// tags: finalTags,
|
||||||
|
// isYoutube: false,
|
||||||
|
// isInternationalMedia: false,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// let id = Cookies.get("idCreate");
|
||||||
|
|
||||||
|
// if (scheduleId !== undefined) {
|
||||||
|
// requestData.attachFromScheduleId = Number(scheduleId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (id == undefined) {
|
||||||
|
// const response = await createMedia(requestData);
|
||||||
|
// console.log("Form Data Submitted:", requestData);
|
||||||
|
|
||||||
|
// if (response?.error) {
|
||||||
|
// MySwal.fire("Error", response?.message, "error");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
||||||
|
// id = response?.data?.data;
|
||||||
|
|
||||||
|
// const formMedia = new FormData();
|
||||||
|
// console.log("Thumbnail : ", files[0]);
|
||||||
|
// formMedia.append("file", files[0]);
|
||||||
|
// const responseThumbnail = await uploadThumbnail(id, formMedia);
|
||||||
|
// if (responseThumbnail?.error == true) {
|
||||||
|
// error(responseThumbnail?.message);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const progressInfoArr = [];
|
||||||
|
// for (const item of files) {
|
||||||
|
// progressInfoArr.push({ percentage: 0, fileName: item.name });
|
||||||
|
// }
|
||||||
|
// progressInfo = progressInfoArr;
|
||||||
|
// setIsStartUpload(true);
|
||||||
|
// setProgressList(progressInfoArr);
|
||||||
|
|
||||||
|
// close();
|
||||||
|
// // showProgress();
|
||||||
|
// files.map(async (item: any, index: number) => {
|
||||||
|
// await uploadResumableFile(index, String(id), item, "0");
|
||||||
|
// });
|
||||||
|
|
||||||
|
// Cookies.remove("idCreate");
|
||||||
|
|
||||||
|
// // MySwal.fire("Sukses", "Data berhasil disimpan.", "success");
|
||||||
|
// };
|
||||||
|
|
||||||
const save = async (data: AudioSchema) => {
|
const save = async (data: AudioSchema) => {
|
||||||
loading();
|
loading();
|
||||||
const finalTags = tags.join(", ");
|
const finalTags = tags.join(", ");
|
||||||
const finalTitle = isSwitchOn ? title : data.title;
|
const finalTitle = isSwitchOn ? title : data.title;
|
||||||
const finalDescription = isSwitchOn
|
|
||||||
|
// pilih description dasar
|
||||||
|
let finalDescription = isSwitchOn
|
||||||
? data.description
|
? data.description
|
||||||
: selectedFileType === "rewrite"
|
: selectedFileType === "rewrite"
|
||||||
? data.rewriteDescription
|
? data.rewriteDescription
|
||||||
: data.descriptionOri;
|
: data.descriptionOri;
|
||||||
|
|
||||||
|
// 👉 tempelkan hasil translate ke field form & pakai sebagai description
|
||||||
|
if (translatedContent) {
|
||||||
|
data.descriptionOri = translatedContent; // update ke form
|
||||||
|
finalDescription = translatedContent; // pakai untuk request
|
||||||
|
console.log(
|
||||||
|
"🌍 Translate dimasukkan ke descriptionOri:",
|
||||||
|
translatedContent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!finalDescription?.trim()) {
|
if (!finalDescription?.trim()) {
|
||||||
MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error");
|
MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error");
|
||||||
return;
|
return;
|
||||||
|
|
@ -555,8 +660,8 @@ export default function FormAudio() {
|
||||||
} = {
|
} = {
|
||||||
...data,
|
...data,
|
||||||
title: finalTitle,
|
title: finalTitle,
|
||||||
description: htmlToString(finalDescription),
|
description: htmlToString(finalDescription), // ✅ plain text versi translate
|
||||||
htmlDescription: finalDescription,
|
htmlDescription: finalDescription, // ✅ html versi translate
|
||||||
fileTypeId,
|
fileTypeId,
|
||||||
categoryId: selectedCategory,
|
categoryId: selectedCategory,
|
||||||
subCategoryId: selectedCategory,
|
subCategoryId: selectedCategory,
|
||||||
|
|
@ -583,6 +688,7 @@ export default function FormAudio() {
|
||||||
MySwal.fire("Error", response?.message, "error");
|
MySwal.fire("Error", response?.message, "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
||||||
id = response?.data?.data;
|
id = response?.data?.data;
|
||||||
|
|
||||||
|
|
@ -596,10 +702,10 @@ export default function FormAudio() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const progressInfoArr = [];
|
const progressInfoArr = files.map((item) => ({
|
||||||
for (const item of files) {
|
percentage: 0,
|
||||||
progressInfoArr.push({ percentage: 0, fileName: item.name });
|
fileName: item.name,
|
||||||
}
|
}));
|
||||||
progressInfo = progressInfoArr;
|
progressInfo = progressInfoArr;
|
||||||
setIsStartUpload(true);
|
setIsStartUpload(true);
|
||||||
setProgressList(progressInfoArr);
|
setProgressList(progressInfoArr);
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,9 @@ import {
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
import { getCookiesDecrypt } from "@/lib/utils";
|
||||||
|
import { close, loading } from "@/config/swal";
|
||||||
|
import { translateText } from "@/service/content/ai";
|
||||||
|
|
||||||
const audioSchema = z.object({
|
const audioSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -135,24 +138,20 @@ const CustomEditor = dynamic(
|
||||||
export default function FormAudioUpdate() {
|
export default function FormAudioUpdate() {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { id } = useParams() as { id: string };
|
const { id } = useParams() as { id: string };
|
||||||
console.log(id);
|
console.log(id);
|
||||||
const editor = useRef(null);
|
const editor = useRef(null);
|
||||||
type AudioSchema = z.infer<typeof audioSchema>;
|
type AudioSchema = z.infer<typeof audioSchema>;
|
||||||
|
|
||||||
let progressInfo: any = [];
|
let progressInfo: any = [];
|
||||||
let counterUpdateProgress = 0;
|
let counterUpdateProgress = 0;
|
||||||
const [progressList, setProgressList] = useState<any>([]);
|
const [progressList, setProgressList] = useState<any>([]);
|
||||||
let uploadPersen = 0;
|
let uploadPersen = 0;
|
||||||
const [isStartUpload, setIsStartUpload] = useState(false);
|
const [isStartUpload, setIsStartUpload] = useState(false);
|
||||||
const [counterProgress, setCounterProgress] = useState(0);
|
const [counterProgress, setCounterProgress] = useState(0);
|
||||||
|
|
||||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||||
const taskId = Cookies.get("taskId");
|
const taskId = Cookies.get("taskId");
|
||||||
const scheduleId = Cookies.get("scheduleId");
|
const scheduleId = Cookies.get("scheduleId");
|
||||||
const scheduleType = Cookies.get("scheduleType");
|
const scheduleType = Cookies.get("scheduleType");
|
||||||
|
|
||||||
const t = useTranslations("Form");
|
const t = useTranslations("Form");
|
||||||
const [categories, setCategories] = useState<Category[]>([]);
|
const [categories, setCategories] = useState<Category[]>([]);
|
||||||
const [selectedCategory, setSelectedCategory] = useState<any>();
|
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||||
|
|
@ -198,6 +197,11 @@ export default function FormAudioUpdate() {
|
||||||
const [mainCheckboxChangeType, setMainCheckboxChangeType] =
|
const [mainCheckboxChangeType, setMainCheckboxChangeType] =
|
||||||
useState<string>("");
|
useState<string>("");
|
||||||
|
|
||||||
|
const [isLoadingTranslate, setIsLoadingTranslate] = useState(false);
|
||||||
|
const [translatedContent, setTranslatedContent] = React.useState("");
|
||||||
|
const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id");
|
||||||
|
const roleId = getCookiesDecrypt("urie");
|
||||||
|
|
||||||
const options: Option[] = [
|
const options: Option[] = [
|
||||||
{ id: "all", name: "SEMUA" },
|
{ id: "all", name: "SEMUA" },
|
||||||
{ id: "5", name: "UMUM" },
|
{ id: "5", name: "UMUM" },
|
||||||
|
|
@ -234,6 +238,7 @@ export default function FormAudioUpdate() {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
setValue,
|
setValue,
|
||||||
|
getValues,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<AudioSchema>({
|
} = useForm<AudioSchema>({
|
||||||
resolver: zodResolver(audioSchema),
|
resolver: zodResolver(audioSchema),
|
||||||
|
|
@ -514,7 +519,7 @@ export default function FormAudioUpdate() {
|
||||||
// Jika wilayah dicentang, auto centang POLDA, SATKER
|
// Jika wilayah dicentang, auto centang POLDA, SATKER
|
||||||
if (key === "wilayah") {
|
if (key === "wilayah") {
|
||||||
currentSelection.wilayah = value;
|
currentSelection.wilayah = value;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
// Ketika wilayah dicentang, auto centang POLDA, SATKER
|
// Ketika wilayah dicentang, auto centang POLDA, SATKER
|
||||||
currentSelection.polda = true;
|
currentSelection.polda = true;
|
||||||
|
|
@ -535,7 +540,9 @@ export default function FormAudioUpdate() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Checklist SATKER POLRI dan semua sub-itemsnya
|
// Checklist SATKER POLRI dan semua sub-itemsnya
|
||||||
const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI");
|
const satkerItem = listDest.find(
|
||||||
|
(item: any) => item.name === "SATKER POLRI"
|
||||||
|
);
|
||||||
if (satkerItem) {
|
if (satkerItem) {
|
||||||
currentFileLevels.add(Number(satkerItem.id));
|
currentFileLevels.add(Number(satkerItem.id));
|
||||||
// Checklist semua sub-items di bawah SATKER POLRI
|
// Checklist semua sub-items di bawah SATKER POLRI
|
||||||
|
|
@ -569,7 +576,9 @@ export default function FormAudioUpdate() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hapus SATKER POLRI dan semua sub-itemsnya
|
// Hapus SATKER POLRI dan semua sub-itemsnya
|
||||||
const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI");
|
const satkerItem = listDest.find(
|
||||||
|
(item: any) => item.name === "SATKER POLRI"
|
||||||
|
);
|
||||||
if (satkerItem) {
|
if (satkerItem) {
|
||||||
currentFileLevels.delete(Number(satkerItem.id));
|
currentFileLevels.delete(Number(satkerItem.id));
|
||||||
// Hapus semua sub-items di bawah SATKER POLRI
|
// Hapus semua sub-items di bawah SATKER POLRI
|
||||||
|
|
@ -763,7 +772,11 @@ export default function FormAudioUpdate() {
|
||||||
const temp = [];
|
const temp = [];
|
||||||
for (let i = 0; i < filePlacements?.length; i++) {
|
for (let i = 0; i < filePlacements?.length; i++) {
|
||||||
const file = files[i] as any;
|
const file = files[i] as any;
|
||||||
if (file.id && filePlacements[file.id] && filePlacements[file.id].length > 0) {
|
if (
|
||||||
|
file.id &&
|
||||||
|
filePlacements[file.id] &&
|
||||||
|
filePlacements[file.id].length > 0
|
||||||
|
) {
|
||||||
const now = filePlacements[file.id];
|
const now = filePlacements[file.id];
|
||||||
const normalizedNow = now.map((item): PlacementType => {
|
const normalizedNow = now.map((item): PlacementType => {
|
||||||
const value = String(item);
|
const value = String(item);
|
||||||
|
|
@ -873,14 +886,16 @@ export default function FormAudioUpdate() {
|
||||||
} else if (placement === "semua") {
|
} else if (placement === "semua") {
|
||||||
placementToAdd = "all";
|
placementToAdd = "all";
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = temp[index] || [];
|
const now = temp[index] || [];
|
||||||
if (!now.includes(placementToAdd)) {
|
if (!now.includes(placementToAdd)) {
|
||||||
now.push(placementToAdd);
|
now.push(placementToAdd);
|
||||||
}
|
}
|
||||||
// Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist
|
// Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist
|
||||||
const requiredItems = ["mabes", "wilayah", "international"];
|
const requiredItems = ["mabes", "wilayah", "international"];
|
||||||
const hasAllRequired = requiredItems.every(item => now.includes(item));
|
const hasAllRequired = requiredItems.every((item) =>
|
||||||
|
now.includes(item)
|
||||||
|
);
|
||||||
if (hasAllRequired && !now.includes("all")) {
|
if (hasAllRequired && !now.includes("all")) {
|
||||||
now.push("all");
|
now.push("all");
|
||||||
}
|
}
|
||||||
|
|
@ -923,8 +938,8 @@ export default function FormAudioUpdate() {
|
||||||
} else {
|
} else {
|
||||||
if (placement === "wilayah") {
|
if (placement === "wilayah") {
|
||||||
// Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker
|
// Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker
|
||||||
const now = temp[index]?.filter((a) =>
|
const now = temp[index]?.filter(
|
||||||
a !== "wilayah" && a !== "polda" && a !== "satker"
|
(a) => a !== "wilayah" && a !== "polda" && a !== "satker"
|
||||||
);
|
);
|
||||||
temp[index] = now;
|
temp[index] = now;
|
||||||
} else if (placement === "polda") {
|
} else if (placement === "polda") {
|
||||||
|
|
@ -943,16 +958,18 @@ export default function FormAudioUpdate() {
|
||||||
} else if (placement === "semua") {
|
} else if (placement === "semua") {
|
||||||
placementToRemove = "all";
|
placementToRemove = "all";
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = temp[index]?.filter((a) => a !== placementToRemove);
|
const now = temp[index]?.filter((a) => a !== placementToRemove);
|
||||||
temp[index] = now;
|
temp[index] = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hapus "all" jika tidak semua item ter-checklist
|
// Hapus "all" jika tidak semua item ter-checklist
|
||||||
const currentNow = temp[index] || [];
|
const currentNow = temp[index] || [];
|
||||||
if (currentNow.includes("all")) {
|
if (currentNow.includes("all")) {
|
||||||
const requiredItems = ["mabes", "wilayah", "international"];
|
const requiredItems = ["mabes", "wilayah", "international"];
|
||||||
const hasAllRequired = requiredItems.every(item => currentNow.includes(item));
|
const hasAllRequired = requiredItems.every((item) =>
|
||||||
|
currentNow.includes(item)
|
||||||
|
);
|
||||||
if (!hasAllRequired) {
|
if (!hasAllRequired) {
|
||||||
const newData = currentNow.filter((b) => b !== "all");
|
const newData = currentNow.filter((b) => b !== "all");
|
||||||
temp[index] = newData;
|
temp[index] = newData;
|
||||||
|
|
@ -1073,12 +1090,18 @@ export default function FormAudioUpdate() {
|
||||||
.map((p: string) => {
|
.map((p: string) => {
|
||||||
const trimmed = p.trim();
|
const trimmed = p.trim();
|
||||||
switch (trimmed) {
|
switch (trimmed) {
|
||||||
case "all": return "all";
|
case "all":
|
||||||
case "mabes": return "nasional";
|
return "all";
|
||||||
case "polda": return "wilayah";
|
case "mabes":
|
||||||
case "satker": return "satker";
|
return "nasional";
|
||||||
case "international": return "international";
|
case "polda":
|
||||||
default: return trimmed;
|
return "wilayah";
|
||||||
|
case "satker":
|
||||||
|
return "satker";
|
||||||
|
case "international":
|
||||||
|
return "international";
|
||||||
|
default:
|
||||||
|
return trimmed;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return mappedPlacements;
|
return mappedPlacements;
|
||||||
|
|
@ -1112,8 +1135,10 @@ export default function FormAudioUpdate() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (file.placements) {
|
if (file.placements) {
|
||||||
const placements = file.placements.split(",").map((p: string) => p.trim());
|
const placements = file.placements
|
||||||
|
.split(",")
|
||||||
|
.map((p: string) => p.trim());
|
||||||
|
|
||||||
// Map dari format backend ke checkbox
|
// Map dari format backend ke checkbox
|
||||||
if (placements.includes("all")) {
|
if (placements.includes("all")) {
|
||||||
selection.semua = true;
|
selection.semua = true;
|
||||||
|
|
@ -1177,7 +1202,6 @@ export default function FormAudioUpdate() {
|
||||||
initState();
|
initState();
|
||||||
}, [refresh, setValue]);
|
}, [refresh, setValue]);
|
||||||
|
|
||||||
|
|
||||||
const handleCheckboxChange = (id: string) => {
|
const handleCheckboxChange = (id: string) => {
|
||||||
if (id === "all") {
|
if (id === "all") {
|
||||||
// Select all options except "all"
|
// Select all options except "all"
|
||||||
|
|
@ -1197,12 +1221,19 @@ export default function FormAudioUpdate() {
|
||||||
|
|
||||||
const save = async (data: AudioSchema) => {
|
const save = async (data: AudioSchema) => {
|
||||||
const finalTags = tags.join(", ");
|
const finalTags = tags.join(", ");
|
||||||
|
|
||||||
|
// ✅ tentukan isi description sesuai pilihan bahasa
|
||||||
|
const descFinal =
|
||||||
|
selectedLang === "en" && translatedContent
|
||||||
|
? translatedContent
|
||||||
|
: data.description;
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
...data,
|
...data,
|
||||||
id: detail?.id,
|
id: detail?.id,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: htmlToString(data.description),
|
description: htmlToString(descFinal),
|
||||||
htmlDescription: data.description,
|
htmlDescription: descFinal,
|
||||||
fileTypeId,
|
fileTypeId,
|
||||||
categoryId: selectedTarget,
|
categoryId: selectedTarget,
|
||||||
subCategoryId: selectedTarget,
|
subCategoryId: selectedTarget,
|
||||||
|
|
@ -1441,7 +1472,6 @@ export default function FormAudioUpdate() {
|
||||||
</div>
|
</div>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
function success() {
|
function success() {
|
||||||
MySwal.fire({
|
MySwal.fire({
|
||||||
title: "Sukses",
|
title: "Sukses",
|
||||||
|
|
@ -1565,6 +1595,105 @@ export default function FormAudioUpdate() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="py-3 space-y-2">
|
<div className="py-3 space-y-2">
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
<Label>
|
||||||
|
{t("description", { defaultValue: "Description" })}
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
{roleId === "14" && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
loading();
|
||||||
|
setIsLoadingTranslate(true);
|
||||||
|
const res = await translateText({
|
||||||
|
text: getValues("description"),
|
||||||
|
sourceLang: "ID",
|
||||||
|
targetLang: "EN",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.error) {
|
||||||
|
const resultText =
|
||||||
|
res?.data?.data?.translations?.[0]?.text || "";
|
||||||
|
|
||||||
|
setTranslatedContent(resultText);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
close();
|
||||||
|
console.error("Translate gagal:", err);
|
||||||
|
} finally {
|
||||||
|
close();
|
||||||
|
setIsLoadingTranslate(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="px-3 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600"
|
||||||
|
>
|
||||||
|
{isLoadingTranslate
|
||||||
|
? "Translating..."
|
||||||
|
: "Translate to English"}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Pilihan bahasa untuk posting */}
|
||||||
|
{roleId === "14" && (
|
||||||
|
<div className="flex items-center gap-4 mb-2">
|
||||||
|
<label className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="id"
|
||||||
|
checked={selectedLang === "id"}
|
||||||
|
onChange={() => setSelectedLang("id")}
|
||||||
|
/>
|
||||||
|
<span>Gunakan Bahasa Indonesia</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Editor Bahasa Indonesia */}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<CustomEditor
|
||||||
|
onChange={field.onChange}
|
||||||
|
initialData={field.value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Editor Bahasa Inggris */}
|
||||||
|
{translatedContent && (
|
||||||
|
<div className="mt-4">
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<Label className="text-[15px]">English Version</Label>
|
||||||
|
<label className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="en"
|
||||||
|
checked={selectedLang === "en"}
|
||||||
|
onChange={() => setSelectedLang("en")}
|
||||||
|
disabled={!translatedContent}
|
||||||
|
/>
|
||||||
|
<span>Gunakan Bahasa Inggris</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CustomEditor
|
||||||
|
onChange={(val: any) => setTranslatedContent(val)}
|
||||||
|
initialData={translatedContent}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{errors.description?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.description.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{/* <div className="py-3 space-y-2">
|
||||||
<Label>
|
<Label>
|
||||||
{t("description", { defaultValue: "Description" })}
|
{t("description", { defaultValue: "Description" })}
|
||||||
</Label>
|
</Label>
|
||||||
|
|
@ -1580,7 +1709,7 @@ export default function FormAudioUpdate() {
|
||||||
{errors.description.message}
|
{errors.description.message}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div> */}
|
||||||
<div className="py-3 space-y-2">
|
<div className="py-3 space-y-2">
|
||||||
<Label>
|
<Label>
|
||||||
{t("select-file", { defaultValue: "Select File" })}
|
{t("select-file", { defaultValue: "Select File" })}
|
||||||
|
|
@ -1641,17 +1770,19 @@ export default function FormAudioUpdate() {
|
||||||
<div className="flex-grow">
|
<div className="flex-grow">
|
||||||
<div>
|
<div>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
width="80"
|
width="80"
|
||||||
height="80"
|
height="80"
|
||||||
viewBox="0 0 20 20"
|
viewBox="0 0 20 20"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
d="M14.702 2.226A1 1 0 0 1 16 3.18v6.027a5.5 5.5 0 0 0-1-.184V6.18L8 8.368V15.5a2.5 2.5 0 1 1-1-2V5.368a1 1 0 0 1 .702-.955zM8 7.32l7-2.187V3.18L8 5.368zM5.5 14a1.5 1.5 0 1 0 0 3a1.5 1.5 0 0 0 0-3m13.5.5a4.5 4.5 0 1 1-9 0a4.5 4.5 0 0 1 9 0m-2.265-.436l-2.994-1.65a.5.5 0 0 0-.741.438v3.3a.5.5 0 0 0 .741.438l2.994-1.65a.5.5 0 0 0 0-.876"
|
d="M14.702 2.226A1 1 0 0 1 16 3.18v6.027a5.5 5.5 0 0 0-1-.184V6.18L8 8.368V15.5a2.5 2.5 0 1 1-1-2V5.368a1 1 0 0 1 .702-.955zM8 7.32l7-2.187V3.18L8 5.368zM5.5 14a1.5 1.5 0 1 0 0 3a1.5 1.5 0 0 0 0-3m13.5.5a4.5 4.5 0 1 1-9 0a4.5 4.5 0 0 1 9 0m-2.265-.436l-2.994-1.65a.5.5 0 0 0-.741.438v3.3a.5.5 0 0 0 .741.438l2.994-1.65a.5.5 0 0 0 0-.876"
|
||||||
/>
|
/>
|
||||||
</svg>{" "}
|
</svg>{" "}
|
||||||
<p className="font-medium">{file.fileName}</p>
|
<p className="font-medium">
|
||||||
|
{file.fileName}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<a
|
<a
|
||||||
href={file.url}
|
href={file.url}
|
||||||
|
|
@ -1663,7 +1794,7 @@ export default function FormAudioUpdate() {
|
||||||
defaultValue: "View File",
|
defaultValue: "View File",
|
||||||
})}
|
})}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-white rounded-md p-4 border">
|
<div className="bg-white rounded-md p-4 border">
|
||||||
{/* Checkbox Tingkat Utama */}
|
{/* Checkbox Tingkat Utama */}
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
|
@ -1709,276 +1840,290 @@ export default function FormAudioUpdate() {
|
||||||
>
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Detail Wilayah */}
|
{/* Detail Wilayah */}
|
||||||
{fileUnitSelections[index]?.wilayah && isDetailOfRegionShowed && (
|
{fileUnitSelections[index]?.wilayah &&
|
||||||
<div className="border-t border-gray-200 pt-2">
|
isDetailOfRegionShowed && (
|
||||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
<div className="border-t border-gray-200 pt-2">
|
||||||
Detail Wilayah:
|
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||||
</p>
|
Detail Wilayah:
|
||||||
|
</p>
|
||||||
|
|
||||||
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||||
{[
|
{[
|
||||||
{ key: "polda", label: "POLDA" },
|
{ key: "polda", label: "POLDA" },
|
||||||
{ key: "satker", label: "SATKER" },
|
{
|
||||||
].map((item, idx) => (
|
key: "satker",
|
||||||
<div
|
label: "SATKER",
|
||||||
key={item.key}
|
},
|
||||||
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
].map((item, idx) => (
|
||||||
>
|
<div
|
||||||
<Checkbox
|
key={item.key}
|
||||||
id={`${item.key}-${index}`}
|
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
checked={
|
|
||||||
fileUnitSelections[index]?.[
|
|
||||||
item.key as keyof typeof unitSelection
|
|
||||||
] || false
|
|
||||||
}
|
|
||||||
onCheckedChange={(value) => {
|
|
||||||
handleFileUnitChange(
|
|
||||||
index,
|
|
||||||
item.key as keyof typeof unitSelection,
|
|
||||||
value as boolean
|
|
||||||
);
|
|
||||||
setupPlacement(
|
|
||||||
index,
|
|
||||||
item.key,
|
|
||||||
Boolean(value)
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Label
|
|
||||||
htmlFor={`${item.key}-${index}`}
|
|
||||||
className="text-sm font-medium cursor-pointer"
|
|
||||||
>
|
>
|
||||||
{item.label}
|
<Checkbox
|
||||||
</Label>
|
id={`${item.key}-${index}`}
|
||||||
</div>
|
checked={
|
||||||
))}
|
fileUnitSelections[index]?.[
|
||||||
|
item.key as keyof typeof unitSelection
|
||||||
{/* Tombol Kustom sejajar dengan checkbox */}
|
] || false
|
||||||
<div className="flex items-center justify-center p-3">
|
}
|
||||||
<Dialog>
|
onCheckedChange={(value) => {
|
||||||
<DialogTrigger asChild>
|
handleFileUnitChange(
|
||||||
<Button
|
index,
|
||||||
variant="outline"
|
item.key as keyof typeof unitSelection,
|
||||||
size="sm"
|
value as boolean
|
||||||
className="gap-2"
|
);
|
||||||
|
setupPlacement(
|
||||||
|
index,
|
||||||
|
item.key,
|
||||||
|
Boolean(value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${item.key}-${index}`}
|
||||||
|
className="text-sm font-medium cursor-pointer"
|
||||||
>
|
>
|
||||||
<Icon
|
{item.label}
|
||||||
icon="material-symbols:tune"
|
</Label>
|
||||||
width={16}
|
</div>
|
||||||
height={16}
|
))}
|
||||||
/>
|
|
||||||
{t("custom", {
|
|
||||||
defaultValue: "Kustom",
|
|
||||||
})}
|
|
||||||
</Button>
|
|
||||||
</DialogTrigger>
|
|
||||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
|
||||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
|
||||||
<DialogTitle className="text-lg font-semibold">
|
|
||||||
Daftar Wilayah POLDA dan SATKER
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
|
||||||
{listDest.map(
|
|
||||||
(polda: any) => (
|
|
||||||
<div
|
|
||||||
key={polda.id}
|
|
||||||
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
|
||||||
>
|
|
||||||
{/* Header POLDA */}
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
|
||||||
<Checkbox
|
|
||||||
checked={
|
|
||||||
fileCheckedLevels[
|
|
||||||
index
|
|
||||||
]?.has(
|
|
||||||
Number(
|
|
||||||
polda.id
|
|
||||||
)
|
|
||||||
) || false
|
|
||||||
}
|
|
||||||
onCheckedChange={() =>
|
|
||||||
handleFileCheckboxChangePlacement(
|
|
||||||
index,
|
|
||||||
Number(polda.id)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span className="font-semibold text-gray-900 text-sm">
|
|
||||||
{polda.name}
|
|
||||||
</span>
|
|
||||||
</Label>
|
|
||||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
|
||||||
{polda.name === "SATKER POLRI" && polda.subDestination && (
|
|
||||||
<button
|
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
toggleExpand(
|
|
||||||
polda.id
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
icon={
|
|
||||||
expandedPolda[
|
|
||||||
polda.id
|
|
||||||
]
|
|
||||||
? "mdi:chevron-up"
|
|
||||||
: "mdi:chevron-down"
|
|
||||||
}
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
{/* Tombol Kustom sejajar dengan checkbox */}
|
||||||
{polda.name === "SATKER POLRI" && polda.subDestination &&
|
<div className="flex items-center justify-center p-3">
|
||||||
expandedPolda[
|
<Dialog>
|
||||||
polda.id
|
<DialogTrigger asChild>
|
||||||
] && (
|
<Button
|
||||||
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
variant="outline"
|
||||||
{/* Tombol Pilih Semua untuk sub-items */}
|
size="sm"
|
||||||
<div className="mb-2 flex justify-start">
|
className="gap-2"
|
||||||
{(() => {
|
>
|
||||||
const allSubItemsChecked =
|
<Icon
|
||||||
polda.subDestination?.every(
|
icon="material-symbols:tune"
|
||||||
(
|
width={16}
|
||||||
sub: any
|
height={16}
|
||||||
) =>
|
/>
|
||||||
fileCheckedLevels[
|
{t("custom", {
|
||||||
index
|
defaultValue: "Kustom",
|
||||||
]?.has(
|
})}
|
||||||
Number(
|
</Button>
|
||||||
sub.id
|
</DialogTrigger>
|
||||||
)
|
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||||
)
|
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||||
|
<DialogTitle className="text-lg font-semibold">
|
||||||
|
Daftar Wilayah POLDA dan
|
||||||
|
SATKER
|
||||||
|
</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||||
|
{listDest.map(
|
||||||
|
(polda: any) => (
|
||||||
|
<div
|
||||||
|
key={polda.id}
|
||||||
|
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
||||||
|
>
|
||||||
|
{/* Header POLDA */}
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
||||||
|
<Checkbox
|
||||||
|
checked={
|
||||||
|
fileCheckedLevels[
|
||||||
|
index
|
||||||
|
]?.has(
|
||||||
|
Number(
|
||||||
|
polda.id
|
||||||
|
)
|
||||||
|
) || false
|
||||||
|
}
|
||||||
|
onCheckedChange={() =>
|
||||||
|
handleFileCheckboxChangePlacement(
|
||||||
|
index,
|
||||||
|
Number(
|
||||||
|
polda.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span className="font-semibold text-gray-900 text-sm">
|
||||||
|
{polda.name}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||||
|
{polda.name ===
|
||||||
|
"SATKER POLRI" &&
|
||||||
|
polda.subDestination && (
|
||||||
|
<button
|
||||||
|
onClick={(
|
||||||
|
e
|
||||||
|
) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
toggleExpand(
|
||||||
|
polda.id
|
||||||
);
|
);
|
||||||
return (
|
}}
|
||||||
<Button
|
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
||||||
size="sm"
|
>
|
||||||
variant="outline"
|
<Icon
|
||||||
className="text-xs h-6 px-2"
|
icon={
|
||||||
onClick={() =>
|
expandedPolda[
|
||||||
handleSelectAllSubItems(
|
polda.id
|
||||||
index,
|
]
|
||||||
polda
|
? "mdi:chevron-up"
|
||||||
)
|
: "mdi:chevron-down"
|
||||||
}
|
}
|
||||||
>
|
width={16}
|
||||||
{allSubItemsChecked ? (
|
height={16}
|
||||||
<>
|
/>
|
||||||
<Icon
|
</button>
|
||||||
icon="material-symbols:check-indeterminate-small"
|
)}
|
||||||
width={
|
</div>
|
||||||
12
|
|
||||||
}
|
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||||
height={
|
{polda.name ===
|
||||||
12
|
"SATKER POLRI" &&
|
||||||
}
|
polda.subDestination &&
|
||||||
className="mr-1"
|
expandedPolda[
|
||||||
/>
|
polda.id
|
||||||
Batal
|
] && (
|
||||||
Semua
|
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
||||||
</>
|
{/* Tombol Pilih Semua untuk sub-items */}
|
||||||
) : (
|
<div className="mb-2 flex justify-start">
|
||||||
<>
|
{(() => {
|
||||||
<Icon
|
const allSubItemsChecked =
|
||||||
icon="material-symbols:check-all"
|
polda.subDestination?.every(
|
||||||
width={
|
(
|
||||||
12
|
sub: any
|
||||||
}
|
) =>
|
||||||
height={
|
|
||||||
12
|
|
||||||
}
|
|
||||||
className="mr-1"
|
|
||||||
/>
|
|
||||||
Pilih
|
|
||||||
Semua
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1">
|
|
||||||
{polda.subDestination.map(
|
|
||||||
(
|
|
||||||
sub: any
|
|
||||||
) => (
|
|
||||||
<Label
|
|
||||||
key={
|
|
||||||
sub.id
|
|
||||||
}
|
|
||||||
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
|
||||||
>
|
|
||||||
<Checkbox
|
|
||||||
checked={
|
|
||||||
fileCheckedLevels[
|
fileCheckedLevels[
|
||||||
index
|
index
|
||||||
]?.has(
|
]?.has(
|
||||||
Number(
|
Number(
|
||||||
sub.id
|
sub.id
|
||||||
)
|
)
|
||||||
) ||
|
)
|
||||||
false
|
);
|
||||||
}
|
return (
|
||||||
onCheckedChange={() =>
|
<Button
|
||||||
handleFileCheckboxChangePlacement(
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
className="text-xs h-6 px-2"
|
||||||
|
onClick={() =>
|
||||||
|
handleSelectAllSubItems(
|
||||||
index,
|
index,
|
||||||
Number(sub.id)
|
polda
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
>
|
||||||
<span className="text-gray-700">
|
{allSubItemsChecked ? (
|
||||||
{
|
<>
|
||||||
sub.name
|
<Icon
|
||||||
|
icon="material-symbols:check-indeterminate-small"
|
||||||
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
height={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
className="mr-1"
|
||||||
|
/>
|
||||||
|
Batal
|
||||||
|
Semua
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Icon
|
||||||
|
icon="material-symbols:check-all"
|
||||||
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
height={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
className="mr-1"
|
||||||
|
/>
|
||||||
|
Pilih
|
||||||
|
Semua
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
{polda.subDestination.map(
|
||||||
|
(
|
||||||
|
sub: any
|
||||||
|
) => (
|
||||||
|
<Label
|
||||||
|
key={
|
||||||
|
sub.id
|
||||||
}
|
}
|
||||||
</span>
|
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
||||||
</Label>
|
>
|
||||||
)
|
<Checkbox
|
||||||
)}
|
checked={
|
||||||
</div>
|
fileCheckedLevels[
|
||||||
</div>
|
index
|
||||||
)}
|
]?.has(
|
||||||
|
Number(
|
||||||
</div>
|
sub.id
|
||||||
)
|
)
|
||||||
)}
|
) ||
|
||||||
</div>
|
false
|
||||||
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
}
|
||||||
<DialogClose asChild>
|
onCheckedChange={() =>
|
||||||
<Button variant="outline">
|
handleFileCheckboxChangePlacement(
|
||||||
{t("cancel", {
|
index,
|
||||||
defaultValue: "Batal",
|
Number(
|
||||||
})}
|
sub.id
|
||||||
</Button>
|
)
|
||||||
</DialogClose>
|
)
|
||||||
<DialogClose asChild>
|
}
|
||||||
<Button>Simpan</Button>
|
/>
|
||||||
</DialogClose>
|
<span className="text-gray-700">
|
||||||
</div>
|
{
|
||||||
</DialogContent>
|
sub.name
|
||||||
</Dialog>
|
}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="outline">
|
||||||
|
{t("cancel", {
|
||||||
|
defaultValue: "Batal",
|
||||||
|
})}
|
||||||
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button>Simpan</Button>
|
||||||
|
</DialogClose>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,6 @@ export default function FormImage() {
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
const [isLoadingData, setIsLoadingData] = useState<boolean>(false);
|
const [isLoadingData, setIsLoadingData] = useState<boolean>(false);
|
||||||
const [localContent, setLocalContent] = useState("");
|
const [localContent, setLocalContent] = useState("");
|
||||||
const [isLoadingTranslate, setIsLoadingTranslate] = useState(false);
|
|
||||||
const [articleIds, setArticleIds] = useState<string[]>([]);
|
const [articleIds, setArticleIds] = useState<string[]>([]);
|
||||||
const [isGeneratedArticle, setIsGeneratedArticle] = useState(false);
|
const [isGeneratedArticle, setIsGeneratedArticle] = useState(false);
|
||||||
const [articleBody, setArticleBody] = useState<string>("");
|
const [articleBody, setArticleBody] = useState<string>("");
|
||||||
|
|
@ -149,6 +148,7 @@ export default function FormImage() {
|
||||||
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||||
const [filesTemp, setFilesTemp] = useState<File[]>([]);
|
const [filesTemp, setFilesTemp] = useState<File[]>([]);
|
||||||
const [publishedFor, setPublishedFor] = useState<string[]>([]);
|
const [publishedFor, setPublishedFor] = useState<string[]>([]);
|
||||||
|
const [isLoadingTranslate, setIsLoadingTranslate] = useState(false);
|
||||||
const [translatedContent, setTranslatedContent] = React.useState("");
|
const [translatedContent, setTranslatedContent] = React.useState("");
|
||||||
const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id");
|
const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id");
|
||||||
|
|
||||||
|
|
@ -555,8 +555,9 @@ export default function FormImage() {
|
||||||
|
|
||||||
const finalTags = tags.join(", ");
|
const finalTags = tags.join(", ");
|
||||||
const finalTitle = isSwitchOn ? title : data.title;
|
const finalTitle = isSwitchOn ? title : data.title;
|
||||||
// const finalDescription = articleBody || data.description;
|
|
||||||
const finalDescription = isSwitchOn
|
// pilih description dasar
|
||||||
|
let finalDescription = isSwitchOn
|
||||||
? data.description
|
? data.description
|
||||||
: selectedFileType === "rewrite"
|
: selectedFileType === "rewrite"
|
||||||
? data.rewriteDescription
|
? data.rewriteDescription
|
||||||
|
|
@ -567,6 +568,15 @@ export default function FormImage() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 👉 tempelkan hasil translate ke field form agar ikut terkirim
|
||||||
|
if (translatedContent) {
|
||||||
|
data.descriptionOri = translatedContent;
|
||||||
|
console.log(
|
||||||
|
"🌍 Translate dimasukkan ke descriptionOri:",
|
||||||
|
translatedContent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let requestData: {
|
let requestData: {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|
@ -585,8 +595,8 @@ export default function FormImage() {
|
||||||
} = {
|
} = {
|
||||||
...data,
|
...data,
|
||||||
title: finalTitle,
|
title: finalTitle,
|
||||||
description: htmlToString(finalDescription),
|
description: htmlToString(finalDescription), // plain text
|
||||||
htmlDescription: finalDescription,
|
htmlDescription: finalDescription, // versi HTML
|
||||||
fileTypeId,
|
fileTypeId,
|
||||||
categoryId: selectedCategory,
|
categoryId: selectedCategory,
|
||||||
subCategoryId: selectedCategory,
|
subCategoryId: selectedCategory,
|
||||||
|
|
@ -611,6 +621,7 @@ export default function FormImage() {
|
||||||
|
|
||||||
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
||||||
id = response?.data?.data;
|
id = response?.data?.data;
|
||||||
|
|
||||||
const formMedia = new FormData();
|
const formMedia = new FormData();
|
||||||
const thumbnail = files[0];
|
const thumbnail = files[0];
|
||||||
formMedia.append("file", thumbnail);
|
formMedia.append("file", thumbnail);
|
||||||
|
|
@ -620,6 +631,7 @@ export default function FormImage() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const progressInfoArr = files.map((item) => ({
|
const progressInfoArr = files.map((item) => ({
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
fileName: item.name,
|
fileName: item.name,
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -542,6 +542,102 @@ export default function FormTeks() {
|
||||||
}
|
}
|
||||||
}, [articleBody, setValue]);
|
}, [articleBody, setValue]);
|
||||||
|
|
||||||
|
// const save = async (data: TeksSchema) => {
|
||||||
|
// loading();
|
||||||
|
|
||||||
|
// if (files.length === 0) {
|
||||||
|
// MySwal.fire("Error", "Minimal 1 file harus diunggah.", "error");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const finalTags = tags.join(", ");
|
||||||
|
// const finalTitle = isSwitchOn ? title : data.title;
|
||||||
|
// // const finalDescription = articleBody || data.description;
|
||||||
|
// const finalDescription = isSwitchOn
|
||||||
|
// ? data.description
|
||||||
|
// : selectedFileType === "rewrite"
|
||||||
|
// ? data.rewriteDescription
|
||||||
|
// : data.descriptionOri;
|
||||||
|
|
||||||
|
// if (!finalDescription?.trim()) {
|
||||||
|
// MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let requestData: {
|
||||||
|
// title: string;
|
||||||
|
// description: string;
|
||||||
|
// htmlDescription: string;
|
||||||
|
// fileTypeId: string;
|
||||||
|
// categoryId: any;
|
||||||
|
// subCategoryId: any;
|
||||||
|
// uploadedBy: string;
|
||||||
|
// statusId: string;
|
||||||
|
// publishedFor: string;
|
||||||
|
// creatorName: string;
|
||||||
|
// tags: string;
|
||||||
|
// isYoutube: boolean;
|
||||||
|
// isInternationalMedia: boolean;
|
||||||
|
// attachFromScheduleId?: number;
|
||||||
|
// } = {
|
||||||
|
// ...data,
|
||||||
|
// title: finalTitle,
|
||||||
|
// description: htmlToString(finalDescription),
|
||||||
|
// htmlDescription: finalDescription,
|
||||||
|
// fileTypeId,
|
||||||
|
// categoryId: selectedCategory,
|
||||||
|
// subCategoryId: selectedCategory,
|
||||||
|
// uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
||||||
|
// statusId: "1",
|
||||||
|
// publishedFor: publishedFor.join(","),
|
||||||
|
// creatorName: data.creatorName,
|
||||||
|
// tags: finalTags,
|
||||||
|
// isYoutube: false,
|
||||||
|
// isInternationalMedia: false,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// let id = Cookies.get("idCreate");
|
||||||
|
|
||||||
|
// if (scheduleId !== undefined) {
|
||||||
|
// requestData.attachFromScheduleId = Number(scheduleId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (id == undefined) {
|
||||||
|
// const response = await createMedia(requestData);
|
||||||
|
// console.log("Form Data Submitted:", requestData);
|
||||||
|
|
||||||
|
// Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
||||||
|
// id = response?.data?.data;
|
||||||
|
// const formMedia = new FormData();
|
||||||
|
// const thumbnail = files[0];
|
||||||
|
// formMedia.append("file", thumbnail);
|
||||||
|
// const responseThumbnail = await uploadThumbnail(id, formMedia);
|
||||||
|
// if (responseThumbnail?.error == true) {
|
||||||
|
// error(responseThumbnail?.message);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// const progressInfoArr = files.map((item) => ({
|
||||||
|
// percentage: 0,
|
||||||
|
// fileName: item.name,
|
||||||
|
// }));
|
||||||
|
// progressInfo = progressInfoArr;
|
||||||
|
// setIsStartUpload(true);
|
||||||
|
// setProgressList(progressInfoArr);
|
||||||
|
|
||||||
|
// close();
|
||||||
|
// files.map(async (item: any, index: number) => {
|
||||||
|
// await uploadResumableFile(
|
||||||
|
// index,
|
||||||
|
// String(id),
|
||||||
|
// item,
|
||||||
|
// fileTypeId == "2" || fileTypeId == "4" ? item.duration : "0"
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
|
||||||
|
// Cookies.remove("idCreate");
|
||||||
|
// };
|
||||||
|
|
||||||
const save = async (data: TeksSchema) => {
|
const save = async (data: TeksSchema) => {
|
||||||
loading();
|
loading();
|
||||||
|
|
||||||
|
|
@ -564,6 +660,15 @@ export default function FormTeks() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 👉 tempelkan hasil translate ke field form agar ikut terkirim
|
||||||
|
if (translatedContent) {
|
||||||
|
data.descriptionOri = translatedContent;
|
||||||
|
console.log(
|
||||||
|
"🌍 Translate dimasukkan ke descriptionOri:",
|
||||||
|
translatedContent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let requestData: {
|
let requestData: {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,9 @@ import {
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
import { getCookiesDecrypt } from "@/lib/utils";
|
||||||
|
import { translateText } from "@/service/content/ai";
|
||||||
|
import { close } from "@/config/swal";
|
||||||
|
|
||||||
const teksSchema = z.object({
|
const teksSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -137,24 +140,20 @@ const CustomEditor = dynamic(
|
||||||
export default function FormTeksUpdate() {
|
export default function FormTeksUpdate() {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { id } = useParams() as { id: string };
|
const { id } = useParams() as { id: string };
|
||||||
console.log(id);
|
console.log(id);
|
||||||
const editor = useRef(null);
|
const editor = useRef(null);
|
||||||
type TeksSchema = z.infer<typeof teksSchema>;
|
type TeksSchema = z.infer<typeof teksSchema>;
|
||||||
|
|
||||||
let progressInfo: any = [];
|
let progressInfo: any = [];
|
||||||
let counterUpdateProgress = 0;
|
let counterUpdateProgress = 0;
|
||||||
const [progressList, setProgressList] = useState<any>([]);
|
const [progressList, setProgressList] = useState<any>([]);
|
||||||
let uploadPersen = 0;
|
let uploadPersen = 0;
|
||||||
const [isStartUpload, setIsStartUpload] = useState(false);
|
const [isStartUpload, setIsStartUpload] = useState(false);
|
||||||
const [counterProgress, setCounterProgress] = useState(0);
|
const [counterProgress, setCounterProgress] = useState(0);
|
||||||
|
|
||||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||||
const taskId = Cookies.get("taskId");
|
const taskId = Cookies.get("taskId");
|
||||||
const scheduleId = Cookies.get("scheduleId");
|
const scheduleId = Cookies.get("scheduleId");
|
||||||
const scheduleType = Cookies.get("scheduleType");
|
const scheduleType = Cookies.get("scheduleType");
|
||||||
|
|
||||||
const t = useTranslations("Form");
|
const t = useTranslations("Form");
|
||||||
const [categories, setCategories] = useState<Category[]>([]);
|
const [categories, setCategories] = useState<Category[]>([]);
|
||||||
const [selectedCategory, setSelectedCategory] = useState<any>();
|
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||||
|
|
@ -162,7 +161,6 @@ export default function FormTeksUpdate() {
|
||||||
const [detail, setDetail] = useState<Detail>();
|
const [detail, setDetail] = useState<Detail>();
|
||||||
const [refresh, setRefresh] = useState(false);
|
const [refresh, setRefresh] = useState(false);
|
||||||
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
||||||
|
|
||||||
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||||
const [fileUnitSelections, setFileUnitSelections] = useState<
|
const [fileUnitSelections, setFileUnitSelections] = useState<
|
||||||
Array<{
|
Array<{
|
||||||
|
|
@ -201,16 +199,24 @@ export default function FormTeksUpdate() {
|
||||||
const [tempFile, setTempFile] = useState<TempFileItem[]>([]);
|
const [tempFile, setTempFile] = useState<TempFileItem[]>([]);
|
||||||
const [publishedFor, setPublishedFor] = useState<string[]>([]);
|
const [publishedFor, setPublishedFor] = useState<string[]>([]);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [isLoadingTranslate, setIsLoadingTranslate] = useState(false);
|
||||||
|
const [translatedContent, setTranslatedContent] = React.useState("");
|
||||||
|
const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id");
|
||||||
|
const roleId = getCookiesDecrypt("urie");
|
||||||
|
|
||||||
let fileTypeId = "3";
|
let fileTypeId = "3";
|
||||||
const isDetailOfRegionShowed = false;
|
const isDetailOfRegionShowed = false;
|
||||||
|
|
||||||
const { getRootProps, getInputProps } = useDropzone({
|
const { getRootProps, getInputProps } = useDropzone({
|
||||||
onDrop: (acceptedFiles) => {
|
onDrop: (acceptedFiles) => {
|
||||||
setFiles(acceptedFiles.map((file) => Object.assign(file, {
|
setFiles(
|
||||||
id: uuidv4(),
|
acceptedFiles.map((file) =>
|
||||||
preview: URL.createObjectURL(file)
|
Object.assign(file, {
|
||||||
})));
|
id: uuidv4(),
|
||||||
|
preview: URL.createObjectURL(file),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
accept: {
|
accept: {
|
||||||
"application/pdf": [],
|
"application/pdf": [],
|
||||||
|
|
@ -232,6 +238,7 @@ export default function FormTeksUpdate() {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
setValue,
|
setValue,
|
||||||
|
getValues,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<TeksSchema>({
|
} = useForm<TeksSchema>({
|
||||||
resolver: zodResolver(teksSchema),
|
resolver: zodResolver(teksSchema),
|
||||||
|
|
@ -533,7 +540,7 @@ export default function FormTeksUpdate() {
|
||||||
// Jika wilayah dicentang, auto centang POLDA, SATKER
|
// Jika wilayah dicentang, auto centang POLDA, SATKER
|
||||||
if (key === "wilayah") {
|
if (key === "wilayah") {
|
||||||
currentSelection.wilayah = value;
|
currentSelection.wilayah = value;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
// Ketika wilayah dicentang, auto centang POLDA, SATKER
|
// Ketika wilayah dicentang, auto centang POLDA, SATKER
|
||||||
currentSelection.polda = true;
|
currentSelection.polda = true;
|
||||||
|
|
@ -554,7 +561,9 @@ export default function FormTeksUpdate() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Checklist SATKER POLRI dan semua sub-itemsnya
|
// Checklist SATKER POLRI dan semua sub-itemsnya
|
||||||
const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI");
|
const satkerItem = listDest.find(
|
||||||
|
(item: any) => item.name === "SATKER POLRI"
|
||||||
|
);
|
||||||
if (satkerItem) {
|
if (satkerItem) {
|
||||||
currentFileLevels.add(Number(satkerItem.id));
|
currentFileLevels.add(Number(satkerItem.id));
|
||||||
// Checklist semua sub-items di bawah SATKER POLRI
|
// Checklist semua sub-items di bawah SATKER POLRI
|
||||||
|
|
@ -588,7 +597,9 @@ export default function FormTeksUpdate() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hapus SATKER POLRI dan semua sub-itemsnya
|
// Hapus SATKER POLRI dan semua sub-itemsnya
|
||||||
const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI");
|
const satkerItem = listDest.find(
|
||||||
|
(item: any) => item.name === "SATKER POLRI"
|
||||||
|
);
|
||||||
if (satkerItem) {
|
if (satkerItem) {
|
||||||
currentFileLevels.delete(Number(satkerItem.id));
|
currentFileLevels.delete(Number(satkerItem.id));
|
||||||
// Hapus semua sub-items di bawah SATKER POLRI
|
// Hapus semua sub-items di bawah SATKER POLRI
|
||||||
|
|
@ -687,9 +698,14 @@ export default function FormTeksUpdate() {
|
||||||
|
|
||||||
// Update filePlacements berdasarkan perubahan di modal
|
// Update filePlacements berdasarkan perubahan di modal
|
||||||
// Cek apakah ini adalah POLDA atau SATKER yang diubah
|
// Cek apakah ini adalah POLDA atau SATKER yang diubah
|
||||||
const changedItem = listDest.find((item: any) => Number(item.id) === levelId);
|
const changedItem = listDest.find(
|
||||||
|
(item: any) => Number(item.id) === levelId
|
||||||
|
);
|
||||||
if (changedItem) {
|
if (changedItem) {
|
||||||
if (changedItem.levelNumber === 2 && changedItem.name !== "SATKER POLRI") {
|
if (
|
||||||
|
changedItem.levelNumber === 2 &&
|
||||||
|
changedItem.name !== "SATKER POLRI"
|
||||||
|
) {
|
||||||
// Ini adalah POLDA
|
// Ini adalah POLDA
|
||||||
const isChecked = fileCheckedLevels[fileIndex]?.has(levelId) || false;
|
const isChecked = fileCheckedLevels[fileIndex]?.has(levelId) || false;
|
||||||
setupPlacement(fileIndex, "polda", isChecked);
|
setupPlacement(fileIndex, "polda", isChecked);
|
||||||
|
|
@ -798,13 +814,18 @@ export default function FormTeksUpdate() {
|
||||||
// Update filePlacements berdasarkan perubahan di modal
|
// Update filePlacements berdasarkan perubahan di modal
|
||||||
// Cek apakah ini adalah SATKER POLRI yang diubah
|
// Cek apakah ini adalah SATKER POLRI yang diubah
|
||||||
if (polda.name === "SATKER POLRI") {
|
if (polda.name === "SATKER POLRI") {
|
||||||
const isChecked = fileCheckedLevels[fileIndex]?.has(Number(polda.id)) || false;
|
const isChecked =
|
||||||
|
fileCheckedLevels[fileIndex]?.has(Number(polda.id)) || false;
|
||||||
setupPlacement(fileIndex, "satker", isChecked);
|
setupPlacement(fileIndex, "satker", isChecked);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPlacement = () => {
|
const getPlacement = () => {
|
||||||
const temp: Array<{ mediaFileId: number | string; placements: string; customLocationPlacements: string }> = [];
|
const temp: Array<{
|
||||||
|
mediaFileId: number | string;
|
||||||
|
placements: string;
|
||||||
|
customLocationPlacements: string;
|
||||||
|
}> = [];
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i] as any;
|
const file = files[i] as any;
|
||||||
const now = filePlacements[i];
|
const now = filePlacements[i];
|
||||||
|
|
@ -916,14 +937,16 @@ export default function FormTeksUpdate() {
|
||||||
} else if (placement === "semua") {
|
} else if (placement === "semua") {
|
||||||
placementToAdd = "all";
|
placementToAdd = "all";
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = temp[index] || [];
|
const now = temp[index] || [];
|
||||||
if (!now.includes(placementToAdd)) {
|
if (!now.includes(placementToAdd)) {
|
||||||
now.push(placementToAdd);
|
now.push(placementToAdd);
|
||||||
}
|
}
|
||||||
// Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist
|
// Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist
|
||||||
const requiredItems = ["mabes", "wilayah", "international"];
|
const requiredItems = ["mabes", "wilayah", "international"];
|
||||||
const hasAllRequired = requiredItems.every(item => now.includes(item));
|
const hasAllRequired = requiredItems.every((item) =>
|
||||||
|
now.includes(item)
|
||||||
|
);
|
||||||
if (hasAllRequired && !now.includes("all")) {
|
if (hasAllRequired && !now.includes("all")) {
|
||||||
now.push("all");
|
now.push("all");
|
||||||
}
|
}
|
||||||
|
|
@ -966,8 +989,8 @@ export default function FormTeksUpdate() {
|
||||||
} else {
|
} else {
|
||||||
if (placement === "wilayah") {
|
if (placement === "wilayah") {
|
||||||
// Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker
|
// Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker
|
||||||
const now = temp[index]?.filter((a) =>
|
const now = temp[index]?.filter(
|
||||||
a !== "wilayah" && a !== "polda" && a !== "satker"
|
(a) => a !== "wilayah" && a !== "polda" && a !== "satker"
|
||||||
);
|
);
|
||||||
temp[index] = now;
|
temp[index] = now;
|
||||||
} else if (placement === "polda") {
|
} else if (placement === "polda") {
|
||||||
|
|
@ -986,16 +1009,18 @@ export default function FormTeksUpdate() {
|
||||||
} else if (placement === "semua") {
|
} else if (placement === "semua") {
|
||||||
placementToRemove = "all";
|
placementToRemove = "all";
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = temp[index]?.filter((a) => a !== placementToRemove);
|
const now = temp[index]?.filter((a) => a !== placementToRemove);
|
||||||
temp[index] = now;
|
temp[index] = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hapus "all" jika tidak semua item ter-checklist
|
// Hapus "all" jika tidak semua item ter-checklist
|
||||||
const currentNow = temp[index] || [];
|
const currentNow = temp[index] || [];
|
||||||
if (currentNow.includes("all")) {
|
if (currentNow.includes("all")) {
|
||||||
const requiredItems = ["mabes", "wilayah", "international"];
|
const requiredItems = ["mabes", "wilayah", "international"];
|
||||||
const hasAllRequired = requiredItems.every(item => currentNow.includes(item));
|
const hasAllRequired = requiredItems.every((item) =>
|
||||||
|
currentNow.includes(item)
|
||||||
|
);
|
||||||
if (!hasAllRequired) {
|
if (!hasAllRequired) {
|
||||||
const newData = currentNow.filter((b) => b !== "all");
|
const newData = currentNow.filter((b) => b !== "all");
|
||||||
temp[index] = newData;
|
temp[index] = newData;
|
||||||
|
|
@ -1107,27 +1132,33 @@ export default function FormTeksUpdate() {
|
||||||
setFiles(formattedFiles);
|
setFiles(formattedFiles);
|
||||||
|
|
||||||
// Inisialisasi filePlacements dari detail (biarkan format backend, normalisasi dilakukan saat submit)
|
// Inisialisasi filePlacements dari detail (biarkan format backend, normalisasi dilakukan saat submit)
|
||||||
const initialFilePlacements: string[][] = details.files.map((file: any) => {
|
const initialFilePlacements: string[][] = details.files.map(
|
||||||
if (file.placements) {
|
(file: any) => {
|
||||||
return file.placements.split(",").map((p: string) => p.trim());
|
if (file.placements) {
|
||||||
|
return file.placements.split(",").map((p: string) => p.trim());
|
||||||
|
}
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
return [];
|
);
|
||||||
});
|
|
||||||
setFilePlacements(initialFilePlacements);
|
setFilePlacements(initialFilePlacements);
|
||||||
|
|
||||||
// Inisialisasi fileCheckedLevels dari detail
|
// Inisialisasi fileCheckedLevels dari detail
|
||||||
const initialFileCheckedLevels: Set<number>[] = details.files.map((file: any) => {
|
const initialFileCheckedLevels: Set<number>[] = details.files.map(
|
||||||
const checkedLevels = new Set<number>();
|
(file: any) => {
|
||||||
if (file.customLocationPlacements) {
|
const checkedLevels = new Set<number>();
|
||||||
const levelIds = file.customLocationPlacements.split(",").map((id: string) => Number(id.trim()));
|
if (file.customLocationPlacements) {
|
||||||
levelIds.forEach((id: number) => {
|
const levelIds = file.customLocationPlacements
|
||||||
if (!isNaN(id)) {
|
.split(",")
|
||||||
checkedLevels.add(id);
|
.map((id: string) => Number(id.trim()));
|
||||||
}
|
levelIds.forEach((id: number) => {
|
||||||
});
|
if (!isNaN(id)) {
|
||||||
|
checkedLevels.add(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return checkedLevels;
|
||||||
}
|
}
|
||||||
return checkedLevels;
|
);
|
||||||
});
|
|
||||||
setFileCheckedLevels(initialFileCheckedLevels);
|
setFileCheckedLevels(initialFileCheckedLevels);
|
||||||
|
|
||||||
// Inisialisasi fileUnitSelections dari detail
|
// Inisialisasi fileUnitSelections dari detail
|
||||||
|
|
@ -1142,7 +1173,9 @@ export default function FormTeksUpdate() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (file.placements) {
|
if (file.placements) {
|
||||||
const placements = file.placements.split(",").map((p: string) => p.trim());
|
const placements = file.placements
|
||||||
|
.split(",")
|
||||||
|
.map((p: string) => p.trim());
|
||||||
|
|
||||||
if (placements.includes("all")) {
|
if (placements.includes("all")) {
|
||||||
selection.semua = true;
|
selection.semua = true;
|
||||||
|
|
@ -1153,7 +1186,8 @@ export default function FormTeksUpdate() {
|
||||||
selection.satker = true;
|
selection.satker = true;
|
||||||
} else {
|
} else {
|
||||||
if (placements.includes("mabes")) selection.nasional = true;
|
if (placements.includes("mabes")) selection.nasional = true;
|
||||||
if (placements.includes("international")) selection.international = true;
|
if (placements.includes("international"))
|
||||||
|
selection.international = true;
|
||||||
if (placements.includes("polda")) selection.polda = true;
|
if (placements.includes("polda")) selection.polda = true;
|
||||||
if (placements.includes("satker")) selection.satker = true;
|
if (placements.includes("satker")) selection.satker = true;
|
||||||
// Wilayah aktif jika ada "wilayah" ATAU ada polda/satker
|
// Wilayah aktif jika ada "wilayah" ATAU ada polda/satker
|
||||||
|
|
@ -1195,7 +1229,6 @@ export default function FormTeksUpdate() {
|
||||||
initState();
|
initState();
|
||||||
}, [refresh, setValue]);
|
}, [refresh, setValue]);
|
||||||
|
|
||||||
|
|
||||||
const handleCheckboxChange = (id: string) => {
|
const handleCheckboxChange = (id: string) => {
|
||||||
if (id === "all") {
|
if (id === "all") {
|
||||||
// Select all options except "all"
|
// Select all options except "all"
|
||||||
|
|
@ -1216,12 +1249,19 @@ export default function FormTeksUpdate() {
|
||||||
const save = async (data: TeksSchema) => {
|
const save = async (data: TeksSchema) => {
|
||||||
loading();
|
loading();
|
||||||
const finalTags = tags.join(", ");
|
const finalTags = tags.join(", ");
|
||||||
|
|
||||||
|
// ✅ tentukan isi description sesuai pilihan bahasa
|
||||||
|
const descFinal =
|
||||||
|
selectedLang === "en" && translatedContent
|
||||||
|
? translatedContent
|
||||||
|
: data.description;
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
...data,
|
...data,
|
||||||
id: detail?.id,
|
id: detail?.id,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: htmlToString(data.description),
|
description: htmlToString(descFinal), // plain text
|
||||||
htmlDescription: data.description,
|
htmlDescription: descFinal, // HTML (dipakai di editor/preview)
|
||||||
fileTypeId,
|
fileTypeId,
|
||||||
categoryId: selectedTarget,
|
categoryId: selectedTarget,
|
||||||
subCategoryId: selectedTarget,
|
subCategoryId: selectedTarget,
|
||||||
|
|
@ -1456,7 +1496,6 @@ export default function FormTeksUpdate() {
|
||||||
</div>
|
</div>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === "Enter" && e.currentTarget.value.trim()) {
|
if (e.key === "Enter" && e.currentTarget.value.trim()) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
@ -1552,7 +1591,107 @@ export default function FormTeksUpdate() {
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="py-3 space-y-2">
|
<div className="py-3 space-y-2">
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
<Label>
|
||||||
|
{t("description", { defaultValue: "Description" })}
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
{roleId === "14" && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
loading();
|
||||||
|
setIsLoadingTranslate(true);
|
||||||
|
const res = await translateText({
|
||||||
|
text: getValues("description"),
|
||||||
|
sourceLang: "ID",
|
||||||
|
targetLang: "EN",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.error) {
|
||||||
|
const resultText =
|
||||||
|
res?.data?.data?.translations?.[0]?.text || "";
|
||||||
|
|
||||||
|
setTranslatedContent(resultText);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
close();
|
||||||
|
console.error("Translate gagal:", err);
|
||||||
|
} finally {
|
||||||
|
close();
|
||||||
|
setIsLoadingTranslate(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="px-3 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600"
|
||||||
|
>
|
||||||
|
{isLoadingTranslate
|
||||||
|
? "Translating..."
|
||||||
|
: "Translate to English"}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Pilihan bahasa untuk posting */}
|
||||||
|
{roleId === "14" && (
|
||||||
|
<div className="flex items-center gap-4 mb-2">
|
||||||
|
<label className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="id"
|
||||||
|
checked={selectedLang === "id"}
|
||||||
|
onChange={() => setSelectedLang("id")}
|
||||||
|
/>
|
||||||
|
<span>Gunakan Bahasa Indonesia</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Editor Bahasa Indonesia */}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<CustomEditor
|
||||||
|
onChange={field.onChange}
|
||||||
|
initialData={field.value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Editor Bahasa Inggris */}
|
||||||
|
{translatedContent && (
|
||||||
|
<div className="mt-4">
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<Label className="text-[15px]">English Version</Label>
|
||||||
|
<label className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="en"
|
||||||
|
checked={selectedLang === "en"}
|
||||||
|
onChange={() => setSelectedLang("en")}
|
||||||
|
disabled={!translatedContent}
|
||||||
|
/>
|
||||||
|
<span>Gunakan Bahasa Inggris</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CustomEditor
|
||||||
|
onChange={(val: any) => setTranslatedContent(val)}
|
||||||
|
initialData={translatedContent}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{errors.description?.message && (
|
||||||
|
<p className="text-red-400 text-sm">
|
||||||
|
{errors.description.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{/* <div className="py-3 space-y-2">
|
||||||
<Label>
|
<Label>
|
||||||
{t("description", { defaultValue: "Description" })}
|
{t("description", { defaultValue: "Description" })}
|
||||||
</Label>
|
</Label>
|
||||||
|
|
@ -1568,7 +1707,7 @@ export default function FormTeksUpdate() {
|
||||||
{errors.description.message}
|
{errors.description.message}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div> */}
|
||||||
<div className="py-3 space-y-2">
|
<div className="py-3 space-y-2">
|
||||||
<Label>
|
<Label>
|
||||||
{t("select-file", { defaultValue: "Select File" })}
|
{t("select-file", { defaultValue: "Select File" })}
|
||||||
|
|
@ -1669,7 +1808,9 @@ export default function FormTeksUpdate() {
|
||||||
<Checkbox
|
<Checkbox
|
||||||
// id={`${item.key}-${index}`}
|
// id={`${item.key}-${index}`}
|
||||||
checked={
|
checked={
|
||||||
fileUnitSelections[files.indexOf(file)]?.[
|
fileUnitSelections[
|
||||||
|
files.indexOf(file)
|
||||||
|
]?.[
|
||||||
item.key as keyof typeof unitSelection
|
item.key as keyof typeof unitSelection
|
||||||
] || false
|
] || false
|
||||||
}
|
}
|
||||||
|
|
@ -1691,268 +1832,305 @@ export default function FormTeksUpdate() {
|
||||||
className="text-sm font-medium cursor-pointer"
|
className="text-sm font-medium cursor-pointer"
|
||||||
>
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Detail Wilayah */}
|
{/* Detail Wilayah */}
|
||||||
{fileUnitSelections[files.indexOf(file)]?.wilayah && isDetailOfRegionShowed && (
|
{fileUnitSelections[files.indexOf(file)]
|
||||||
<div className="border-t border-gray-200 pt-2">
|
?.wilayah &&
|
||||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
isDetailOfRegionShowed && (
|
||||||
Detail Wilayah:
|
<div className="border-t border-gray-200 pt-2">
|
||||||
</p>
|
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||||
|
Detail Wilayah:
|
||||||
|
</p>
|
||||||
|
|
||||||
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||||
{[
|
{[
|
||||||
{ key: "polda", label: "POLDA" },
|
{ key: "polda", label: "POLDA" },
|
||||||
{ key: "satker", label: "SATKER" },
|
{
|
||||||
].map((item, idx) => (
|
key: "satker",
|
||||||
<div
|
label: "SATKER",
|
||||||
key={item.key}
|
},
|
||||||
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
].map((item, idx) => (
|
||||||
>
|
<div
|
||||||
<Checkbox
|
key={item.key}
|
||||||
id={`${item.key}-${index}`}
|
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
checked={
|
|
||||||
fileUnitSelections[files.indexOf(file)]?.[
|
|
||||||
item.key as keyof typeof unitSelection
|
|
||||||
] || false
|
|
||||||
}
|
|
||||||
onCheckedChange={(value) => {
|
|
||||||
handleFileUnitChange(
|
|
||||||
files.indexOf(file),
|
|
||||||
item.key as keyof typeof unitSelection,
|
|
||||||
value as boolean
|
|
||||||
);
|
|
||||||
setupPlacement(
|
|
||||||
files.indexOf(file),
|
|
||||||
item.key as keyof typeof unitSelection,
|
|
||||||
Boolean(value)
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Label
|
|
||||||
htmlFor={`${item.key}-${index}`}
|
|
||||||
className="text-sm font-medium cursor-pointer"
|
|
||||||
>
|
>
|
||||||
{item.label}
|
<Checkbox
|
||||||
</Label>
|
id={`${item.key}-${index}`}
|
||||||
</div>
|
checked={
|
||||||
))}
|
fileUnitSelections[
|
||||||
|
files.indexOf(file)
|
||||||
{/* Tombol Kustom sejajar dengan checkbox */}
|
]?.[
|
||||||
<div className="flex items-center justify-center p-3">
|
item.key as keyof typeof unitSelection
|
||||||
<Dialog>
|
] || false
|
||||||
<DialogTrigger asChild>
|
}
|
||||||
<Button
|
onCheckedChange={(value) => {
|
||||||
variant="outline"
|
handleFileUnitChange(
|
||||||
size="sm"
|
files.indexOf(file),
|
||||||
className="gap-2"
|
item.key as keyof typeof unitSelection,
|
||||||
|
value as boolean
|
||||||
|
);
|
||||||
|
setupPlacement(
|
||||||
|
files.indexOf(file),
|
||||||
|
item.key as keyof typeof unitSelection,
|
||||||
|
Boolean(value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${item.key}-${index}`}
|
||||||
|
className="text-sm font-medium cursor-pointer"
|
||||||
>
|
>
|
||||||
<Icon
|
{item.label}
|
||||||
icon="material-symbols:tune"
|
</Label>
|
||||||
width={16}
|
</div>
|
||||||
height={16}
|
))}
|
||||||
/>
|
|
||||||
{t("custom", {
|
|
||||||
defaultValue: "Kustom",
|
|
||||||
})}
|
|
||||||
</Button>
|
|
||||||
</DialogTrigger>
|
|
||||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
|
||||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
|
||||||
<DialogTitle className="text-lg font-semibold">
|
|
||||||
Daftar Wilayah POLDA dan SATKER
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
|
||||||
{listDest.map(
|
|
||||||
(polda: any) => (
|
|
||||||
<div
|
|
||||||
key={polda.id}
|
|
||||||
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
|
||||||
>
|
|
||||||
{/* Header POLDA */}
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
|
||||||
<Checkbox
|
|
||||||
checked={
|
|
||||||
fileCheckedLevels[
|
|
||||||
files.indexOf(file)
|
|
||||||
]?.has(
|
|
||||||
Number(
|
|
||||||
polda.id
|
|
||||||
)
|
|
||||||
) || false
|
|
||||||
}
|
|
||||||
onCheckedChange={() =>
|
|
||||||
handleFileCheckboxChangePlacement(
|
|
||||||
files.indexOf(file),
|
|
||||||
Number(polda.id)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span className="font-semibold text-gray-900 text-sm">
|
|
||||||
{polda.name}
|
|
||||||
</span>
|
|
||||||
</Label>
|
|
||||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
|
||||||
{polda.name === "SATKER POLRI" && polda.subDestination && (
|
|
||||||
<button
|
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
toggleExpand(
|
|
||||||
Number(polda.id)
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
icon={
|
|
||||||
expandedPolda[Number(polda.id)]
|
|
||||||
? "mdi:chevron-up"
|
|
||||||
: "mdi:chevron-down"
|
|
||||||
}
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
{/* Tombol Kustom sejajar dengan checkbox */}
|
||||||
{polda.name === "SATKER POLRI" && polda.subDestination &&
|
<div className="flex items-center justify-center p-3">
|
||||||
expandedPolda[Number(polda.id)] && (
|
<Dialog>
|
||||||
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
<DialogTrigger asChild>
|
||||||
{/* Tombol Pilih Semua untuk sub-items */}
|
<Button
|
||||||
<div className="mb-2 flex justify-start">
|
variant="outline"
|
||||||
{(() => {
|
size="sm"
|
||||||
const allSubItemsChecked =
|
className="gap-2"
|
||||||
polda.subDestination?.every(
|
>
|
||||||
(
|
<Icon
|
||||||
sub: any
|
icon="material-symbols:tune"
|
||||||
) =>
|
width={16}
|
||||||
fileCheckedLevels[
|
height={16}
|
||||||
files.indexOf(file)
|
/>
|
||||||
]?.has(
|
{t("custom", {
|
||||||
Number(
|
defaultValue: "Kustom",
|
||||||
sub.id
|
})}
|
||||||
)
|
</Button>
|
||||||
)
|
</DialogTrigger>
|
||||||
|
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||||
|
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||||
|
<DialogTitle className="text-lg font-semibold">
|
||||||
|
Daftar Wilayah POLDA dan
|
||||||
|
SATKER
|
||||||
|
</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||||
|
{listDest.map(
|
||||||
|
(polda: any) => (
|
||||||
|
<div
|
||||||
|
key={polda.id}
|
||||||
|
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
||||||
|
>
|
||||||
|
{/* Header POLDA */}
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
||||||
|
<Checkbox
|
||||||
|
checked={
|
||||||
|
fileCheckedLevels[
|
||||||
|
files.indexOf(
|
||||||
|
file
|
||||||
|
)
|
||||||
|
]?.has(
|
||||||
|
Number(
|
||||||
|
polda.id
|
||||||
|
)
|
||||||
|
) || false
|
||||||
|
}
|
||||||
|
onCheckedChange={() =>
|
||||||
|
handleFileCheckboxChangePlacement(
|
||||||
|
files.indexOf(
|
||||||
|
file
|
||||||
|
),
|
||||||
|
Number(
|
||||||
|
polda.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span className="font-semibold text-gray-900 text-sm">
|
||||||
|
{polda.name}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||||
|
{polda.name ===
|
||||||
|
"SATKER POLRI" &&
|
||||||
|
polda.subDestination && (
|
||||||
|
<button
|
||||||
|
onClick={(
|
||||||
|
e
|
||||||
|
) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
toggleExpand(
|
||||||
|
Number(
|
||||||
|
polda.id
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return (
|
}}
|
||||||
<Button
|
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
||||||
size="sm"
|
>
|
||||||
variant="outline"
|
<Icon
|
||||||
className="text-xs h-6 px-2"
|
icon={
|
||||||
onClick={() =>
|
expandedPolda[
|
||||||
handleSelectAllSubItems(
|
Number(
|
||||||
files.indexOf(file),
|
polda.id
|
||||||
polda
|
|
||||||
)
|
)
|
||||||
}
|
]
|
||||||
>
|
? "mdi:chevron-up"
|
||||||
{allSubItemsChecked ? (
|
: "mdi:chevron-down"
|
||||||
<>
|
}
|
||||||
<Icon
|
width={16}
|
||||||
icon="material-symbols:check-indeterminate-small"
|
height={16}
|
||||||
width={
|
/>
|
||||||
12
|
</button>
|
||||||
}
|
)}
|
||||||
height={
|
</div>
|
||||||
12
|
|
||||||
}
|
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||||
className="mr-1"
|
{polda.name ===
|
||||||
/>
|
"SATKER POLRI" &&
|
||||||
Batal
|
polda.subDestination &&
|
||||||
Semua
|
expandedPolda[
|
||||||
</>
|
Number(polda.id)
|
||||||
) : (
|
] && (
|
||||||
<>
|
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
||||||
<Icon
|
{/* Tombol Pilih Semua untuk sub-items */}
|
||||||
icon="material-symbols:check-all"
|
<div className="mb-2 flex justify-start">
|
||||||
width={
|
{(() => {
|
||||||
12
|
const allSubItemsChecked =
|
||||||
}
|
polda.subDestination?.every(
|
||||||
height={
|
(
|
||||||
12
|
sub: any
|
||||||
}
|
) =>
|
||||||
className="mr-1"
|
|
||||||
/>
|
|
||||||
Pilih
|
|
||||||
Semua
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1">
|
|
||||||
{polda.subDestination.map(
|
|
||||||
(
|
|
||||||
sub: any
|
|
||||||
) => (
|
|
||||||
<Label
|
|
||||||
key={
|
|
||||||
sub.id
|
|
||||||
}
|
|
||||||
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
|
||||||
>
|
|
||||||
<Checkbox
|
|
||||||
checked={
|
|
||||||
fileCheckedLevels[
|
fileCheckedLevels[
|
||||||
files.indexOf(file)
|
files.indexOf(
|
||||||
|
file
|
||||||
|
)
|
||||||
]?.has(
|
]?.has(
|
||||||
Number(
|
Number(
|
||||||
sub.id
|
sub.id
|
||||||
)
|
)
|
||||||
) ||
|
)
|
||||||
false
|
);
|
||||||
}
|
return (
|
||||||
onCheckedChange={() =>
|
<Button
|
||||||
handleFileCheckboxChangePlacement(
|
size="sm"
|
||||||
files.indexOf(file),
|
variant="outline"
|
||||||
Number(sub.id)
|
className="text-xs h-6 px-2"
|
||||||
|
onClick={() =>
|
||||||
|
handleSelectAllSubItems(
|
||||||
|
files.indexOf(
|
||||||
|
file
|
||||||
|
),
|
||||||
|
polda
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
>
|
||||||
<span className="text-gray-700">
|
{allSubItemsChecked ? (
|
||||||
{
|
<>
|
||||||
sub.name
|
<Icon
|
||||||
|
icon="material-symbols:check-indeterminate-small"
|
||||||
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
height={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
className="mr-1"
|
||||||
|
/>
|
||||||
|
Batal
|
||||||
|
Semua
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Icon
|
||||||
|
icon="material-symbols:check-all"
|
||||||
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
height={
|
||||||
|
12
|
||||||
|
}
|
||||||
|
className="mr-1"
|
||||||
|
/>
|
||||||
|
Pilih
|
||||||
|
Semua
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
{polda.subDestination.map(
|
||||||
|
(
|
||||||
|
sub: any
|
||||||
|
) => (
|
||||||
|
<Label
|
||||||
|
key={
|
||||||
|
sub.id
|
||||||
}
|
}
|
||||||
</span>
|
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
||||||
</Label>
|
>
|
||||||
)
|
<Checkbox
|
||||||
)}
|
checked={
|
||||||
|
fileCheckedLevels[
|
||||||
|
files.indexOf(
|
||||||
|
file
|
||||||
|
)
|
||||||
|
]?.has(
|
||||||
|
Number(
|
||||||
|
sub.id
|
||||||
|
)
|
||||||
|
) ||
|
||||||
|
false
|
||||||
|
}
|
||||||
|
onCheckedChange={() =>
|
||||||
|
handleFileCheckboxChangePlacement(
|
||||||
|
files.indexOf(
|
||||||
|
file
|
||||||
|
),
|
||||||
|
Number(
|
||||||
|
sub.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span className="text-gray-700">
|
||||||
|
{
|
||||||
|
sub.name
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
</div>
|
||||||
|
)
|
||||||
</div>
|
)}
|
||||||
)
|
</div>
|
||||||
)}
|
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
||||||
</div>
|
<DialogClose asChild>
|
||||||
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
<Button variant="outline">
|
||||||
<DialogClose asChild>
|
{t("cancel", {
|
||||||
<Button variant="outline">
|
defaultValue: "Batal",
|
||||||
{t("cancel", {
|
})}
|
||||||
defaultValue: "Batal",
|
</Button>
|
||||||
})}
|
</DialogClose>
|
||||||
</Button>
|
<DialogClose asChild>
|
||||||
</DialogClose>
|
<Button>Simpan</Button>
|
||||||
<DialogClose asChild>
|
</DialogClose>
|
||||||
<Button>Simpan</Button>
|
</div>
|
||||||
</DialogClose>
|
</DialogContent>
|
||||||
</div>
|
</Dialog>
|
||||||
</DialogContent>
|
</div>
|
||||||
</Dialog>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -549,6 +549,15 @@ export default function FormVideo() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 👉 tempelkan hasil translate ke form agar ikut terkirim
|
||||||
|
if (translatedContent) {
|
||||||
|
data.descriptionOri = translatedContent;
|
||||||
|
console.log(
|
||||||
|
"🌍 Translate dimasukkan ke descriptionOri:",
|
||||||
|
translatedContent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let requestData: {
|
let requestData: {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue