Merge branch 'main' of https://gitlab.com/hanifsalafi/mediahub_redesign into prod
This commit is contained in:
commit
f2bfd3f36a
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
"use client";
|
||||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,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" }),
|
||||
|
|
@ -136,24 +139,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>();
|
||||
|
|
@ -199,6 +198,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" },
|
||||
|
|
@ -235,6 +239,7 @@ export default function FormAudioUpdate() {
|
|||
control,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useForm<AudioSchema>({
|
||||
resolver: zodResolver(audioSchema),
|
||||
|
|
@ -515,7 +520,7 @@ export default function FormAudioUpdate() {
|
|||
// Jika wilayah dicentang, auto centang POLDA, SATKER
|
||||
if (key === "wilayah") {
|
||||
currentSelection.wilayah = value;
|
||||
|
||||
|
||||
if (value) {
|
||||
// Ketika wilayah dicentang, auto centang POLDA, SATKER
|
||||
currentSelection.polda = true;
|
||||
|
|
@ -536,7 +541,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
|
||||
|
|
@ -570,7 +577,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
|
||||
|
|
@ -764,7 +773,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);
|
||||
|
|
@ -874,14 +887,16 @@ export default function FormAudioUpdate() {
|
|||
} else if (placement === "semua") {
|
||||
placementToAdd = "all";
|
||||
}
|
||||
|
||||
|
||||
const now = temp[index] || [];
|
||||
if (!now.includes(placementToAdd)) {
|
||||
now.push(placementToAdd);
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
|
|
@ -924,8 +939,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") {
|
||||
|
|
@ -944,16 +959,18 @@ export default function FormAudioUpdate() {
|
|||
} else if (placement === "semua") {
|
||||
placementToRemove = "all";
|
||||
}
|
||||
|
||||
|
||||
const now = temp[index]?.filter((a) => a !== placementToRemove);
|
||||
temp[index] = now;
|
||||
}
|
||||
|
||||
|
||||
// Hapus "all" jika tidak semua item ter-checklist
|
||||
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;
|
||||
|
|
@ -1074,12 +1091,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;
|
||||
|
|
@ -1113,8 +1136,10 @@ 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")) {
|
||||
selection.semua = true;
|
||||
|
|
@ -1178,7 +1203,6 @@ export default function FormAudioUpdate() {
|
|||
initState();
|
||||
}, [refresh, setValue]);
|
||||
|
||||
|
||||
const handleCheckboxChange = (id: string) => {
|
||||
if (id === "all") {
|
||||
// Select all options except "all"
|
||||
|
|
@ -1198,12 +1222,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,
|
||||
|
|
@ -1442,7 +1473,6 @@ export default function FormAudioUpdate() {
|
|||
</div>
|
||||
));
|
||||
|
||||
|
||||
function success() {
|
||||
MySwal.fire({
|
||||
title: "Sukses",
|
||||
|
|
@ -1566,6 +1596,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>
|
||||
|
|
@ -1581,7 +1710,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" })}
|
||||
|
|
@ -1642,17 +1771,19 @@ export default function FormAudioUpdate() {
|
|||
<div className="flex-grow">
|
||||
<div>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="80"
|
||||
height="80"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M14.702 2.226A1 1 0 0 1 16 3.18v6.027a5.5 5.5 0 0 0-1-.184V6.18L8 8.368V15.5a2.5 2.5 0 1 1-1-2V5.368a1 1 0 0 1 .702-.955zM8 7.32l7-2.187V3.18L8 5.368zM5.5 14a1.5 1.5 0 1 0 0 3a1.5 1.5 0 0 0 0-3m13.5.5a4.5 4.5 0 1 1-9 0a4.5 4.5 0 0 1 9 0m-2.265-.436l-2.994-1.65a.5.5 0 0 0-.741.438v3.3a.5.5 0 0 0 .741.438l2.994-1.65a.5.5 0 0 0 0-.876"
|
||||
/>
|
||||
</svg>{" "}
|
||||
<p className="font-medium">{file.fileName}</p>
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="80"
|
||||
height="80"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M14.702 2.226A1 1 0 0 1 16 3.18v6.027a5.5 5.5 0 0 0-1-.184V6.18L8 8.368V15.5a2.5 2.5 0 1 1-1-2V5.368a1 1 0 0 1 .702-.955zM8 7.32l7-2.187V3.18L8 5.368zM5.5 14a1.5 1.5 0 1 0 0 3a1.5 1.5 0 0 0 0-3m13.5.5a4.5 4.5 0 1 1-9 0a4.5 4.5 0 0 1 9 0m-2.265-.436l-2.994-1.65a.5.5 0 0 0-.741.438v3.3a.5.5 0 0 0 .741.438l2.994-1.65a.5.5 0 0 0 0-.876"
|
||||
/>
|
||||
</svg>{" "}
|
||||
<p className="font-medium">
|
||||
{file.fileName}
|
||||
</p>
|
||||
</div>
|
||||
<a
|
||||
href={file.url}
|
||||
|
|
@ -1664,7 +1795,7 @@ export default function FormAudioUpdate() {
|
|||
defaultValue: "View File",
|
||||
})}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-white rounded-md p-4 border">
|
||||
{/* Checkbox Tingkat Utama */}
|
||||
<div className="space-y-4">
|
||||
|
|
@ -1710,276 +1841,290 @@ export default function FormAudioUpdate() {
|
|||
>
|
||||
{item.label}
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Detail Wilayah */}
|
||||
{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:
|
||||
</p>
|
||||
{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:
|
||||
</p>
|
||||
|
||||
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
{[
|
||||
{ key: "polda", label: "POLDA" },
|
||||
{ key: "satker", label: "SATKER" },
|
||||
].map((item, idx) => (
|
||||
<div
|
||||
key={item.key}
|
||||
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||
>
|
||||
<Checkbox
|
||||
id={`${item.key}-${index}`}
|
||||
checked={
|
||||
fileUnitSelections[index]?.[
|
||||
item.key as keyof typeof unitSelection
|
||||
] || false
|
||||
}
|
||||
onCheckedChange={(value) => {
|
||||
handleFileUnitChange(
|
||||
index,
|
||||
item.key as keyof typeof unitSelection,
|
||||
value as boolean
|
||||
);
|
||||
setupPlacement(
|
||||
index,
|
||||
item.key,
|
||||
Boolean(value)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`${item.key}-${index}`}
|
||||
className="text-sm font-medium cursor-pointer"
|
||||
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
{[
|
||||
{ key: "polda", label: "POLDA" },
|
||||
{
|
||||
key: "satker",
|
||||
label: "SATKER",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
<div
|
||||
key={item.key}
|
||||
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||
>
|
||||
{item.label}
|
||||
</Label>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Tombol Kustom sejajar dengan checkbox */}
|
||||
<div className="flex items-center justify-center p-3">
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
<Checkbox
|
||||
id={`${item.key}-${index}`}
|
||||
checked={
|
||||
fileUnitSelections[index]?.[
|
||||
item.key as keyof typeof unitSelection
|
||||
] || false
|
||||
}
|
||||
onCheckedChange={(value) => {
|
||||
handleFileUnitChange(
|
||||
index,
|
||||
item.key as keyof typeof unitSelection,
|
||||
value as boolean
|
||||
);
|
||||
setupPlacement(
|
||||
index,
|
||||
item.key,
|
||||
Boolean(value)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`${item.key}-${index}`}
|
||||
className="text-sm font-medium cursor-pointer"
|
||||
>
|
||||
<Icon
|
||||
icon="material-symbols:tune"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
{t("custom", {
|
||||
defaultValue: "Kustom",
|
||||
})}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||
<DialogTitle className="text-lg font-semibold">
|
||||
Daftar Wilayah POLDA dan SATKER
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||
{listDest.map(
|
||||
(polda: any) => (
|
||||
<div
|
||||
key={polda.id}
|
||||
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
||||
>
|
||||
{/* Header POLDA */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
||||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
index
|
||||
]?.has(
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
) || false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
index,
|
||||
Number(polda.id)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="font-semibold text-gray-900 text-sm">
|
||||
{polda.name}
|
||||
</span>
|
||||
</Label>
|
||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleExpand(
|
||||
polda.id
|
||||
);
|
||||
}}
|
||||
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
||||
>
|
||||
<Icon
|
||||
icon={
|
||||
expandedPolda[
|
||||
polda.id
|
||||
]
|
||||
? "mdi:chevron-up"
|
||||
: "mdi:chevron-down"
|
||||
}
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{item.label}
|
||||
</Label>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination &&
|
||||
expandedPolda[
|
||||
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">
|
||||
{(() => {
|
||||
const allSubItemsChecked =
|
||||
polda.subDestination?.every(
|
||||
(
|
||||
sub: any
|
||||
) =>
|
||||
fileCheckedLevels[
|
||||
index
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
)
|
||||
{/* Tombol Kustom sejajar dengan checkbox */}
|
||||
<div className="flex items-center justify-center p-3">
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
>
|
||||
<Icon
|
||||
icon="material-symbols:tune"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
{t("custom", {
|
||||
defaultValue: "Kustom",
|
||||
})}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||
<DialogTitle className="text-lg font-semibold">
|
||||
Daftar Wilayah POLDA dan
|
||||
SATKER
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||
{listDest.map(
|
||||
(polda: any) => (
|
||||
<div
|
||||
key={polda.id}
|
||||
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
||||
>
|
||||
{/* Header POLDA */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
||||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
index
|
||||
]?.has(
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
) || false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
index,
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="font-semibold text-gray-900 text-sm">
|
||||
{polda.name}
|
||||
</span>
|
||||
</Label>
|
||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination && (
|
||||
<button
|
||||
onClick={(
|
||||
e
|
||||
) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleExpand(
|
||||
polda.id
|
||||
);
|
||||
return (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="text-xs h-6 px-2"
|
||||
onClick={() =>
|
||||
handleSelectAllSubItems(
|
||||
index,
|
||||
polda
|
||||
)
|
||||
}
|
||||
>
|
||||
{allSubItemsChecked ? (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-indeterminate-small"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Batal
|
||||
Semua
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-all"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Pilih
|
||||
Semua
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
{polda.subDestination.map(
|
||||
(
|
||||
sub: any
|
||||
) => (
|
||||
<Label
|
||||
key={
|
||||
sub.id
|
||||
}
|
||||
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
||||
>
|
||||
<Checkbox
|
||||
checked={
|
||||
}}
|
||||
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
||||
>
|
||||
<Icon
|
||||
icon={
|
||||
expandedPolda[
|
||||
polda.id
|
||||
]
|
||||
? "mdi:chevron-up"
|
||||
: "mdi:chevron-down"
|
||||
}
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination &&
|
||||
expandedPolda[
|
||||
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">
|
||||
{(() => {
|
||||
const allSubItemsChecked =
|
||||
polda.subDestination?.every(
|
||||
(
|
||||
sub: any
|
||||
) =>
|
||||
fileCheckedLevels[
|
||||
index
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
) ||
|
||||
false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
)
|
||||
);
|
||||
return (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="text-xs h-6 px-2"
|
||||
onClick={() =>
|
||||
handleSelectAllSubItems(
|
||||
index,
|
||||
Number(sub.id)
|
||||
polda
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="text-gray-700">
|
||||
{
|
||||
sub.name
|
||||
>
|
||||
{allSubItemsChecked ? (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-indeterminate-small"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Batal
|
||||
Semua
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-all"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Pilih
|
||||
Semua
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
{polda.subDestination.map(
|
||||
(
|
||||
sub: any
|
||||
) => (
|
||||
<Label
|
||||
key={
|
||||
sub.id
|
||||
}
|
||||
</span>
|
||||
</Label>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">
|
||||
{t("cancel", {
|
||||
defaultValue: "Batal",
|
||||
})}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<DialogClose asChild>
|
||||
<Button>Simpan</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
||||
>
|
||||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
index
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
) ||
|
||||
false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
index,
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="text-gray-700">
|
||||
{
|
||||
sub.name
|
||||
}
|
||||
</span>
|
||||
</Label>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">
|
||||
{t("cancel", {
|
||||
defaultValue: "Batal",
|
||||
})}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<DialogClose asChild>
|
||||
<Button>Simpan</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,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" }),
|
||||
|
|
@ -138,24 +141,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>();
|
||||
|
|
@ -163,7 +162,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<{
|
||||
|
|
@ -202,16 +200,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, {
|
||||
id: uuidv4(),
|
||||
preview: URL.createObjectURL(file)
|
||||
})));
|
||||
setFiles(
|
||||
acceptedFiles.map((file) =>
|
||||
Object.assign(file, {
|
||||
id: uuidv4(),
|
||||
preview: URL.createObjectURL(file),
|
||||
})
|
||||
)
|
||||
);
|
||||
},
|
||||
accept: {
|
||||
"application/pdf": [],
|
||||
|
|
@ -233,6 +239,7 @@ export default function FormTeksUpdate() {
|
|||
control,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useForm<TeksSchema>({
|
||||
resolver: zodResolver(teksSchema),
|
||||
|
|
@ -534,7 +541,7 @@ export default function FormTeksUpdate() {
|
|||
// Jika wilayah dicentang, auto centang POLDA, SATKER
|
||||
if (key === "wilayah") {
|
||||
currentSelection.wilayah = value;
|
||||
|
||||
|
||||
if (value) {
|
||||
// Ketika wilayah dicentang, auto centang POLDA, SATKER
|
||||
currentSelection.polda = true;
|
||||
|
|
@ -555,7 +562,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
|
||||
|
|
@ -589,7 +598,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
|
||||
|
|
@ -688,9 +699,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);
|
||||
|
|
@ -799,13 +815,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];
|
||||
|
|
@ -917,14 +938,16 @@ export default function FormTeksUpdate() {
|
|||
} else if (placement === "semua") {
|
||||
placementToAdd = "all";
|
||||
}
|
||||
|
||||
|
||||
const now = temp[index] || [];
|
||||
if (!now.includes(placementToAdd)) {
|
||||
now.push(placementToAdd);
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
|
|
@ -967,8 +990,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") {
|
||||
|
|
@ -987,16 +1010,18 @@ export default function FormTeksUpdate() {
|
|||
} else if (placement === "semua") {
|
||||
placementToRemove = "all";
|
||||
}
|
||||
|
||||
|
||||
const now = temp[index]?.filter((a) => a !== placementToRemove);
|
||||
temp[index] = now;
|
||||
}
|
||||
|
||||
|
||||
// Hapus "all" jika tidak semua item ter-checklist
|
||||
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;
|
||||
|
|
@ -1108,27 +1133,33 @@ 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) => {
|
||||
if (file.placements) {
|
||||
return file.placements.split(",").map((p: string) => p.trim());
|
||||
const initialFilePlacements: string[][] = details.files.map(
|
||||
(file: any) => {
|
||||
if (file.placements) {
|
||||
return file.placements.split(",").map((p: string) => p.trim());
|
||||
}
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
});
|
||||
);
|
||||
setFilePlacements(initialFilePlacements);
|
||||
|
||||
// Inisialisasi fileCheckedLevels dari detail
|
||||
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()));
|
||||
levelIds.forEach((id: number) => {
|
||||
if (!isNaN(id)) {
|
||||
checkedLevels.add(id);
|
||||
}
|
||||
});
|
||||
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()));
|
||||
levelIds.forEach((id: number) => {
|
||||
if (!isNaN(id)) {
|
||||
checkedLevels.add(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
return checkedLevels;
|
||||
}
|
||||
return checkedLevels;
|
||||
});
|
||||
);
|
||||
setFileCheckedLevels(initialFileCheckedLevels);
|
||||
|
||||
// Inisialisasi fileUnitSelections dari detail
|
||||
|
|
@ -1143,7 +1174,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;
|
||||
|
|
@ -1154,7 +1187,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
|
||||
|
|
@ -1196,7 +1230,6 @@ export default function FormTeksUpdate() {
|
|||
initState();
|
||||
}, [refresh, setValue]);
|
||||
|
||||
|
||||
const handleCheckboxChange = (id: string) => {
|
||||
if (id === "all") {
|
||||
// Select all options except "all"
|
||||
|
|
@ -1217,12 +1250,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,
|
||||
|
|
@ -1457,7 +1497,6 @@ export default function FormTeksUpdate() {
|
|||
</div>
|
||||
));
|
||||
|
||||
|
||||
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === "Enter" && e.currentTarget.value.trim()) {
|
||||
e.preventDefault();
|
||||
|
|
@ -1553,7 +1592,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>
|
||||
|
|
@ -1569,7 +1708,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" })}
|
||||
|
|
@ -1670,7 +1809,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
|
||||
}
|
||||
|
|
@ -1692,268 +1833,305 @@ export default function FormTeksUpdate() {
|
|||
className="text-sm font-medium cursor-pointer"
|
||||
>
|
||||
{item.label}
|
||||
</Label>
|
||||
</div>
|
||||
</Label>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Detail Wilayah */}
|
||||
{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:
|
||||
</p>
|
||||
{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:
|
||||
</p>
|
||||
|
||||
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
{[
|
||||
{ key: "polda", label: "POLDA" },
|
||||
{ key: "satker", label: "SATKER" },
|
||||
].map((item, idx) => (
|
||||
<div
|
||||
key={item.key}
|
||||
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||
>
|
||||
<Checkbox
|
||||
id={`${item.key}-${index}`}
|
||||
checked={
|
||||
fileUnitSelections[files.indexOf(file)]?.[
|
||||
item.key as keyof typeof unitSelection
|
||||
] || false
|
||||
}
|
||||
onCheckedChange={(value) => {
|
||||
handleFileUnitChange(
|
||||
files.indexOf(file),
|
||||
item.key as keyof typeof unitSelection,
|
||||
value as boolean
|
||||
);
|
||||
setupPlacement(
|
||||
files.indexOf(file),
|
||||
item.key as keyof typeof unitSelection,
|
||||
Boolean(value)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`${item.key}-${index}`}
|
||||
className="text-sm font-medium cursor-pointer"
|
||||
{/* Checkbox Sub-kategori dengan tombol Kustom sejajar */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
{[
|
||||
{ key: "polda", label: "POLDA" },
|
||||
{
|
||||
key: "satker",
|
||||
label: "SATKER",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
<div
|
||||
key={item.key}
|
||||
className="flex items-center gap-2 p-3 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||
>
|
||||
{item.label}
|
||||
</Label>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Tombol Kustom sejajar dengan checkbox */}
|
||||
<div className="flex items-center justify-center p-3">
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
<Checkbox
|
||||
id={`${item.key}-${index}`}
|
||||
checked={
|
||||
fileUnitSelections[
|
||||
files.indexOf(file)
|
||||
]?.[
|
||||
item.key as keyof typeof unitSelection
|
||||
] || false
|
||||
}
|
||||
onCheckedChange={(value) => {
|
||||
handleFileUnitChange(
|
||||
files.indexOf(file),
|
||||
item.key as keyof typeof unitSelection,
|
||||
value as boolean
|
||||
);
|
||||
setupPlacement(
|
||||
files.indexOf(file),
|
||||
item.key as keyof typeof unitSelection,
|
||||
Boolean(value)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`${item.key}-${index}`}
|
||||
className="text-sm font-medium cursor-pointer"
|
||||
>
|
||||
<Icon
|
||||
icon="material-symbols:tune"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
{t("custom", {
|
||||
defaultValue: "Kustom",
|
||||
})}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||
<DialogTitle className="text-lg font-semibold">
|
||||
Daftar Wilayah POLDA dan SATKER
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||
{listDest.map(
|
||||
(polda: any) => (
|
||||
<div
|
||||
key={polda.id}
|
||||
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
||||
>
|
||||
{/* Header POLDA */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
||||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
files.indexOf(file)
|
||||
]?.has(
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
) || false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
files.indexOf(file),
|
||||
Number(polda.id)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="font-semibold text-gray-900 text-sm">
|
||||
{polda.name}
|
||||
</span>
|
||||
</Label>
|
||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||
{polda.name === "SATKER POLRI" && polda.subDestination && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleExpand(
|
||||
Number(polda.id)
|
||||
);
|
||||
}}
|
||||
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
||||
>
|
||||
<Icon
|
||||
icon={
|
||||
expandedPolda[Number(polda.id)]
|
||||
? "mdi:chevron-up"
|
||||
: "mdi:chevron-down"
|
||||
}
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{item.label}
|
||||
</Label>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||
{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">
|
||||
{(() => {
|
||||
const allSubItemsChecked =
|
||||
polda.subDestination?.every(
|
||||
(
|
||||
sub: any
|
||||
) =>
|
||||
fileCheckedLevels[
|
||||
files.indexOf(file)
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
)
|
||||
{/* Tombol Kustom sejajar dengan checkbox */}
|
||||
<div className="flex items-center justify-center p-3">
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
>
|
||||
<Icon
|
||||
icon="material-symbols:tune"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
{t("custom", {
|
||||
defaultValue: "Kustom",
|
||||
})}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||
<DialogTitle className="text-lg font-semibold">
|
||||
Daftar Wilayah POLDA dan
|
||||
SATKER
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||
{listDest.map(
|
||||
(polda: any) => (
|
||||
<div
|
||||
key={polda.id}
|
||||
className="border border-gray-200 rounded-lg p-2 bg-white hover:shadow-sm transition-shadow"
|
||||
>
|
||||
{/* Header POLDA */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="flex items-center gap-3 flex-1 cursor-pointer">
|
||||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
files.indexOf(
|
||||
file
|
||||
)
|
||||
]?.has(
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
) || false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
files.indexOf(
|
||||
file
|
||||
),
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="font-semibold text-gray-900 text-sm">
|
||||
{polda.name}
|
||||
</span>
|
||||
</Label>
|
||||
{/* Tombol expand hanya untuk SATKER POLRI */}
|
||||
{polda.name ===
|
||||
"SATKER POLRI" &&
|
||||
polda.subDestination && (
|
||||
<button
|
||||
onClick={(
|
||||
e
|
||||
) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleExpand(
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
);
|
||||
return (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="text-xs h-6 px-2"
|
||||
onClick={() =>
|
||||
handleSelectAllSubItems(
|
||||
files.indexOf(file),
|
||||
polda
|
||||
}}
|
||||
className="p-1 hover:bg-gray-100 rounded-md transition-colors"
|
||||
>
|
||||
<Icon
|
||||
icon={
|
||||
expandedPolda[
|
||||
Number(
|
||||
polda.id
|
||||
)
|
||||
}
|
||||
>
|
||||
{allSubItemsChecked ? (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-indeterminate-small"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Batal
|
||||
Semua
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-all"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Pilih
|
||||
Semua
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
{polda.subDestination.map(
|
||||
(
|
||||
sub: any
|
||||
) => (
|
||||
<Label
|
||||
key={
|
||||
sub.id
|
||||
}
|
||||
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
||||
>
|
||||
<Checkbox
|
||||
checked={
|
||||
]
|
||||
? "mdi:chevron-up"
|
||||
: "mdi:chevron-down"
|
||||
}
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sub-items hanya untuk SATKER POLRI */}
|
||||
{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">
|
||||
{(() => {
|
||||
const allSubItemsChecked =
|
||||
polda.subDestination?.every(
|
||||
(
|
||||
sub: any
|
||||
) =>
|
||||
fileCheckedLevels[
|
||||
files.indexOf(file)
|
||||
files.indexOf(
|
||||
file
|
||||
)
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
) ||
|
||||
false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
files.indexOf(file),
|
||||
Number(sub.id)
|
||||
)
|
||||
);
|
||||
return (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="text-xs h-6 px-2"
|
||||
onClick={() =>
|
||||
handleSelectAllSubItems(
|
||||
files.indexOf(
|
||||
file
|
||||
),
|
||||
polda
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="text-gray-700">
|
||||
{
|
||||
sub.name
|
||||
>
|
||||
{allSubItemsChecked ? (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-indeterminate-small"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Batal
|
||||
Semua
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-all"
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Pilih
|
||||
Semua
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
{polda.subDestination.map(
|
||||
(
|
||||
sub: any
|
||||
) => (
|
||||
<Label
|
||||
key={
|
||||
sub.id
|
||||
}
|
||||
</span>
|
||||
</Label>
|
||||
)
|
||||
)}
|
||||
className="flex items-center gap-2 p-2 rounded-md hover:bg-gray-50 transition-colors cursor-pointer text-xs"
|
||||
>
|
||||
<Checkbox
|
||||
checked={
|
||||
fileCheckedLevels[
|
||||
files.indexOf(
|
||||
file
|
||||
)
|
||||
]?.has(
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
) ||
|
||||
false
|
||||
}
|
||||
onCheckedChange={() =>
|
||||
handleFileCheckboxChangePlacement(
|
||||
files.indexOf(
|
||||
file
|
||||
),
|
||||
Number(
|
||||
sub.id
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="text-gray-700">
|
||||
{
|
||||
sub.name
|
||||
}
|
||||
</span>
|
||||
</Label>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">
|
||||
{t("cancel", {
|
||||
defaultValue: "Batal",
|
||||
})}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<DialogClose asChild>
|
||||
<Button>Simpan</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-end gap-3 border-t border-gray-200 pt-4">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">
|
||||
{t("cancel", {
|
||||
defaultValue: "Batal",
|
||||
})}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<DialogClose asChild>
|
||||
<Button>Simpan</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -243,7 +243,10 @@ export default function FilterAudioComponent(props: {
|
|||
{newContent?.map((audio: any) => (
|
||||
<CarouselItem key={audio?.id} className="md:basis-1/2 lg:basis-1/3">
|
||||
<Link
|
||||
href={`${prefixPath}${audio?.slug}`}
|
||||
href={`${prefixPath}/audio/detail/${audio?.slug
|
||||
?.split("/")
|
||||
.pop()}`}
|
||||
// href={`${prefixPath}/audio/detail/${audio?.slug}`}
|
||||
// href={prefixPath + `/audio/detail/${audio?.slug}`}
|
||||
// onClick={() =>
|
||||
// router.push(prefixPath + `/audio/detail/${audio?.slug}`)
|
||||
|
|
|
|||
|
|
@ -214,7 +214,10 @@ export default function FilterDocumentComponent(props: {
|
|||
{newContent?.map((text: any) => (
|
||||
<CarouselItem key={text?.id} className="md:basis-1/2 lg:basis-1/3">
|
||||
<Link
|
||||
href={`${prefixPath}${text?.slug}`}
|
||||
href={`${prefixPath}/text/detail/${text?.slug
|
||||
?.split("/")
|
||||
.pop()}`}
|
||||
// href={`${prefixPath}/document/detail/${text?.slug}`}
|
||||
// href={prefixPath + `/document/detail/${text?.slug}`}
|
||||
// onClick={() =>
|
||||
// router.push(prefixPath + `/document/detail/${text?.slug}`)
|
||||
|
|
|
|||
|
|
@ -200,7 +200,10 @@ export default function FilterImageComponent(props: {
|
|||
{newContent?.map((image: any) => (
|
||||
<CarouselItem key={image?.id} className="md:basis-1/2 lg:basis-1/3">
|
||||
<Link
|
||||
href={`${prefixPath}${image?.slug}`}
|
||||
href={`${prefixPath}/image/detail/${image?.slug
|
||||
?.split("/")
|
||||
.pop()}`}
|
||||
// href={prefixPath + `/image/detail/${image?.slug}`}
|
||||
// onClick={() =>
|
||||
// router.push(prefixPath + `/image/detail/${image?.slug}`)
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -161,7 +161,10 @@ export default function FilterVideoComponent(props: {
|
|||
{newContent?.map((video: any) => (
|
||||
<CarouselItem key={video?.id} className="md:basis-1/2 lg:basis-1/3">
|
||||
<Link
|
||||
href={`${prefixPath}${video?.slug}`}
|
||||
href={`${prefixPath}/video/detail/${video?.slug
|
||||
?.split("/")
|
||||
.pop()}`}
|
||||
// href={`${prefixPath}/video/detail/${video?.slug}`}
|
||||
// href={prefixPath + `/video/detail/${video?.slug}`}
|
||||
// onClick={() =>
|
||||
// router.push(prefixPath + `/video/detail/${video?.slug}`)
|
||||
|
|
|
|||
Loading…
Reference in New Issue