11"use client" ;
22
3- import DashboardContent from "@components/admin/dashboard-content" ;
4- import { Metric } from "@components/admin/dashboard/metric" ;
5- import { Todo } from "@components/admin/dashboard/to-do" ;
6- import LoadingScreen from "@components/admin/loading-screen" ;
3+ import { useContext , useState } from "react" ;
74import {
85 AddressContext ,
96 ProfileContext ,
107 SiteInfoContext ,
118} from "@components/contexts" ;
12- import { UIConstants } from "@courselit/common-models" ;
9+ import { UIConstants , Constants } from "@courselit/common-models" ;
1310import { checkPermission } from "@courselit/utils" ;
14- import { DASHBOARD_PAGE_HEADER , OVERVIEW_HEADER } from "@ui-config/strings" ;
15- import { useContext } from "react" ;
11+ import {
12+ DASHBOARD_PAGE_HEADER ,
13+ OVERVIEW_HEADER ,
14+ UNNAMED_USER ,
15+ } from "@ui-config/strings" ;
16+ import { TIME_RANGES } from "@ui-config/constants" ;
17+ import { useActivities } from "@/hooks/use-activities" ;
18+ import dynamic from "next/dynamic" ;
19+ import DashboardContent from "@components/admin/dashboard-content" ;
20+ const Todo = dynamic ( ( ) =>
21+ import ( "@components/admin/dashboard/to-do" ) . then ( ( mod ) => ( {
22+ default : mod . Todo ,
23+ } ) ) ,
24+ ) ;
25+ const LoadingScreen = dynamic ( ( ) => import ( "@components/admin/loading-screen" ) ) ;
26+ const MetricCard = dynamic ( ( ) => import ( "../product/[id]/metric-card" ) ) ;
27+ const SalesCard = dynamic ( ( ) => import ( "./sales-card" ) ) ;
1628
29+ // Dynamically import UI components
30+ const Select = dynamic ( ( ) =>
31+ import ( "@/components/ui/select" ) . then ( ( mod ) => ( { default : mod . Select } ) ) ,
32+ ) ;
33+ const SelectContent = dynamic ( ( ) =>
34+ import ( "@/components/ui/select" ) . then ( ( mod ) => ( {
35+ default : mod . SelectContent ,
36+ } ) ) ,
37+ ) ;
38+ const SelectItem = dynamic ( ( ) =>
39+ import ( "@/components/ui/select" ) . then ( ( mod ) => ( {
40+ default : mod . SelectItem ,
41+ } ) ) ,
42+ ) ;
43+ const SelectTrigger = dynamic ( ( ) =>
44+ import ( "@/components/ui/select" ) . then ( ( mod ) => ( {
45+ default : mod . SelectTrigger ,
46+ } ) ) ,
47+ ) ;
48+ const SelectValue = dynamic ( ( ) =>
49+ import ( "@/components/ui/select" ) . then ( ( mod ) => ( {
50+ default : mod . SelectValue ,
51+ } ) ) ,
52+ ) ;
53+
54+ // Dynamically import icons
55+ const DollarSign = dynamic ( ( ) =>
56+ import ( "lucide-react" ) . then ( ( mod ) => ( { default : mod . DollarSign } ) ) ,
57+ ) ;
58+ const UserPlus = dynamic ( ( ) =>
59+ import ( "lucide-react" ) . then ( ( mod ) => ( { default : mod . UserPlus } ) ) ,
60+ ) ;
61+ const Users = dynamic ( ( ) =>
62+ import ( "lucide-react" ) . then ( ( mod ) => ( { default : mod . Users } ) ) ,
63+ ) ;
64+ const Mail = dynamic ( ( ) =>
65+ import ( "lucide-react" ) . then ( ( mod ) => ( { default : mod . Mail } ) ) ,
66+ ) ;
1767const breadcrumbs = [ { label : OVERVIEW_HEADER , href : "#" } ] ;
1868
1969export default function Page ( ) {
2070 const siteInfo = useContext ( SiteInfoContext ) ;
2171 const address = useContext ( AddressContext ) ;
2272 const { profile } = useContext ( ProfileContext ) ;
73+ const [ timeRange , setTimeRange ] = useState ( "7d" ) ;
74+ const { data : salesData , loading : salesLoading } = useActivities (
75+ Constants . ActivityType . PURCHASED ,
76+ timeRange ,
77+ undefined ,
78+ true ,
79+ ) ;
2380
2481 if (
2582 ! checkPermission ( profile . permissions ! , [
@@ -36,13 +93,79 @@ export default function Page() {
3693
3794 return (
3895 < DashboardContent breadcrumbs = { breadcrumbs } >
39- < h1 className = "text-4xl font-semibold mb-8" >
40- { DASHBOARD_PAGE_HEADER }
96+ < div className = "flex justify-between items-center mb-8" >
97+ < h1 className = "text-4xl font-semibold mb-4" >
98+ { DASHBOARD_PAGE_HEADER } ,{ " " }
99+ { profile . name ? profile . name . split ( " " ) [ 0 ] : UNNAMED_USER }
100+ </ h1 >
101+ < div >
102+ < Select value = { timeRange } onValueChange = { setTimeRange } >
103+ < SelectTrigger className = "w-[140px]" >
104+ < SelectValue placeholder = "Select time range" />
105+ </ SelectTrigger >
106+ < SelectContent >
107+ { TIME_RANGES . map ( ( range ) => (
108+ < SelectItem
109+ key = { range . value }
110+ value = { range . value }
111+ >
112+ { range . label }
113+ </ SelectItem >
114+ ) ) }
115+ </ SelectContent >
116+ </ Select >
117+ </ div >
118+ </ div >
119+ { /* <h1 className="text-4xl font-semibold mb-8">
120+ {DASHBOARD_PAGE_HEADER}, {profile.name ? profile.name.split(" ")[0] : ""}
41121 </h1>
42- < div className = "mb-8" >
43- < Todo siteinfo = { siteInfo } />
122+ <Select value={timeRange} onValueChange={setTimeRange}>
123+ <SelectTrigger className="w-[140px]">
124+ <SelectValue placeholder="Select time range" />
125+ </SelectTrigger>
126+ <SelectContent>
127+ {TIME_RANGES.map((range) => (
128+ <SelectItem
129+ key={range.value}
130+ value={range.value}
131+ >
132+ {range.label}
133+ </SelectItem>
134+ ))}
135+ </SelectContent>
136+ </Select> */ }
137+ < Todo siteinfo = { siteInfo } />
138+ < div className = "grid gap-4 md:grid-cols-2 lg:grid-cols-2" >
139+ < MetricCard
140+ title = "Sales"
141+ icon = {
142+ < DollarSign className = "h-4 w-4 text-muted-foreground" />
143+ }
144+ type = { Constants . ActivityType . PURCHASED }
145+ duration = { timeRange }
146+ />
147+ < MetricCard
148+ title = "Customers"
149+ icon = {
150+ < UserPlus className = "h-4 w-4 text-muted-foreground" />
151+ }
152+ type = { Constants . ActivityType . ENROLLED }
153+ duration = { timeRange }
154+ />
155+ < MetricCard
156+ title = "New community members"
157+ icon = { < Users className = "h-4 w-4 text-muted-foreground" /> }
158+ type = { Constants . ActivityType . COMMUNITY_JOINED }
159+ duration = { timeRange }
160+ />
161+ < MetricCard
162+ title = "Subscribers"
163+ icon = { < Mail className = "h-4 w-4 text-muted-foreground" /> }
164+ type = { Constants . ActivityType . NEWSLETTER_SUBSCRIBED }
165+ duration = { timeRange }
166+ />
44167 </ div >
45- < div className = "grid xs:grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4" >
168+ { /* <div className="grid xs:grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
46169 <Metric
47170 title="Revenue"
48171 type="purchased"
@@ -67,7 +190,8 @@ export default function Page() {
67190 duration="7d"
68191 address={address}
69192 />
70- </ div >
193+ </div> */ }
194+ < SalesCard data = { salesData } loading = { salesLoading } />
71195 </ DashboardContent >
72196 ) ;
73197}
0 commit comments