From 1103f5f42f92f94fddccfc08d376856ab9c00180 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Sat, 21 Jun 2025 20:17:25 +0700 Subject: [PATCH] fixing --- components/form/content/audio-update-form.tsx | 124 +++--- components/form/content/image-update-form.tsx | 131 ++++--- components/form/content/teks-update-form.tsx | 124 +++--- components/form/content/video-update-form.tsx | 37 +- .../form/task-ta/task-ta-detail-form.tsx | 10 +- components/landing-page/hero-new.tsx | 40 +- .../landing-page/search-section-new.tsx | 362 +++++++++++++----- service/landing/landing.ts | 4 +- 8 files changed, 523 insertions(+), 309 deletions(-) diff --git a/components/form/content/audio-update-form.tsx b/components/form/content/audio-update-form.tsx index 4c9cb9a1..ee15183e 100644 --- a/components/form/content/audio-update-form.tsx +++ b/components/form/content/audio-update-form.tsx @@ -244,6 +244,11 @@ export default function FormAudioUpdate() { const details = response?.data?.data; setDetail(details); + setSelectedTarget(String(details.category.id)); + + setValue("title", details.title); + setValue("description", details.description); + setValue("creatorName", details.creatorName); if (details?.files) { setPrefFiles(details.files); @@ -266,15 +271,15 @@ export default function FormAudioUpdate() { setTags(details.tags.split(",").map((tag: string) => tag.trim())); } - const matchingCategory = categories.find( - (category) => category.id === details.categoryId - ); + // const matchingCategory = categories.find( + // (category) => category.id === details.categoryId + // ); - if (matchingCategory) { - setSelectedTarget(matchingCategory.name); - } + // if (matchingCategory) { + // setSelectedTarget(matchingCategory.name); + // } - setSelectedTarget(details.categoryId); + // setSelectedTarget(details.categoryId); const filesData = details.files || []; const fileUrls = filesData.map((file: { secondaryUrl: string }) => @@ -350,6 +355,10 @@ export default function FormAudioUpdate() { const response = await createMedia(requestData); console.log("Form Data Submitted:", requestData); + if (response?.error) { + error(response?.message); + return false; + } const formMedia = new FormData(); const thumbnail = files[0]; @@ -403,48 +412,50 @@ export default function FormAudioUpdate() { "X-XSRF-TOKEN": csrfToken, }; - const upload = new Upload(file, { - endpoint: `${process.env.NEXT_PUBLIC_API}/media/file/upload`, - headers: headers, - retryDelays: [0, 3000, 6000, 12_000, 24_000], - chunkSize: 20_000, - metadata: { - mediaid: id, - filename: file.name, - filetype: file.type, - duration, - isWatermark: "false", // hardcode - }, - onBeforeRequest: function (req) { - var xhr = req.getUnderlyingObject(); - xhr.withCredentials = true; - }, - onError: async (e: any) => { - console.log("Error upload :", e); - error(e); - }, - onChunkComplete: ( - chunkSize: any, - bytesAccepted: any, - bytesTotal: any - ) => { - const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); - progressInfo[idx].percentage = uploadPersen; - counterUpdateProgress++; - console.log(counterUpdateProgress); - setProgressList(progressInfo); - setCounterProgress(counterUpdateProgress); - }, - onSuccess: async () => { - uploadPersen = 100; - progressInfo[idx].percentage = 100; - counterUpdateProgress++; - setCounterProgress(counterUpdateProgress); - successTodo(); - }, - }); + if (!file.secondaryUrl || file.secondaryUrl == "") { + const upload = new Upload(file, { + endpoint: `${process.env.NEXT_PUBLIC_API}/media/file/upload`, + headers: headers, + retryDelays: [0, 3000, 6000, 12_000, 24_000], + chunkSize: 20_000, + metadata: { + mediaid: id, + filename: file.name, + filetype: file.type, + duration, + isWatermark: "false", // hardcode + }, + onBeforeRequest: function (req) { + var xhr = req.getUnderlyingObject(); + xhr.withCredentials = true; + }, + onError: async (e: any) => { + console.log("Error upload :", e); + error(e); + }, + onChunkComplete: ( + chunkSize: any, + bytesAccepted: any, + bytesTotal: any + ) => { + const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); + progressInfo[idx].percentage = uploadPersen; + counterUpdateProgress++; + console.log(counterUpdateProgress); + setProgressList(progressInfo); + setCounterProgress(counterUpdateProgress); + }, + onSuccess: async () => { + uploadPersen = 100; + progressInfo[idx].percentage = 100; + counterUpdateProgress++; + setCounterProgress(counterUpdateProgress); + successTodo(); + }, + }); - upload.start(); + upload.start(); + } } const onSubmit = (data: AudioSchema) => { @@ -659,7 +670,7 @@ export default function FormAudioUpdate() { @@ -675,7 +686,7 @@ export default function FormAudioUpdate() {
diff --git a/components/form/content/image-update-form.tsx b/components/form/content/image-update-form.tsx index 7391cf2c..1ab93172 100644 --- a/components/form/content/image-update-form.tsx +++ b/components/form/content/image-update-form.tsx @@ -266,6 +266,11 @@ export default function FormImageUpdate() { const details = response?.data?.data; setDetail(details); + setSelectedTarget(String(details.category.id)); + + setValue("title", details.title); + setValue("description", details.description); + setValue("creatorName", details.creatorName); if (details?.files) { setFiles(details.files); @@ -288,15 +293,15 @@ export default function FormImageUpdate() { setTags(details.tags.split(",").map((tag: string) => tag.trim())); } - const matchingCategory = categories.find( - (category) => category.id === details.categoryId - ); + // const matchingCategory = categories.find( + // (category) => category.id === details.categoryId + // ); - if (matchingCategory) { - setSelectedTarget(matchingCategory.name); - } + // if (matchingCategory) { + // setSelectedTarget(matchingCategory.name); + // } - setSelectedTarget(details.categoryId); // Untuk dropdown + // setSelectedTarget(details.categoryId); // Untuk dropdown } } initState(); @@ -367,6 +372,10 @@ export default function FormImageUpdate() { const response = await createMedia(requestData); console.log("Form Data Submitted:", requestData); + if (response?.error) { + error(response?.message); + return false; + } const formMedia = new FormData(); const thumbnail = files[0]; @@ -387,6 +396,7 @@ export default function FormImageUpdate() { close(); // showProgress(); + console.log("files:", files); files.map(async (item: any, index: number) => { await uploadResumableFile( index, @@ -425,48 +435,50 @@ export default function FormImageUpdate() { "X-XSRF-TOKEN": csrfToken, }; - const upload = new Upload(file, { - endpoint: `${process.env.NEXT_PUBLIC_API}/media/file/upload`, - headers: headers, - retryDelays: [0, 3000, 6000, 12_000, 24_000], - chunkSize: 20_000, - metadata: { - mediaid: id, - filename: file.name, - filetype: file.type, - duration, - isWatermark: "true", // hardcode - }, - onBeforeRequest: function (req) { - var xhr = req.getUnderlyingObject(); - xhr.withCredentials = true; - }, - onError: async (e: any) => { - console.log("Error upload :", e); - error(e); - }, - onChunkComplete: ( - chunkSize: any, - bytesAccepted: any, - bytesTotal: any - ) => { - const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); - progressInfo[idx].percentage = uploadPersen; - counterUpdateProgress++; - console.log(counterUpdateProgress); - setProgressList(progressInfo); - setCounterProgress(counterUpdateProgress); - }, - onSuccess: async () => { - uploadPersen = 100; - progressInfo[idx].percentage = 100; - counterUpdateProgress++; - setCounterProgress(counterUpdateProgress); - successTodo(); - }, - }); + if (!file.secondaryUrl || file.secondaryUrl == "") { + const upload = new Upload(file, { + endpoint: `${process.env.NEXT_PUBLIC_API}/media/file/upload`, + headers: headers, + retryDelays: [0, 3000, 6000, 12_000, 24_000], + chunkSize: 20_000, + metadata: { + mediaid: id, + filename: file.name, + filetype: file.type, + duration, + isWatermark: "true", // hardcode + }, + onBeforeRequest: function (req) { + var xhr = req.getUnderlyingObject(); + xhr.withCredentials = true; + }, + onError: async (e: any) => { + console.log("Error upload :", e); + error(e); + }, + onChunkComplete: ( + chunkSize: any, + bytesAccepted: any, + bytesTotal: any + ) => { + const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); + progressInfo[idx].percentage = uploadPersen; + counterUpdateProgress++; + console.log(counterUpdateProgress); + setProgressList(progressInfo); + setCounterProgress(counterUpdateProgress); + }, + onSuccess: async () => { + uploadPersen = 100; + progressInfo[idx].percentage = 100; + counterUpdateProgress++; + setCounterProgress(counterUpdateProgress); + successTodo(); + }, + }); - upload.start(); + upload.start(); + } } const onSubmit = (data: ImageSchema) => { @@ -671,7 +683,7 @@ export default function FormImageUpdate() { @@ -687,21 +699,21 @@ export default function FormImageUpdate() {
diff --git a/components/form/content/teks-update-form.tsx b/components/form/content/teks-update-form.tsx index 7323b430..cf6c2894 100644 --- a/components/form/content/teks-update-form.tsx +++ b/components/form/content/teks-update-form.tsx @@ -239,6 +239,11 @@ export default function FormTeksUpdate() { const details = response?.data?.data; setDetail(details); + setSelectedTarget(String(details.category.id)); + + setValue("title", details.title); + setValue("description", details.description); + setValue("creatorName", details.creatorName); if (details?.files) { setFiles(details.files); @@ -260,15 +265,15 @@ export default function FormTeksUpdate() { setTags(details.tags.split(",").map((tag: string) => tag.trim())); } - const matchingCategory = categories.find( - (category) => category.id === details.categoryId - ); + // const matchingCategory = categories.find( + // (category) => category.id === details.categoryId + // ); - if (matchingCategory) { - setSelectedTarget(matchingCategory.name); - } + // if (matchingCategory) { + // setSelectedTarget(matchingCategory.name); + // } - setSelectedTarget(details.categoryId); // Untuk dropdown + // setSelectedTarget(details.categoryId); // Untuk dropdown } } initState(); @@ -339,6 +344,10 @@ export default function FormTeksUpdate() { const response = await createMedia(requestData); console.log("Form Data Submitted:", requestData); + if (response?.error) { + error(response?.message); + return false; + } const formMedia = new FormData(); const thumbnail = files[0]; @@ -397,48 +406,50 @@ export default function FormTeksUpdate() { "X-XSRF-TOKEN": csrfToken, }; - const upload = new Upload(file, { - endpoint: `${process.env.NEXT_PUBLIC_API}/media/file/upload`, - headers: headers, - retryDelays: [0, 3000, 6000, 12_000, 24_000], - chunkSize: 20_000, - metadata: { - mediaid: id, - filename: file.name, - filetype: file.type, - duration, - isWatermark: "true", // hardcode - }, - onBeforeRequest: function (req) { - var xhr = req.getUnderlyingObject(); - xhr.withCredentials = true; - }, - onError: async (e: any) => { - console.log("Error upload :", e); - error(e); - }, - onChunkComplete: ( - chunkSize: any, - bytesAccepted: any, - bytesTotal: any - ) => { - const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); - progressInfo[idx].percentage = uploadPersen; - counterUpdateProgress++; - console.log(counterUpdateProgress); - setProgressList(progressInfo); - setCounterProgress(counterUpdateProgress); - }, - onSuccess: async () => { - uploadPersen = 100; - progressInfo[idx].percentage = 100; - counterUpdateProgress++; - setCounterProgress(counterUpdateProgress); - successTodo(); - }, - }); + if (!file.secondaryUrl || file.secondaryUrl == "") { + const upload = new Upload(file, { + endpoint: `${process.env.NEXT_PUBLIC_API}/media/file/upload`, + headers: headers, + retryDelays: [0, 3000, 6000, 12_000, 24_000], + chunkSize: 20_000, + metadata: { + mediaid: id, + filename: file.name, + filetype: file.type, + duration, + isWatermark: "true", // hardcode + }, + onBeforeRequest: function (req) { + var xhr = req.getUnderlyingObject(); + xhr.withCredentials = true; + }, + onError: async (e: any) => { + console.log("Error upload :", e); + error(e); + }, + onChunkComplete: ( + chunkSize: any, + bytesAccepted: any, + bytesTotal: any + ) => { + const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); + progressInfo[idx].percentage = uploadPersen; + counterUpdateProgress++; + console.log(counterUpdateProgress); + setProgressList(progressInfo); + setCounterProgress(counterUpdateProgress); + }, + onSuccess: async () => { + uploadPersen = 100; + progressInfo[idx].percentage = 100; + counterUpdateProgress++; + setCounterProgress(counterUpdateProgress); + successTodo(); + }, + }); - upload.start(); + upload.start(); + } } const onSubmit = (data: TeksSchema) => { @@ -615,7 +626,7 @@ export default function FormTeksUpdate() { @@ -631,7 +642,7 @@ export default function FormTeksUpdate() {
diff --git a/components/form/content/video-update-form.tsx b/components/form/content/video-update-form.tsx index 959c6aae..64378831 100644 --- a/components/form/content/video-update-form.tsx +++ b/components/form/content/video-update-form.tsx @@ -262,6 +262,11 @@ export default function FormVideoUpdate() { const details = response?.data?.data; setDetail(details); + setSelectedTarget(String(details.category.id)); + + setValue("title", details.title); + setValue("description", details.description); + setValue("creatorName", details.creatorName); if (details?.files) { setFiles(details.files); @@ -283,15 +288,15 @@ export default function FormVideoUpdate() { setTags(details.tags.split(",").map((tag: string) => tag.trim())); } - const matchingCategory = categories.find( - (category) => category.id === details.categoryId - ); + // const matchingCategory = categories.find( + // (category) => category.id === details.categoryId + // ); + // console.log("LALALALAL", matchingCategory) + // if (matchingCategory) { + // setSelectedTarget(String(matchingCategory.id)); + // } - if (matchingCategory) { - setSelectedTarget(matchingCategory.name); - } - - setSelectedTarget(details.categoryId); // Untuk dropdown + // setSelectedTarget(details.categoryId); // Untuk dropdown const filesData = details.files || []; const fileUrls = filesData.map((files: { url: string }) => @@ -727,7 +732,7 @@ export default function FormVideoUpdate() { @@ -743,7 +748,7 @@ export default function FormVideoUpdate() {
diff --git a/components/form/task-ta/task-ta-detail-form.tsx b/components/form/task-ta/task-ta-detail-form.tsx index c2554dc6..e667b7b8 100644 --- a/components/form/task-ta/task-ta-detail-form.tsx +++ b/components/form/task-ta/task-ta-detail-form.tsx @@ -113,6 +113,7 @@ export type taskDetail = { broadcastType: string; narration: string; is_active: string; + isAssignmentAccepted: boolean; isDone: any; }; @@ -1340,7 +1341,7 @@ export default function FormTaskTaDetail() { "" )}
*/} -
+
{/*
*/} - {/*
+
-
*/} +
void; @@ -67,6 +67,12 @@ const HeroModal = ({ const locale = params?.locale; const swiperRef = useRef(null); + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + useEffect(() => { async function fetchCategories() { const url = "https://netidhub.com/api/csrf"; @@ -167,7 +173,7 @@ const HeroModal = ({ {list?.categoryName || "Liputan Kegiatan"} - +

{list?.title}

@@ -226,6 +232,12 @@ const HeroNew = (props: { group?: string }) => { const [newContent, setNewContent] = useState(); const [selectedTab, setSelectedTab] = useState("image"); + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + useEffect(() => { fecthNewContent(); }, [selectedTab]); @@ -263,7 +275,6 @@ const HeroNew = (props: { group?: string }) => { setNewContent(response?.data?.data?.content); }; - useEffect(() => { const timer = setTimeout(() => { setIsLoading(false); @@ -415,7 +426,18 @@ const HeroNew = (props: { group?: string }) => {
{/* Konten judul, dll */} -
+ {list?.categoryName} @@ -424,7 +446,7 @@ const HeroNew = (props: { group?: string }) => { {formatDateToIndonesian(new Date(list?.createdAt))}{" "} {list?.timezone || "WIB"} | 👁 {list?.clickCount}

-
+ {/* Tombol navigasi di atas gambar */} @@ -458,12 +480,12 @@ const HeroNew = (props: { group?: string }) => { diff --git a/components/landing-page/search-section-new.tsx b/components/landing-page/search-section-new.tsx index b1b27514..bc698988 100644 --- a/components/landing-page/search-section-new.tsx +++ b/components/landing-page/search-section-new.tsx @@ -4,7 +4,14 @@ import { useParams, useRouter } from "next/navigation"; import router from "next/router"; import React, { useEffect, useState } from "react"; import { Icon } from "@iconify/react/dist/iconify.js"; -import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "../ui/select"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, +} from "../ui/select"; import Image from "next/image"; import { getHeroData } from "@/service/landing/landing"; import { title } from "process"; @@ -21,7 +28,16 @@ const ScrollableContent = () => { const params = useParams(); const locale = params?.locale; const t = useTranslations("LandingPage"); - const [content, setContent] = useState(); + const [contentPolda, setContentPolda] = useState(); + const [contentSatker, setContentSatker] = useState(); + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; useEffect(() => { async function fetchCategories() { @@ -42,15 +58,23 @@ const ScrollableContent = () => { } fetchCategories(); - initFetch(); + initFetchPolda(); + initFetchSatker(); }, []); - const initFetch = async () => { - const response = await getHeroData(locale == "en"); + const initFetchPolda = async () => { + const response = await getHeroData(locale == "en", "polda"); console.log(response); let data = response?.data?.data?.content; - setContent(data); + setContentPolda(data); + }; + const initFetchSatker = async () => { + const response = await getHeroData(locale == "en", "satker"); + console.log(response); + let data = response?.data?.data?.content; + + setContentSatker(data); }; return ( @@ -66,14 +90,23 @@ const ScrollableContent = () => {
-

{t("officialCoverage")}

+

+ {t("officialCoverage")} +

- + - setSearch(e.target.value)} /> + setSearch(e.target.value)} + />
- @@ -113,82 +161,133 @@ const ScrollableContent = () => {
{/* Berita Polda */}
-

{t("regionNews")}

+

+ {t("regionNews")} +

- {(seeAllValuePolda ? content : content?.slice(0, 3))?.map((item: any, index: number) => ( -
-
+ {(seeAllValuePolda ? contentPolda : contentPolda?.slice(0, 3))?.map( + (item: any, index: number) => ( +
+
+ + {item?.title} +
+ + + + + + +
+ +
+ {/* */} - {item?.title} -
- - - - - - -
+

+ {item.categoryName} +

+

+ {item.title} +

+

+ {htmlToString(item.description)} +

- {/* */} -
-

{item.categoryName}

-

{item.title}

-

{htmlToString(item.description)}

-
+ ) + )} + {contentPolda?.length > 3 && ( +
+
- ))} - {/* {" "} */} - {/* Tombol See More / See Less */} - {content?.length > 3 && ( -
- -
- )} + )}
{/* Berita SATKER */}
-

{t("divisionNews")}

+

+ {t("divisionNews")} +

@@ -201,12 +300,12 @@ const ScrollableContent = () => { {item.title} @@ -238,23 +337,45 @@ const ScrollableContent = () => { */} - {(seeAllValueSatker ? content : content?.slice(0, 3))?.map((item: any, index: number) => ( -
-
+ {(seeAllValueSatker + ? contentSatker + : contentSatker?.slice(0, 3) + )?.map((item: any, index: number) => ( +
+
- {item?.title} + {item?.title}
- + { {/* */} -
-

{item.categoryName}

-

{item.title}

-

{htmlToString(item.description)}

-
+ +

+ {item.categoryName} +

+

+ {item.title} +

+

+ {htmlToString(item.description)} +

+
))} - {/* Tombol See More / See Less */} - {content?.length > 3 && ( -
- -
- )} + {/* Tombol See More / See Less */} + {contentSatker?.length > 3 && ( +
+ +
+ )}
diff --git a/service/landing/landing.ts b/service/landing/landing.ts index d8e798e6..e61e8220 100644 --- a/service/landing/landing.ts +++ b/service/landing/landing.ts @@ -31,9 +31,9 @@ export async function getCsrfToken() { // } } -export async function getHeroData(isInt: Boolean = false) { +export async function getHeroData(isInt: Boolean = false, unitType= "") { return await httpGetInterceptor( - `media/public/list?enablePage=1&sort=desc&sortBy=createdAt&size=5&page=0&typeId=1&title=&categoryId=&fileFormats=&tags=&group=&startDate=&endDate=&month=&year=&isInt=${isInt}` + `media/public/list?enablePage=1&sort=desc&sortBy=createdAt&size=5&page=0&typeId=1&title=&categoryId=&fileFormats=&tags=&group=&startDate=&endDate=&month=&year=&isInt=${isInt}${unitType==""?"":unitType=='polda'?'&isAllPolda=true':'&isAllSatker=true'}` ); }