From b02622ff5026cafc29821dd20768c56b9875931f Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 13 Jan 2025 11:50:39 +0700 Subject: [PATCH 1/5] fix:menu satker, create category --- .../settings/category/component/create.tsx | 213 +++++++++++------- lib/menus.ts | 149 +++++++----- messages/en.json | 1 + messages/in.json | 1 + 4 files changed, 227 insertions(+), 137 deletions(-) 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 + +
+
+ + +
+
+ +
+ )} + /> + )} + Date: Mon, 13 Jan 2025 11:51:56 +0700 Subject: [PATCH 2/5] little update --- .../(protected)/admin/settings/category/component/create.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/[locale]/(protected)/admin/settings/category/component/create.tsx b/app/[locale]/(protected)/admin/settings/category/component/create.tsx index 4db8b7e2..0b9994c4 100644 --- a/app/[locale]/(protected)/admin/settings/category/component/create.tsx +++ b/app/[locale]/(protected)/admin/settings/category/component/create.tsx @@ -190,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(","); From 350c061263b49da2ddb9d70085996d2cb957f795 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 13 Jan 2025 12:33:42 +0700 Subject: [PATCH 3/5] fix:edit category polda satker --- .../settings/category/component/edit.tsx | 170 ++++++++++-------- 1 file changed, 99 insertions(+), 71 deletions(-) diff --git a/app/[locale]/(protected)/admin/settings/category/component/edit.tsx b/app/[locale]/(protected)/admin/settings/category/component/edit.tsx index 316e6a74..dae2cd75 100644 --- a/app/[locale]/(protected)/admin/settings/category/component/edit.tsx +++ b/app/[locale]/(protected)/admin/settings/category/component/edit.tsx @@ -38,6 +38,9 @@ import { UnitMapping } from "./unit-mapping"; import { useDropzone } from "react-dropzone"; import { CloudUpload } from "lucide-react"; import { useToast } from "@/components/ui/use-toast"; +import Cookies from "js-cookie"; +import { getCookiesDecrypt } from "@/lib/utils"; + const FormSchema = z.object({ title: z.string({ required_error: "Required", @@ -112,7 +115,10 @@ export default function EditCategoryModal(props: { const [files, setFiles] = useState([]); const [isOpen, setIsOpen] = useState(false); const { toast } = useToast(); - + const roleId = getCookiesDecrypt("urie"); + const levelNumber = getCookiesDecrypt("ulne"); + const userLevelId = getCookiesDecrypt("ulie"); + const poldaState = Cookies.get("state"); const router = useRouter(); const [satkerData, setSatkerData] = useState([]); const [unitData, setUnitData] = useState([]); @@ -344,79 +350,101 @@ export default function EditCategoryModal(props: {
)} /> + {Number(levelNumber) === 1 ? ( + ( + + Target Publish - ( - - Target Publish - -
-
- { - if (checked) { - form.setValue( - "selectedUser", - userList.map((item) => item.id) +
+
+ { + if (checked) { + form.setValue( + "selectedUser", + userList.map((item) => item.id) + ); + } else { + form.setValue("selectedUser", []); + } + }} + /> + +
+ {userList.map((item) => ( + { + return ( + +
+ + { + return checked + ? field.onChange([ + ...field.value, + item.id, + ]) + : field.onChange( + field.value?.filter( + (value) => value !== item.id + ) + ); + }} + /> + + + {item.name} + +
+
); - } else { - form.setValue("selectedUser", []); - } - }} - /> - + }} + /> + ))}
- {userList.map((item) => ( - { - return ( - -
- - { - return checked - ? field.onChange([ - ...field.value, - item.id, - ]) - : field.onChange( - field.value?.filter( - (value) => value !== item.id - ) - ); - }} - /> - - - {item.name} - -
-
- ); - }} - /> - ))} -
- - - )} - /> + + + )} + /> + ) : ( + ( + + Wilayah Publish + +
+
+ + +
+
+ +
+ )} + /> + )} + Date: Mon, 13 Jan 2025 12:37:53 +0700 Subject: [PATCH 4/5] feat: update category and thumbnail --- service/content/content.ts | 2 +- service/settings/settings.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service/content/content.ts b/service/content/content.ts index 686ea83c..e6a0a41a 100644 --- a/service/content/content.ts +++ b/service/content/content.ts @@ -168,7 +168,7 @@ export async function uploadThumbnail(id: any, data: any) { const headers = { "Content-Type": "multipart/form-data", }; - return httpPostInterceptor(url, data, { headers }); + return httpPostInterceptor(url, data, headers); } export async function detailSPIT(id: any) { diff --git a/service/settings/settings.ts b/service/settings/settings.ts index 551bfc94..673eb01a 100644 --- a/service/settings/settings.ts +++ b/service/settings/settings.ts @@ -39,7 +39,7 @@ export async function postCategory(data: any) { const headers = { "Content-Type": "multipart/form-data", }; - return httpPostInterceptor(url, data, { headers }); + return httpPostInterceptor(url, data, headers); } export async function getPrivacy(id: string) { From 525f158388987c55846ccfe302b7eaae425f69ab Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 13 Jan 2025 12:48:58 +0700 Subject: [PATCH 5/5] fix create new categ satker polda --- .../settings/category/component/edit.tsx | 273 +++++++++--------- 1 file changed, 137 insertions(+), 136 deletions(-) diff --git a/app/[locale]/(protected)/admin/settings/category/component/edit.tsx b/app/[locale]/(protected)/admin/settings/category/component/edit.tsx index dae2cd75..aebf2356 100644 --- a/app/[locale]/(protected)/admin/settings/category/component/edit.tsx +++ b/app/[locale]/(protected)/admin/settings/category/component/edit.tsx @@ -350,28 +350,101 @@ export default function EditCategoryModal(props: { )} /> + ( + + Target Publish + +
+
+ { + if (checked) { + form.setValue( + "selectedUser", + userList.map((item) => item.id) + ); + } else { + form.setValue("selectedUser", []); + } + }} + /> + +
+ {userList.map((item) => ( + { + return ( + +
+ + { + return checked + ? field.onChange([ + ...field.value, + item.id, + ]) + : field.onChange( + field.value?.filter( + (value) => value !== item.id + ) + ); + }} + /> + + + {item.name} + +
+
+ ); + }} + /> + ))} +
+ +
+ )} + /> + {Number(levelNumber) === 1 ? ( ( - Target Publish + Wilayah Publish
{ if (checked) { form.setValue( - "selectedUser", - userList.map((item) => item.id) + "publishTo", + publishToList.map((item) => item.id) ); } else { - form.setValue("selectedUser", []); + form.setValue("publishTo", []); } }} /> @@ -379,44 +452,64 @@ export default function EditCategoryModal(props: { Semua
- {userList.map((item) => ( - { - return ( - -
- - { - return checked - ? field.onChange([ - ...field.value, - item.id, - ]) - : field.onChange( - field.value?.filter( - (value) => value !== item.id - ) - ); - }} - /> - - - {item.name} - -
-
- ); - }} - /> + {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)} + isDetail={isDetail ? true : false} + initData={unitData} + /> + )} + {item.id === "satker" && + form.getValues("publishTo")?.includes(item.id) && ( + setSatkerData(data)} + isDetail={isDetail ? true : false} + initData={satkerData} + /> + )} + ))}
@@ -445,98 +538,6 @@ export default function EditCategoryModal(props: { /> )} - ( - - 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}{" "} - -
-
- ); - }} - /> - {item.id === "polda" && - form.getValues("publishTo")?.includes(item.id) && ( - setUnitData(data)} - isDetail={isDetail ? true : false} - initData={unitData} - /> - )} - {item.id === "satker" && - form.getValues("publishTo")?.includes(item.id) && ( - setSatkerData(data)} - isDetail={isDetail ? true : false} - initData={satkerData} - /> - )} - - ))} -
- -
- )} - />