-
Notifications
You must be signed in to change notification settings - Fork 7
feat(dashboard): enhance client dashboard with new analytics charts and design improvements #447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f6887fc
feat(dashboard): add new chart data types and calculations to repository
ariefgp b683074
feat(dashboard): add 6 new chart components for analytics insights
ariefgp fb51585
refactor(dashboard): improve period-comparison with shared styles and…
ariefgp 6684466
refactor(category-performance): use shared styles and add accessibility
ariefgp 00a79bd
refactor(approval-trend): use shared styles and add accessibility
ariefgp ca431b7
refactor(submission-calendar): use shared styles, locale-aware dates,…
ariefgp 63d2c93
refactor(engagement-distribution): use shared styles and add accessib…
ariefgp e3ee63e
refactor(engagement-rate-chart): use shared styles, translations, and…
ariefgp 32cfb95
fix(dashboard): fix pie chart label overlap and calendar layout issues
ariefgp fe62fb0
fix(approval-trend): use unique ID for SVG gradient to prevent collis…
ariefgp 964ef9b
fix(category-performance): use exact displayCategory match in toolti…
ariefgp 67c5aa6
fix(period-comparison): remove invalid role="list" ARIA attribute
ariefgp 7aa7b95
chore: remove unused mock-dashboard-stats
ariefgp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| "use client"; | ||
|
|
||
| import { useId } from "react"; | ||
| import { useTranslations } from "next-intl"; | ||
| import { | ||
| AreaChart, | ||
| Area, | ||
| XAxis, | ||
| YAxis, | ||
| CartesianGrid, | ||
| Tooltip, | ||
| ResponsiveContainer, | ||
| } from "recharts"; | ||
| import type { ApprovalTrendDataExport } from "@/hooks/use-dashboard-stats"; | ||
| import { | ||
| CARD_BASE_STYLES, | ||
| TITLE_STYLES, | ||
| SUBTITLE_STYLES, | ||
| VALUE_STYLES, | ||
| TOOLTIP_STYLES, | ||
| } from "./styles"; | ||
|
|
||
| interface ApprovalTrendProps { | ||
| data: ApprovalTrendDataExport[]; | ||
| isLoading?: boolean; | ||
| } | ||
|
|
||
| export function ApprovalTrend({ data, isLoading = false }: ApprovalTrendProps) { | ||
| const gradientId = useId(); | ||
| const t = useTranslations("client.dashboard.APPROVAL_TREND"); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <div className={CARD_BASE_STYLES}> | ||
| <div className="animate-pulse"> | ||
| <div className="h-4 bg-gray-200 dark:bg-gray-700 rounded-sm mb-4 w-1/3"></div> | ||
| <div className="h-64 bg-gray-200 dark:bg-gray-700 rounded-sm"></div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (!data || data.length === 0) { | ||
| return ( | ||
| <div className={CARD_BASE_STYLES}> | ||
| <h3 className={TITLE_STYLES}>{t("TITLE")}</h3> | ||
| <p className="text-gray-500 dark:text-gray-400 text-center py-8"> | ||
| {t("NO_DATA")} | ||
| </p> | ||
| <p className={`${SUBTITLE_STYLES} text-center`}> | ||
| {t("NO_DATA_DESC")} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const latestRate = data[data.length - 1]?.rate || 0; | ||
| const firstRate = data[0]?.rate || 0; | ||
| const rateChange = latestRate - firstRate; | ||
| const totalSubmissions = data.reduce((sum, item) => sum + item.total, 0); | ||
| const totalApproved = data.reduce((sum, item) => sum + item.approved, 0); | ||
|
|
||
| return ( | ||
| <section className={CARD_BASE_STYLES} aria-labelledby="approval-trend-title"> | ||
| <div className="flex items-center justify-between mb-4"> | ||
| <div> | ||
| <h3 id="approval-trend-title" className={TITLE_STYLES}>{t("TITLE")}</h3> | ||
| <p className={SUBTITLE_STYLES}>{t("SUBTITLE")}</p> | ||
| </div> | ||
| <div className="text-right"> | ||
| <div className={VALUE_STYLES}>{latestRate.toFixed(0)}%</div> | ||
| <div | ||
| className={`text-xs ${ | ||
| rateChange >= 0 | ||
| ? "text-green-600 dark:text-green-400" | ||
| : "text-red-600 dark:text-red-400" | ||
| }`} | ||
| > | ||
| {rateChange >= 0 ? "+" : ""} | ||
| {rateChange.toFixed(0)}% | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <ResponsiveContainer width="100%" height={200}> | ||
| <AreaChart | ||
| data={data} | ||
| margin={{ top: 10, right: 10, left: 0, bottom: 0 }} | ||
| > | ||
| <defs> | ||
| <linearGradient | ||
| id={`approvalGradient-${gradientId}`} | ||
| x1="0" | ||
| y1="0" | ||
| x2="0" | ||
| y2="1" | ||
| > | ||
| <stop | ||
| offset="5%" | ||
| stopColor="#10B981" | ||
| stopOpacity={0.3} | ||
| /> | ||
| <stop | ||
| offset="95%" | ||
| stopColor="#10B981" | ||
| stopOpacity={0} | ||
| /> | ||
| </linearGradient> | ||
| </defs> | ||
| <CartesianGrid | ||
| strokeDasharray="3 3" | ||
| stroke="var(--tw-prose-hr, #e5e7eb)" | ||
| vertical={false} | ||
| /> | ||
| <XAxis dataKey="month" stroke="#6B7280" fontSize={12} /> | ||
| <YAxis | ||
| stroke="#6B7280" | ||
| fontSize={12} | ||
| domain={[0, 100]} | ||
| tickFormatter={(value: number) => `${value}%`} | ||
| /> | ||
| <Tooltip | ||
| contentStyle={TOOLTIP_STYLES} | ||
| formatter={(value) => [ | ||
| `${Number(value).toFixed(1)}%`, | ||
| t("APPROVAL_RATE"), | ||
| ]} | ||
| /> | ||
| <Area | ||
| type="monotone" | ||
| dataKey="rate" | ||
| stroke="#10B981" | ||
| strokeWidth={2} | ||
| fill={`url(#approvalGradient-${gradientId})`} | ||
| /> | ||
| </AreaChart> | ||
| </ResponsiveContainer> | ||
| <div className="mt-4 flex justify-between text-xs text-gray-500 dark:text-gray-400"> | ||
| <span> | ||
| {t("TOTAL")}: {totalSubmissions} | ||
| </span> | ||
| <span> | ||
| {t("APPROVED")}: {totalApproved} | ||
| </span> | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| "use client"; | ||
|
|
||
| import { useTranslations } from "next-intl"; | ||
| import { | ||
| BarChart, | ||
| Bar, | ||
| XAxis, | ||
| YAxis, | ||
| CartesianGrid, | ||
| Tooltip, | ||
| ResponsiveContainer, | ||
| Cell, | ||
| } from "recharts"; | ||
| import type { CategoryPerformanceDataExport } from "@/hooks/use-dashboard-stats"; | ||
| import { | ||
| CARD_BASE_STYLES, | ||
| TITLE_STYLES, | ||
| SUBTITLE_STYLES, | ||
| TOOLTIP_STYLES, | ||
| CHART_COLORS, | ||
| } from "./styles"; | ||
|
|
||
| interface CategoryPerformanceProps { | ||
| data: CategoryPerformanceDataExport[]; | ||
| isLoading?: boolean; | ||
| } | ||
|
|
||
| export function CategoryPerformance({ data, isLoading = false }: CategoryPerformanceProps) { | ||
| const t = useTranslations("client.dashboard.CATEGORY_PERFORMANCE"); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <div className={CARD_BASE_STYLES}> | ||
| <div className="animate-pulse"> | ||
| <div className="h-4 bg-gray-200 dark:bg-gray-700 rounded-sm mb-4 w-1/3"></div> | ||
| <div className="h-64 bg-gray-200 dark:bg-gray-700 rounded-sm"></div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (!data || data.length === 0) { | ||
| return ( | ||
| <div className={CARD_BASE_STYLES}> | ||
| <h3 className={TITLE_STYLES}>{t("TITLE")}</h3> | ||
| <p className="text-gray-500 dark:text-gray-400 text-center py-8"> | ||
| {t("NO_DATA")} | ||
| </p> | ||
| <p className={`${SUBTITLE_STYLES} text-center`}> | ||
| {t("NO_DATA_DESC")} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const chartData = data.map((item) => ({ | ||
| ...item, | ||
| displayCategory: | ||
| item.category.length > 15 | ||
| ? `${item.category.substring(0, 15)}...` | ||
| : item.category, | ||
| })); | ||
|
|
||
| return ( | ||
| <section className={CARD_BASE_STYLES} aria-labelledby="category-performance-title"> | ||
| <div className="flex items-center justify-between mb-4"> | ||
| <h3 id="category-performance-title" className={TITLE_STYLES}>{t("TITLE")}</h3> | ||
| <span className={SUBTITLE_STYLES}>{t("SUBTITLE")}</span> | ||
| </div> | ||
| <ResponsiveContainer width="100%" height={250}> | ||
| <BarChart | ||
| data={chartData} | ||
| layout="vertical" | ||
| margin={{ top: 5, right: 30, left: 20, bottom: 5 }} | ||
| > | ||
| <CartesianGrid | ||
| strokeDasharray="3 3" | ||
| stroke="var(--tw-prose-hr, #e5e7eb)" | ||
| horizontal={true} | ||
| vertical={false} | ||
| /> | ||
| <XAxis | ||
| type="number" | ||
| stroke="#6B7280" | ||
| fontSize={12} | ||
| tickFormatter={(value: number) => value.toFixed(1)} | ||
| /> | ||
| <YAxis | ||
| type="category" | ||
| dataKey="displayCategory" | ||
| stroke="#6B7280" | ||
| fontSize={12} | ||
| width={100} | ||
| /> | ||
| <Tooltip | ||
| contentStyle={TOOLTIP_STYLES} | ||
| formatter={(value, name) => { | ||
| if (name === "avgEngagement") { | ||
| return [Number(value).toFixed(2), t("AVG_ENGAGEMENT")]; | ||
| } | ||
| return [value, String(name)]; | ||
| }} | ||
| labelFormatter={(label) => { | ||
| const item = chartData.find( | ||
| (d) => d.displayCategory === String(label) | ||
| ); | ||
| return item ? item.category : String(label); | ||
| }} | ||
| /> | ||
| <Bar dataKey="avgEngagement" radius={[0, 4, 4, 0]}> | ||
| {chartData.map((_, index) => ( | ||
| <Cell | ||
| key={`cell-${index}`} | ||
| fill={CHART_COLORS[index % CHART_COLORS.length]} | ||
| /> | ||
| ))} | ||
| </Bar> | ||
| </BarChart> | ||
| </ResponsiveContainer> | ||
| <div className="mt-4 grid grid-cols-2 gap-2 text-xs"> | ||
| {data.slice(0, 4).map((item, index) => ( | ||
| <div key={item.category} className="flex items-center gap-2"> | ||
| <div | ||
| className="h-2 w-2 rounded-full shrink-0" | ||
| style={{ | ||
| backgroundColor: CHART_COLORS[index % CHART_COLORS.length], | ||
| }} | ||
| /> | ||
| <span className="text-gray-600 dark:text-gray-400 truncate"> | ||
| {item.category} | ||
| </span> | ||
| <span className="text-gray-900 dark:text-gray-100 font-medium shrink-0"> | ||
| {item.itemCount} {t("ITEMS").toLowerCase()} | ||
ariefgp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </span> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.