-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d77e24c
commit f0b998c
Showing
6 changed files
with
161 additions
and
162 deletions.
There are no files selected for viewing
216 changes: 91 additions & 125 deletions
216
apps/myaccount/myaccount-web-app/src/app/(me)/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1,122 @@ | ||
import { auth, protectAuth } from "@/auth"; | ||
import BreadCrumb from "@/components/breadcrumb"; | ||
import { ConnectionClient } from "@/components/tables/connections-tables/client"; | ||
import apiService from '@/service/api.service'; | ||
import { CalendarDateRangePicker } from "@/components/date-range-picker"; | ||
import { Button } from "@/components/ui/button"; | ||
import { protectAuth } from "@/auth"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { ScrollArea } from "@/components/ui/scroll-area"; | ||
import { Separator } from "@/components/ui/separator"; | ||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
import { ActivityHistoryClient } from "@/components/tables/activity-tables/client"; | ||
import UserService from 'service/user.service'; | ||
import ActivityTableSection from "./activity-history-section"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import UserService from "@/service/user.service"; | ||
|
||
const breadcrumbItems = [{ title: "Home", link: "/" }]; | ||
|
||
async function getStatistics() { | ||
const session = await auth(); | ||
const userService = UserService() | ||
if (!session) { | ||
return | ||
} | ||
async function fetchStatistics(token: string) { | ||
const userService = UserService(); | ||
|
||
try { | ||
const res = userService.getUserStatistics(session) | ||
return res; | ||
} catch (e) { | ||
console.log(e); | ||
return await userService.getUserStatistics(token); | ||
} catch (error) { | ||
console.error("Error fetching statistics:", error); | ||
return { | ||
activeAppsConnections: 0, | ||
activeSubscriptions: { total_count: 0 }, | ||
expenses: 0 | ||
expenses: 0, | ||
}; | ||
} | ||
} | ||
|
||
export default async function Page() { | ||
const statistics = await getStatistics(); | ||
const session = await protectAuth() | ||
const user = session?.user; | ||
if (!user) return | ||
const userService = UserService(); | ||
const session = await protectAuth(); | ||
|
||
return ( | ||
<ScrollArea className="h-full"> | ||
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6"> | ||
|
||
<div className="text-center space-y-2 mb-12"> | ||
<div className="flex justify-center items-center"> | ||
<Avatar className="h-32 w-32"> | ||
<AvatarImage | ||
src={user.photoURL ?? ""} | ||
alt={user.displayName ?? ""} | ||
/> | ||
<AvatarFallback>{(user.displayName || user.email)?.[0]?.toLocaleUpperCase()}</AvatarFallback> | ||
</Avatar> | ||
</div> | ||
<h1 className="text-2xl font-semibold">Welcome, {user?.firstName} Inc</h1> | ||
<p className="text-gray-500">Manage your info, privacy, and security to make Eartho work better for you.</p> | ||
</div> | ||
if (!session?.accessToken) return null; | ||
|
||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3"> | ||
<Card> | ||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> | ||
<CardTitle className="text-sm font-medium"> | ||
Active Apps | ||
</CardTitle> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
className="h-4 w-4 text-muted-foreground" | ||
> | ||
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /> | ||
<circle cx="9" cy="7" r="4" /> | ||
<path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" /> | ||
</svg> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="text-2xl font-bold">{statistics?.activeAppsConnections || 0}</div> | ||
<p className="text-xs text-muted-foreground"> | ||
0% from last month | ||
</p> | ||
</CardContent> | ||
</Card> | ||
<Card> | ||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> | ||
<CardTitle className="text-sm font-medium"> | ||
Active Subscriptions | ||
</CardTitle> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
className="h-4 w-4 text-muted-foreground" | ||
> | ||
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /> | ||
<circle cx="9" cy="7" r="4" /> | ||
<path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" /> | ||
</svg> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="text-2xl font-bold">{statistics?.activeSubscriptions?.total_count || 0}</div> | ||
<p className="text-xs text-muted-foreground"> | ||
0% from last month | ||
</p> | ||
</CardContent> | ||
</Card> | ||
<Card> | ||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> | ||
<CardTitle className="text-sm font-medium">Expenses</CardTitle> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
className="h-4 w-4 text-muted-foreground" | ||
> | ||
<path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" /> | ||
</svg> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="text-2xl font-bold">${statistics?.expenses || 0}</div> | ||
<p className="text-xs text-muted-foreground"> | ||
0% from last month | ||
</p> | ||
</CardContent> | ||
</Card> | ||
const [statistics, user] = await Promise.all([ | ||
fetchStatistics(session.accessToken), | ||
userService.getUserProfile(session.accessToken), | ||
]); | ||
|
||
</div> | ||
if (!user) return null; | ||
|
||
<div className="pt-8 pb-8"> | ||
<Separator /> | ||
</div> | ||
return ( | ||
<ScrollArea className="h-full"> | ||
<div className="flex-1 p-4 md:p-8 pt-6"> | ||
<UserWelcomeSection user={user} /> | ||
<StatisticsSection statistics={statistics} /> | ||
<Separator className="mt-8 mb-8" /> | ||
<ActivityTableSection /> | ||
</div> | ||
</ScrollArea> | ||
); | ||
} | ||
|
||
function UserWelcomeSection({ user }: { user: any }) { | ||
return ( | ||
<div className="text-center space-y-2 mb-12"> | ||
<AvatarContainer user={user} /> | ||
<h1 className="text-2xl font-semibold">Welcome {user?.firstName ?? "To Eartho"}</h1> | ||
<p className="text-gray-500"> | ||
Manage your info, privacy, and security to make Eartho work better for you. | ||
</p> | ||
</div> | ||
); | ||
} | ||
|
||
function AvatarContainer({ user }: { user: any }) { | ||
return ( | ||
<div className="flex justify-center items-center"> | ||
<Avatar className="h-32 w-32"> | ||
<AvatarImage src={user.photoURL ?? ""} alt={user.displayName ?? ""} /> | ||
<AvatarFallback> | ||
{(user.displayName || user.email)?.[0]?.toUpperCase()} | ||
</AvatarFallback> | ||
</Avatar> | ||
</div> | ||
); | ||
} | ||
|
||
function StatisticsSection({ statistics }: { statistics: any }) { | ||
return ( | ||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3"> | ||
<StatisticCard title="Active Apps" value={statistics?.activeAppsConnections || 0} /> | ||
<StatisticCard title="Active Subscriptions" value={statistics?.activeSubscriptions?.total_count || 0} /> | ||
<StatisticCard title="Expenses" value={`$${statistics?.expenses || 0}`} /> | ||
</div> | ||
); | ||
} | ||
|
||
function StatisticCard({ title, value }: { title: string; value: string | number }) { | ||
return ( | ||
<Card> | ||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> | ||
<CardTitle className="text-sm font-medium">{title}</CardTitle> | ||
<IconPlaceholder /> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="text-2xl font-bold">{value}</div> | ||
<p className="text-xs text-muted-foreground">0% from last month</p> | ||
</CardContent> | ||
</Card> | ||
); | ||
} | ||
|
||
function IconPlaceholder() { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
className="h-4 w-4 text-muted-foreground" | ||
> | ||
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /> | ||
<circle cx="9" cy="7" r="4" /> | ||
<path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" /> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.