2026-10-05 18:10:18 -04:00
|
|
|
import { useStore } from '@tanstack/react-form';
|
|
|
|
|
import { useAppForm, Form } from '@/components/form';
|
|
|
|
|
import { Dialog } from '@/components/elements/dialog';
|
|
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
|
|
|
|
import { NewButton } from '@/components/elements/NewButton';
|
|
|
|
|
import type { WithClassname } from '@/components/types';
|
2021-05-03 21:26:09 -07:00
|
|
|
import Can from '@/components/elements/Can';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { useCurrentServerUuid } from '@/api/server/queries';
|
|
|
|
|
import { createServerBackupInput, useCreateServerBackup } from '@/api/server/backups/queries';
|
2020-04-04 10:59:25 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const CreateBackupDialogContent = ({ onClose }: { onClose: () => void }) => {
|
|
|
|
|
const uuid = useCurrentServerUuid()!;
|
|
|
|
|
const createBackup = useCreateServerBackup();
|
2020-04-04 10:59:25 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const form = useAppForm({
|
|
|
|
|
defaultValues: { name: '', ignored: '', isLocked: false },
|
|
|
|
|
onSubmit: async ({ value }) => {
|
|
|
|
|
try {
|
|
|
|
|
await createBackup.mutateAsync(createServerBackupInput(uuid, value));
|
|
|
|
|
onClose();
|
|
|
|
|
} catch {
|
|
|
|
|
// Error toast is handled by the mutation.
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const isSubmitting = useStore(form.store, (state) => state.isSubmitting);
|
2020-04-04 10:59:25 -07:00
|
|
|
|
|
|
|
|
return (
|
2026-10-05 18:10:18 -04:00
|
|
|
<Dialog
|
|
|
|
|
open
|
|
|
|
|
title={'Create server backup'}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
preventExternalClose={isSubmitting}
|
|
|
|
|
hideCloseIcon={isSubmitting}
|
|
|
|
|
>
|
|
|
|
|
<SpinnerOverlay visible={isSubmitting} />
|
|
|
|
|
<Form form={form}>
|
|
|
|
|
<form.AppField
|
2021-05-03 21:26:09 -07:00
|
|
|
name={'name'}
|
2026-10-05 18:10:18 -04:00
|
|
|
validators={{
|
|
|
|
|
onChange: ({ value }) =>
|
|
|
|
|
value.length <= 191 ? undefined : 'The backup name must not exceed 191 characters.',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{(field) => (
|
|
|
|
|
<field.TextField
|
|
|
|
|
label={'Backup name'}
|
|
|
|
|
description={'If provided, the name that should be used to reference this backup.'}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</form.AppField>
|
|
|
|
|
<div className={'mt-6'}>
|
|
|
|
|
<form.AppField name={'ignored'}>
|
|
|
|
|
{(field) => (
|
|
|
|
|
<field.TextAreaField
|
|
|
|
|
label={'Ignored Files & Directories'}
|
|
|
|
|
rows={6}
|
|
|
|
|
description={`
|
|
|
|
|
Enter the files or folders to ignore while generating this backup. Leave blank to use
|
|
|
|
|
the contents of the .pteroignore file in the root of the server directory if present.
|
|
|
|
|
Wildcard matching of files and folders is supported in addition to negating a rule by
|
|
|
|
|
prefixing the path with an exclamation point.
|
|
|
|
|
`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</form.AppField>
|
2020-04-04 10:59:25 -07:00
|
|
|
</div>
|
2021-05-03 21:26:09 -07:00
|
|
|
<Can action={'backup.delete'}>
|
2026-10-05 18:10:18 -04:00
|
|
|
<div className={'mt-6 bg-card border border-border shadow-inner p-4 rounded-sm'}>
|
|
|
|
|
<form.AppField name={'isLocked'}>
|
|
|
|
|
{(field) => (
|
|
|
|
|
<field.SwitchField
|
|
|
|
|
label={'Locked'}
|
|
|
|
|
description={'Prevents this backup from being deleted until explicitly unlocked.'}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</form.AppField>
|
2021-05-03 21:26:09 -07:00
|
|
|
</div>
|
|
|
|
|
</Can>
|
2026-10-05 18:10:18 -04:00
|
|
|
<div className={'flex justify-end mt-6'}>
|
|
|
|
|
<form.AppForm>
|
|
|
|
|
<form.SubmitButton>Start backup</form.SubmitButton>
|
|
|
|
|
</form.AppForm>
|
2020-04-04 10:59:25 -07:00
|
|
|
</div>
|
|
|
|
|
</Form>
|
2026-10-05 18:10:18 -04:00
|
|
|
</Dialog>
|
2020-04-04 10:59:25 -07:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const CreateBackupButton = ({ className }: WithClassname) => (
|
|
|
|
|
<Dialog.Trigger
|
|
|
|
|
trigger={({ onClick }) => (
|
|
|
|
|
<NewButton className={className} onClick={onClick}>
|
|
|
|
|
New backup
|
|
|
|
|
</NewButton>
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{({ open, onClose }) => open && <CreateBackupDialogContent onClose={onClose} />}
|
|
|
|
|
</Dialog.Trigger>
|
|
|
|
|
);
|
2020-04-04 10:59:25 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
export default CreateBackupButton;
|