react-groundwork 0.0.0-stage → 0.1.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.
- package/.env.example +6 -0
- package/.gitattributes +2 -0
- package/.prettierignore +7 -0
- package/.prettierrc.json +12 -0
- package/README.md +24 -2
- package/cli/index.js +119 -0
- package/components.json +25 -0
- package/eslint.config.js +17 -0
- package/index.html +13 -0
- package/jsconfig.json +8 -0
- package/package.json +111 -4
- package/public/.htaccess +11 -0
- package/public/logo.png +0 -0
- package/src/App.jsx +14 -0
- package/src/api/api.routes.js +12 -0
- package/src/api/api.services.js +8 -0
- package/src/api/apiCall.js +128 -0
- package/src/api/apiHelpers.js +20 -0
- package/src/assets/css/index.css +173 -0
- package/src/assets/images/placeholders/placeholder-170x166.png +0 -0
- package/src/assets/images/placeholders/placeholder-360x260.png +0 -0
- package/src/assets/images/placeholders/placeholder-372x225.png +0 -0
- package/src/assets/images/placeholders/placeholder-40x40.png +0 -0
- package/src/assets/images/placeholders/placeholder-451x392.png +0 -0
- package/src/components/common/AppChart.jsx +56 -0
- package/src/components/common/Breadcrumbs.jsx +90 -0
- package/src/components/common/DataTable.jsx +203 -0
- package/src/components/common/DatePicker.jsx +275 -0
- package/src/components/common/DialogComponent.jsx +308 -0
- package/src/components/common/ErrorStateComponent.jsx +46 -0
- package/src/components/common/FullscreenToggle.jsx +54 -0
- package/src/components/common/HeadingComponent.jsx +29 -0
- package/src/components/common/LoadingComponent.jsx +33 -0
- package/src/components/common/NetworkStatus.jsx +103 -0
- package/src/components/common/NoDataComponent.jsx +45 -0
- package/src/components/common/Pagination.jsx +128 -0
- package/src/components/common/ParagraphComponent.jsx +14 -0
- package/src/components/common/PhoneInputComponent.jsx +242 -0
- package/src/components/common/ReactSelect.jsx +145 -0
- package/src/components/common/SearchSelect.jsx +176 -0
- package/src/components/common/SeeMore.jsx +26 -0
- package/src/components/common/SortableHeader.jsx +23 -0
- package/src/components/common/theme-toggle.jsx +39 -0
- package/src/components/layout/AuthLayout.jsx +90 -0
- package/src/components/layout/PageLayout.jsx +32 -0
- package/src/components/layout/SidebarLayout.jsx +233 -0
- package/src/components/ui/avatar.jsx +84 -0
- package/src/components/ui/badge.jsx +43 -0
- package/src/components/ui/button.jsx +44 -0
- package/src/components/ui/card.jsx +69 -0
- package/src/components/ui/checkbox.jsx +25 -0
- package/src/components/ui/dialog.jsx +149 -0
- package/src/components/ui/empty.jsx +82 -0
- package/src/components/ui/input.jsx +19 -0
- package/src/components/ui/label.jsx +19 -0
- package/src/components/ui/select.jsx +156 -0
- package/src/components/ui/skeleton.jsx +7 -0
- package/src/components/ui/sonner.jsx +37 -0
- package/src/components/ui/switch.jsx +23 -0
- package/src/components/ui/table.jsx +74 -0
- package/src/components/ui/textarea.jsx +16 -0
- package/src/constants/constant.js +16 -0
- package/src/context/theme-provider.jsx +48 -0
- package/src/features/components/ComponentFormDialog.jsx +162 -0
- package/src/features/components/ComponentsTable.jsx +219 -0
- package/src/features/components/componentStyles.js +16 -0
- package/src/features/components/mockData.js +407 -0
- package/src/features/playground/BasicsSection.jsx +122 -0
- package/src/features/playground/DataSection.jsx +210 -0
- package/src/features/playground/DemoCard.jsx +21 -0
- package/src/features/playground/FeedbackSection.jsx +309 -0
- package/src/features/playground/FormsSection.jsx +188 -0
- package/src/features/playground/UtilitiesSection.jsx +200 -0
- package/src/hooks/useApiHandler.jsx +82 -0
- package/src/hooks/useDebounce.js +12 -0
- package/src/lib/utils.js +1 -0
- package/src/main.jsx +16 -0
- package/src/pages/auth/ForgotPasswordPage.jsx +101 -0
- package/src/pages/auth/LoginPage.jsx +120 -0
- package/src/pages/auth/SignupPage.jsx +135 -0
- package/src/pages/views/ComponentsPage.jsx +316 -0
- package/src/pages/views/DashboardPage.jsx +260 -0
- package/src/pages/views/LandingPage.jsx +772 -0
- package/src/pages/views/NotFoundPage.jsx +30 -0
- package/src/pages/views/PlaygroundPage.jsx +50 -0
- package/src/routes/AppRoutes.jsx +29 -0
- package/src/routes/ProtectedRoute.jsx +18 -0
- package/src/utils/exportCsv.js +17 -0
- package/src/utils/formatCurrency.js +19 -0
- package/src/utils/formatDateTime.js +34 -0
- package/src/utils/handleSessionExpire.js +22 -0
- package/src/utils/logger.js +34 -0
- package/vite.config.js +23 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Link, useNavigate } from "react-router-dom";
|
|
3
|
+
import { toast } from "sonner";
|
|
4
|
+
import { Loader2, Lock, Mail } from "lucide-react";
|
|
5
|
+
import AuthLayout from "@/components/layout/AuthLayout";
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import { Input } from "@/components/ui/input";
|
|
8
|
+
import { Label } from "@/components/ui/label";
|
|
9
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
10
|
+
import { setToken, setUser } from "@/constants/constant";
|
|
11
|
+
|
|
12
|
+
export const generateMockToken = () => `mock_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
13
|
+
|
|
14
|
+
export const mockLogin = (email) => {
|
|
15
|
+
const name = email.split("@")[0]?.replace(/[._-]/g, " ") || "Demo User";
|
|
16
|
+
const user = {
|
|
17
|
+
full_name: name.replace(/\b\w/g, (c) => c.toUpperCase()),
|
|
18
|
+
email,
|
|
19
|
+
role_name: "Admin",
|
|
20
|
+
};
|
|
21
|
+
setToken(generateMockToken());
|
|
22
|
+
setUser(user);
|
|
23
|
+
return user;
|
|
24
|
+
};
|
|
25
|
+
const LoginPage = () => {
|
|
26
|
+
const navigate = useNavigate();
|
|
27
|
+
const [form, setForm] = useState({ email: "", password: "" });
|
|
28
|
+
const [remember, setRemember] = useState(true);
|
|
29
|
+
const [loading, setLoading] = useState(false);
|
|
30
|
+
|
|
31
|
+
const handleChange = (e) => {
|
|
32
|
+
setForm((prev) => ({ ...prev, [e.target.name]: e.target.value }));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const handleSubmit = (e) => {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
|
|
38
|
+
if (!form.email || !form.password) {
|
|
39
|
+
toast.error("Enter your email and password.");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setLoading(true);
|
|
44
|
+
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
mockLogin(form.email);
|
|
47
|
+
setLoading(false);
|
|
48
|
+
toast.success("You're logged in.");
|
|
49
|
+
navigate("/dashboard", { replace: true });
|
|
50
|
+
}, 800);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<AuthLayout
|
|
55
|
+
title="Welcome back"
|
|
56
|
+
subtitle="Enter your email and password to continue."
|
|
57
|
+
footer={
|
|
58
|
+
<>
|
|
59
|
+
Don't have an account?{" "}
|
|
60
|
+
<Link to="/signup" className="font-medium text-primary hover:underline">
|
|
61
|
+
Sign up
|
|
62
|
+
</Link>
|
|
63
|
+
</>
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
<form className="space-y-4" onSubmit={handleSubmit}>
|
|
67
|
+
<div className="space-y-1.5">
|
|
68
|
+
<Label htmlFor="email">Email</Label>
|
|
69
|
+
<div className="relative">
|
|
70
|
+
<Mail className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
71
|
+
<Input
|
|
72
|
+
id="email"
|
|
73
|
+
name="email"
|
|
74
|
+
type="email"
|
|
75
|
+
autoComplete="email"
|
|
76
|
+
placeholder="Enter your email"
|
|
77
|
+
className="pl-8"
|
|
78
|
+
value={form.email}
|
|
79
|
+
onChange={handleChange}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<div className="space-y-1.5">
|
|
85
|
+
<div className="flex items-center justify-between">
|
|
86
|
+
<Label htmlFor="password">Password</Label>
|
|
87
|
+
<Link to="/forgot-password" className="text-xs font-medium text-primary hover:underline">
|
|
88
|
+
Forgot password?
|
|
89
|
+
</Link>
|
|
90
|
+
</div>
|
|
91
|
+
<div className="relative">
|
|
92
|
+
<Lock className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
93
|
+
<Input
|
|
94
|
+
id="password"
|
|
95
|
+
name="password"
|
|
96
|
+
type="password"
|
|
97
|
+
autoComplete="current-password"
|
|
98
|
+
placeholder="Enter your password"
|
|
99
|
+
className="pl-8"
|
|
100
|
+
value={form.password}
|
|
101
|
+
onChange={handleChange}
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<label className="flex cursor-pointer items-center gap-2 text-sm text-muted-foreground">
|
|
107
|
+
<Checkbox checked={remember} onCheckedChange={setRemember} />
|
|
108
|
+
Remember me
|
|
109
|
+
</label>
|
|
110
|
+
|
|
111
|
+
<Button type="submit" size="lg" className="w-full" disabled={loading}>
|
|
112
|
+
{loading && <Loader2 className="animate-spin" />}
|
|
113
|
+
{loading ? "Logging in..." : "Log in"}
|
|
114
|
+
</Button>
|
|
115
|
+
</form>
|
|
116
|
+
</AuthLayout>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default LoginPage;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Link, useNavigate } from "react-router-dom";
|
|
3
|
+
import { toast } from "sonner";
|
|
4
|
+
import { Loader2, Lock, Mail, User } from "lucide-react";
|
|
5
|
+
import AuthLayout from "@/components/layout/AuthLayout";
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import { Input } from "@/components/ui/input";
|
|
8
|
+
import { Label } from "@/components/ui/label";
|
|
9
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
10
|
+
|
|
11
|
+
const SignupPage = () => {
|
|
12
|
+
const navigate = useNavigate();
|
|
13
|
+
const [form, setForm] = useState({
|
|
14
|
+
fullName: "",
|
|
15
|
+
email: "",
|
|
16
|
+
password: "",
|
|
17
|
+
});
|
|
18
|
+
const [agreed, setAgreed] = useState(false);
|
|
19
|
+
const [loading, setLoading] = useState(false);
|
|
20
|
+
|
|
21
|
+
const handleChange = (e) => {
|
|
22
|
+
setForm((prev) => ({ ...prev, [e.target.name]: e.target.value }));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const handleSubmit = (e) => {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
|
|
28
|
+
if (!form.fullName || !form.email || !form.password) {
|
|
29
|
+
toast.error("Fill in all fields to continue.");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (form.password.length < 6) {
|
|
33
|
+
toast.error("Password must be at least 6 characters.");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!agreed) {
|
|
37
|
+
toast.error("Accept the Terms of Service and Privacy Policy to continue.");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setLoading(true);
|
|
42
|
+
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
setLoading(false);
|
|
45
|
+
toast.success("Account created. Log in to continue.");
|
|
46
|
+
navigate("/login", { replace: true });
|
|
47
|
+
}, 800);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<AuthLayout
|
|
52
|
+
title="Create an account"
|
|
53
|
+
subtitle="Enter your details to get started."
|
|
54
|
+
footer={
|
|
55
|
+
<>
|
|
56
|
+
Already have an account?{" "}
|
|
57
|
+
<Link to="/login" className="font-medium text-primary hover:underline">
|
|
58
|
+
Log in
|
|
59
|
+
</Link>
|
|
60
|
+
</>
|
|
61
|
+
}
|
|
62
|
+
>
|
|
63
|
+
<form className="space-y-4" onSubmit={handleSubmit}>
|
|
64
|
+
<div className="space-y-1.5">
|
|
65
|
+
<Label htmlFor="fullName">Full name</Label>
|
|
66
|
+
<div className="relative">
|
|
67
|
+
<User className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
68
|
+
<Input
|
|
69
|
+
id="fullName"
|
|
70
|
+
name="fullName"
|
|
71
|
+
autoComplete="name"
|
|
72
|
+
placeholder="Enter your name"
|
|
73
|
+
className="pl-8"
|
|
74
|
+
value={form.fullName}
|
|
75
|
+
onChange={handleChange}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<div className="space-y-1.5">
|
|
81
|
+
<Label htmlFor="email">Email</Label>
|
|
82
|
+
<div className="relative">
|
|
83
|
+
<Mail className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
84
|
+
<Input
|
|
85
|
+
id="email"
|
|
86
|
+
name="email"
|
|
87
|
+
type="email"
|
|
88
|
+
autoComplete="email"
|
|
89
|
+
placeholder="Enter your email"
|
|
90
|
+
className="pl-8"
|
|
91
|
+
value={form.email}
|
|
92
|
+
onChange={handleChange}
|
|
93
|
+
/>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div className="space-y-1.5">
|
|
98
|
+
<Label htmlFor="password">Password</Label>
|
|
99
|
+
<div className="relative">
|
|
100
|
+
<Lock className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
101
|
+
<Input
|
|
102
|
+
id="password"
|
|
103
|
+
name="password"
|
|
104
|
+
type="password"
|
|
105
|
+
autoComplete="new-password"
|
|
106
|
+
placeholder="Enter your password"
|
|
107
|
+
className="pl-8"
|
|
108
|
+
value={form.password}
|
|
109
|
+
onChange={handleChange}
|
|
110
|
+
aria-describedby="password-hint"
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
<p id="password-hint" className="text-xs text-muted-foreground">
|
|
114
|
+
Use at least 6 characters.
|
|
115
|
+
</p>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<label className="flex cursor-pointer items-start gap-2 text-sm text-muted-foreground">
|
|
119
|
+
<Checkbox checked={agreed} onCheckedChange={setAgreed} className="mt-0.5" />
|
|
120
|
+
<span>
|
|
121
|
+
I agree to the <span className="font-medium text-foreground">Terms of Service</span> and{" "}
|
|
122
|
+
<span className="font-medium text-foreground">Privacy Policy</span>
|
|
123
|
+
</span>
|
|
124
|
+
</label>
|
|
125
|
+
|
|
126
|
+
<Button type="submit" size="lg" className="w-full" disabled={loading}>
|
|
127
|
+
{loading && <Loader2 className="animate-spin" />}
|
|
128
|
+
{loading ? "Creating account..." : "Create account"}
|
|
129
|
+
</Button>
|
|
130
|
+
</form>
|
|
131
|
+
</AuthLayout>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export default SignupPage;
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { toast } from "sonner";
|
|
3
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
4
|
+
import { Download, PackagePlus, Search, Trash2, X } from "lucide-react";
|
|
5
|
+
import PageLayout from "@/components/layout/PageLayout";
|
|
6
|
+
import Pagination from "@/components/common/Pagination";
|
|
7
|
+
import DialogComponent from "@/components/common/DialogComponent";
|
|
8
|
+
import SearchSelect from "@/components/common/SearchSelect";
|
|
9
|
+
import ComponentFormDialog from "@/features/components/ComponentFormDialog";
|
|
10
|
+
import ComponentsTable from "@/features/components/ComponentsTable";
|
|
11
|
+
import { SORT_RANKS } from "@/features/components/componentStyles";
|
|
12
|
+
import { Button } from "@/components/ui/button";
|
|
13
|
+
import { Input } from "@/components/ui/input";
|
|
14
|
+
import { cn } from "@/lib/utils";
|
|
15
|
+
import { COMPONENT_CATEGORIES, COMPONENT_STATUSES, INITIAL_COMPONENTS } from "@/features/components/mockData";
|
|
16
|
+
import { exportCsv } from "@/utils/exportCsv";
|
|
17
|
+
|
|
18
|
+
const EXPORT_COLUMNS = [
|
|
19
|
+
{ key: "name", label: "Name" },
|
|
20
|
+
{ key: "path", label: "File path" },
|
|
21
|
+
{ key: "category", label: "Category" },
|
|
22
|
+
{ key: "tags", label: "Tags" },
|
|
23
|
+
{ key: "status", label: "Status" },
|
|
24
|
+
{ key: "description", label: "Description" },
|
|
25
|
+
{ key: "updatedAt", label: "Updated" },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const STATUS_TABS = ["All", ...COMPONENT_STATUSES];
|
|
29
|
+
|
|
30
|
+
const CATEGORY_FILTER_ITEMS = [
|
|
31
|
+
{ value: "all", label: "All categories" },
|
|
32
|
+
...COMPONENT_CATEGORIES.map((category) => ({ value: category, label: category })),
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const matchesSearch = (item, query) => {
|
|
36
|
+
const q = query.trim().toLowerCase();
|
|
37
|
+
if (!q) return true;
|
|
38
|
+
return [item.name, item.path, item.description].some((field) => field.toLowerCase().includes(q));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const compareBy = (key, order) => (a, b) => {
|
|
42
|
+
const ranks = SORT_RANKS[key];
|
|
43
|
+
const result = ranks ? ranks[a[key]] - ranks[b[key]] : String(a[key]).localeCompare(String(b[key]));
|
|
44
|
+
return order === "asc" ? result : -result;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const StatusTabs = ({ value, onChange, counts }) => (
|
|
48
|
+
<div className="inline-flex max-w-full overflow-x-auto rounded-lg bg-muted p-1">
|
|
49
|
+
{STATUS_TABS.map((tab) => {
|
|
50
|
+
const active = value === tab;
|
|
51
|
+
return (
|
|
52
|
+
<button
|
|
53
|
+
key={tab}
|
|
54
|
+
type="button"
|
|
55
|
+
onClick={() => onChange(tab)}
|
|
56
|
+
className={cn(
|
|
57
|
+
"relative shrink-0 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",
|
|
58
|
+
active ? "text-foreground" : "text-muted-foreground hover:text-foreground",
|
|
59
|
+
)}
|
|
60
|
+
>
|
|
61
|
+
{active && (
|
|
62
|
+
<motion.span
|
|
63
|
+
layoutId="components-status-tab"
|
|
64
|
+
className="absolute inset-0 rounded-md bg-card shadow-sm ring-1 ring-foreground/5"
|
|
65
|
+
transition={{ type: "spring", stiffness: 420, damping: 34 }}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
68
|
+
<span className="relative flex items-center gap-1.5 whitespace-nowrap">
|
|
69
|
+
{tab}
|
|
70
|
+
<span
|
|
71
|
+
className={cn(
|
|
72
|
+
"rounded-full px-1.5 text-[10px] tabular-nums",
|
|
73
|
+
active ? "bg-primary/10 text-primary" : "bg-foreground/5",
|
|
74
|
+
)}
|
|
75
|
+
>
|
|
76
|
+
{counts[tab]}
|
|
77
|
+
</span>
|
|
78
|
+
</span>
|
|
79
|
+
</button>
|
|
80
|
+
);
|
|
81
|
+
})}
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const ComponentsPage = () => {
|
|
86
|
+
const [components, setComponents] = useState(INITIAL_COMPONENTS);
|
|
87
|
+
const [search, setSearch] = useState("");
|
|
88
|
+
const [statusFilter, setStatusFilter] = useState("All");
|
|
89
|
+
const [categoryFilter, setCategoryFilter] = useState("all");
|
|
90
|
+
const [sortBy, setSortBy] = useState("name");
|
|
91
|
+
const [sortOrder, setSortOrder] = useState("asc");
|
|
92
|
+
const [selectedIds, setSelectedIds] = useState(() => new Set());
|
|
93
|
+
|
|
94
|
+
const [formDialog, setFormDialog] = useState({ open: false, component: null, key: 0 });
|
|
95
|
+
const [deleteDialog, setDeleteDialog] = useState({ open: false, components: [] });
|
|
96
|
+
|
|
97
|
+
const searched = components.filter(
|
|
98
|
+
(item) => matchesSearch(item, search) && (categoryFilter === "all" || item.category === categoryFilter),
|
|
99
|
+
);
|
|
100
|
+
const statusCounts = Object.fromEntries(
|
|
101
|
+
STATUS_TABS.map((tab) => [tab, tab === "All" ? searched.length : searched.filter((c) => c.status === tab).length]),
|
|
102
|
+
);
|
|
103
|
+
const filtered = searched
|
|
104
|
+
.filter((item) => statusFilter === "All" || item.status === statusFilter)
|
|
105
|
+
.sort(compareBy(sortBy, sortOrder));
|
|
106
|
+
|
|
107
|
+
const hasFilters = Boolean(search) || categoryFilter !== "all" || statusFilter !== "All";
|
|
108
|
+
|
|
109
|
+
const handleSort = (key) => {
|
|
110
|
+
if (key === sortBy) {
|
|
111
|
+
setSortOrder((prev) => (prev === "asc" ? "desc" : "asc"));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
setSortBy(key);
|
|
115
|
+
setSortOrder("asc");
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const clearFilters = () => {
|
|
119
|
+
setSearch("");
|
|
120
|
+
setCategoryFilter("all");
|
|
121
|
+
setStatusFilter("All");
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const toggleRow = (id) =>
|
|
125
|
+
setSelectedIds((prev) => {
|
|
126
|
+
const next = new Set(prev);
|
|
127
|
+
if (next.has(id)) next.delete(id);
|
|
128
|
+
else next.add(id);
|
|
129
|
+
return next;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const toggleAllOnPage = (checked, rows) =>
|
|
133
|
+
setSelectedIds((prev) => {
|
|
134
|
+
const next = new Set(prev);
|
|
135
|
+
rows.forEach((row) => (checked ? next.add(row.id) : next.delete(row.id)));
|
|
136
|
+
return next;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const openForm = (component = null) => setFormDialog((prev) => ({ open: true, component, key: prev.key + 1 }));
|
|
140
|
+
const closeForm = () => setFormDialog((prev) => ({ ...prev, open: false }));
|
|
141
|
+
const closeDelete = () => setDeleteDialog((prev) => ({ ...prev, open: false }));
|
|
142
|
+
|
|
143
|
+
const handleSave = (values) => {
|
|
144
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
145
|
+
const editing = formDialog.component;
|
|
146
|
+
if (editing) {
|
|
147
|
+
setComponents((prev) => prev.map((c) => (c.id === editing.id ? { ...c, ...values, updatedAt: today } : c)));
|
|
148
|
+
toast.success("Component updated.");
|
|
149
|
+
} else {
|
|
150
|
+
setComponents((prev) => [{ ...values, id: Date.now(), updatedAt: today }, ...prev]);
|
|
151
|
+
toast.success("Component added.");
|
|
152
|
+
}
|
|
153
|
+
closeForm();
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handleDelete = () => {
|
|
157
|
+
const ids = new Set(deleteDialog.components.map((c) => c.id));
|
|
158
|
+
setComponents((prev) => prev.filter((c) => !ids.has(c.id)));
|
|
159
|
+
setSelectedIds((prev) => new Set([...prev].filter((id) => !ids.has(id))));
|
|
160
|
+
toast.success(ids.size === 1 ? "Component deleted." : `${ids.size} components deleted.`);
|
|
161
|
+
closeDelete();
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const selectedComponents = components.filter((c) => selectedIds.has(c.id));
|
|
165
|
+
const deleteCount = deleteDialog.components.length;
|
|
166
|
+
|
|
167
|
+
const handleExport = () => {
|
|
168
|
+
const rows = (selectedComponents.length ? selectedComponents : filtered).map((c) => ({
|
|
169
|
+
...c,
|
|
170
|
+
tags: c.tags.join(", "),
|
|
171
|
+
}));
|
|
172
|
+
exportCsv({ filename: "components.csv", columns: EXPORT_COLUMNS, rows });
|
|
173
|
+
toast.success(`Exported ${rows.length} ${rows.length === 1 ? "component" : "components"} to components.csv.`);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<PageLayout showSidebar variant="table" className="p-2">
|
|
178
|
+
<div className="flex min-h-0 flex-1 flex-col gap-4">
|
|
179
|
+
<div className="flex flex-col justify-between gap-3 sm:flex-row sm:items-center">
|
|
180
|
+
<div>
|
|
181
|
+
<h1 className="font-heading text-2xl font-bold tracking-tight">Components</h1>
|
|
182
|
+
<p className="text-sm text-muted-foreground">Every UI component in this template, with where to find it.</p>
|
|
183
|
+
</div>
|
|
184
|
+
<div className="flex items-center gap-2">
|
|
185
|
+
<Button
|
|
186
|
+
variant="outline"
|
|
187
|
+
className="h-9"
|
|
188
|
+
onClick={handleExport}
|
|
189
|
+
disabled={filtered.length === 0}
|
|
190
|
+
title={
|
|
191
|
+
selectedComponents.length ? "Export the selected components to CSV" : "Export the filtered list to CSV"
|
|
192
|
+
}
|
|
193
|
+
>
|
|
194
|
+
<Download />
|
|
195
|
+
Export CSV
|
|
196
|
+
</Button>
|
|
197
|
+
<Button className="h-9" onClick={() => openForm()}>
|
|
198
|
+
<PackagePlus />
|
|
199
|
+
Add component
|
|
200
|
+
</Button>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
<div className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl bg-card ring-1 ring-foreground/10">
|
|
205
|
+
<div className="flex shrink-0 flex-col gap-3 border-b border-border p-4 lg:flex-row lg:items-center lg:justify-between">
|
|
206
|
+
<StatusTabs value={statusFilter} counts={statusCounts} onChange={setStatusFilter} />
|
|
207
|
+
|
|
208
|
+
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
|
209
|
+
<div className="relative sm:w-64">
|
|
210
|
+
<Search className="pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
211
|
+
<Input
|
|
212
|
+
placeholder="Search name, path or description"
|
|
213
|
+
className="h-9 pl-9 text-sm"
|
|
214
|
+
value={search}
|
|
215
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
216
|
+
/>
|
|
217
|
+
</div>
|
|
218
|
+
|
|
219
|
+
<SearchSelect
|
|
220
|
+
options={CATEGORY_FILTER_ITEMS}
|
|
221
|
+
value={categoryFilter}
|
|
222
|
+
onValueChange={(value) => setCategoryFilter(value || "all")}
|
|
223
|
+
searchPlaceholder="Search categories"
|
|
224
|
+
className="sm:w-44"
|
|
225
|
+
/>
|
|
226
|
+
|
|
227
|
+
{hasFilters && (
|
|
228
|
+
<Button variant="ghost" className="h-9 text-muted-foreground" onClick={clearFilters}>
|
|
229
|
+
<X />
|
|
230
|
+
Clear filters
|
|
231
|
+
</Button>
|
|
232
|
+
)}
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<AnimatePresence initial={false}>
|
|
237
|
+
{selectedIds.size > 0 && (
|
|
238
|
+
<motion.div
|
|
239
|
+
initial={{ height: 0, opacity: 0 }}
|
|
240
|
+
animate={{ height: "auto", opacity: 1 }}
|
|
241
|
+
exit={{ height: 0, opacity: 0 }}
|
|
242
|
+
transition={{ duration: 0.2, ease: "easeOut" }}
|
|
243
|
+
className="shrink-0 overflow-hidden"
|
|
244
|
+
>
|
|
245
|
+
<div className="flex items-center justify-between gap-3 border-b border-primary/15 bg-primary/5 px-4 py-2.5">
|
|
246
|
+
<p className="text-sm">
|
|
247
|
+
<span className="font-semibold text-primary">{selectedIds.size}</span>{" "}
|
|
248
|
+
{selectedIds.size === 1 ? "component" : "components"} selected
|
|
249
|
+
</p>
|
|
250
|
+
<div className="flex items-center gap-2">
|
|
251
|
+
<Button variant="ghost" size="sm" onClick={() => setSelectedIds(new Set())}>
|
|
252
|
+
Clear selection
|
|
253
|
+
</Button>
|
|
254
|
+
<Button
|
|
255
|
+
variant="destructive"
|
|
256
|
+
size="sm"
|
|
257
|
+
onClick={() => setDeleteDialog({ open: true, components: selectedComponents })}
|
|
258
|
+
>
|
|
259
|
+
<Trash2 />
|
|
260
|
+
Delete selected
|
|
261
|
+
</Button>
|
|
262
|
+
</div>
|
|
263
|
+
</div>
|
|
264
|
+
</motion.div>
|
|
265
|
+
)}
|
|
266
|
+
</AnimatePresence>
|
|
267
|
+
|
|
268
|
+
<Pagination items={filtered} label="components">
|
|
269
|
+
{(rows) => (
|
|
270
|
+
<ComponentsTable
|
|
271
|
+
rows={rows}
|
|
272
|
+
sortBy={sortBy}
|
|
273
|
+
sortOrder={sortOrder}
|
|
274
|
+
onSort={handleSort}
|
|
275
|
+
selectedIds={selectedIds}
|
|
276
|
+
onToggleRow={toggleRow}
|
|
277
|
+
onToggleAll={(checked) => toggleAllOnPage(checked, rows)}
|
|
278
|
+
onEdit={openForm}
|
|
279
|
+
onDelete={(component) => setDeleteDialog({ open: true, components: [component] })}
|
|
280
|
+
emptyTitle={hasFilters ? "No components match your filters" : "No components yet"}
|
|
281
|
+
emptyDescription={
|
|
282
|
+
hasFilters
|
|
283
|
+
? "Try a different search term or clear the filters."
|
|
284
|
+
: "Select Add component to add the first one."
|
|
285
|
+
}
|
|
286
|
+
/>
|
|
287
|
+
)}
|
|
288
|
+
</Pagination>
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
<ComponentFormDialog
|
|
293
|
+
key={formDialog.key}
|
|
294
|
+
open={formDialog.open}
|
|
295
|
+
onOpenChange={(next) => !next && closeForm()}
|
|
296
|
+
component={formDialog.component}
|
|
297
|
+
components={components}
|
|
298
|
+
onSubmit={handleSave}
|
|
299
|
+
/>
|
|
300
|
+
|
|
301
|
+
<DialogComponent.Confirm
|
|
302
|
+
open={deleteDialog.open}
|
|
303
|
+
onOpenChange={(next) => !next && closeDelete()}
|
|
304
|
+
title={deleteCount > 1 ? `Delete ${deleteCount} components?` : "Delete component?"}
|
|
305
|
+
description={
|
|
306
|
+
deleteCount === 1
|
|
307
|
+
? `"${deleteDialog.components[0].name}" will be removed from the catalog. This can't be undone.`
|
|
308
|
+
: `${deleteCount} components will be removed from the catalog. This can't be undone.`
|
|
309
|
+
}
|
|
310
|
+
onConfirm={handleDelete}
|
|
311
|
+
/>
|
|
312
|
+
</PageLayout>
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export default ComponentsPage;
|