import { useForm, usePage } from '@inertiajs/react'; import type { SharedData } from '@/types'; import { FormEventHandler, ReactNode, useState } from 'react'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { CheckCircle2Icon, LoaderCircleIcon, XCircleIcon } from 'lucide-react'; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { FormField, FormFields } from '@/components/ui/form'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Alert, AlertDescription } from '@/components/ui/alert'; function Disable(): ReactNode { const [open, setOpen] = useState(false); const form = useForm(); const submit = () => { form.post(route('profile.disable-two-factor'), { preserveScroll: true, onSuccess: () => setOpen(false), }); }; return ( Disable Two Factor Disable two factor Disable two factor Are you sure you want to enable two factor authentication? Cancel {form.processing && } Disable ); } function Enable() { const form = useForm(); const submit: FormEventHandler = (e) => { e.preventDefault(); form.post(route('profile.enable-two-factor')); }; return ( {form.processing && } Enable Two Factor ); } export default function TwoFactor() { const page = usePage< SharedData & { flash: { data?: { qr_code?: string; qr_code_url?: string; recovery_codes?: string[]; }; }; } >(); return ( Two factor authentication Enable or Disable two factor authentication {page.props.flash.data?.qr_code && ( Scan this QR code with your authenticator app QR Code URL Recovery Codes )} {page.props.auth.user.two_factor_enabled ? ( Two factor authentication is enabled ) : ( Two factor authentication is not enabled )} {!page.props.auth.user.two_factor_enabled && } {page.props.auth.user.two_factor_enabled && } ); }
Are you sure you want to enable two factor authentication?
Two factor authentication is enabled