2021-09-13 05:50:12 +00:00
import EggSelect from '@/components/admin/servers/EggSelect' ;
import NestSelect from '@/components/admin/servers/NestSelect' ;
2021-05-20 22:00:46 +00:00
import FormikSwitch from '@/components/elements/FormikSwitch' ;
2021-09-13 05:50:12 +00:00
import React , { useState } from 'react' ;
import Button from '@/components/elements/Button' ;
2021-05-20 22:00:46 +00:00
import Input from '@/components/elements/Input' ;
import AdminBox from '@/components/admin/AdminBox' ;
import tw from 'twin.macro' ;
import { object } from 'yup' ;
import Field from '@/components/elements/Field' ;
import SpinnerOverlay from '@/components/elements/SpinnerOverlay' ;
2021-09-13 05:50:12 +00:00
import { Form , Formik , useFormikContext } from 'formik' ;
2021-05-20 22:00:46 +00:00
import { Context } from '@/components/admin/servers/ServerRouter' ;
import { ApplicationStore } from '@/state' ;
import { Actions , useStoreActions } from 'easy-peasy' ;
import Label from '@/components/elements/Label' ;
2021-09-13 05:50:12 +00:00
// interface Values {
// startupCommand: string;
// image: string;
//
// eggId: number;
// skipScripts: boolean;
// }
2021-05-20 22:00:46 +00:00
2021-09-13 05:50:12 +00:00
function ServerStartupLineContainer ( ) {
2021-05-20 22:00:46 +00:00
const { isSubmitting } = useFormikContext ( ) ;
return (
2021-09-13 05:50:12 +00:00
< AdminBox title = { 'Startup Command' } css = { tw ` relative w-full ` } >
2021-05-20 22:00:46 +00:00
< SpinnerOverlay visible = { isSubmitting } / >
< Form css = { tw ` mb-0 ` } >
2021-09-13 05:50:12 +00:00
< div css = { tw ` mb-6 ` } >
2021-05-20 22:00:46 +00:00
< Field
2021-09-13 05:50:12 +00:00
id = { 'startupCommand' }
name = { 'startupCommand' }
label = { 'Startup Command' }
type = { 'text' }
description = { 'Edit your server\'s startup command here. The following variables are available by default: {{SERVER_MEMORY}}, {{SERVER_IP}}, and {{SERVER_PORT}}.' }
2021-05-20 22:00:46 +00:00
/ >
< / div >
2021-09-13 05:50:12 +00:00
< div >
< Label > Default Startup Command < / Label >
< Input disabled / >
< / div >
2021-05-20 22:00:46 +00:00
< / Form >
< / AdminBox >
) ;
2021-09-13 05:50:12 +00:00
}
2021-05-20 22:00:46 +00:00
2021-09-13 05:50:12 +00:00
function ServerServiceContainer ( { nestId : nestId2 , eggId } : { nestId : number | null ; eggId : number | null } ) {
2021-05-20 22:00:46 +00:00
const { isSubmitting } = useFormikContext ( ) ;
2021-09-13 05:50:12 +00:00
const [ nestId , setNestId ] = useState < number | null > ( nestId2 ) ;
2021-05-20 22:00:46 +00:00
return (
< AdminBox title = { 'Service Configuration' } css = { tw ` relative w-full ` } >
< SpinnerOverlay visible = { isSubmitting } / >
< Form css = { tw ` mb-0 ` } >
2021-09-13 05:50:12 +00:00
< div css = { tw ` mb-6 ` } >
< NestSelect nestId = { nestId } setNestId = { setNestId } / >
< / div >
< div css = { tw ` mb-6 ` } >
< EggSelect nestId = { nestId } eggId = { eggId || undefined } / >
< / div >
< div css = { tw ` bg-neutral-800 border border-neutral-900 shadow-inner p-4 rounded ` } >
< FormikSwitch
name = { 'skipScript' }
label = { 'Skip Egg Install Script' }
description = { 'SoonTM' }
/ >
2021-05-20 22:00:46 +00:00
< / div >
< / Form >
< / AdminBox >
) ;
2021-09-13 05:50:12 +00:00
}
2021-05-20 22:00:46 +00:00
2021-09-13 05:50:12 +00:00
function ServerImageContainer ( ) {
2021-05-20 22:00:46 +00:00
const { isSubmitting } = useFormikContext ( ) ;
return (
2021-09-13 05:50:12 +00:00
< AdminBox title = { 'Image Configuration' } css = { tw ` relative w-full ` } >
2021-05-20 22:00:46 +00:00
< SpinnerOverlay visible = { isSubmitting } / >
< Form css = { tw ` mb-0 ` } >
2021-09-13 05:50:12 +00:00
< div css = { tw ` md:w-full md:flex md:flex-col ` } >
< div >
2021-05-20 22:00:46 +00:00
< Field
2021-09-13 05:50:12 +00:00
id = { 'image' }
name = { 'image' }
label = { 'Docker Image' }
type = { 'text' }
2021-05-20 22:00:46 +00:00
/ >
< / div >
< / div >
< / Form >
< / AdminBox >
) ;
2021-09-13 05:50:12 +00:00
}
2021-05-20 22:00:46 +00:00
2021-09-13 05:50:12 +00:00
export default function ServerStartupContainer ( ) {
const { clearFlashes } = useStoreActions ( ( actions : Actions < ApplicationStore > ) = > actions . flashes ) ;
2021-05-20 22:00:46 +00:00
const server = Context . useStoreState ( state = > state . server ) ;
if ( server === undefined ) {
return (
< > < / >
) ;
}
2021-09-13 05:50:12 +00:00
const submit = ( ) = > {
2021-05-20 22:00:46 +00:00
clearFlashes ( 'server' ) ;
} ;
return (
< Formik
onSubmit = { submit }
initialValues = { {
startupCommand : server.container.startupCommand ,
2021-09-13 05:50:12 +00:00
image : server.container.image ,
eggId : 0 ,
skipScripts : false ,
2021-05-20 22:00:46 +00:00
} }
2021-09-13 05:50:12 +00:00
validationSchema = { object ( ) . shape ( { } ) }
2021-05-20 22:00:46 +00:00
>
2021-09-13 05:50:12 +00:00
{ ( { isSubmitting , isValid } ) = > (
< div css = { tw ` flex flex-col ` } >
< div css = { tw ` flex flex-row mb-8 ` } >
< ServerStartupLineContainer / >
< / div >
< div css = { tw ` grid grid-cols-2 gap-x-8 mb-8 ` } >
< div css = { tw ` flex ` } >
< ServerServiceContainer nestId = { server ? . nestId || null } eggId = { server ? . eggId || null } / >
2021-05-20 22:00:46 +00:00
< / div >
2021-09-13 05:50:12 +00:00
< div css = { tw ` flex ` } >
< ServerImageContainer / >
2021-05-20 22:00:46 +00:00
< / div >
2021-09-13 05:50:12 +00:00
< / div >
{ /*<div css={tw`grid gap-8 md:grid-cols-2`}>*/ }
{ /* {variables.map((variable, i) => (*/ }
{ /* <TitledGreyBox*/ }
{ /* key={i}*/ }
{ /* title={<p css={tw`text-sm uppercase`}>{variable.name}</p>}*/ }
{ /* >*/ }
{ /* <InputSpinner visible={false}>*/ }
{ /* <Input*/ }
{ /* name={variable.envVariable}*/ }
{ /* defaultValue={variable.serverValue}*/ }
{ /* placeholder={variable.defaultValue}*/ }
{ /* />*/ }
{ /* </InputSpinner>*/ }
{ /* <p css={tw`mt-1 text-xs text-neutral-300`}>*/ }
{ /* {variable.description}*/ }
{ /* </p>*/ }
{ /* </TitledGreyBox>*/ }
{ /* ))}*/ }
{ /*</div>*/ }
< div css = { tw ` py-2 pr-6 mt-4 rounded shadow-md bg-neutral-700 ` } >
< div css = { tw ` flex flex-row ` } >
< Button type = "submit" size = "small" css = { tw ` ml-auto ` } disabled = { isSubmitting || ! isValid } >
Save Changes
< / Button >
2021-05-20 22:00:46 +00:00
< / div >
< / div >
2021-09-13 05:50:12 +00:00
< / div >
) }
2021-05-20 22:00:46 +00:00
< / Formik >
) ;
2021-09-13 05:50:12 +00:00
}