mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { useAppForm, Form } from '@/components/form';
|
|
import type { DialogProps } from '@/components/elements/dialog';
|
|
import { Dialog } from '@/components/elements/dialog';
|
|
import { useServerDirectory } from '@/state/server';
|
|
import { join } from 'pathe';
|
|
|
|
type Props = DialogProps & {
|
|
onFileNamed: (name: string) => void;
|
|
};
|
|
|
|
export default function FileNameModal({ onFileNamed, onClose, ...props }: Props) {
|
|
const directory = useServerDirectory();
|
|
|
|
const form = useAppForm({
|
|
defaultValues: { fileName: '' },
|
|
onSubmit: async ({ value }) => {
|
|
onFileNamed(join(directory, value.fileName));
|
|
},
|
|
});
|
|
|
|
return (
|
|
<Dialog
|
|
onClose={() => {
|
|
form.reset();
|
|
onClose();
|
|
}}
|
|
{...props}
|
|
>
|
|
<Form form={form}>
|
|
<form.AppField
|
|
name={'fileName'}
|
|
validators={{ onChange: ({ value }) => (value.length >= 1 ? undefined : 'Required') }}
|
|
>
|
|
{(field) => (
|
|
<field.TextField
|
|
id={'fileName'}
|
|
label={'File Name'}
|
|
description={'Enter the name that this file should be saved as.'}
|
|
autoFocus
|
|
/>
|
|
)}
|
|
</form.AppField>
|
|
<div className={'mt-6 text-right'}>
|
|
<form.AppForm>
|
|
<form.SubmitButton>Create File</form.SubmitButton>
|
|
</form.AppForm>
|
|
</div>
|
|
</Form>
|
|
</Dialog>
|
|
);
|
|
}
|