mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-19 01:55:08 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
102 lines
4.4 KiB
TypeScript
102 lines
4.4 KiB
TypeScript
import { useForm } from '@inertiajs/react';
|
|
import { FormEventHandler, useRef } from 'react';
|
|
|
|
// Components...
|
|
import InputError from '@/components/input-error';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
|
|
import HeadingSmall from '@/components/heading-small';
|
|
import { useTranslation } from '@/hooks/use-translation';
|
|
|
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
|
|
|
export default function DeleteUser({ graceDays }: { graceDays: number }) {
|
|
const { t } = useTranslation();
|
|
const passwordInput = useRef<HTMLInputElement>(null);
|
|
const { data, setData, delete: destroy, processing, reset, errors, clearErrors } = useForm({ password: '' });
|
|
|
|
const deleteUser: FormEventHandler = (e) => {
|
|
e.preventDefault();
|
|
|
|
destroy(route('profile.destroy'), {
|
|
preserveScroll: true,
|
|
onSuccess: () => closeModal(),
|
|
onError: () => passwordInput.current?.focus(),
|
|
onFinish: () => reset(),
|
|
});
|
|
};
|
|
|
|
const closeModal = () => {
|
|
clearErrors();
|
|
reset();
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<HeadingSmall
|
|
title={t('Delete account')}
|
|
description={t('Deactivate your account now; it is permanently erased after :days days', { days: graceDays })}
|
|
/>
|
|
<div className="space-y-4 rounded-lg border border-red-100 bg-red-50 p-4 dark:border-red-200/10 dark:bg-red-700/10">
|
|
<div className="relative space-y-0.5 text-red-600 dark:text-red-100">
|
|
<p className="font-medium">{t('Warning')}</p>
|
|
<p className="text-sm">
|
|
{t(
|
|
'Your account is deactivated immediately. After :days days it is permanently erased, including your identifying details in the activity log — this cannot be undone.',
|
|
{ days: graceDays },
|
|
)}
|
|
</p>
|
|
</div>
|
|
|
|
<Dialog>
|
|
<DialogTrigger asChild>
|
|
<Button variant="destructive">{t('Delete account')}</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogTitle>{t('Are you sure you want to delete your account?')}</DialogTitle>
|
|
<DialogDescription>
|
|
{t('Your account will be deactivated now and permanently erased after :days days. Enter your password to confirm.', {
|
|
days: graceDays,
|
|
})}
|
|
</DialogDescription>
|
|
<form className="space-y-6" onSubmit={deleteUser}>
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="password" className="sr-only">
|
|
{t('Password')}
|
|
</Label>
|
|
|
|
<Input
|
|
id="password"
|
|
type="password"
|
|
name="password"
|
|
ref={passwordInput}
|
|
value={data.password}
|
|
onChange={(e) => setData('password', e.target.value)}
|
|
placeholder={t('Password')}
|
|
autoComplete="current-password"
|
|
/>
|
|
|
|
<InputError message={errors.password} />
|
|
</div>
|
|
|
|
<DialogFooter>
|
|
<DialogClose asChild>
|
|
<Button variant="secondary" onClick={closeModal}>
|
|
{t('Cancel')}
|
|
</Button>
|
|
</DialogClose>
|
|
|
|
<Button variant="destructive" disabled={processing} asChild>
|
|
<button type="submit">{t('Delete account')}</button>
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|