diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index 6e9ce4aa..0e0b086c 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -69,6 +69,7 @@ import { getCookiesDecrypt } from "@/lib/utils"; import { error } from "@/lib/swal"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; +import { close, loading } from "@/config/swal"; // Types interface Category { @@ -163,6 +164,7 @@ export default function FormConvertSPIT() { const router = useRouter(); const t = useTranslations("Form"); const { id } = useParams() as { id: string }; + const [isAlreadySaved, setIsAlreadySaved] = useState(false); // Form state const { @@ -198,35 +200,33 @@ export default function FormConvertSPIT() { const [showRewriteEditor, setShowRewriteEditor] = useState(false); const [isGeneratingRewrite, setIsGeneratingRewrite] = useState(false); const [isLoadingRewrite, setIsLoadingRewrite] = useState(false); - - // Media state const [detailThumb, setDetailThumb] = useState([]); const [thumbsSwiper, setThumbsSwiper] = useState(null); const [files, setFiles] = useState([]); const [filePlacements, setFilePlacements] = useState([]); - - // Content rewrite state const [articleIds, setArticleIds] = useState([]); const [selectedArticleId, setSelectedArticleId] = useState( null ); const [articleBody, setArticleBody] = useState(""); - - // Form data state const [tags, setTags] = useState([]); const [publishedFor, setPublishedFor] = useState([]); const [inputRef] = useState(useRef(null)); - - // User permissions const userLevelId = getCookiesDecrypt("ulie"); const roleId = getCookiesDecrypt("urie"); const [isUserMabesApprover, setIsUserMabesApprover] = useState(false); - // Initialize component useEffect(() => { initializeComponent(); }, []); + // useEffect(() => { + // const savedFlag = localStorage.getItem(`spit_saved_${id}`); + // if (savedFlag === "true") { + // setIsAlreadySaved(true); + // } + // }, [id]); + useEffect(() => { checkUserPermissions(); }, [userLevelId, roleId]); @@ -294,9 +294,12 @@ export default function FormConvertSPIT() { }; const loadDetail = async () => { + loading() try { const response = await detailSPIT(id); const details = response?.data?.data; + setIsAlreadySaved(details?.isPublish ? true : false) + if (!details) { throw new Error("Detail not found"); @@ -323,13 +326,11 @@ export default function FormConvertSPIT() { details.contentRewriteDescription || "" ); - // Set category if (details.categoryId) { setSelectedCategoryId(details.categoryId); await loadTags(details.categoryId); } - // Set tags if (details.contentTag) { const initialTags = details.contentTag .split(",") @@ -340,9 +341,9 @@ export default function FormConvertSPIT() { console.error("Failed to load detail:", error); throw error; } + close() }; - // Event handlers const handleCategoryChange = async (categoryId: string) => { const id = Number(categoryId); setSelectedCategoryId(id); @@ -601,6 +602,9 @@ export default function FormConvertSPIT() { await convertSPIT(requestData); + // localStorage.setItem(`spit_saved_${id}`, "true"); + // setIsAlreadySaved(true); + MySwal.fire({ title: "Success", text: "Data saved successfully", @@ -608,7 +612,8 @@ export default function FormConvertSPIT() { confirmButtonColor: "#3085d6", }).then(() => { // router.push("/in/contributor/content/spit"); - router.replace(`${window.location.pathname}?id=${id}`); + // router.replace(`${window.location.pathname}?id=${id}`); + loadDetail() }); } catch (error) { console.error("Failed to save:", error); @@ -1164,15 +1169,28 @@ export default function FormConvertSPIT() { + + {isAlreadySaved && ( + + + + Konten sudah disimpan. Anda tidak dapat menyimpan ulang. + + + )}