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 Swal from "sweetalert2";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "@/i18n/routing";
|
||||
|
||||
const useTableColumns = () => {
|
||||
const t = useTranslations("Table");
|
||||
|
|
@ -181,14 +182,11 @@ const useTableColumns = () => {
|
|||
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 data = { id };
|
||||
const response = await deleteMedia(data);
|
||||
|
||||
if (response?.error) {
|
||||
|
|
@ -230,16 +228,21 @@ const useTableColumns = () => {
|
|||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||
const userId = getCookiesDecrypt("uie");
|
||||
const userLevelId = getCookiesDecrypt("ulie");
|
||||
const roleId = getCookiesDecrypt("urie");
|
||||
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||
|
||||
React.useEffect(() => {
|
||||
if (userLevelId !== undefined && roleId !== undefined) {
|
||||
setIsMabesApprover(
|
||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
||||
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||
);
|
||||
}
|
||||
}, [userLevelId, roleId]);
|
||||
|
||||
const canEdit =
|
||||
Number(row.original.uploadedById) === Number(userId) ||
|
||||
isMabesApprover ||
|
||||
roleId === 14;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
|
@ -260,16 +263,8 @@ const useTableColumns = () => {
|
|||
View
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
{/* <Link
|
||||
href={`/contributor/content/audio/update/${row.original.id}`}
|
||||
>
|
||||
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
||||
<SquarePen className="w-4 h-4 me-1.5" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
</Link> */}
|
||||
{(Number(row.original.uploadedById) === Number(userId) ||
|
||||
isMabesApprover) && (
|
||||
|
||||
{canEdit && (
|
||||
<Link
|
||||
href={`/contributor/content/audio/update/${row.original.id}`}
|
||||
>
|
||||
|
|
@ -279,6 +274,7 @@ const useTableColumns = () => {
|
|||
</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"
|
||||
|
|
@ -286,15 +282,6 @@ const useTableColumns = () => {
|
|||
<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>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -186,11 +186,7 @@ const useTableColumns = () => {
|
|||
const MySwal = withReactContent(Swal);
|
||||
|
||||
async function doDelete(id: any) {
|
||||
// loading();
|
||||
const data = {
|
||||
id,
|
||||
};
|
||||
|
||||
const data = { id };
|
||||
const response = await deleteMedia(data);
|
||||
|
||||
if (response?.error) {
|
||||
|
|
@ -232,16 +228,21 @@ const useTableColumns = () => {
|
|||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||
const userId = getCookiesDecrypt("uie");
|
||||
const userLevelId = getCookiesDecrypt("ulie");
|
||||
const roleId = getCookiesDecrypt("urie");
|
||||
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||
|
||||
React.useEffect(() => {
|
||||
if (userLevelId !== undefined && roleId !== undefined) {
|
||||
setIsMabesApprover(
|
||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
||||
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||
);
|
||||
}
|
||||
}, [userLevelId, roleId]);
|
||||
|
||||
const canEdit =
|
||||
Number(row.original.uploadedById) === Number(userId) ||
|
||||
isMabesApprover ||
|
||||
roleId === 14;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
|
@ -262,16 +263,8 @@ const useTableColumns = () => {
|
|||
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) && (
|
||||
|
||||
{canEdit && (
|
||||
<Link
|
||||
href={`/contributor/content/image/update/${row.original.id}`}
|
||||
>
|
||||
|
|
@ -281,6 +274,7 @@ const useTableColumns = () => {
|
|||
</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"
|
||||
|
|
@ -288,20 +282,138 @@ const useTableColumns = () => {
|
|||
<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>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
// {
|
||||
// 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;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { deleteMedia } from "@/service/content/content";
|
|||
import withReactContent from "sweetalert2-react-content";
|
||||
import Swal from "sweetalert2";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "@/i18n/routing";
|
||||
|
||||
const useTableColumns = () => {
|
||||
const t = useTranslations("Table");
|
||||
|
|
@ -176,20 +177,18 @@ const useTableColumns = () => {
|
|||
);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
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 data = { id };
|
||||
const response = await deleteMedia(data);
|
||||
|
||||
if (response?.error) {
|
||||
|
|
@ -231,16 +230,21 @@ const useTableColumns = () => {
|
|||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||
const userId = getCookiesDecrypt("uie");
|
||||
const userLevelId = getCookiesDecrypt("ulie");
|
||||
const roleId = getCookiesDecrypt("urie");
|
||||
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||
|
||||
React.useEffect(() => {
|
||||
if (userLevelId !== undefined && roleId !== undefined) {
|
||||
setIsMabesApprover(
|
||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
||||
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||
);
|
||||
}
|
||||
}, [userLevelId, roleId]);
|
||||
|
||||
const canEdit =
|
||||
Number(row.original.uploadedById) === Number(userId) ||
|
||||
isMabesApprover ||
|
||||
roleId === 14;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
|
@ -261,8 +265,8 @@ const useTableColumns = () => {
|
|||
View
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
{(Number(row.original.uploadedById) === Number(userId) ||
|
||||
isMabesApprover) && (
|
||||
|
||||
{canEdit && (
|
||||
<Link
|
||||
href={`/contributor/content/teks/update/${row.original.id}`}
|
||||
>
|
||||
|
|
@ -272,14 +276,7 @@ const useTableColumns = () => {
|
|||
</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"
|
||||
|
|
@ -287,20 +284,136 @@ const useTableColumns = () => {
|
|||
<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>
|
||||
);
|
||||
},
|
||||
},
|
||||
// {
|
||||
// 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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import Swal from "sweetalert2";
|
|||
import withReactContent from "sweetalert2-react-content";
|
||||
import { error } from "@/lib/swal";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "@/i18n/routing";
|
||||
|
||||
const useTableColumns = () => {
|
||||
const t = useTranslations("Table");
|
||||
|
|
@ -176,20 +177,18 @@ const useTableColumns = () => {
|
|||
);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
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 data = { id };
|
||||
const response = await deleteMedia(data);
|
||||
|
||||
if (response?.error) {
|
||||
|
|
@ -231,16 +230,21 @@ const useTableColumns = () => {
|
|||
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
||||
const userId = getCookiesDecrypt("uie");
|
||||
const userLevelId = getCookiesDecrypt("ulie");
|
||||
const roleId = getCookiesDecrypt("urie");
|
||||
const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number
|
||||
|
||||
React.useEffect(() => {
|
||||
if (userLevelId !== undefined && roleId !== undefined) {
|
||||
setIsMabesApprover(
|
||||
Number(userLevelId) == 216 && Number(roleId) == 3
|
||||
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||
);
|
||||
}
|
||||
}, [userLevelId, roleId]);
|
||||
|
||||
const canEdit =
|
||||
Number(row.original.uploadedById) === Number(userId) ||
|
||||
isMabesApprover ||
|
||||
roleId === 14;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
|
@ -261,16 +265,8 @@ const useTableColumns = () => {
|
|||
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) && (
|
||||
|
||||
{canEdit && (
|
||||
<Link
|
||||
href={`/contributor/content/video/update/${row.original.id}`}
|
||||
>
|
||||
|
|
@ -280,6 +276,7 @@ const useTableColumns = () => {
|
|||
</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"
|
||||
|
|
@ -287,20 +284,136 @@ const useTableColumns = () => {
|
|||
<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>
|
||||
);
|
||||
},
|
||||
},
|
||||
// {
|
||||
// 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;
|
||||
|
|
|
|||
|
|
@ -523,15 +523,120 @@ export default function FormAudio() {
|
|||
}
|
||||
}, [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) => {
|
||||
loading();
|
||||
const finalTags = tags.join(", ");
|
||||
const finalTitle = isSwitchOn ? title : data.title;
|
||||
const finalDescription = isSwitchOn
|
||||
|
||||
// pilih description dasar
|
||||
let finalDescription = isSwitchOn
|
||||
? data.description
|
||||
: selectedFileType === "rewrite"
|
||||
? data.rewriteDescription
|
||||
: 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()) {
|
||||
MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error");
|
||||
return;
|
||||
|
|
@ -555,8 +660,8 @@ export default function FormAudio() {
|
|||
} = {
|
||||
...data,
|
||||
title: finalTitle,
|
||||
description: htmlToString(finalDescription),
|
||||
htmlDescription: finalDescription,
|
||||
description: htmlToString(finalDescription), // ✅ plain text versi translate
|
||||
htmlDescription: finalDescription, // ✅ html versi translate
|
||||
fileTypeId,
|
||||
categoryId: selectedCategory,
|
||||
subCategoryId: selectedCategory,
|
||||
|
|
@ -583,6 +688,7 @@ export default function FormAudio() {
|
|||
MySwal.fire("Error", response?.message, "error");
|
||||
return;
|
||||
}
|
||||
|
||||
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
||||
id = response?.data?.data;
|
||||
|
||||
|
|
@ -596,10 +702,10 @@ export default function FormAudio() {
|
|||
}
|
||||
}
|
||||
|
||||
const progressInfoArr = [];
|
||||
for (const item of files) {
|
||||
progressInfoArr.push({ percentage: 0, fileName: item.name });
|
||||
}
|
||||
const progressInfoArr = files.map((item) => ({
|
||||
percentage: 0,
|
||||
fileName: item.name,
|
||||
}));
|
||||
progressInfo = progressInfoArr;
|
||||
setIsStartUpload(true);
|
||||
setProgressList(progressInfoArr);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ import {
|
|||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
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({
|
||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||
|
|
@ -135,24 +138,20 @@ const CustomEditor = dynamic(
|
|||
export default function FormAudioUpdate() {
|
||||
const MySwal = withReactContent(Swal);
|
||||
const router = useRouter();
|
||||
|
||||
const { id } = useParams() as { id: string };
|
||||
console.log(id);
|
||||
const editor = useRef(null);
|
||||
type AudioSchema = z.infer<typeof audioSchema>;
|
||||
|
||||
let progressInfo: any = [];
|
||||
let counterUpdateProgress = 0;
|
||||
const [progressList, setProgressList] = useState<any>([]);
|
||||
let uploadPersen = 0;
|
||||
const [isStartUpload, setIsStartUpload] = useState(false);
|
||||
const [counterProgress, setCounterProgress] = useState(0);
|
||||
|
||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||
const taskId = Cookies.get("taskId");
|
||||
const scheduleId = Cookies.get("scheduleId");
|
||||
const scheduleType = Cookies.get("scheduleType");
|
||||
|
||||
const t = useTranslations("Form");
|
||||
const [categories, setCategories] = useState<Category[]>([]);
|
||||
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||
|
|
@ -198,6 +197,11 @@ export default function FormAudioUpdate() {
|
|||
const [mainCheckboxChangeType, setMainCheckboxChangeType] =
|
||||
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[] = [
|
||||
{ id: "all", name: "SEMUA" },
|
||||
{ id: "5", name: "UMUM" },
|
||||
|
|
@ -234,6 +238,7 @@ export default function FormAudioUpdate() {
|
|||
control,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useForm<AudioSchema>({
|
||||
resolver: zodResolver(audioSchema),
|
||||
|
|
@ -535,7 +540,9 @@ export default function FormAudioUpdate() {
|
|||
});
|
||||
|
||||
// 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) {
|
||||
currentFileLevels.add(Number(satkerItem.id));
|
||||
// Checklist semua sub-items di bawah SATKER POLRI
|
||||
|
|
@ -569,7 +576,9 @@ export default function FormAudioUpdate() {
|
|||
});
|
||||
|
||||
// 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) {
|
||||
currentFileLevels.delete(Number(satkerItem.id));
|
||||
// Hapus semua sub-items di bawah SATKER POLRI
|
||||
|
|
@ -763,7 +772,11 @@ export default function FormAudioUpdate() {
|
|||
const temp = [];
|
||||
for (let i = 0; i < filePlacements?.length; i++) {
|
||||
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 normalizedNow = now.map((item): PlacementType => {
|
||||
const value = String(item);
|
||||
|
|
@ -880,7 +893,9 @@ export default function FormAudioUpdate() {
|
|||
}
|
||||
// Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist
|
||||
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")) {
|
||||
now.push("all");
|
||||
}
|
||||
|
|
@ -923,8 +938,8 @@ export default function FormAudioUpdate() {
|
|||
} else {
|
||||
if (placement === "wilayah") {
|
||||
// Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker
|
||||
const now = temp[index]?.filter((a) =>
|
||||
a !== "wilayah" && a !== "polda" && a !== "satker"
|
||||
const now = temp[index]?.filter(
|
||||
(a) => a !== "wilayah" && a !== "polda" && a !== "satker"
|
||||
);
|
||||
temp[index] = now;
|
||||
} else if (placement === "polda") {
|
||||
|
|
@ -952,7 +967,9 @@ export default function FormAudioUpdate() {
|
|||
const currentNow = temp[index] || [];
|
||||
if (currentNow.includes("all")) {
|
||||
const requiredItems = ["mabes", "wilayah", "international"];
|
||||
const hasAllRequired = requiredItems.every(item => currentNow.includes(item));
|
||||
const hasAllRequired = requiredItems.every((item) =>
|
||||
currentNow.includes(item)
|
||||
);
|
||||
if (!hasAllRequired) {
|
||||
const newData = currentNow.filter((b) => b !== "all");
|
||||
temp[index] = newData;
|
||||
|
|
@ -1073,12 +1090,18 @@ export default function FormAudioUpdate() {
|
|||
.map((p: string) => {
|
||||
const trimmed = p.trim();
|
||||
switch (trimmed) {
|
||||
case "all": return "all";
|
||||
case "mabes": return "nasional";
|
||||
case "polda": return "wilayah";
|
||||
case "satker": return "satker";
|
||||
case "international": return "international";
|
||||
default: return trimmed;
|
||||
case "all":
|
||||
return "all";
|
||||
case "mabes":
|
||||
return "nasional";
|
||||
case "polda":
|
||||
return "wilayah";
|
||||
case "satker":
|
||||
return "satker";
|
||||
case "international":
|
||||
return "international";
|
||||
default:
|
||||
return trimmed;
|
||||
}
|
||||
});
|
||||
return mappedPlacements;
|
||||
|
|
@ -1112,7 +1135,9 @@ export default function FormAudioUpdate() {
|
|||
};
|
||||
|
||||
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
|
||||
if (placements.includes("all")) {
|
||||
|
|
@ -1177,7 +1202,6 @@ export default function FormAudioUpdate() {
|
|||
initState();
|
||||
}, [refresh, setValue]);
|
||||
|
||||
|
||||
const handleCheckboxChange = (id: string) => {
|
||||
if (id === "all") {
|
||||
// Select all options except "all"
|
||||
|
|
@ -1197,12 +1221,19 @@ export default function FormAudioUpdate() {
|
|||
|
||||
const save = async (data: AudioSchema) => {
|
||||
const finalTags = tags.join(", ");
|
||||
|
||||
// ✅ tentukan isi description sesuai pilihan bahasa
|
||||
const descFinal =
|
||||
selectedLang === "en" && translatedContent
|
||||
? translatedContent
|
||||
: data.description;
|
||||
|
||||
const requestData = {
|
||||
...data,
|
||||
id: detail?.id,
|
||||
title: data.title,
|
||||
description: htmlToString(data.description),
|
||||
htmlDescription: data.description,
|
||||
description: htmlToString(descFinal),
|
||||
htmlDescription: descFinal,
|
||||
fileTypeId,
|
||||
categoryId: selectedTarget,
|
||||
subCategoryId: selectedTarget,
|
||||
|
|
@ -1441,7 +1472,6 @@ export default function FormAudioUpdate() {
|
|||
</div>
|
||||
));
|
||||
|
||||
|
||||
function success() {
|
||||
MySwal.fire({
|
||||
title: "Sukses",
|
||||
|
|
@ -1565,6 +1595,105 @@ export default function FormAudioUpdate() {
|
|||
</div>
|
||||
|
||||
<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>
|
||||
{t("description", { defaultValue: "Description" })}
|
||||
</Label>
|
||||
|
|
@ -1580,7 +1709,7 @@ export default function FormAudioUpdate() {
|
|||
{errors.description.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div> */}
|
||||
<div className="py-3 space-y-2">
|
||||
<Label>
|
||||
{t("select-file", { defaultValue: "Select File" })}
|
||||
|
|
@ -1651,7 +1780,9 @@ export default function FormAudioUpdate() {
|
|||
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>{" "}
|
||||
<p className="font-medium">{file.fileName}</p>
|
||||
<p className="font-medium">
|
||||
{file.fileName}
|
||||
</p>
|
||||
</div>
|
||||
<a
|
||||
href={file.url}
|
||||
|
|
@ -1714,7 +1845,8 @@ export default function FormAudioUpdate() {
|
|||
</div>
|
||||
|
||||
{/* Detail Wilayah */}
|
||||
{fileUnitSelections[index]?.wilayah && isDetailOfRegionShowed && (
|
||||
{fileUnitSelections[index]?.wilayah &&
|
||||
isDetailOfRegionShowed && (
|
||||
<div className="border-t border-gray-200 pt-2">
|
||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||
Detail Wilayah:
|
||||
|
|
@ -1724,7 +1856,10 @@ export default function FormAudioUpdate() {
|
|||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
{[
|
||||
{ key: "polda", label: "POLDA" },
|
||||
{ key: "satker", label: "SATKER" },
|
||||
{
|
||||
key: "satker",
|
||||
label: "SATKER",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
<div
|
||||
key={item.key}
|
||||
|
|
@ -1781,7 +1916,8 @@ export default function FormAudioUpdate() {
|
|||
<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
|
||||
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">
|
||||
|
|
@ -1807,7 +1943,9 @@ export default function FormAudioUpdate() {
|
|||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
index,
|
||||
Number(polda.id)
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
|
@ -1816,9 +1954,13 @@ export default function FormAudioUpdate() {
|
|||
</span>
|
||||
</Label>
|
||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination && (
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
onClick={(
|
||||
e
|
||||
) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleExpand(
|
||||
|
|
@ -1843,7 +1985,9 @@ export default function FormAudioUpdate() {
|
|||
</div>
|
||||
|
||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination &&
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination &&
|
||||
expandedPolda[
|
||||
polda.id
|
||||
] && (
|
||||
|
|
@ -1936,7 +2080,9 @@ export default function FormAudioUpdate() {
|
|||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
index,
|
||||
Number(sub.id)
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
|
@ -1951,7 +2097,6 @@ export default function FormAudioUpdate() {
|
|||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,6 @@ export default function FormImage() {
|
|||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [isLoadingData, setIsLoadingData] = useState<boolean>(false);
|
||||
const [localContent, setLocalContent] = useState("");
|
||||
const [isLoadingTranslate, setIsLoadingTranslate] = useState(false);
|
||||
const [articleIds, setArticleIds] = useState<string[]>([]);
|
||||
const [isGeneratedArticle, setIsGeneratedArticle] = useState(false);
|
||||
const [articleBody, setArticleBody] = useState<string>("");
|
||||
|
|
@ -149,6 +148,7 @@ export default function FormImage() {
|
|||
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||
const [filesTemp, setFilesTemp] = useState<File[]>([]);
|
||||
const [publishedFor, setPublishedFor] = useState<string[]>([]);
|
||||
const [isLoadingTranslate, setIsLoadingTranslate] = useState(false);
|
||||
const [translatedContent, setTranslatedContent] = React.useState("");
|
||||
const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id");
|
||||
|
||||
|
|
@ -555,8 +555,9 @@ export default function FormImage() {
|
|||
|
||||
const finalTags = tags.join(", ");
|
||||
const finalTitle = isSwitchOn ? title : data.title;
|
||||
// const finalDescription = articleBody || data.description;
|
||||
const finalDescription = isSwitchOn
|
||||
|
||||
// pilih description dasar
|
||||
let finalDescription = isSwitchOn
|
||||
? data.description
|
||||
: selectedFileType === "rewrite"
|
||||
? data.rewriteDescription
|
||||
|
|
@ -567,6 +568,15 @@ export default function FormImage() {
|
|||
return;
|
||||
}
|
||||
|
||||
// 👉 tempelkan hasil translate ke field form agar ikut terkirim
|
||||
if (translatedContent) {
|
||||
data.descriptionOri = translatedContent;
|
||||
console.log(
|
||||
"🌍 Translate dimasukkan ke descriptionOri:",
|
||||
translatedContent
|
||||
);
|
||||
}
|
||||
|
||||
let requestData: {
|
||||
title: string;
|
||||
description: string;
|
||||
|
|
@ -585,8 +595,8 @@ export default function FormImage() {
|
|||
} = {
|
||||
...data,
|
||||
title: finalTitle,
|
||||
description: htmlToString(finalDescription),
|
||||
htmlDescription: finalDescription,
|
||||
description: htmlToString(finalDescription), // plain text
|
||||
htmlDescription: finalDescription, // versi HTML
|
||||
fileTypeId,
|
||||
categoryId: selectedCategory,
|
||||
subCategoryId: selectedCategory,
|
||||
|
|
@ -611,6 +621,7 @@ export default function FormImage() {
|
|||
|
||||
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
||||
id = response?.data?.data;
|
||||
|
||||
const formMedia = new FormData();
|
||||
const thumbnail = files[0];
|
||||
formMedia.append("file", thumbnail);
|
||||
|
|
@ -620,6 +631,7 @@ export default function FormImage() {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const progressInfoArr = files.map((item) => ({
|
||||
percentage: 0,
|
||||
fileName: item.name,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -542,6 +542,102 @@ export default function FormTeks() {
|
|||
}
|
||||
}, [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) => {
|
||||
loading();
|
||||
|
||||
|
|
@ -564,6 +660,15 @@ export default function FormTeks() {
|
|||
return;
|
||||
}
|
||||
|
||||
// 👉 tempelkan hasil translate ke field form agar ikut terkirim
|
||||
if (translatedContent) {
|
||||
data.descriptionOri = translatedContent;
|
||||
console.log(
|
||||
"🌍 Translate dimasukkan ke descriptionOri:",
|
||||
translatedContent
|
||||
);
|
||||
}
|
||||
|
||||
let requestData: {
|
||||
title: string;
|
||||
description: string;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ import {
|
|||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
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({
|
||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||
|
|
@ -137,24 +140,20 @@ const CustomEditor = dynamic(
|
|||
export default function FormTeksUpdate() {
|
||||
const MySwal = withReactContent(Swal);
|
||||
const router = useRouter();
|
||||
|
||||
const { id } = useParams() as { id: string };
|
||||
console.log(id);
|
||||
const editor = useRef(null);
|
||||
type TeksSchema = z.infer<typeof teksSchema>;
|
||||
|
||||
let progressInfo: any = [];
|
||||
let counterUpdateProgress = 0;
|
||||
const [progressList, setProgressList] = useState<any>([]);
|
||||
let uploadPersen = 0;
|
||||
const [isStartUpload, setIsStartUpload] = useState(false);
|
||||
const [counterProgress, setCounterProgress] = useState(0);
|
||||
|
||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||
const taskId = Cookies.get("taskId");
|
||||
const scheduleId = Cookies.get("scheduleId");
|
||||
const scheduleType = Cookies.get("scheduleType");
|
||||
|
||||
const t = useTranslations("Form");
|
||||
const [categories, setCategories] = useState<Category[]>([]);
|
||||
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||
|
|
@ -162,7 +161,6 @@ export default function FormTeksUpdate() {
|
|||
const [detail, setDetail] = useState<Detail>();
|
||||
const [refresh, setRefresh] = useState(false);
|
||||
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
||||
|
||||
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||
const [fileUnitSelections, setFileUnitSelections] = useState<
|
||||
Array<{
|
||||
|
|
@ -201,16 +199,24 @@ export default function FormTeksUpdate() {
|
|||
const [tempFile, setTempFile] = useState<TempFileItem[]>([]);
|
||||
const [publishedFor, setPublishedFor] = useState<string[]>([]);
|
||||
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";
|
||||
const isDetailOfRegionShowed = false;
|
||||
|
||||
const { getRootProps, getInputProps } = useDropzone({
|
||||
onDrop: (acceptedFiles) => {
|
||||
setFiles(acceptedFiles.map((file) => Object.assign(file, {
|
||||
setFiles(
|
||||
acceptedFiles.map((file) =>
|
||||
Object.assign(file, {
|
||||
id: uuidv4(),
|
||||
preview: URL.createObjectURL(file)
|
||||
})));
|
||||
preview: URL.createObjectURL(file),
|
||||
})
|
||||
)
|
||||
);
|
||||
},
|
||||
accept: {
|
||||
"application/pdf": [],
|
||||
|
|
@ -232,6 +238,7 @@ export default function FormTeksUpdate() {
|
|||
control,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useForm<TeksSchema>({
|
||||
resolver: zodResolver(teksSchema),
|
||||
|
|
@ -554,7 +561,9 @@ export default function FormTeksUpdate() {
|
|||
});
|
||||
|
||||
// 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) {
|
||||
currentFileLevels.add(Number(satkerItem.id));
|
||||
// Checklist semua sub-items di bawah SATKER POLRI
|
||||
|
|
@ -588,7 +597,9 @@ export default function FormTeksUpdate() {
|
|||
});
|
||||
|
||||
// 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) {
|
||||
currentFileLevels.delete(Number(satkerItem.id));
|
||||
// Hapus semua sub-items di bawah SATKER POLRI
|
||||
|
|
@ -687,9 +698,14 @@ export default function FormTeksUpdate() {
|
|||
|
||||
// Update filePlacements berdasarkan perubahan di modal
|
||||
// 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.levelNumber === 2 && changedItem.name !== "SATKER POLRI") {
|
||||
if (
|
||||
changedItem.levelNumber === 2 &&
|
||||
changedItem.name !== "SATKER POLRI"
|
||||
) {
|
||||
// Ini adalah POLDA
|
||||
const isChecked = fileCheckedLevels[fileIndex]?.has(levelId) || false;
|
||||
setupPlacement(fileIndex, "polda", isChecked);
|
||||
|
|
@ -798,13 +814,18 @@ export default function FormTeksUpdate() {
|
|||
// Update filePlacements berdasarkan perubahan di modal
|
||||
// Cek apakah ini adalah SATKER POLRI yang diubah
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
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++) {
|
||||
const file = files[i] as any;
|
||||
const now = filePlacements[i];
|
||||
|
|
@ -923,7 +944,9 @@ export default function FormTeksUpdate() {
|
|||
}
|
||||
// Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist
|
||||
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")) {
|
||||
now.push("all");
|
||||
}
|
||||
|
|
@ -966,8 +989,8 @@ export default function FormTeksUpdate() {
|
|||
} else {
|
||||
if (placement === "wilayah") {
|
||||
// Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker
|
||||
const now = temp[index]?.filter((a) =>
|
||||
a !== "wilayah" && a !== "polda" && a !== "satker"
|
||||
const now = temp[index]?.filter(
|
||||
(a) => a !== "wilayah" && a !== "polda" && a !== "satker"
|
||||
);
|
||||
temp[index] = now;
|
||||
} else if (placement === "polda") {
|
||||
|
|
@ -995,7 +1018,9 @@ export default function FormTeksUpdate() {
|
|||
const currentNow = temp[index] || [];
|
||||
if (currentNow.includes("all")) {
|
||||
const requiredItems = ["mabes", "wilayah", "international"];
|
||||
const hasAllRequired = requiredItems.every(item => currentNow.includes(item));
|
||||
const hasAllRequired = requiredItems.every((item) =>
|
||||
currentNow.includes(item)
|
||||
);
|
||||
if (!hasAllRequired) {
|
||||
const newData = currentNow.filter((b) => b !== "all");
|
||||
temp[index] = newData;
|
||||
|
|
@ -1107,19 +1132,24 @@ export default function FormTeksUpdate() {
|
|||
setFiles(formattedFiles);
|
||||
|
||||
// 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(
|
||||
(file: any) => {
|
||||
if (file.placements) {
|
||||
return file.placements.split(",").map((p: string) => p.trim());
|
||||
}
|
||||
return [];
|
||||
});
|
||||
}
|
||||
);
|
||||
setFilePlacements(initialFilePlacements);
|
||||
|
||||
// Inisialisasi fileCheckedLevels dari detail
|
||||
const initialFileCheckedLevels: Set<number>[] = details.files.map((file: any) => {
|
||||
const initialFileCheckedLevels: Set<number>[] = details.files.map(
|
||||
(file: any) => {
|
||||
const checkedLevels = new Set<number>();
|
||||
if (file.customLocationPlacements) {
|
||||
const levelIds = file.customLocationPlacements.split(",").map((id: string) => Number(id.trim()));
|
||||
const levelIds = file.customLocationPlacements
|
||||
.split(",")
|
||||
.map((id: string) => Number(id.trim()));
|
||||
levelIds.forEach((id: number) => {
|
||||
if (!isNaN(id)) {
|
||||
checkedLevels.add(id);
|
||||
|
|
@ -1127,7 +1157,8 @@ export default function FormTeksUpdate() {
|
|||
});
|
||||
}
|
||||
return checkedLevels;
|
||||
});
|
||||
}
|
||||
);
|
||||
setFileCheckedLevels(initialFileCheckedLevels);
|
||||
|
||||
// Inisialisasi fileUnitSelections dari detail
|
||||
|
|
@ -1142,7 +1173,9 @@ export default function FormTeksUpdate() {
|
|||
};
|
||||
|
||||
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")) {
|
||||
selection.semua = true;
|
||||
|
|
@ -1153,7 +1186,8 @@ export default function FormTeksUpdate() {
|
|||
selection.satker = true;
|
||||
} else {
|
||||
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("satker")) selection.satker = true;
|
||||
// Wilayah aktif jika ada "wilayah" ATAU ada polda/satker
|
||||
|
|
@ -1195,7 +1229,6 @@ export default function FormTeksUpdate() {
|
|||
initState();
|
||||
}, [refresh, setValue]);
|
||||
|
||||
|
||||
const handleCheckboxChange = (id: string) => {
|
||||
if (id === "all") {
|
||||
// Select all options except "all"
|
||||
|
|
@ -1216,12 +1249,19 @@ export default function FormTeksUpdate() {
|
|||
const save = async (data: TeksSchema) => {
|
||||
loading();
|
||||
const finalTags = tags.join(", ");
|
||||
|
||||
// ✅ tentukan isi description sesuai pilihan bahasa
|
||||
const descFinal =
|
||||
selectedLang === "en" && translatedContent
|
||||
? translatedContent
|
||||
: data.description;
|
||||
|
||||
const requestData = {
|
||||
...data,
|
||||
id: detail?.id,
|
||||
title: data.title,
|
||||
description: htmlToString(data.description),
|
||||
htmlDescription: data.description,
|
||||
description: htmlToString(descFinal), // plain text
|
||||
htmlDescription: descFinal, // HTML (dipakai di editor/preview)
|
||||
fileTypeId,
|
||||
categoryId: selectedTarget,
|
||||
subCategoryId: selectedTarget,
|
||||
|
|
@ -1456,7 +1496,6 @@ export default function FormTeksUpdate() {
|
|||
</div>
|
||||
));
|
||||
|
||||
|
||||
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === "Enter" && e.currentTarget.value.trim()) {
|
||||
e.preventDefault();
|
||||
|
|
@ -1552,7 +1591,107 @@ export default function FormTeksUpdate() {
|
|||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
{t("description", { defaultValue: "Description" })}
|
||||
</Label>
|
||||
|
|
@ -1568,7 +1707,7 @@ export default function FormTeksUpdate() {
|
|||
{errors.description.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div> */}
|
||||
<div className="py-3 space-y-2">
|
||||
<Label>
|
||||
{t("select-file", { defaultValue: "Select File" })}
|
||||
|
|
@ -1669,7 +1808,9 @@ export default function FormTeksUpdate() {
|
|||
<Checkbox
|
||||
// id={`${item.key}-${index}`}
|
||||
checked={
|
||||
fileUnitSelections[files.indexOf(file)]?.[
|
||||
fileUnitSelections[
|
||||
files.indexOf(file)
|
||||
]?.[
|
||||
item.key as keyof typeof unitSelection
|
||||
] || false
|
||||
}
|
||||
|
|
@ -1697,7 +1838,9 @@ export default function FormTeksUpdate() {
|
|||
</div>
|
||||
|
||||
{/* Detail Wilayah */}
|
||||
{fileUnitSelections[files.indexOf(file)]?.wilayah && isDetailOfRegionShowed && (
|
||||
{fileUnitSelections[files.indexOf(file)]
|
||||
?.wilayah &&
|
||||
isDetailOfRegionShowed && (
|
||||
<div className="border-t border-gray-200 pt-2">
|
||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||
Detail Wilayah:
|
||||
|
|
@ -1707,7 +1850,10 @@ export default function FormTeksUpdate() {
|
|||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
{[
|
||||
{ key: "polda", label: "POLDA" },
|
||||
{ key: "satker", label: "SATKER" },
|
||||
{
|
||||
key: "satker",
|
||||
label: "SATKER",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
<div
|
||||
key={item.key}
|
||||
|
|
@ -1716,7 +1862,9 @@ export default function FormTeksUpdate() {
|
|||
<Checkbox
|
||||
id={`${item.key}-${index}`}
|
||||
checked={
|
||||
fileUnitSelections[files.indexOf(file)]?.[
|
||||
fileUnitSelections[
|
||||
files.indexOf(file)
|
||||
]?.[
|
||||
item.key as keyof typeof unitSelection
|
||||
] || false
|
||||
}
|
||||
|
|
@ -1764,7 +1912,8 @@ export default function FormTeksUpdate() {
|
|||
<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
|
||||
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">
|
||||
|
|
@ -1780,7 +1929,9 @@ export default function FormTeksUpdate() {
|
|||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
files.indexOf(file)
|
||||
files.indexOf(
|
||||
file
|
||||
)
|
||||
]?.has(
|
||||
Number(
|
||||
polda.id
|
||||
|
|
@ -1789,8 +1940,12 @@ export default function FormTeksUpdate() {
|
|||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
files.indexOf(file),
|
||||
Number(polda.id)
|
||||
files.indexOf(
|
||||
file
|
||||
),
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
|
@ -1799,20 +1954,30 @@ export default function FormTeksUpdate() {
|
|||
</span>
|
||||
</Label>
|
||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination && (
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
onClick={(
|
||||
e
|
||||
) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleExpand(
|
||||
Number(polda.id)
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
);
|
||||
}}
|
||||
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
||||
>
|
||||
<Icon
|
||||
icon={
|
||||
expandedPolda[Number(polda.id)]
|
||||
expandedPolda[
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
]
|
||||
? "mdi:chevron-up"
|
||||
: "mdi:chevron-down"
|
||||
}
|
||||
|
|
@ -1824,8 +1989,12 @@ export default function FormTeksUpdate() {
|
|||
</div>
|
||||
|
||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination &&
|
||||
expandedPolda[Number(polda.id)] && (
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination &&
|
||||
expandedPolda[
|
||||
Number(polda.id)
|
||||
] && (
|
||||
<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">
|
||||
|
|
@ -1836,7 +2005,9 @@ export default function FormTeksUpdate() {
|
|||
sub: any
|
||||
) =>
|
||||
fileCheckedLevels[
|
||||
files.indexOf(file)
|
||||
files.indexOf(
|
||||
file
|
||||
)
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
|
|
@ -1850,7 +2021,9 @@ export default function FormTeksUpdate() {
|
|||
className="text-xs h-6 px-2"
|
||||
onClick={() =>
|
||||
handleSelectAllSubItems(
|
||||
files.indexOf(file),
|
||||
files.indexOf(
|
||||
file
|
||||
),
|
||||
polda
|
||||
)
|
||||
}
|
||||
|
|
@ -1904,7 +2077,9 @@ export default function FormTeksUpdate() {
|
|||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
files.indexOf(file)
|
||||
files.indexOf(
|
||||
file
|
||||
)
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
|
|
@ -1914,8 +2089,12 @@ export default function FormTeksUpdate() {
|
|||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
files.indexOf(file),
|
||||
Number(sub.id)
|
||||
files.indexOf(
|
||||
file
|
||||
),
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
|
@ -1930,7 +2109,6 @@ export default function FormTeksUpdate() {
|
|||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -549,6 +549,15 @@ export default function FormVideo() {
|
|||
return;
|
||||
}
|
||||
|
||||
// 👉 tempelkan hasil translate ke form agar ikut terkirim
|
||||
if (translatedContent) {
|
||||
data.descriptionOri = translatedContent;
|
||||
console.log(
|
||||
"🌍 Translate dimasukkan ke descriptionOri:",
|
||||
translatedContent
|
||||
);
|
||||
}
|
||||
|
||||
let requestData: {
|
||||
title: string;
|
||||
description: string;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,14 @@ import {
|
|||
} from "@/components/ui/select";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
||||
import { Dialog, DialogClose, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
|
||||
import { register } from "module";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
|
|
@ -61,6 +68,9 @@ import { useTranslations } from "next-intl";
|
|||
import dynamic from "next/dynamic";
|
||||
import { htmlToString } from "@/utils/globals";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { getCookiesDecrypt } from "@/lib/utils";
|
||||
import { translateText } from "@/service/content/ai";
|
||||
import { close } from "@/config/swal";
|
||||
|
||||
const videoSchema = z.object({
|
||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||
|
|
@ -102,7 +112,13 @@ type Option = {
|
|||
name: string;
|
||||
};
|
||||
|
||||
type PlacementType = "all" | "mabes" | "wilayah" | "polda" | "satker" | "international";
|
||||
type PlacementType =
|
||||
| "all"
|
||||
| "mabes"
|
||||
| "wilayah"
|
||||
| "polda"
|
||||
| "satker"
|
||||
| "international";
|
||||
|
||||
interface FilePlacement {
|
||||
id: string;
|
||||
|
|
@ -147,9 +163,7 @@ export default function FormVideoUpdate() {
|
|||
type VideoSchema = z.infer<typeof videoSchema>;
|
||||
let progressInfo: any = [];
|
||||
let counterUpdateProgress = 0;
|
||||
|
||||
const isDetailOfRegionShowed = false;
|
||||
|
||||
const [progressList, setProgressList] = useState<any>([]);
|
||||
let uploadPersen = 0;
|
||||
const [isStartUpload, setIsStartUpload] = useState(false);
|
||||
|
|
@ -199,12 +213,19 @@ export default function FormVideoUpdate() {
|
|||
const [fileCheckedLevels, setFileCheckedLevels] = useState<{
|
||||
[fileId: string]: Set<number>;
|
||||
}>({});
|
||||
const [isUpdatingFromMainCheckbox, setIsUpdatingFromMainCheckbox] = useState(false);
|
||||
const [mainCheckboxChangeType, setMainCheckboxChangeType] = useState<string | null>(null);
|
||||
const [isUpdatingFromMainCheckbox, setIsUpdatingFromMainCheckbox] =
|
||||
useState(false);
|
||||
const [mainCheckboxChangeType, setMainCheckboxChangeType] = useState<
|
||||
string | null
|
||||
>(null);
|
||||
const [filePlacements, setFilePlacements] = useState<{
|
||||
[fileId: string]: PlacementType[];
|
||||
}>({});
|
||||
const [tempFile, setTempFile] = useState<TempFileItem | null>(null);
|
||||
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[] = [
|
||||
{ id: "all", name: "SEMUA" },
|
||||
|
|
@ -218,10 +239,14 @@ export default function FormVideoUpdate() {
|
|||
|
||||
const { getRootProps, getInputProps } = useDropzone({
|
||||
onDrop: (acceptedFiles) => {
|
||||
setFiles(acceptedFiles.map((file) => Object.assign(file, {
|
||||
setFiles(
|
||||
acceptedFiles.map((file) =>
|
||||
Object.assign(file, {
|
||||
id: uuidv4(),
|
||||
preview: URL.createObjectURL(file)
|
||||
})));
|
||||
preview: URL.createObjectURL(file),
|
||||
})
|
||||
)
|
||||
);
|
||||
},
|
||||
accept: {
|
||||
"video/*": [],
|
||||
|
|
@ -231,23 +256,13 @@ export default function FormVideoUpdate() {
|
|||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
getValues,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<VideoSchema>({
|
||||
resolver: zodResolver(videoSchema),
|
||||
});
|
||||
|
||||
// const handleKeyDown = (e: any) => {
|
||||
// const newTag = e.target.value.trim(); // Ambil nilai input
|
||||
// if (e.key === "Enter" && newTag) {
|
||||
// e.preventDefault(); // Hentikan submit form
|
||||
// if (!tags.includes(newTag)) {
|
||||
// setTags((prevTags) => [...prevTags, newTag]); // Tambah tag baru
|
||||
// setValue("tags", ""); // Kosongkan input
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
if (event.target.files) {
|
||||
const files = Array.from(event.target.files);
|
||||
|
|
@ -374,7 +389,9 @@ export default function FormVideoUpdate() {
|
|||
const initialFilePlacements: { [key: string]: PlacementType[] } = {};
|
||||
details.files.forEach((file: any) => {
|
||||
if (file.placements) {
|
||||
const placements = file.placements.split(",").map((p: string) => p.trim() as PlacementType);
|
||||
const placements = file.placements
|
||||
.split(",")
|
||||
.map((p: string) => p.trim() as PlacementType);
|
||||
initialFilePlacements[file.id] = placements;
|
||||
}
|
||||
});
|
||||
|
|
@ -384,7 +401,9 @@ export default function FormVideoUpdate() {
|
|||
const initialFileCheckedLevels: { [key: string]: Set<number> } = {};
|
||||
details.files.forEach((file: any) => {
|
||||
if (file.customLocationPlacements) {
|
||||
const levelIds = file.customLocationPlacements.split(",").map((id: string) => parseInt(id.trim()));
|
||||
const levelIds = file.customLocationPlacements
|
||||
.split(",")
|
||||
.map((id: string) => parseInt(id.trim()));
|
||||
initialFileCheckedLevels[file.id] = new Set(levelIds);
|
||||
}
|
||||
});
|
||||
|
|
@ -394,11 +413,16 @@ export default function FormVideoUpdate() {
|
|||
const initialFileUnitSelections: { [key: string]: any } = {};
|
||||
details.files.forEach((file: any) => {
|
||||
if (file.placements) {
|
||||
const placements = file.placements.split(",").map((p: string) => p.trim());
|
||||
const placements = file.placements
|
||||
.split(",")
|
||||
.map((p: string) => p.trim());
|
||||
initialFileUnitSelections[file.id] = {
|
||||
semua: placements.includes("all"),
|
||||
nasional: placements.includes("mabes"),
|
||||
wilayah: placements.includes("wilayah") || placements.includes("polda") || placements.includes("satker"),
|
||||
wilayah:
|
||||
placements.includes("wilayah") ||
|
||||
placements.includes("polda") ||
|
||||
placements.includes("satker"),
|
||||
international: placements.includes("international"),
|
||||
polda: placements.includes("polda"),
|
||||
satker: placements.includes("satker"),
|
||||
|
|
@ -439,18 +463,32 @@ export default function FormVideoUpdate() {
|
|||
|
||||
const updateMainCheckboxFromModalLegacy = () => {
|
||||
const checkedPoldaCount = listDest.filter(
|
||||
(item) => item.levelNumber === 2 && item.name !== "SATKER POLRI" && checkedLevels.has(item.id)
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name !== "SATKER POLRI" &&
|
||||
checkedLevels.has(item.id)
|
||||
).length;
|
||||
const hasSelectedPolda = checkedPoldaCount > 0;
|
||||
const allPoldaChecked = checkedPoldaCount === listDest.filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI").length;
|
||||
const allPoldaChecked =
|
||||
checkedPoldaCount ===
|
||||
listDest.filter(
|
||||
(item) => item.levelNumber === 2 && item.name !== "SATKER POLRI"
|
||||
).length;
|
||||
|
||||
const checkedSatkerCount = listDest.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI" && checkedLevels.has(item.id)
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name === "SATKER POLRI" &&
|
||||
checkedLevels.has(item.id)
|
||||
).length;
|
||||
const hasSelectedSatker = checkedSatkerCount > 0;
|
||||
const allSatkerChecked = checkedSatkerCount === listDest.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI").length;
|
||||
const allSatkerChecked =
|
||||
checkedSatkerCount ===
|
||||
listDest.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
).length;
|
||||
|
||||
setUnitSelection(prev => ({
|
||||
setUnitSelection((prev) => ({
|
||||
...prev,
|
||||
polda: hasSelectedPolda,
|
||||
satker: hasSelectedSatker,
|
||||
|
|
@ -461,83 +499,115 @@ export default function FormVideoUpdate() {
|
|||
const syncModalWithMainCheckbox = () => {
|
||||
if (mainCheckboxChangeType === "wilayah_checked") {
|
||||
const poldaIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name !== "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
const satkerIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
const allSatkerSubIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.flatMap(item => item.subDestination.map(sub => sub.id));
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.flatMap((item) => item.subDestination.map((sub) => sub.id));
|
||||
|
||||
setCheckedLevels(prev => {
|
||||
setCheckedLevels((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
[...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach(id => newSet.add(id));
|
||||
[...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach((id) =>
|
||||
newSet.add(id)
|
||||
);
|
||||
return newSet;
|
||||
});
|
||||
} else if (mainCheckboxChangeType === "wilayah_unchecked") {
|
||||
const poldaIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name !== "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
const satkerIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
const allSatkerSubIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.flatMap(item => item.subDestination.map(sub => sub.id));
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.flatMap((item) => item.subDestination.map((sub) => sub.id));
|
||||
|
||||
setCheckedLevels(prev => {
|
||||
setCheckedLevels((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
[...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach(id => newSet.delete(id));
|
||||
[...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach((id) =>
|
||||
newSet.delete(id)
|
||||
);
|
||||
return newSet;
|
||||
});
|
||||
} else if (mainCheckboxChangeType === "polda_checked") {
|
||||
const poldaIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
setCheckedLevels(prev => {
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name !== "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
setCheckedLevels((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
poldaIds.forEach(id => newSet.add(id));
|
||||
poldaIds.forEach((id) => newSet.add(id));
|
||||
return newSet;
|
||||
});
|
||||
} else if (mainCheckboxChangeType === "polda_unchecked") {
|
||||
const poldaIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
setCheckedLevels(prev => {
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name !== "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
setCheckedLevels((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
poldaIds.forEach(id => newSet.delete(id));
|
||||
poldaIds.forEach((id) => newSet.delete(id));
|
||||
return newSet;
|
||||
});
|
||||
} else if (mainCheckboxChangeType === "satker_checked") {
|
||||
const satkerIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
const allSatkerSubIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.flatMap(item => item.subDestination.map(sub => sub.id));
|
||||
setCheckedLevels(prev => {
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.flatMap((item) => item.subDestination.map((sub) => sub.id));
|
||||
setCheckedLevels((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
[...satkerIds, ...allSatkerSubIds].forEach(id => newSet.add(id));
|
||||
[...satkerIds, ...allSatkerSubIds].forEach((id) => newSet.add(id));
|
||||
return newSet;
|
||||
});
|
||||
} else if (mainCheckboxChangeType === "satker_unchecked") {
|
||||
const satkerIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.map(item => item.id);
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.map((item) => item.id);
|
||||
const allSatkerSubIds = listDest
|
||||
.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI")
|
||||
.flatMap(item => item.subDestination.map(sub => sub.id));
|
||||
setCheckedLevels(prev => {
|
||||
.filter(
|
||||
(item) => item.levelNumber === 2 && item.name === "SATKER POLRI"
|
||||
)
|
||||
.flatMap((item) => item.subDestination.map((sub) => sub.id));
|
||||
setCheckedLevels((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
[...satkerIds, ...allSatkerSubIds].forEach(id => newSet.delete(id));
|
||||
[...satkerIds, ...allSatkerSubIds].forEach((id) => newSet.delete(id));
|
||||
return newSet;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileUnitChange = (fileId: string, key: string, value: boolean) => {
|
||||
setFileUnitSelections(prev => {
|
||||
const handleFileUnitChange = (
|
||||
fileId: string,
|
||||
key: string,
|
||||
value: boolean
|
||||
) => {
|
||||
setFileUnitSelections((prev) => {
|
||||
const currentSelection = prev[fileId] || {
|
||||
semua: false,
|
||||
nasional: false,
|
||||
|
|
@ -554,22 +624,22 @@ export default function FormVideoUpdate() {
|
|||
newSelection.satker = true;
|
||||
|
||||
// Update fileCheckedLevels for wilayah
|
||||
setFileCheckedLevels(prevLevels => {
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
const currentFileLevels = prevLevels[fileId] || new Set<number>();
|
||||
const newFileLevels = new Set(currentFileLevels);
|
||||
|
||||
// Add all POLDA items
|
||||
listDest.forEach(item => {
|
||||
listDest.forEach((item) => {
|
||||
if (item.levelNumber === 2 && item.name !== "SATKER POLRI") {
|
||||
newFileLevels.add(item.id);
|
||||
}
|
||||
});
|
||||
|
||||
// Add SATKER POLRI items and their sub-destinations
|
||||
listDest.forEach(item => {
|
||||
listDest.forEach((item) => {
|
||||
if (item.levelNumber === 2 && item.name === "SATKER POLRI") {
|
||||
newFileLevels.add(item.id);
|
||||
item.subDestination.forEach(satkerItem => {
|
||||
item.subDestination.forEach((satkerItem) => {
|
||||
newFileLevels.add(satkerItem.id);
|
||||
});
|
||||
}
|
||||
|
|
@ -582,7 +652,7 @@ export default function FormVideoUpdate() {
|
|||
newSelection.satker = false;
|
||||
|
||||
// Clear fileCheckedLevels for wilayah
|
||||
setFileCheckedLevels(prevLevels => {
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
const newFileLevels = new Set<number>();
|
||||
return { ...prevLevels, [fileId]: newFileLevels };
|
||||
});
|
||||
|
|
@ -598,41 +668,51 @@ export default function FormVideoUpdate() {
|
|||
});
|
||||
|
||||
// Update filePlacements
|
||||
setFilePlacements(prev => {
|
||||
setFilePlacements((prev) => {
|
||||
const currentPlacements = prev[fileId] || [];
|
||||
let newPlacements = [...currentPlacements];
|
||||
|
||||
if (key === "semua" && value) {
|
||||
newPlacements = ["all", "mabes", "wilayah", "polda", "satker", "international"];
|
||||
newPlacements = [
|
||||
"all",
|
||||
"mabes",
|
||||
"wilayah",
|
||||
"polda",
|
||||
"satker",
|
||||
"international",
|
||||
];
|
||||
} else if (key === "semua" && !value) {
|
||||
newPlacements = [];
|
||||
} else if (key === "nasional" && value) {
|
||||
if (!newPlacements.includes("mabes")) newPlacements.push("mabes");
|
||||
} else if (key === "nasional" && !value) {
|
||||
newPlacements = newPlacements.filter(p => p !== "mabes");
|
||||
newPlacements = newPlacements.filter((p) => p !== "mabes");
|
||||
} else if (key === "wilayah" && value) {
|
||||
if (!newPlacements.includes("wilayah")) newPlacements.push("wilayah");
|
||||
if (!newPlacements.includes("polda")) newPlacements.push("polda");
|
||||
if (!newPlacements.includes("satker")) newPlacements.push("satker");
|
||||
} else if (key === "wilayah" && !value) {
|
||||
newPlacements = newPlacements.filter(p => !["wilayah", "polda", "satker"].includes(p));
|
||||
newPlacements = newPlacements.filter(
|
||||
(p) => !["wilayah", "polda", "satker"].includes(p)
|
||||
);
|
||||
} else if (key === "international" && value) {
|
||||
if (!newPlacements.includes("international")) newPlacements.push("international");
|
||||
if (!newPlacements.includes("international"))
|
||||
newPlacements.push("international");
|
||||
} else if (key === "international" && !value) {
|
||||
newPlacements = newPlacements.filter(p => p !== "international");
|
||||
newPlacements = newPlacements.filter((p) => p !== "international");
|
||||
} else if (key === "polda" && value) {
|
||||
if (!newPlacements.includes("polda")) newPlacements.push("polda");
|
||||
} else if (key === "polda" && !value) {
|
||||
newPlacements = newPlacements.filter(p => p !== "polda");
|
||||
newPlacements = newPlacements.filter((p) => p !== "polda");
|
||||
} else if (key === "satker" && value) {
|
||||
if (!newPlacements.includes("satker")) newPlacements.push("satker");
|
||||
} else if (key === "satker" && !value) {
|
||||
newPlacements = newPlacements.filter(p => p !== "satker");
|
||||
newPlacements = newPlacements.filter((p) => p !== "satker");
|
||||
}
|
||||
|
||||
// Remove "all" if any individual option is unchecked
|
||||
if (newPlacements.includes("all") && !value && key !== "semua") {
|
||||
newPlacements = newPlacements.filter(p => p !== "all");
|
||||
newPlacements = newPlacements.filter((p) => p !== "all");
|
||||
}
|
||||
|
||||
return { ...prev, [fileId]: newPlacements };
|
||||
|
|
@ -656,8 +736,12 @@ export default function FormVideoUpdate() {
|
|||
}
|
||||
};
|
||||
|
||||
const handleFileCheckboxChangePlacement = (fileId: string, poldaItem: Destination, isChecked: boolean) => {
|
||||
setFileCheckedLevels(prev => {
|
||||
const handleFileCheckboxChangePlacement = (
|
||||
fileId: string,
|
||||
poldaItem: Destination,
|
||||
isChecked: boolean
|
||||
) => {
|
||||
setFileCheckedLevels((prev) => {
|
||||
const currentFileLevels = prev[fileId] || new Set<number>();
|
||||
const newFileLevels = new Set(currentFileLevels);
|
||||
|
||||
|
|
@ -684,54 +768,58 @@ export default function FormVideoUpdate() {
|
|||
|
||||
// Update fileUnitSelections based on checked levels
|
||||
const updatedFileLevels = fileCheckedLevels[fileId] || new Set<number>();
|
||||
const hasPolda = listDest.some(item =>
|
||||
const hasPolda = listDest.some(
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name !== "SATKER POLRI" &&
|
||||
updatedFileLevels.has(item.id)
|
||||
);
|
||||
const hasSatker = listDest.some(item =>
|
||||
const hasSatker = listDest.some(
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name === "SATKER POLRI" &&
|
||||
updatedFileLevels.has(item.id)
|
||||
);
|
||||
|
||||
setFileUnitSelections(prev => ({
|
||||
setFileUnitSelections((prev) => ({
|
||||
...prev,
|
||||
[fileId]: {
|
||||
...prev[fileId],
|
||||
polda: hasPolda,
|
||||
satker: hasSatker,
|
||||
wilayah: hasPolda || hasSatker,
|
||||
}
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const updateMainCheckboxFromModal = (fileId: string) => {
|
||||
const fileLevels = fileCheckedLevels[fileId] || new Set<number>();
|
||||
const hasPolda = listDest.some(item =>
|
||||
const hasPolda = listDest.some(
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name !== "SATKER POLRI" &&
|
||||
fileLevels.has(item.id)
|
||||
);
|
||||
const hasSatker = listDest.some(item =>
|
||||
const hasSatker = listDest.some(
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name === "SATKER POLRI" &&
|
||||
fileLevels.has(item.id)
|
||||
);
|
||||
|
||||
setFileUnitSelections(prev => ({
|
||||
setFileUnitSelections((prev) => ({
|
||||
...prev,
|
||||
[fileId]: {
|
||||
...prev[fileId],
|
||||
polda: hasPolda,
|
||||
satker: hasSatker,
|
||||
wilayah: hasPolda || hasSatker,
|
||||
}
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const toggleExpand = (poldaId: number) => {
|
||||
setExpandedPolda(prev => {
|
||||
setExpandedPolda((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
if (newSet.has(poldaId)) {
|
||||
newSet.delete(poldaId);
|
||||
|
|
@ -744,22 +832,22 @@ export default function FormVideoUpdate() {
|
|||
|
||||
const handleSelectAllSubItems = (fileId: string, poldaItem: Destination) => {
|
||||
const fileLevels = fileCheckedLevels[fileId] || new Set<number>();
|
||||
const allSubItemsSelected = poldaItem.subDestination.every(subItem =>
|
||||
const allSubItemsSelected = poldaItem.subDestination.every((subItem) =>
|
||||
fileLevels.has(subItem.id)
|
||||
);
|
||||
|
||||
setFileCheckedLevels(prev => {
|
||||
setFileCheckedLevels((prev) => {
|
||||
const currentFileLevels = prev[fileId] || new Set<number>();
|
||||
const newFileLevels = new Set(currentFileLevels);
|
||||
|
||||
if (allSubItemsSelected) {
|
||||
// Unselect all sub-items
|
||||
poldaItem.subDestination.forEach(subItem => {
|
||||
poldaItem.subDestination.forEach((subItem) => {
|
||||
newFileLevels.delete(subItem.id);
|
||||
});
|
||||
} else {
|
||||
// Select all sub-items
|
||||
poldaItem.subDestination.forEach(subItem => {
|
||||
poldaItem.subDestination.forEach((subItem) => {
|
||||
newFileLevels.add(subItem.id);
|
||||
});
|
||||
}
|
||||
|
|
@ -772,7 +860,11 @@ export default function FormVideoUpdate() {
|
|||
const temp = [];
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
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 normalizedNow = now.map((item): PlacementType => {
|
||||
const value = String(item);
|
||||
|
|
@ -800,14 +892,25 @@ export default function FormVideoUpdate() {
|
|||
return temp;
|
||||
};
|
||||
|
||||
const setupPlacement = (fileId: string, placement: string, isChecked: boolean) => {
|
||||
setFilePlacements(prev => {
|
||||
const setupPlacement = (
|
||||
fileId: string,
|
||||
placement: string,
|
||||
isChecked: boolean
|
||||
) => {
|
||||
setFilePlacements((prev) => {
|
||||
const currentPlacements = prev[fileId] || [];
|
||||
let temp = { ...prev };
|
||||
|
||||
if (isChecked) {
|
||||
if (placement === "all") {
|
||||
temp[fileId] = ["all", "mabes", "wilayah", "polda", "satker", "international"];
|
||||
temp[fileId] = [
|
||||
"all",
|
||||
"mabes",
|
||||
"wilayah",
|
||||
"polda",
|
||||
"satker",
|
||||
"international",
|
||||
];
|
||||
} else if (placement === "wilayah") {
|
||||
temp[fileId] = [...currentPlacements, "wilayah", "polda", "satker"];
|
||||
} else if (placement === "polda") {
|
||||
|
|
@ -821,13 +924,15 @@ export default function FormVideoUpdate() {
|
|||
if (placement === "all") {
|
||||
temp[fileId] = [];
|
||||
} else if (placement === "wilayah") {
|
||||
temp[fileId] = currentPlacements.filter(p => !["wilayah", "polda", "satker"].includes(p));
|
||||
temp[fileId] = currentPlacements.filter(
|
||||
(p) => !["wilayah", "polda", "satker"].includes(p)
|
||||
);
|
||||
} else if (placement === "polda") {
|
||||
temp[fileId] = currentPlacements.filter(p => p !== "polda");
|
||||
temp[fileId] = currentPlacements.filter((p) => p !== "polda");
|
||||
} else if (placement === "satker") {
|
||||
temp[fileId] = currentPlacements.filter(p => p !== "satker");
|
||||
temp[fileId] = currentPlacements.filter((p) => p !== "satker");
|
||||
} else {
|
||||
temp[fileId] = currentPlacements.filter(p => p !== placement);
|
||||
temp[fileId] = currentPlacements.filter((p) => p !== placement);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -837,25 +942,27 @@ export default function FormVideoUpdate() {
|
|||
|
||||
const updateModalChecklistLevels = (fileId: string) => {
|
||||
const fileLevels = fileCheckedLevels[fileId] || new Set<number>();
|
||||
const hasPolda = listDest.some(item =>
|
||||
const hasPolda = listDest.some(
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name !== "SATKER POLRI" &&
|
||||
fileLevels.has(item.id)
|
||||
);
|
||||
const hasSatker = listDest.some(item =>
|
||||
const hasSatker = listDest.some(
|
||||
(item) =>
|
||||
item.levelNumber === 2 &&
|
||||
item.name === "SATKER POLRI" &&
|
||||
fileLevels.has(item.id)
|
||||
);
|
||||
|
||||
setFileUnitSelections(prev => ({
|
||||
setFileUnitSelections((prev) => ({
|
||||
...prev,
|
||||
[fileId]: {
|
||||
...prev[fileId],
|
||||
polda: hasPolda,
|
||||
satker: hasSatker,
|
||||
wilayah: hasPolda || hasSatker,
|
||||
}
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
|
|
@ -916,16 +1023,23 @@ export default function FormVideoUpdate() {
|
|||
// // router.push("/en/contributor/content/video");
|
||||
// // });
|
||||
// };
|
||||
|
||||
const save = async (data: VideoSchema) => {
|
||||
loading();
|
||||
|
||||
const finalTags = tags.join(", ");
|
||||
|
||||
const descFinal =
|
||||
selectedLang === "en" && translatedContent
|
||||
? translatedContent
|
||||
: data.description;
|
||||
|
||||
const requestData = {
|
||||
...data,
|
||||
id: detail?.id,
|
||||
title: data.title,
|
||||
description: htmlToString(data.description),
|
||||
htmlDescription: data.description,
|
||||
description: htmlToString(descFinal),
|
||||
htmlDescription: descFinal,
|
||||
fileTypeId,
|
||||
categoryId: selectedTarget,
|
||||
subCategoryId: selectedTarget,
|
||||
|
|
@ -959,7 +1073,6 @@ export default function FormVideoUpdate() {
|
|||
formMedia.append("file", thumbnail);
|
||||
const responseThumbnail = await uploadThumbnail(id, formMedia);
|
||||
if (responseThumbnail?.error) {
|
||||
// Perbaiki pengecekan error
|
||||
error(responseThumbnail?.message);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1150,7 +1263,6 @@ export default function FormVideoUpdate() {
|
|||
</div>
|
||||
));
|
||||
|
||||
|
||||
function success() {
|
||||
MySwal.fire({
|
||||
title: "Sukses",
|
||||
|
|
@ -1273,6 +1385,105 @@ export default function FormVideoUpdate() {
|
|||
</div>
|
||||
|
||||
<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>
|
||||
{t("description", { defaultValue: "Description" })}
|
||||
</Label>
|
||||
|
|
@ -1288,7 +1499,7 @@ export default function FormVideoUpdate() {
|
|||
{errors.description.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div> */}
|
||||
<div className="py-3 space-y-2">
|
||||
<Label>
|
||||
{t("select-file", { defaultValue: "Select File" })}
|
||||
|
|
@ -1417,7 +1628,8 @@ export default function FormVideoUpdate() {
|
|||
</div>
|
||||
|
||||
{/* Detail Wilayah */}
|
||||
{fileUnitSelections[file.id]?.wilayah && isDetailOfRegionShowed && (
|
||||
{fileUnitSelections[file.id]?.wilayah &&
|
||||
isDetailOfRegionShowed && (
|
||||
<div className="border-t border-gray-200 pt-2">
|
||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||
Detail Wilayah:
|
||||
|
|
@ -1427,7 +1639,10 @@ export default function FormVideoUpdate() {
|
|||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
{[
|
||||
{ key: "polda", label: "POLDA" },
|
||||
{ key: "satker", label: "SATKER" },
|
||||
{
|
||||
key: "satker",
|
||||
label: "SATKER",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
<div
|
||||
key={item.key}
|
||||
|
|
@ -1436,7 +1651,9 @@ export default function FormVideoUpdate() {
|
|||
<Checkbox
|
||||
id={`${item.key}-${index}`}
|
||||
checked={
|
||||
fileUnitSelections[file.id]?.[
|
||||
fileUnitSelections[
|
||||
file.id
|
||||
]?.[
|
||||
item.key as keyof typeof unitSelection
|
||||
] || false
|
||||
}
|
||||
|
|
@ -1484,7 +1701,8 @@ export default function FormVideoUpdate() {
|
|||
<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
|
||||
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">
|
||||
|
|
@ -1511,7 +1729,13 @@ export default function FormVideoUpdate() {
|
|||
handleFileCheckboxChangePlacement(
|
||||
file.id,
|
||||
polda,
|
||||
!fileCheckedLevels[file.id]?.has(Number(polda.id))
|
||||
!fileCheckedLevels[
|
||||
file.id
|
||||
]?.has(
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
|
@ -1520,9 +1744,13 @@ export default function FormVideoUpdate() {
|
|||
</span>
|
||||
</Label>
|
||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination && (
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
onClick={(
|
||||
e
|
||||
) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleExpand(
|
||||
|
|
@ -1547,7 +1775,9 @@ export default function FormVideoUpdate() {
|
|||
</div>
|
||||
|
||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination &&
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination &&
|
||||
expandedPolda.has(
|
||||
polda.id
|
||||
) && (
|
||||
|
|
@ -1561,7 +1791,8 @@ export default function FormVideoUpdate() {
|
|||
sub: any
|
||||
) =>
|
||||
fileCheckedLevels[
|
||||
file.id
|
||||
file
|
||||
.id
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
|
|
@ -1629,7 +1860,8 @@ export default function FormVideoUpdate() {
|
|||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
file.id
|
||||
file
|
||||
.id
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
|
|
@ -1641,7 +1873,14 @@ export default function FormVideoUpdate() {
|
|||
handleFileCheckboxChangePlacement(
|
||||
file.id,
|
||||
polda,
|
||||
!fileCheckedLevels[file.id]?.has(Number(sub.id))
|
||||
!fileCheckedLevels[
|
||||
file
|
||||
.id
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
|
@ -1656,7 +1895,6 @@ export default function FormVideoUpdate() {
|
|||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
|
|
|
|||
Loading…
Reference in New Issue