Skip to content

Commit 2981955

Browse files
committed
feat: enhance Dashboard component with user information display
- Added user information retrieval using getCurrentUser and displayed details in a new Card component. - Implemented loading state for user data to improve user experience. - Refactored imports to include necessary UI components for better organization.
1 parent 42cd41a commit 2981955

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

tauri-app/src/pages/Dashboard.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import { Button } from "@/components/ui/button";
2-
import { signOut } from "@/services/auth";
2+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
3+
import { getCurrentUser, signOut } from "@/services/auth";
4+
import { useEffect, useState } from "react";
35
import { useNavigate } from "react-router-dom";
46

7+
type userInfo = {
8+
email: string,
9+
fullname: string,
10+
id: string,
11+
tier: string,
12+
trialActive: boolean,
13+
trialEndsAt?: Date,
14+
username: string
15+
}
16+
517
export default function Dashboard() {
618
const navigate = useNavigate();
719
const handleLogout = async () => {
@@ -12,9 +24,45 @@ export default function Dashboard() {
1224
console.error("Logout failed:", err);
1325
}
1426
};
27+
const [user, setUser] = useState<userInfo>()
28+
29+
useEffect(() => {
30+
async function getUser() {
31+
const userData = await getCurrentUser();
32+
console.debug(userData);
33+
setUser({
34+
...userData,
35+
trialEndsAt: userData.trialEndsAt ? new Date(userData.trialEndsAt) : undefined,
36+
});
37+
}
38+
getUser()
39+
}, [getCurrentUser])
1540

1641
return (
1742
<div className="p-4 space-y-4">
43+
<Card>
44+
<CardHeader>
45+
<CardTitle>User Information</CardTitle>
46+
<CardDescription>Details about your account.</CardDescription>
47+
</CardHeader>
48+
<CardContent>
49+
{user ? (
50+
<div className="space-y-2">
51+
<p><strong>Email:</strong> {user.email}</p>
52+
<p><strong>Full Name:</strong> {user.fullname}</p>
53+
<p><strong>Username:</strong> {user.username}</p>
54+
<p><strong>Tier:</strong> {user.tier}</p>
55+
<p><strong>Trial Active:</strong> {user.trialActive ? "Yes" : "No"}</p>
56+
{user.trialEndsAt && (
57+
<p><strong>Trial Ends At:</strong> {user.trialEndsAt.toLocaleDateString()}</p>
58+
)}
59+
</div>
60+
) : (
61+
<p>Loading user information...</p>
62+
)}
63+
</CardContent>
64+
</Card>
65+
1866
<Button
1967
onClick={handleLogout}
2068
className="w-full flex items-center justify-center gap-2 mt-6"

0 commit comments

Comments
 (0)