import { Egg } from '@/api/admin/eggs/getEgg'; import updateEgg from '@/api/admin/eggs/updateEgg'; import Field from '@/components/elements/Field'; import useFlash from '@/plugins/useFlash'; import { shell } from '@codemirror/legacy-modes/mode/shell'; import { faScroll } from '@fortawesome/free-solid-svg-icons'; import { Form, Formik, FormikHelpers } from 'formik'; import React from 'react'; import tw from 'twin.macro'; import AdminBox from '@/components/admin/AdminBox'; import Button from '@/components/elements/Button'; import Editor from '@/components/elements/Editor'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; interface Values { scriptContainer: string; scriptEntry: string; scriptInstall: string; } export default function EggInstallContainer ({ egg }: { egg: Egg }) { const { clearFlashes, clearAndAddHttpError } = useFlash(); let fetchFileContent: null | (() => Promise) = null; const submit = async (values: Values, { setSubmitting }: FormikHelpers) => { if (fetchFileContent === null) { return; } values.scriptInstall = await fetchFileContent(); clearFlashes('egg'); updateEgg(egg.id, values) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'egg', error }); }) .then(() => setSubmitting(false)); }; return ( {({ isSubmitting, isValid }) => (
{ fetchFileContent = value; }} />
)}
); }