Skip to content

Commit 4a99e01

Browse files
committed
fix: Better error handling UX
1 parent 4b764ec commit 4a99e01

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/components/account/Invoicing.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import { Skeleton } from '@heroui/skeleton';
22
import { getInvoiceDrafts } from '@lib/api/backend';
33
import { BorderedCard } from '@shared/cards/BorderedCard';
4+
import { DetailedAlert } from '@shared/DetailedAlert';
45
import EmptyData from '@shared/EmptyData';
56
import ListHeader from '@shared/ListHeader';
67
import { InvoiceDraft } from '@typedefs/general';
78
import _ from 'lodash';
89
import { useEffect, useState } from 'react';
910
import toast from 'react-hot-toast';
10-
import { RiDraftLine, RiErrorWarningLine, RiFileInfoLine } from 'react-icons/ri';
11+
import { RiCloseCircleLine, RiDraftLine, RiFileInfoLine } from 'react-icons/ri';
1112
import BillingMonthSelect from './BillingMonthSelect';
1213
import DraftInvoiceCard from './DraftInvoiceCard';
1314

1415
function Invoicing() {
15-
const [billingInfo, _setBillingInfo] = useState({
16-
companyName: '—',
17-
billingEmail: '—',
18-
vatNumber: '—',
19-
paymentAddress: '—',
20-
});
21-
2216
const [uniqueMonths, setUniqueMonths] = useState<string[]>([]);
2317
const [invoiceDrafts, setInvoiceDrafts] = useState<InvoiceDraft[] | undefined>();
2418

@@ -62,8 +56,9 @@ function Invoicing() {
6256
setUniqueMonths(months);
6357
} catch (error: any) {
6458
console.error(error);
65-
setError(error.message);
66-
toast.error('Failed to fetch invoice drafts.');
59+
const errorMessage = 'Failed to fetch invoice drafts';
60+
setError(errorMessage);
61+
toast.error(errorMessage);
6762
} finally {
6863
setLoading(false);
6964
}
@@ -112,9 +107,14 @@ function Invoicing() {
112107
))}
113108
</>
114109
) : error !== null ? (
115-
<div className="row gap-1.5 rounded-lg bg-red-100 p-4 text-red-700">
116-
<RiErrorWarningLine className="text-xl" />
117-
<div className="text-sm font-medium">{error}</div>
110+
<div className="py-8 lg:py-12">
111+
<DetailedAlert
112+
variant="red"
113+
icon={<RiCloseCircleLine />}
114+
title="Error"
115+
description={<div>{error}</div>}
116+
isCompact
117+
/>
118118
</div>
119119
) : invoiceDrafts === undefined || selectedMonth === undefined || !invoiceDrafts.length ? (
120120
<div className="center-all w-full p-14">

src/pages/tunnels/Tunnels.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { TunnelingSecrets } from '@typedefs/general';
1616
import { Tunnel } from '@typedefs/tunnels';
1717
import { useEffect, useState } from 'react';
1818
import toast from 'react-hot-toast';
19-
import { RiAddLine, RiDoorLockLine, RiDraftLine, RiErrorWarningLine, RiPencilLine } from 'react-icons/ri';
19+
import { RiAddLine, RiCloseCircleLine, RiDoorLockLine, RiDraftLine, RiPencilLine } from 'react-icons/ri';
2020
import { useAccount, useSignMessage } from 'wagmi';
2121

2222
function Tunnels() {
@@ -242,9 +242,14 @@ function Tunnels() {
242242
</div>
243243

244244
{error && !isFetchingTunnels && (
245-
<div className="row gap-1.5 rounded-lg bg-red-100 p-4 text-red-700">
246-
<RiErrorWarningLine className="text-xl" />
247-
<div className="text-sm font-medium">{error}</div>
245+
<div className="py-8 lg:py-12">
246+
<DetailedAlert
247+
variant="red"
248+
icon={<RiCloseCircleLine />}
249+
title="Error"
250+
description={<div>{error}</div>}
251+
isCompact
252+
/>
248253
</div>
249254
)}
250255

src/shared/DetailedAlert.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface Props {
88
description: JSX.Element;
99
largeTitle?: boolean;
1010
fullWidth?: boolean;
11+
isCompact?: boolean;
1112
}
1213

1314
export const DetailedAlert: FunctionComponent<PropsWithChildren<Props>> = ({
@@ -18,6 +19,7 @@ export const DetailedAlert: FunctionComponent<PropsWithChildren<Props>> = ({
1819
description,
1920
largeTitle = false,
2021
fullWidth = false,
22+
isCompact = false,
2123
}) => {
2224
const bgColorClass = {
2325
primary: 'bg-primary-100',
@@ -30,12 +32,12 @@ export const DetailedAlert: FunctionComponent<PropsWithChildren<Props>> = ({
3032
};
3133

3234
return (
33-
<div className="col items-center gap-6">
35+
<div className={clsx('col items-center', { 'gap-4': isCompact, 'gap-6': !isCompact })}>
3436
<div className={`center-all rounded-full ${bgColorClass[variant]} p-4`}>
3537
<div className={`text-3xl ${textColorClass[variant]}`}>{icon}</div>
3638
</div>
3739

38-
<div className="col gap-2 text-center">
40+
<div className={clsx('col text-center', { 'gap-1': isCompact, 'gap-2': !isCompact })}>
3941
<div
4042
className={clsx('text-primary-800 font-bold tracking-wider uppercase', {
4143
'text-xl': !largeTitle,

0 commit comments

Comments
 (0)