Skip to content

Commit b93fa47

Browse files
committed
extract alert error to its own component
1 parent bfd7e8c commit b93fa47

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
2+
import { AlertCircleIcon } from 'lucide-react';
3+
4+
export default function AlertError({ errors, title }: { errors: string[]; title?: string }) {
5+
return (
6+
<Alert variant="destructive">
7+
<AlertCircleIcon />
8+
<AlertTitle>{title || 'Something went wrong.'}</AlertTitle>
9+
<AlertDescription>
10+
<ul className="list-inside list-disc text-sm">
11+
{Array.from(new Set(errors)).map((error, index) => (
12+
<li key={index}>{error}</li>
13+
))}
14+
</ul>
15+
</AlertDescription>
16+
</Alert>
17+
);
18+
}

resources/js/components/two-factor-recovery-codes.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
21
import { Button } from '@/components/ui/button';
32
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
43
import { regenerateRecoveryCodes } from '@/routes/two-factor';
54
import { Form } from '@inertiajs/react';
6-
import { AlertCircleIcon, Eye, EyeOff, LockKeyhole, RefreshCw } from 'lucide-react';
5+
import { Eye, EyeOff, LockKeyhole, RefreshCw } from 'lucide-react';
76
import { useCallback, useEffect, useRef, useState } from 'react';
7+
import AlertError from './alert-error';
88

99
interface TwoFactorRecoveryCodesProps {
1010
recoveryCodesList: string[];
@@ -77,17 +77,7 @@ export default function TwoFactorRecoveryCodes({ recoveryCodesList, fetchRecover
7777
>
7878
<div className="mt-3 space-y-3">
7979
{errors?.length ? (
80-
<Alert variant="destructive">
81-
<AlertCircleIcon />
82-
<AlertTitle>Something went wrong.</AlertTitle>
83-
<AlertDescription>
84-
<ul className="list-disc text-sm">
85-
{errors.map((error, index) => (
86-
<li key={index}>{error}</li>
87-
))}
88-
</ul>
89-
</AlertDescription>
90-
</Alert>
80+
<AlertError errors={errors} />
9181
) : (
9282
<>
9383
<div

resources/js/components/two-factor-setup-modal.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import InputError from '@/components/input-error';
2-
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
32
import { Button } from '@/components/ui/button';
43
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
54
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp';
@@ -8,8 +7,9 @@ import { OTP_MAX_LENGTH } from '@/hooks/use-two-factor-auth';
87
import { confirm } from '@/routes/two-factor';
98
import { Form } from '@inertiajs/react';
109
import { REGEXP_ONLY_DIGITS } from 'input-otp';
11-
import { AlertCircleIcon, Check, Copy, Loader2, ScanLine } from 'lucide-react';
10+
import { Check, Copy, Loader2, ScanLine } from 'lucide-react';
1211
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
12+
import AlertError from './alert-error';
1313

1414
function GridScanIcon() {
1515
return (
@@ -50,17 +50,7 @@ function TwoFactorSetupStep({
5050
return (
5151
<>
5252
{errors?.length ? (
53-
<Alert variant="destructive">
54-
<AlertCircleIcon />
55-
<AlertTitle>Something went wrong.</AlertTitle>
56-
<AlertDescription>
57-
<ul className="list-inside list-disc text-sm">
58-
{Array.from(new Set(errors)).map((error, index) => (
59-
<li key={index}>{error}</li>
60-
))}
61-
</ul>
62-
</AlertDescription>
63-
</Alert>
53+
<AlertError errors={errors} />
6454
) : (
6555
<>
6656
<div className="mx-auto flex max-w-md overflow-hidden">

0 commit comments

Comments
 (0)