121 lines
5.4 KiB
TypeScript
Executable File
121 lines
5.4 KiB
TypeScript
Executable File
import { Form } from '@inertiajs/react';
|
||
import { useRef } from 'react';
|
||
import ProfileController from '@/actions/App/Http/Controllers/Settings/ProfileController';
|
||
import Heading from '@/components/heading';
|
||
import InputError from '@/components/input-error';
|
||
import PasswordInput from '@/components/password-input';
|
||
import { Button } from '@/components/ui/button';
|
||
import {
|
||
Dialog,
|
||
DialogClose,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogTitle,
|
||
DialogTrigger,
|
||
} from '@/components/ui/dialog';
|
||
import { Label } from '@/components/ui/label';
|
||
|
||
export default function DeleteUser() {
|
||
const passwordInput = useRef<HTMLInputElement>(null);
|
||
|
||
return (
|
||
<div className="space-y-6">
|
||
<Heading
|
||
variant="small"
|
||
title="Удаление аккаунта"
|
||
description="Удалить аккаунт и все его данные"
|
||
/>
|
||
<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">Внимание</p>
|
||
<p className="text-sm">
|
||
Это действие необратимо. Все маркеры и отметки будут
|
||
удалены.
|
||
</p>
|
||
</div>
|
||
|
||
<Dialog>
|
||
<DialogTrigger asChild>
|
||
<Button
|
||
variant="destructive"
|
||
data-test="delete-user-button"
|
||
>
|
||
Удалить аккаунт
|
||
</Button>
|
||
</DialogTrigger>
|
||
<DialogContent>
|
||
<DialogTitle>
|
||
Вы уверены, что хотите удалить аккаунт?
|
||
</DialogTitle>
|
||
<DialogDescription>
|
||
После удаления аккаунта все его данные будут
|
||
безвозвратно удалены. Введите пароль, чтобы
|
||
подтвердить удаление.
|
||
</DialogDescription>
|
||
|
||
<Form
|
||
{...ProfileController.destroy.form()}
|
||
options={{
|
||
preserveScroll: true,
|
||
}}
|
||
onError={() => passwordInput.current?.focus()}
|
||
resetOnSuccess
|
||
className="space-y-6"
|
||
>
|
||
{({ resetAndClearErrors, processing, errors }) => (
|
||
<>
|
||
<div className="grid gap-2">
|
||
<Label
|
||
htmlFor="password"
|
||
className="sr-only"
|
||
>
|
||
Пароль
|
||
</Label>
|
||
|
||
<PasswordInput
|
||
id="password"
|
||
name="password"
|
||
ref={passwordInput}
|
||
placeholder="Пароль"
|
||
autoComplete="current-password"
|
||
/>
|
||
|
||
<InputError message={errors.password} />
|
||
</div>
|
||
|
||
<DialogFooter className="gap-2">
|
||
<DialogClose asChild>
|
||
<Button
|
||
variant="secondary"
|
||
onClick={() =>
|
||
resetAndClearErrors()
|
||
}
|
||
>
|
||
Отмена
|
||
</Button>
|
||
</DialogClose>
|
||
|
||
<Button
|
||
variant="destructive"
|
||
disabled={processing}
|
||
asChild
|
||
>
|
||
<button
|
||
type="submit"
|
||
data-test="confirm-delete-user-button"
|
||
>
|
||
Удалить аккаунт
|
||
</button>
|
||
</Button>
|
||
</DialogFooter>
|
||
</>
|
||
)}
|
||
</Form>
|
||
</DialogContent>
|
||
</Dialog>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|