Skip to content

Commit e9d5760

Browse files
committed
feat(ui): enhance onboarding UX
- Added loading and error states with spinner and retry - Redirect users to the login page only when not loading and no user data is available. - Wrap the OnboardingWizard with UserProvider
1 parent 2a5ddd6 commit e9d5760

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

apps/ui/src/app/onboarding/onboarding-client.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,53 @@ import { useRouter } from "next/navigation";
44
import { useEffect } from "react";
55

66
import { OnboardingWizard } from "@/components/onboarding/onboarding-wizard";
7+
import { UserProvider } from "@/components/providers/user-provider";
78
import { useUser } from "@/hooks/useUser";
89

910
export function OnboardingClient() {
1011
const router = useRouter();
11-
const { user } = useUser();
12+
const { user, isLoading, error } = useUser();
1213

1314
useEffect(() => {
14-
if (!user) {
15+
if (!isLoading && !user && !error) {
1516
router.push("/login");
1617
}
17-
}, [user, router]);
18+
}, [user, isLoading, error, router]);
19+
20+
if (isLoading) {
21+
return (
22+
<div className="container mx-auto max-w-6xl py-10 flex items-center justify-center">
23+
<div className="text-center">
24+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto mb-4" />
25+
<p className="text-muted-foreground">Loading...</p>
26+
</div>
27+
</div>
28+
);
29+
}
30+
31+
if (error) {
32+
return (
33+
<div className="container mx-auto max-w-6xl py-10 flex items-center justify-center">
34+
<div className="text-center">
35+
<p className="text-destructive mb-4">Failed to load user data</p>
36+
<button
37+
onClick={() => window.location.reload()}
38+
className="px-4 py-2 bg-primary text-primary-foreground rounded"
39+
>
40+
Retry
41+
</button>
42+
</div>
43+
</div>
44+
);
45+
}
1846

1947
if (!user) {
2048
return null;
2149
}
2250

23-
return <OnboardingWizard />;
51+
return (
52+
<UserProvider>
53+
<OnboardingWizard />
54+
</UserProvider>
55+
);
2456
}

0 commit comments

Comments
 (0)