mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 12:25:44 -05:00
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { useAppForm, Form } from '@/components/form';
|
|
import type { DialogProps } from '@/components/elements/dialog';
|
|
import { Dialog } from '@/components/elements/dialog';
|
|
import { join } from 'pathe';
|
|
import { useTranslation } from '@/sdk/localization';
|
|
|
|
type Props = DialogProps & {
|
|
/** The directory the new file is written to. */
|
|
directory: string;
|
|
onFileNamed: (name: string) => void;
|
|
};
|
|
|
|
/** Names a new file before the editor first writes it. */
|
|
export default function FileNameModal({ directory, onFileNamed, onClose, ...props }: Props) {
|
|
const { t } = useTranslation();
|
|
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 : t('Required')) }}
|
|
>
|
|
{(field) => (
|
|
<field.TextField
|
|
id='fileName'
|
|
label={t('File Name')}
|
|
description={t('Enter the name that this file should be saved as.')}
|
|
autoFocus
|
|
/>
|
|
)}
|
|
</form.AppField>
|
|
<div className='mt-6 text-right'>
|
|
<form.AppForm>
|
|
<form.SubmitButton>{t('Create File')}</form.SubmitButton>
|
|
</form.AppForm>
|
|
</div>
|
|
</Form>
|
|
</Dialog>
|
|
);
|
|
}
|