Update file manager design a bit
This commit is contained in:
parent
8bd518048e
commit
2824db7352
9 changed files with 184 additions and 152 deletions
|
@ -1,5 +1,4 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import Modal from '@/components/elements/Modal';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import { Form, Formik, FormikHelpers } from 'formik';
|
||||
import Field from '@/components/elements/Field';
|
||||
|
@ -7,12 +6,15 @@ import { join } from 'path';
|
|||
import { object, string } from 'yup';
|
||||
import createDirectory from '@/api/server/files/createDirectory';
|
||||
import tw from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
import { Button } from '@/components/elements/button/index';
|
||||
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
|
||||
import { WithClassname } from '@/components/types';
|
||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||
import { Dialog } from '@/components/elements/dialog';
|
||||
import Portal from '@/components/elements/Portal';
|
||||
import Code from '@/components/elements/Code';
|
||||
|
||||
interface Values {
|
||||
directoryName: string;
|
||||
|
@ -66,48 +68,57 @@ export default ({ className }: WithClassname) => {
|
|||
|
||||
return (
|
||||
<>
|
||||
<Formik
|
||||
onSubmit={submit}
|
||||
validationSchema={schema}
|
||||
initialValues={{ directoryName: '' }}
|
||||
>
|
||||
{({ resetForm, isSubmitting, values }) => (
|
||||
<Modal
|
||||
visible={visible}
|
||||
dismissable={!isSubmitting}
|
||||
showSpinnerOverlay={isSubmitting}
|
||||
onDismissed={() => {
|
||||
setVisible(false);
|
||||
resetForm();
|
||||
}}
|
||||
>
|
||||
<FlashMessageRender key={'files:directory-modal'}/>
|
||||
<Form css={tw`m-0`}>
|
||||
<Field
|
||||
autoFocus
|
||||
id={'directoryName'}
|
||||
name={'directoryName'}
|
||||
label={'Directory Name'}
|
||||
/>
|
||||
<p css={tw`text-xs mt-2 text-neutral-400 break-all`}>
|
||||
<span css={tw`text-neutral-200`}>This directory will be created as</span>
|
||||
/home/container/
|
||||
<span css={tw`text-cyan-200`}>
|
||||
{join(directory, values.directoryName).replace(/^(\.\.\/|\/)+/, '')}
|
||||
</span>
|
||||
</p>
|
||||
<div css={tw`flex justify-end`}>
|
||||
<Button css={tw`mt-8`}>
|
||||
Create Directory
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
)}
|
||||
</Formik>
|
||||
<Button isSecondary onClick={() => setVisible(true)} className={className}>
|
||||
<Portal>
|
||||
<Formik
|
||||
onSubmit={submit}
|
||||
validationSchema={schema}
|
||||
initialValues={{ directoryName: '' }}
|
||||
>
|
||||
{({ resetForm, submitForm, isSubmitting: _, values }) => (
|
||||
<Dialog
|
||||
title={'Create Directory'}
|
||||
open={visible}
|
||||
onClose={() => {
|
||||
setVisible(false);
|
||||
resetForm();
|
||||
}}
|
||||
>
|
||||
<FlashMessageRender key={'files:directory-modal'}/>
|
||||
<Form css={tw`m-0`}>
|
||||
<Field
|
||||
autoFocus
|
||||
id={'directoryName'}
|
||||
name={'directoryName'}
|
||||
label={'Name'}
|
||||
/>
|
||||
<p css={tw`mt-2 text-sm md:text-base break-all`}>
|
||||
<span css={tw`text-neutral-200`}>This directory will be created as </span>
|
||||
<Code>/home/container/
|
||||
<span css={tw`text-cyan-200`}>
|
||||
{join(directory, values.directoryName).replace(/^(\.\.\/|\/)+/, '')}
|
||||
</span>
|
||||
</Code>
|
||||
</p>
|
||||
</Form>
|
||||
<Dialog.Buttons>
|
||||
<Button.Text
|
||||
className={'w-full sm:w-auto'}
|
||||
onClick={() => {
|
||||
setVisible(false);
|
||||
resetForm();
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Button.Text>
|
||||
<Button className={'w-full sm:w-auto'} onClick={submitForm}>Create</Button>
|
||||
</Dialog.Buttons>
|
||||
</Dialog>
|
||||
)}
|
||||
</Formik>
|
||||
</Portal>
|
||||
<Button.Text onClick={() => setVisible(true)} className={className}>
|
||||
Create Directory
|
||||
</Button>
|
||||
</Button.Text>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Reference in a new issue