2021-09-17 20:33:38 +00:00
|
|
|
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';
|
2021-07-21 18:18:53 +00:00
|
|
|
import { shell } from '@codemirror/legacy-modes/mode/shell';
|
2021-09-17 20:33:38 +00:00
|
|
|
import { faScroll } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { Form, Formik, FormikHelpers } from 'formik';
|
2021-05-20 22:00:46 +00:00
|
|
|
import React from 'react';
|
|
|
|
import tw from 'twin.macro';
|
|
|
|
import AdminBox from '@/components/admin/AdminBox';
|
|
|
|
import Button from '@/components/elements/Button';
|
2021-07-21 18:18:53 +00:00
|
|
|
import Editor from '@/components/elements/Editor';
|
2021-05-20 22:00:46 +00:00
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
|
|
|
|
2021-09-17 20:33:38 +00:00
|
|
|
interface Values {
|
|
|
|
scriptContainer: string;
|
|
|
|
scriptEntry: string;
|
|
|
|
scriptInstall: string;
|
|
|
|
}
|
2021-05-20 22:00:46 +00:00
|
|
|
|
2021-09-17 20:33:38 +00:00
|
|
|
export default function EggInstallContainer ({ egg }: { egg: Egg }) {
|
|
|
|
const { clearFlashes, clearAndAddHttpError } = useFlash();
|
|
|
|
|
|
|
|
let fetchFileContent: null | (() => Promise<string>) = null;
|
|
|
|
|
|
|
|
const submit = async (values: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
|
|
|
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));
|
|
|
|
};
|
2021-05-20 22:00:46 +00:00
|
|
|
|
|
|
|
return (
|
2021-09-17 20:33:38 +00:00
|
|
|
<Formik
|
|
|
|
onSubmit={submit}
|
|
|
|
initialValues={{
|
|
|
|
scriptContainer: egg.scriptContainer,
|
|
|
|
scriptEntry: egg.scriptEntry,
|
|
|
|
scriptInstall: '',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{({ isSubmitting, isValid }) => (
|
|
|
|
<AdminBox icon={faScroll} title={'Install Script'} padding={false}>
|
|
|
|
<div css={tw`relative pb-4`}>
|
|
|
|
<SpinnerOverlay visible={isSubmitting}/>
|
|
|
|
|
|
|
|
<Form>
|
|
|
|
<Editor
|
|
|
|
overrides={tw`h-96 mb-4`}
|
|
|
|
initialContent={egg.scriptInstall || ''}
|
|
|
|
mode={shell}
|
|
|
|
fetchContent={value => {
|
|
|
|
fetchFileContent = value;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div css={tw`mx-6 mb-4`}>
|
|
|
|
<div css={tw`grid grid-cols-3 gap-x-8 gap-y-6`}>
|
|
|
|
<Field
|
|
|
|
id={'scriptContainer'}
|
|
|
|
name={'scriptContainer'}
|
|
|
|
label={'Install Container'}
|
|
|
|
type={'text'}
|
|
|
|
description={'The Docker image to use for running this installation script.'}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Field
|
|
|
|
id={'scriptEntry'}
|
|
|
|
name={'scriptEntry'}
|
|
|
|
label={'Install Entrypoint'}
|
|
|
|
type={'text'}
|
|
|
|
description={'The command that should be used to run this script inside of the installation container.'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={tw`flex flex-row border-t border-neutral-600`}>
|
|
|
|
<Button type={'submit'} size={'small'} css={tw`ml-auto mr-6 mt-4`} disabled={isSubmitting || !isValid}>
|
|
|
|
Save Changes
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Form>
|
2021-05-20 22:00:46 +00:00
|
|
|
</div>
|
2021-09-17 20:33:38 +00:00
|
|
|
</AdminBox>
|
|
|
|
)}
|
|
|
|
</Formik>
|
2021-05-20 22:00:46 +00:00
|
|
|
);
|
2021-09-17 20:33:38 +00:00
|
|
|
}
|