import { useEggFromRoute } from '@/api/admin/egg'; import updateEgg from '@/api/admin/eggs/updateEgg'; import EggDeleteButton from '@/components/admin/nests/eggs/EggDeleteButton'; import EggExportButton from '@/components/admin/nests/eggs/EggExportButton'; import Button from '@/components/elements/Button'; // import Editor from '@/components/elements/Editor'; import Field, { TextareaField } from '@/components/elements/Field'; import Input from '@/components/elements/Input'; import Label from '@/components/elements/Label'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import useFlash from '@/plugins/useFlash'; // import { jsonLanguage } from '@codemirror/lang-json'; import { faDocker } from '@fortawesome/free-brands-svg-icons'; import { faEgg, faFireAlt, faMicrochip, faTerminal } from '@fortawesome/free-solid-svg-icons'; import { forwardRef, useImperativeHandle, useRef } from 'react'; import AdminBox from '@/components/admin/AdminBox'; import { useNavigate } from 'react-router-dom'; import tw from 'twin.macro'; import { object } from 'yup'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; export function EggInformationContainer() { const { isSubmitting } = useFormikContext(); return ( ); } function EggDetailsContainer() { const { data: egg } = useEggFromRoute(); if (!egg) { return null; } return (
); } export function EggStartupContainer({ className }: { className?: string }) { const { isSubmitting } = useFormikContext(); return ( ); } export function EggImageContainer() { const { isSubmitting } = useFormikContext(); return ( ); } export function EggLifecycleContainer() { const { isSubmitting } = useFormikContext(); return ( ); } interface EggProcessContainerProps { className?: string; } export interface EggProcessContainerRef { getStartupConfiguration: () => Promise; getFilesConfiguration: () => Promise; } export const EggProcessContainer = forwardRef(function EggProcessContainer( { className }, ref, ) { // const { isSubmitting, values } = useFormikContext(); const { isSubmitting } = useFormikContext(); let fetchStartupConfiguration: (() => Promise) | null = null; let fetchFilesConfiguration: (() => Promise) | null = null; useImperativeHandle(ref, () => ({ getStartupConfiguration: async () => { if (fetchStartupConfiguration === null) { return new Promise(resolve => resolve(null)); } return await fetchStartupConfiguration(); }, getFilesConfiguration: async () => { if (fetchFilesConfiguration === null) { return new Promise(resolve => resolve(null)); } return await fetchFilesConfiguration(); }, })); return (
{/* {*/} {/* fetchStartupConfiguration = value;*/} {/* }}*/} {/*/>*/}
{/* {*/} {/* fetchFilesConfiguration = value;*/} {/* }}*/} {/*/>*/}
); }); interface Values { name: string; description: string; startup: string; dockerImages: string; configStop: string; configStartup: string; configFiles: string; } export default function EggSettingsContainer() { const navigate = useNavigate(); const ref = useRef(); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { data: egg } = useEggFromRoute(); if (!egg) { return null; } const submit = async (values: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('egg'); values.configStartup = (await ref.current?.getStartupConfiguration()) || ''; values.configFiles = (await ref.current?.getFilesConfiguration()) || ''; updateEgg(egg.id, { ...values, // TODO dockerImages: {}, }) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'egg', error }); }) .then(() => setSubmitting(false)); }; return ( {({ isSubmitting, isValid }) => (
navigate('/admin/nests')} />
)}
); }