create-bluecopa-react-app 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ import * as React from "react"
2
+ import * as TabsPrimitive from "@radix-ui/react-tabs"
3
+
4
+ import { cn } from "@/lib/utils"
5
+
6
+ const Tabs = TabsPrimitive.Root
7
+
8
+ const TabsList = React.forwardRef<
9
+ React.ElementRef<typeof TabsPrimitive.List>,
10
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
11
+ >(({ className, ...props }, ref) => (
12
+ <TabsPrimitive.List
13
+ ref={ref}
14
+ className={cn(
15
+ "inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
16
+ className
17
+ )}
18
+ {...props}
19
+ />
20
+ ))
21
+ TabsList.displayName = TabsPrimitive.List.displayName
22
+
23
+ const TabsTrigger = React.forwardRef<
24
+ React.ElementRef<typeof TabsPrimitive.Trigger>,
25
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
26
+ >(({ className, ...props }, ref) => (
27
+ <TabsPrimitive.Trigger
28
+ ref={ref}
29
+ className={cn(
30
+ "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
31
+ className
32
+ )}
33
+ {...props}
34
+ />
35
+ ))
36
+ TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
37
+
38
+ const TabsContent = React.forwardRef<
39
+ React.ElementRef<typeof TabsPrimitive.Content>,
40
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
41
+ >(({ className, ...props }, ref) => (
42
+ <TabsPrimitive.Content
43
+ ref={ref}
44
+ className={cn(
45
+ "mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
46
+ className
47
+ )}
48
+ {...props}
49
+ />
50
+ ))
51
+ TabsContent.displayName = TabsPrimitive.Content.displayName
52
+
53
+ export { Tabs, TabsList, TabsTrigger, TabsContent }
@@ -0,0 +1,59 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ @layer base {
6
+ :root {
7
+ --background: 0 0% 100%;
8
+ --foreground: 222.2 84% 4.9%;
9
+ --card: 0 0% 100%;
10
+ --card-foreground: 222.2 84% 4.9%;
11
+ --popover: 0 0% 100%;
12
+ --popover-foreground: 222.2 84% 4.9%;
13
+ --primary: 221.2 83.2% 53.3%;
14
+ --primary-foreground: 210 40% 98%;
15
+ --secondary: 210 40% 96%;
16
+ --secondary-foreground: 222.2 84% 4.9%;
17
+ --muted: 210 40% 96%;
18
+ --muted-foreground: 215.4 16.3% 46.9%;
19
+ --accent: 210 40% 96%;
20
+ --accent-foreground: 222.2 84% 4.9%;
21
+ --destructive: 0 84.2% 60.2%;
22
+ --destructive-foreground: 210 40% 98%;
23
+ --border: 214.3 31.8% 91.4%;
24
+ --input: 214.3 31.8% 91.4%;
25
+ --ring: 221.2 83.2% 53.3%;
26
+ --radius: 0.75rem;
27
+ }
28
+
29
+ .dark {
30
+ --background: 222.2 84% 4.9%;
31
+ --foreground: 210 40% 98%;
32
+ --card: 222.2 84% 4.9%;
33
+ --card-foreground: 210 40% 98%;
34
+ --popover: 222.2 84% 4.9%;
35
+ --popover-foreground: 210 40% 98%;
36
+ --primary: 217.2 91.2% 59.8%;
37
+ --primary-foreground: 222.2 84% 4.9%;
38
+ --secondary: 217.2 32.6% 17.5%;
39
+ --secondary-foreground: 210 40% 98%;
40
+ --muted: 217.2 32.6% 17.5%;
41
+ --muted-foreground: 215 20.2% 65.1%;
42
+ --accent: 217.2 32.6% 17.5%;
43
+ --accent-foreground: 210 40% 98%;
44
+ --destructive: 0 62.8% 30.6%;
45
+ --destructive-foreground: 210 40% 98%;
46
+ --border: 217.2 32.6% 17.5%;
47
+ --input: 217.2 32.6% 17.5%;
48
+ --ring: 224.3 76.3% 94.1%;
49
+ }
50
+ }
51
+
52
+ @layer base {
53
+ * {
54
+ @apply border-border;
55
+ }
56
+ body {
57
+ @apply bg-background text-foreground;
58
+ }
59
+ }
@@ -0,0 +1,6 @@
1
+ import { type ClassValue, clsx } from "clsx"
2
+ import { twMerge } from "tailwind-merge"
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs))
6
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react'
2
+ import ReactDOM from 'react-dom/client'
3
+ import App from './App.tsx'
4
+
5
+ ReactDOM.createRoot(document.getElementById('root')!).render(
6
+ <React.StrictMode>
7
+ <App />
8
+ </React.StrictMode>,
9
+ )
@@ -0,0 +1,135 @@
1
+ import React from 'react';
2
+ import { useUser } from '@bluecopa/react';
3
+ import { MetricsOverview } from '@/components/dashboard/MetricsOverview';
4
+ import { TransactionCharts } from '@/components/dashboard/TransactionCharts';
5
+ import { TransactionTable } from '@/components/dashboard/TransactionTable';
6
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
7
+ import { Button } from '@/components/ui/button';
8
+ import { RefreshCw, User, Building } from 'lucide-react';
9
+
10
+ const Dashboard: React.FC = () => {
11
+ const {
12
+ data: userData,
13
+ isLoading: userLoading,
14
+ error: userError,
15
+ refetch: refetchUser
16
+ } = useUser();
17
+
18
+ return (
19
+ <div className="space-y-8">
20
+ {/* Header Section */}
21
+ <div className="flex items-center justify-between">
22
+ <div>
23
+ <h1 className="text-3xl font-bold tracking-tight">Dashboard</h1>
24
+ <p className="text-muted-foreground">
25
+ Welcome to your BlueCopa analytics dashboard
26
+ </p>
27
+ </div>
28
+ <Button onClick={() => refetchUser()} className="flex items-center gap-2">
29
+ <RefreshCw className="h-4 w-4" />
30
+ Refresh All
31
+ </Button>
32
+ </div>
33
+
34
+ {/* User Info Section */}
35
+ {userLoading ? (
36
+ <Card>
37
+ <CardHeader>
38
+ <div className="flex items-center space-x-4">
39
+ <div className="h-12 w-12 bg-muted animate-pulse rounded-full"></div>
40
+ <div>
41
+ <div className="h-5 w-48 bg-muted animate-pulse rounded mb-2"></div>
42
+ <div className="h-4 w-32 bg-muted animate-pulse rounded"></div>
43
+ </div>
44
+ </div>
45
+ </CardHeader>
46
+ </Card>
47
+ ) : userError ? (
48
+ <Card>
49
+ <CardHeader>
50
+ <CardTitle className="text-red-600">Error Loading User Data</CardTitle>
51
+ </CardHeader>
52
+ <CardContent>
53
+ <p className="text-muted-foreground">Failed to load user information.</p>
54
+ </CardContent>
55
+ </Card>
56
+ ) : userData ? (
57
+ <Card>
58
+ <CardHeader>
59
+ <div className="flex items-center space-x-4">
60
+ <div className="h-12 w-12 bg-primary/10 rounded-full flex items-center justify-center">
61
+ <User className="h-6 w-6 text-primary" />
62
+ </div>
63
+ <div>
64
+ <CardTitle className="text-xl">
65
+ {userData.user.firstName} {userData.user.lastName}
66
+ </CardTitle>
67
+ <CardDescription className="flex items-center gap-2">
68
+ <Building className="h-4 w-4" />
69
+ {userData.organization.name} • {userData.user.email}
70
+ </CardDescription>
71
+ </div>
72
+ </div>
73
+ </CardHeader>
74
+ </Card>
75
+ ) : null}
76
+
77
+ {/* Query States Overview */}
78
+ <Card>
79
+ <CardHeader>
80
+ <CardTitle>Copa-lib Demo with TanStack Query</CardTitle>
81
+ <CardDescription>
82
+ Query States Overview - Real-time data fetching status
83
+ </CardDescription>
84
+ </CardHeader>
85
+ <CardContent>
86
+ <div className="grid gap-4 md:grid-cols-3">
87
+ <div className="space-y-2">
88
+ <h4 className="font-medium">User Query</h4>
89
+ <div className="flex items-center gap-2">
90
+ <div className={`h-2 w-2 rounded-full ${userLoading ? 'bg-yellow-500' : userError ? 'bg-red-500' : 'bg-green-500'}`}></div>
91
+ <span className="text-sm text-muted-foreground">
92
+ {userLoading ? 'Loading...' : userError ? 'Error' : 'Success'}
93
+ </span>
94
+ </div>
95
+ </div>
96
+ <div className="space-y-2">
97
+ <h4 className="font-medium">Metrics Query</h4>
98
+ <div className="flex items-center gap-2">
99
+ <div className="h-2 w-2 rounded-full bg-green-500"></div>
100
+ <span className="text-sm text-muted-foreground">Success</span>
101
+ </div>
102
+ </div>
103
+ <div className="space-y-2">
104
+ <h4 className="font-medium">Dataset Query</h4>
105
+ <div className="flex items-center gap-2">
106
+ <div className="h-2 w-2 rounded-full bg-green-500"></div>
107
+ <span className="text-sm text-muted-foreground">Success</span>
108
+ </div>
109
+ </div>
110
+ </div>
111
+ </CardContent>
112
+ </Card>
113
+
114
+ {/* Metrics Overview */}
115
+ <div>
116
+ <h2 className="text-2xl font-semibold mb-6">Key Metrics</h2>
117
+ <MetricsOverview />
118
+ </div>
119
+
120
+ {/* Charts Section */}
121
+ <div>
122
+ <h2 className="text-2xl font-semibold mb-6">Analytics Charts</h2>
123
+ <TransactionCharts />
124
+ </div>
125
+
126
+ {/* Transaction Table */}
127
+ <div>
128
+ <h2 className="text-2xl font-semibold mb-6">Transaction Data</h2>
129
+ <TransactionTable />
130
+ </div>
131
+ </div>
132
+ );
133
+ };
134
+
135
+ export default Dashboard;
@@ -0,0 +1,94 @@
1
+ // Transaction Data Types based on BlueCopa dataset
2
+ export interface TransactionRecord {
3
+ transaction_id: string;
4
+ transaction_day: string;
5
+ payment_end: string;
6
+ city_id: string;
7
+ city: string;
8
+ state: string;
9
+ product_id: string;
10
+ category: string;
11
+ sub_categories: string;
12
+ quantity: number;
13
+ unit_price: number;
14
+ total_amount: number;
15
+ is_online: boolean;
16
+ payment_method: string;
17
+ is_weekend: boolean;
18
+ is_holiday: boolean;
19
+ is_working_day: boolean;
20
+ channel: string;
21
+ delivery_partner: string | null;
22
+ copa_uploaded_at: string;
23
+ copa_source_name: string;
24
+ }
25
+
26
+ export interface DatasetResponse {
27
+ data: {
28
+ schema: Array<{
29
+ name: string;
30
+ data_type: string;
31
+ }>;
32
+ data: TransactionRecord[];
33
+ };
34
+ }
35
+
36
+ export interface MetricResponse {
37
+ data: Array<{
38
+ TotalAmount: number;
39
+ }>;
40
+ }
41
+
42
+ export interface User {
43
+ email: string;
44
+ firstName: string;
45
+ lastName: string;
46
+ externalId: string;
47
+ metadata: Record<string, any>;
48
+ organizationExternalId: string;
49
+ active: boolean;
50
+ createdBy: string | null;
51
+ createdDate: string | null;
52
+ lastModifiedBy: string | null;
53
+ lastModifiedDate: string | null;
54
+ id: string;
55
+ entityVersion: number;
56
+ organizationId: string;
57
+ }
58
+
59
+ export interface Organization {
60
+ name: string;
61
+ externalId: string;
62
+ active: boolean;
63
+ createdBy: string | null;
64
+ createdDate: string | null;
65
+ lastModifiedBy: string | null;
66
+ lastModifiedDate: string | null;
67
+ id: string;
68
+ entityVersion: number;
69
+ }
70
+
71
+ export interface UserResponse {
72
+ user: User;
73
+ organization: Organization;
74
+ }
75
+
76
+ // Chart data types
77
+ export interface CategorySalesData {
78
+ category: string;
79
+ totalSales: number;
80
+ quantity: number;
81
+ }
82
+
83
+ export interface PaymentMethodData {
84
+ paymentMethod: string;
85
+ count: number;
86
+ totalAmount: number;
87
+ }
88
+
89
+ export interface StateAnalytics {
90
+ state: string;
91
+ totalTransactions: number;
92
+ totalAmount: number;
93
+ averageOrderValue: number;
94
+ }
@@ -0,0 +1,77 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ export default {
3
+ darkMode: ["class"],
4
+ content: [
5
+ './pages/**/*.{ts,tsx}',
6
+ './components/**/*.{ts,tsx}',
7
+ './app/**/*.{ts,tsx}',
8
+ './src/**/*.{ts,tsx}',
9
+ ],
10
+ prefix: "",
11
+ theme: {
12
+ container: {
13
+ center: true,
14
+ padding: "2rem",
15
+ screens: {
16
+ "2xl": "1400px",
17
+ },
18
+ },
19
+ extend: {
20
+ colors: {
21
+ border: "hsl(var(--border))",
22
+ input: "hsl(var(--input))",
23
+ ring: "hsl(var(--ring))",
24
+ background: "hsl(var(--background))",
25
+ foreground: "hsl(var(--foreground))",
26
+ primary: {
27
+ DEFAULT: "hsl(var(--primary))",
28
+ foreground: "hsl(var(--primary-foreground))",
29
+ },
30
+ secondary: {
31
+ DEFAULT: "hsl(var(--secondary))",
32
+ foreground: "hsl(var(--secondary-foreground))",
33
+ },
34
+ destructive: {
35
+ DEFAULT: "hsl(var(--destructive))",
36
+ foreground: "hsl(var(--destructive-foreground))",
37
+ },
38
+ muted: {
39
+ DEFAULT: "hsl(var(--muted))",
40
+ foreground: "hsl(var(--muted-foreground))",
41
+ },
42
+ accent: {
43
+ DEFAULT: "hsl(var(--accent))",
44
+ foreground: "hsl(var(--accent-foreground))",
45
+ },
46
+ popover: {
47
+ DEFAULT: "hsl(var(--popover))",
48
+ foreground: "hsl(var(--popover-foreground))",
49
+ },
50
+ card: {
51
+ DEFAULT: "hsl(var(--card))",
52
+ foreground: "hsl(var(--card-foreground))",
53
+ },
54
+ },
55
+ borderRadius: {
56
+ lg: "var(--radius)",
57
+ md: "calc(var(--radius) - 2px)",
58
+ sm: "calc(var(--radius) - 4px)",
59
+ },
60
+ keyframes: {
61
+ "accordion-down": {
62
+ from: { height: "0" },
63
+ to: { height: "var(--radix-accordion-content-height)" },
64
+ },
65
+ "accordion-up": {
66
+ from: { height: "var(--radix-accordion-content-height)" },
67
+ to: { height: "0" },
68
+ },
69
+ },
70
+ animation: {
71
+ "accordion-down": "accordion-down 0.2s ease-out",
72
+ "accordion-up": "accordion-up 0.2s ease-out",
73
+ },
74
+ },
75
+ },
76
+ plugins: [require("tailwindcss-animate")],
77
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react-jsx",
16
+
17
+ /* Linting */
18
+ "strict": false,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+
23
+ /* Path mapping */
24
+ "baseUrl": ".",
25
+ "paths": {
26
+ "@/*": ["./src/*"]
27
+ }
28
+ },
29
+ "include": ["src"],
30
+ "references": [{ "path": "./tsconfig.node.json" }]
31
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'vite'
2
+ import react from '@vitejs/plugin-react'
3
+ import path from 'path'
4
+
5
+ // https://vitejs.dev/config/
6
+ export default defineConfig({
7
+ plugins: [react()],
8
+ resolve: {
9
+ alias: {
10
+ "@": path.resolve(__dirname, "./src"),
11
+ },
12
+ },
13
+ })