diff --git a/app/[locale]/(protected)/admin/settings/category/component/create.tsx b/app/[locale]/(protected)/admin/settings/category/component/create.tsx index 69ed0898..4db8b7e2 100644 --- a/app/[locale]/(protected)/admin/settings/category/component/create.tsx +++ b/app/[locale]/(protected)/admin/settings/category/component/create.tsx @@ -37,6 +37,8 @@ import { useDropzone } from "react-dropzone"; import { CloudUpload } from "lucide-react"; import Image from "next/image"; import { Upload } from "tus-js-client"; +import { getCookiesDecrypt } from "@/lib/utils"; +import Cookies from "js-cookie"; const FormSchema = z.object({ title: z.string({ @@ -103,6 +105,10 @@ const publishToList = [ export default function CreateCategoryModal() { const router = useRouter(); const { toast } = useToast(); + const roleId = getCookiesDecrypt("urie"); + const levelNumber = getCookiesDecrypt("ulne"); + const userLevelId = getCookiesDecrypt("ulie"); + const poldaState = Cookies.get("state"); const [files, setFiles] = useState([]); const [isOpen, setIsOpen] = useState(false); @@ -139,6 +145,14 @@ export default function CreateCategoryModal() { useEffect(() => { getRoles(); + if (Number(levelNumber) === 2) { + form.setValue("publishTo", ["polda"]); + setUnitData([String(userLevelId)]); + } + if (Number(levelNumber) === 3) { + form.setValue("publishTo", ["satker"]); + setSatkerData([String(userLevelId)]); + } }, []); async function getRoles() { @@ -176,7 +190,7 @@ export default function CreateCategoryModal() { const save = async (data: z.infer) => { const formMedia = new FormData(); - loading(); + // loading(); const unit = unitData?.join(","); const satker = satkerData?.join(","); @@ -196,6 +210,10 @@ export default function CreateCategoryModal() { formMedia.append("file", files[0]); formMedia.append("publishedLocation", data.publishTo.sort().join(",")); formMedia.append("publishedLocationLevel", join); + formMedia.append( + "isInt", + data.publishTo.includes("internasional") ? "true" : "false" + ); const response = await postCategory(formMedia); close(); @@ -374,94 +392,117 @@ export default function CreateCategoryModal() { )} /> - ( - - Wilayah Publish + {Number(levelNumber) === 1 ? ( + ( + + Wilayah Publish -
-
- { - if (checked) { - form.setValue( - "publishTo", - publishToList.map((item) => item.id) - ); - } else { - form.setValue("publishTo", []); - } - }} - /> - -
- {publishToList.map((item) => ( - <> - { - return ( - -
- - { - return checked - ? field.onChange([ - ...field.value, - item.id, - ]) - : field.onChange( - field.value?.filter( - (value) => value !== item.id - ) - ); - }} - /> - - - {item.name}{" "} - -
-
- ); +
+
+ { + if (checked) { + form.setValue( + "publishTo", + publishToList.map((item) => item.id) + ); + } else { + form.setValue("publishTo", []); + } }} /> - {item.id === "polda" && - form.getValues("publishTo")?.includes(item.id) && ( - setUnitData(data)} - /> - )} - {item.id === "satker" && - form.getValues("publishTo")?.includes(item.id) && ( - setSatkerData(data)} - /> - )} - - ))} -
- - - )} - /> + +
+ {publishToList.map((item) => ( + <> + { + return ( + +
+ + { + return checked + ? field.onChange([ + ...field.value, + item.id, + ]) + : field.onChange( + field.value?.filter( + (value) => value !== item.id + ) + ); + }} + /> + + + {item.name}{" "} + +
+
+ ); + }} + /> + {item.id === "polda" && + form.getValues("publishTo")?.includes(item.id) && ( + setUnitData(data)} + /> + )} + {item.id === "satker" && + form.getValues("publishTo")?.includes(item.id) && ( + setSatkerData(data)} + /> + )} + + ))} +
+ +
+ )} + /> + ) : ( + ( + + Wilayah Publish + +
+
+ + +
+
+ +
+ )} + /> + )} +