import { Text } from "ink"; import TextInput from "ink-text-input"; import React, { useEffect, useState } from "react"; import { ImportantText } from "../components/ImportantText"; import { Message } from "../components/Message"; import { BaseAppFork, Seed, generateAppFiles } from "../core"; import { getApp } from "../utils/getApp"; export default function DeleteForm({ slug, action }: { slug: string; action: "delete" | "delete-template" }) { const [confirmedAppSlug, setConfirmedAppSlug] = useState(""); const [state, setState] = useState< | "INITIALIZED" | "DELETION_CONFIRMATION_FAILED" | "DELETION_CONFIRMATION_SUCCESSFUL" | "DELETION_COMPLETED" | "APP_NOT_EXISTS" >("INITIALIZED"); const isTemplate = action === "delete-template"; const app = getApp(slug, isTemplate); useEffect(() => { if (!app) { setState("APP_NOT_EXISTS"); } }, []); useEffect(() => { if (state === "DELETION_CONFIRMATION_SUCCESSFUL") { (async () => { await BaseAppFork.delete({ slug, isTemplate }); Seed.revert({ slug }); await generateAppFiles(); // successMsg({ text: `App with slug ${slug} has been deleted`, done: true }); setState("DELETION_COMPLETED"); })(); } }, [slug, state]); if (state === "INITIALIZED") { return ( <> Type below the slug of the {isTemplate ? "Template" : "App"} that you want to delete. It would cleanup the app directory and App table and Credential table. { if (value === slug) { setState("DELETION_CONFIRMATION_SUCCESSFUL"); } else { setState("DELETION_CONFIRMATION_FAILED"); } }} onChange={(val) => { setConfirmedAppSlug(val); }} /> ); } if (state === "APP_NOT_EXISTS") { return ( ); } if (state === "DELETION_CONFIRMATION_SUCCESSFUL") { return ( ); } if (state === "DELETION_COMPLETED") { return ( ); } if (state === "DELETION_CONFIRMATION_FAILED") { return ( ); } return null; }