Skip to content

Commit b66cb03

Browse files
chore: improve app layout with auto reties and manual retry buttons (#613)
1 parent b254c46 commit b66cb03

File tree

1 file changed

+45
-33
lines changed

1 file changed

+45
-33
lines changed

apps/web/src/app/[orgShortcode]/layout.tsx

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Sidebar from './_components/sidebar';
44
import { GlobalStoreProvider } from '@/src/providers/global-store-provider';
5-
import { buttonVariants } from '@/src/components/shadcn-ui/button';
5+
import { Button } from '@/src/components/shadcn-ui/button';
66
import { SpinnerGap } from '@phosphor-icons/react';
77
import Link from 'next/link';
88
import { platform } from '@/src/lib/trpc';
@@ -18,7 +18,10 @@ export default function Layout({
1818
data: storeData,
1919
isLoading: storeDataLoading,
2020
error: storeError
21-
} = platform.org.store.getStoreData.useQuery({ orgShortcode });
21+
} = platform.org.store.getStoreData.useQuery(
22+
{ orgShortcode },
23+
{ retry: 3, retryDelay: (attemptIndex) => attemptIndex * 5000 }
24+
);
2225

2326
const { data: hasEmailIdentity } =
2427
platform.org.mail.emailIdentities.userHasEmailIdentities.useQuery({
@@ -29,28 +32,39 @@ export default function Layout({
2932
return (
3033
<div className="flex h-full w-full flex-col items-center justify-center gap-2">
3134
<SpinnerGap className="text-base-11 h-20 w-20 animate-spin" />
35+
<span className="text-slate-11 font-bold">
36+
<span className="font-display text-slate-12 text-bold">UnInbox</span>{' '}
37+
is Loading...
38+
</span>
3239
</div>
3340
);
3441
}
3542

36-
if (storeError && !storeDataLoading) {
43+
if (storeError) {
3744
return (
3845
<div className="flex h-full w-full flex-col items-center justify-center gap-2">
3946
<h1 className="text-red-11 text-2xl font-bold">An Error Occurred!</h1>
4047
<span className="text-red-11 whitespace-pre font-mono text-xl">
4148
{storeError.message}
4249
</span>
43-
44-
<Link
45-
className={buttonVariants({ variant: 'outline' })}
46-
href="/">
47-
Go Back Home
48-
</Link>
50+
<div className="flex gap-2">
51+
<Button
52+
variant="outline"
53+
className="flex-1"
54+
asChild>
55+
<Link href="/">Go Back</Link>
56+
</Button>
57+
<Button
58+
className="flex-1"
59+
onClick={() => window.location.reload()}>
60+
Retry
61+
</Button>
62+
</div>
4963
</div>
5064
);
5165
}
5266

53-
if (!storeDataLoading && !storeData?.currentOrg) {
67+
if (!storeData?.currentOrg) {
5468
return (
5569
<div className="flex h-full w-full flex-col items-center justify-center gap-2">
5670
<h1 className="text-red-11 text-2xl font-bold">Invalid Org</h1>
@@ -61,32 +75,30 @@ export default function Layout({
6175
does not exists or you are not part of that org!
6276
</span>
6377

64-
<Link
65-
className={buttonVariants({ variant: 'outline' })}
66-
href="/">
67-
Go Back Home
68-
</Link>
78+
<Button
79+
variant="outline"
80+
className="flex-1"
81+
asChild>
82+
<Link href="/">Go Back</Link>
83+
</Button>
6984
</div>
7085
);
7186
}
7287

73-
if (storeData) {
74-
return (
75-
<GlobalStoreProvider initialState={storeData}>
76-
<div className="bg-base-1 max-w-svh flex h-full max-h-svh w-full flex-row gap-0 overflow-hidden p-0">
77-
<div className="h-full max-h-full w-fit">
78-
<Sidebar />
79-
</div>
80-
<div className="flex h-full w-full flex-row p-0">
81-
<RealtimeProvider>{children}</RealtimeProvider>
82-
</div>
83-
84-
<NewConvoSheet />
85-
{hasEmailIdentity && !hasEmailIdentity.hasIdentity && (
86-
<ClaimEmailIdentity />
87-
)}
88+
return (
89+
<GlobalStoreProvider initialState={storeData}>
90+
<div className="bg-base-1 max-w-svh flex h-full max-h-svh w-full flex-row gap-0 overflow-hidden p-0">
91+
<div className="h-full max-h-full w-fit">
92+
<Sidebar />
8893
</div>
89-
</GlobalStoreProvider>
90-
);
91-
}
94+
<div className="flex h-full w-full flex-row p-0">
95+
<RealtimeProvider>{children}</RealtimeProvider>
96+
</div>
97+
<NewConvoSheet />
98+
{hasEmailIdentity && !hasEmailIdentity.hasIdentity && (
99+
<ClaimEmailIdentity />
100+
)}
101+
</div>
102+
</GlobalStoreProvider>
103+
);
92104
}

0 commit comments

Comments
 (0)