fix: conflict in image-update-form
This commit is contained in:
parent
4605ef3aeb
commit
c7b2456a78
|
|
@ -247,162 +247,6 @@ export default function FormImageUpdate() {
|
||||||
) as PlacementType[];
|
) as PlacementType[];
|
||||||
};
|
};
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
setCategories(resCategory);
|
|
||||||
// console.log("data category", resCategory);
|
|
||||||
|
|
||||||
if (scheduleId && scheduleType === "3") {
|
|
||||||
const findCategory = resCategory.find((o) =>
|
|
||||||
o.name.toLowerCase().includes("pers rilis")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (findCategory) {
|
|
||||||
// setValue("categoryId", findCategory.id);
|
|
||||||
setSelectedCategory(findCategory.id);
|
|
||||||
const response = await getTagsBySubCategoryId(findCategory.id);
|
|
||||||
setTags(response?.data?.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch categories:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
async function initState() {
|
|
||||||
if (id) {
|
|
||||||
const response = await detailMedia(id);
|
|
||||||
const details = response?.data?.data;
|
|
||||||
|
|
||||||
setDetail(details);
|
|
||||||
|
|
||||||
// Set the selected target to the category ID from details
|
|
||||||
setSelectedTarget(String(details.category.id));
|
|
||||||
setTempFile(details?.files);
|
|
||||||
|
|
||||||
setValue("title", details.title);
|
|
||||||
setValue("description", details.htmlDescription);
|
|
||||||
setValue("creatorName", details.creatorName);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
setValue("title", details.title);
|
|
||||||
setValue("description", details.htmlDescription);
|
|
||||||
setValue("creatorName", details.creatorName);
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
if (details?.files) {
|
|
||||||
const formattedFiles = details.files.map((file: any) => ({
|
|
||||||
...file,
|
|
||||||
id: file.id,
|
|
||||||
fileName: file.fileName,
|
|
||||||
size: file.size,
|
|
||||||
thumbnailFileUrl: file.thumbnailFileUrl,
|
|
||||||
url: file.url,
|
|
||||||
}));
|
|
||||||
|
|
||||||
setFiles(formattedFiles);
|
|
||||||
|
|
||||||
// Inisialisasi filePlacements dari detail
|
|
||||||
const initialFilePlacements = details.files.map((file: any) => {
|
|
||||||
if (file.placements) {
|
|
||||||
// Map dari format backend ke format internal
|
|
||||||
const mappedPlacements = file.placements
|
|
||||||
.split(",")
|
|
||||||
.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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return mappedPlacements;
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
setFilePlacements(initialFilePlacements);
|
|
||||||
|
|
||||||
// Inisialisasi fileCheckedLevels dari detail
|
|
||||||
const initialFileCheckedLevels = details.files.map((file: any) => {
|
|
||||||
if (file.customLocationPlacements) {
|
|
||||||
const levelIds = file.customLocationPlacements
|
|
||||||
.split(",")
|
|
||||||
.map((id: string) => Number(id.trim()))
|
|
||||||
.filter((id: number) => !isNaN(id));
|
|
||||||
return new Set(levelIds);
|
|
||||||
}
|
|
||||||
return new Set<number>();
|
|
||||||
});
|
|
||||||
setFileCheckedLevels(initialFileCheckedLevels);
|
|
||||||
|
|
||||||
// Inisialisasi fileUnitSelections dari detail
|
|
||||||
const initialFileUnitSelections = details.files.map((file: any) => {
|
|
||||||
const selection = {
|
|
||||||
semua: false,
|
|
||||||
nasional: false,
|
|
||||||
wilayah: false,
|
|
||||||
international: false,
|
|
||||||
polda: false,
|
|
||||||
satker: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (file.placements) {
|
|
||||||
const placements = file.placements
|
|
||||||
.split(",")
|
|
||||||
.map((p: string) => p.trim());
|
|
||||||
|
|
||||||
// Map dari format backend ke checkbox
|
|
||||||
if (placements.includes("all")) {
|
|
||||||
selection.semua = true;
|
|
||||||
selection.nasional = true;
|
|
||||||
selection.wilayah = true;
|
|
||||||
selection.international = true;
|
|
||||||
selection.polda = true;
|
|
||||||
selection.satker = true;
|
|
||||||
} else {
|
|
||||||
if (placements.includes("mabes")) {
|
|
||||||
selection.nasional = true;
|
|
||||||
}
|
|
||||||
if (placements.includes("wilayah")) {
|
|
||||||
selection.wilayah = true;
|
|
||||||
}
|
|
||||||
if (placements.includes("polda")) {
|
|
||||||
selection.polda = true;
|
|
||||||
selection.wilayah = true; // Auto-check wilayah when polda is present
|
|
||||||
}
|
|
||||||
if (placements.includes("satker")) {
|
|
||||||
selection.satker = true;
|
|
||||||
selection.wilayah = true; // Auto-check wilayah when satker is present
|
|
||||||
}
|
|
||||||
if (placements.includes("international")) {
|
|
||||||
selection.international = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return selection;
|
|
||||||
});
|
|
||||||
setFileUnitSelections(initialFileUnitSelections);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (details?.publishedFor) {
|
|
||||||
// Split string "7" to an array ["7"] if needed
|
|
||||||
setPublishedFor(details.publishedFor.split(","));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (details?.tags) {
|
|
||||||
setTags(details.tags.split(",").map((tag: string) => tag.trim()));
|
|
||||||
}
|
|
||||||
=======
|
|
||||||
const toggleExpand = (idStr: string) => {
|
const toggleExpand = (idStr: string) => {
|
||||||
setExpandedPolda((prev) => ({ ...prev, [idStr]: !prev[idStr] }));
|
setExpandedPolda((prev) => ({ ...prev, [idStr]: !prev[idStr] }));
|
||||||
};
|
};
|
||||||
|
|
@ -421,7 +265,6 @@ export default function FormImageUpdate() {
|
||||||
console.error("Error fetching destinations", e);
|
console.error("Error fetching destinations", e);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
>>>>>>> 5b6ffd086332104beb9f02b1414b48cda3f030a0
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -984,23 +827,9 @@ export default function FormImageUpdate() {
|
||||||
file: any,
|
file: any,
|
||||||
duration: string
|
duration: string
|
||||||
) {
|
) {
|
||||||
<<<<<<< HEAD
|
|
||||||
// console.log(idx, id, file, duration);
|
|
||||||
|
|
||||||
// const placements = getPlacement(file.placements);
|
|
||||||
// console.log("Placementttt: : ", placements);
|
|
||||||
|
|
||||||
const resCsrf = await getCsrfToken();
|
|
||||||
const csrfToken = resCsrf?.data?.token;
|
|
||||||
// console.log("CSRF TOKEN : ", csrfToken);
|
|
||||||
const headers = {
|
|
||||||
"X-XSRF-TOKEN": csrfToken,
|
|
||||||
};
|
|
||||||
=======
|
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.token;
|
const csrfToken = resCsrf?.data?.token;
|
||||||
const headers = { "X-XSRF-TOKEN": csrfToken };
|
const headers = { "X-XSRF-TOKEN": csrfToken };
|
||||||
>>>>>>> 5b6ffd086332104beb9f02b1414b48cda3f030a0
|
|
||||||
|
|
||||||
if (!file.secondaryUrl || file.secondaryUrl == "") {
|
if (!file.secondaryUrl || file.secondaryUrl == "") {
|
||||||
const upload = new Upload(file, {
|
const upload = new Upload(file, {
|
||||||
|
|
@ -1031,10 +860,6 @@ export default function FormImageUpdate() {
|
||||||
const percent = Math.floor((bytesAccepted / bytesTotal) * 100);
|
const percent = Math.floor((bytesAccepted / bytesTotal) * 100);
|
||||||
progressInfo[idx].percentage = percent;
|
progressInfo[idx].percentage = percent;
|
||||||
counterUpdateProgress++;
|
counterUpdateProgress++;
|
||||||
<<<<<<< HEAD
|
|
||||||
// console.log(counterUpdateProgress);
|
|
||||||
=======
|
|
||||||
>>>>>>> 5b6ffd086332104beb9f02b1414b48cda3f030a0
|
|
||||||
setProgressList(progressInfo);
|
setProgressList(progressInfo);
|
||||||
setCounterProgress(counterUpdateProgress);
|
setCounterProgress(counterUpdateProgress);
|
||||||
},
|
},
|
||||||
|
|
@ -1253,53 +1078,6 @@ export default function FormImageUpdate() {
|
||||||
onChange={(e) => setTranslatedTitle(e.target.value)}
|
onChange={(e) => setTranslatedTitle(e.target.value)}
|
||||||
placeholder="English version"
|
placeholder="English version"
|
||||||
/>
|
/>
|
||||||
<<<<<<< HEAD
|
|
||||||
{errors.title?.message && (
|
|
||||||
<p className="text-red-400 text-sm">
|
|
||||||
{errors.title.message}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div> */}
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="py-3 w-full space-y-2">
|
|
||||||
<Label>{t("category", { defaultValue: "Category" })}</Label>
|
|
||||||
<Select
|
|
||||||
value={selectedTarget}
|
|
||||||
onValueChange={(id) => {
|
|
||||||
// console.log("Selected Category ID:", id);
|
|
||||||
setSelectedTarget(id);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SelectTrigger size="md">
|
|
||||||
<SelectValue placeholder="Pilih" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{/* Show the category from details if it doesn't exist in categories list */}
|
|
||||||
{detail &&
|
|
||||||
!categories.find(
|
|
||||||
(cat) =>
|
|
||||||
String(cat.id) === String(detail.category.id)
|
|
||||||
) && (
|
|
||||||
<SelectItem
|
|
||||||
key={String(detail.category.id)}
|
|
||||||
value={String(detail.category.id)}
|
|
||||||
>
|
|
||||||
{detail.category.name}
|
|
||||||
</SelectItem>
|
|
||||||
)}
|
|
||||||
{categories.map((category) => (
|
|
||||||
<SelectItem
|
|
||||||
key={String(category.id)}
|
|
||||||
value={String(category.id)}
|
|
||||||
>
|
|
||||||
{category.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
=======
|
|
||||||
>>>>>>> 5b6ffd086332104beb9f02b1414b48cda3f030a0
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -1955,31 +1733,6 @@ export default function FormImageUpdate() {
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<<<<<<< HEAD
|
|
||||||
<div className="px-3 py-3 flex flex-row items-center text-blue-500 gap-2 text-sm">
|
|
||||||
<MailIcon />
|
|
||||||
<p className="">
|
|
||||||
{t("suggestion-box", { defaultValue: "Suggestion Box" })} (0)
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="px-3 py-3">
|
|
||||||
<p>{t("information", { defaultValue: "Information" })}:</p>
|
|
||||||
{/* <p>{detail?.status}</p> */}
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
<div className="flex flex-row justify-end gap-3">
|
|
||||||
<div className="mt-4">
|
|
||||||
<Button type="submit" color="primary">
|
|
||||||
{t("submit", { defaultValue: "Submit" })}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div className="mt-4">
|
|
||||||
<Link href={"/contributor/content/image"}>
|
|
||||||
<Button type="submit" color="primary" variant="outline">
|
|
||||||
{t("cancel", { defaultValue: "Cancel" })}
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
=======
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Publish Target */}
|
{/* Publish Target */}
|
||||||
|
|
@ -2003,7 +1756,6 @@ export default function FormImageUpdate() {
|
||||||
<Label htmlFor={option.id}>{option.name}</Label>
|
<Label htmlFor={option.id}>{option.name}</Label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
>>>>>>> 5b6ffd086332104beb9f02b1414b48cda3f030a0
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue