Add support for creating a new file
This commit is contained in:
parent
d75073116f
commit
e784218645
6 changed files with 116 additions and 23 deletions
54
resources/scripts/components/server/files/FileNameModal.tsx
Normal file
54
resources/scripts/components/server/files/FileNameModal.tsx
Normal file
|
@ -0,0 +1,54 @@
|
|||
import React from 'react';
|
||||
import Modal, { RequiredModalProps } from '@/components/elements/Modal';
|
||||
import { Form, Formik, FormikActions } from 'formik';
|
||||
import { object, string } from 'yup';
|
||||
import Field from '@/components/elements/Field';
|
||||
|
||||
type Props = RequiredModalProps & {
|
||||
onFileNamed: (name: string) => void;
|
||||
};
|
||||
|
||||
interface Values {
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export default ({ onFileNamed, onDismissed, ...props }: Props) => {
|
||||
const submit = (values: Values, { setSubmitting }: FormikActions<Values>) => {
|
||||
onFileNamed(values.fileName);
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
onSubmit={submit}
|
||||
initialValues={{ fileName: '' }}
|
||||
validationSchema={object().shape({
|
||||
fileName: string().required().min(1),
|
||||
})}
|
||||
>
|
||||
{({ resetForm }) => (
|
||||
<Modal
|
||||
onDismissed={() => {
|
||||
resetForm();
|
||||
onDismissed();
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<Form>
|
||||
<Field
|
||||
id={'fileName'}
|
||||
name={'fileName'}
|
||||
label={'File Name'}
|
||||
description={'Enter the name that this file should be saved as.'}
|
||||
/>
|
||||
<div className={'mt-6 text-right'}>
|
||||
<button className={'btn btn-primary btn-sm'}>
|
||||
Create File
|
||||
</button>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
)}
|
||||
</Formik>
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue