Add notification context and privacy toggle for analytics

Introduces a NotificationProvider context to centralize notification logic and state, refactoring UnifiedNotifications to use this context. Adds a privacy toggle to AnalyticsDashboard and RevenueChart to allow hiding sensitive numbers. Updates layout to wrap the app with NotificationProvider.
This commit is contained in:
NotII
2025-07-28 22:50:55 +02:00
parent 2452a3c5f6
commit 48cfd45fb1
6 changed files with 460 additions and 287 deletions

View File

@@ -12,6 +12,7 @@ import { ChartSkeleton } from './SkeletonLoaders';
interface RevenueChartProps {
timeRange: string;
hideNumbers?: boolean;
}
interface ChartDataPoint {
@@ -21,7 +22,7 @@ interface ChartDataPoint {
formattedDate: string;
}
export default function RevenueChart({ timeRange }: RevenueChartProps) {
export default function RevenueChart({ timeRange, hideNumbers = false }: RevenueChartProps) {
const [data, setData] = useState<RevenueData[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@@ -75,6 +76,19 @@ export default function RevenueChart({ timeRange }: RevenueChartProps) {
const totalOrders = safeData.reduce((sum, item) => sum + (item.orders || 0), 0);
const averageRevenue = safeData.length > 0 ? totalRevenue / safeData.length : 0;
// Function to mask sensitive numbers
const maskValue = (value: string): string => {
if (!hideNumbers) return value;
// For currency values (£X.XX), show £***
if (value.includes('£')) {
return '£***';
}
// For regular numbers, replace with asterisks
return '***';
};
// Custom tooltip for the chart
const CustomTooltip = ({ active, payload, label }: any) => {
if (active && payload && payload.length) {
@@ -83,10 +97,10 @@ export default function RevenueChart({ timeRange }: RevenueChartProps) {
<div className="bg-white p-3 border border-gray-200 rounded-lg shadow-lg">
<p className="text-sm font-medium text-gray-900">{data.formattedDate}</p>
<p className="text-sm text-blue-600">
Revenue: <span className="font-semibold">{formatGBP(data.revenue)}</span>
Revenue: <span className="font-semibold">{hideNumbers ? '£***' : formatGBP(data.revenue)}</span>
</p>
<p className="text-sm text-green-600">
Orders: <span className="font-semibold">{data.orders}</span>
Orders: <span className="font-semibold">{hideNumbers ? '***' : data.orders}</span>
</p>
</div>
);
@@ -173,7 +187,7 @@ export default function RevenueChart({ timeRange }: RevenueChartProps) {
/>
<YAxis
tick={{ fontSize: 12 }}
tickFormatter={(value) => `£${(value / 1000).toFixed(0)}k`}
tickFormatter={(value) => hideNumbers ? '***' : `£${(value / 1000).toFixed(0)}k`}
/>
<Tooltip content={<CustomTooltip />} />
<Bar
@@ -191,19 +205,19 @@ export default function RevenueChart({ timeRange }: RevenueChartProps) {
<div className="grid grid-cols-3 gap-4 pt-4 border-t">
<div className="text-center">
<div className="text-2xl font-bold text-green-600">
{formatGBP(totalRevenue)}
{maskValue(formatGBP(totalRevenue))}
</div>
<div className="text-sm text-muted-foreground">Total Revenue</div>
</div>
<div className="text-center">
<div className="text-2xl font-bold text-blue-600">
{totalOrders}
{maskValue(totalOrders.toString())}
</div>
<div className="text-sm text-muted-foreground">Total Orders</div>
</div>
<div className="text-center">
<div className="text-2xl font-bold text-purple-600">
{formatGBP(averageRevenue)}
{maskValue(formatGBP(averageRevenue))}
</div>
<div className="text-sm text-muted-foreground">Avg Daily Revenue</div>
</div>