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,188 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Input } from "@/components/ui/input";
|
|
3
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
4
|
+
import { Label } from "@/components/ui/label";
|
|
5
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
6
|
+
import { Switch } from "@/components/ui/switch";
|
|
7
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
8
|
+
import SearchSelect from "@/components/common/SearchSelect";
|
|
9
|
+
import ReactSelect from "@/components/common/ReactSelect";
|
|
10
|
+
import DatePicker from "@/components/common/DatePicker";
|
|
11
|
+
import PhoneInputComponent from "@/components/common/PhoneInputComponent";
|
|
12
|
+
import DemoCard from "@/features/playground/DemoCard";
|
|
13
|
+
import { COMPONENT_CATEGORIES, COMPONENT_TAGS } from "@/features/components/mockData";
|
|
14
|
+
|
|
15
|
+
const toOptions = (items) => items.map((item) => ({ value: item, label: item }));
|
|
16
|
+
const CATEGORY_OPTIONS = toOptions(COMPONENT_CATEGORIES);
|
|
17
|
+
const TAG_OPTIONS = toOptions(COMPONENT_TAGS);
|
|
18
|
+
const THEME_ITEMS = [
|
|
19
|
+
{ value: "light", label: "Light" },
|
|
20
|
+
{ value: "dark", label: "Dark" },
|
|
21
|
+
{ value: "system", label: "System" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const Value = ({ children }) => (
|
|
25
|
+
<p className="truncate text-xs text-muted-foreground">
|
|
26
|
+
Value: <span className="font-mono text-foreground">{children || "—"}</span>
|
|
27
|
+
</p>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const FormsSection = () => {
|
|
31
|
+
const [text, setText] = useState("");
|
|
32
|
+
const [notes, setNotes] = useState("");
|
|
33
|
+
const [agree, setAgree] = useState(true);
|
|
34
|
+
const [notify, setNotify] = useState(false);
|
|
35
|
+
const [theme, setTheme] = useState("system");
|
|
36
|
+
const [category, setCategory] = useState("Common");
|
|
37
|
+
const [tags, setTags] = useState(["Form", "Input"]);
|
|
38
|
+
const [reactSelectValue, setReactSelectValue] = useState(null);
|
|
39
|
+
const [date, setDate] = useState("");
|
|
40
|
+
const [phone, setPhone] = useState("");
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3">
|
|
44
|
+
<DemoCard
|
|
45
|
+
title="Input, Textarea and Label"
|
|
46
|
+
description="Basic text fields."
|
|
47
|
+
file="src/components/ui/input.jsx"
|
|
48
|
+
contentClassName="space-y-3"
|
|
49
|
+
>
|
|
50
|
+
<div className="space-y-1.5">
|
|
51
|
+
<Label htmlFor="pg-name" className="text-xs">
|
|
52
|
+
Project name
|
|
53
|
+
</Label>
|
|
54
|
+
<Input id="pg-name" placeholder="my-app" value={text} onChange={(e) => setText(e.target.value)} />
|
|
55
|
+
</div>
|
|
56
|
+
<div className="space-y-1.5">
|
|
57
|
+
<Label htmlFor="pg-notes" className="text-xs">
|
|
58
|
+
Notes
|
|
59
|
+
</Label>
|
|
60
|
+
<Textarea
|
|
61
|
+
id="pg-notes"
|
|
62
|
+
placeholder="Write something..."
|
|
63
|
+
value={notes}
|
|
64
|
+
onChange={(e) => setNotes(e.target.value)}
|
|
65
|
+
/>
|
|
66
|
+
</div>
|
|
67
|
+
<Input placeholder="Disabled input" disabled />
|
|
68
|
+
<Input placeholder="Invalid input" aria-invalid />
|
|
69
|
+
</DemoCard>
|
|
70
|
+
|
|
71
|
+
<DemoCard
|
|
72
|
+
title="Checkbox and Switch"
|
|
73
|
+
description="Boolean inputs."
|
|
74
|
+
file="src/components/ui/checkbox.jsx"
|
|
75
|
+
contentClassName="space-y-4"
|
|
76
|
+
>
|
|
77
|
+
<label className="flex items-center gap-2.5 text-sm">
|
|
78
|
+
<Checkbox checked={agree} onCheckedChange={setAgree} />
|
|
79
|
+
Use the template's folder structure
|
|
80
|
+
</label>
|
|
81
|
+
<label className="flex items-center gap-2.5 text-sm">
|
|
82
|
+
<Checkbox indeterminate />
|
|
83
|
+
Indeterminate state
|
|
84
|
+
</label>
|
|
85
|
+
<label className="flex items-center justify-between gap-2.5 text-sm">
|
|
86
|
+
Email notifications
|
|
87
|
+
<Switch checked={notify} onCheckedChange={setNotify} />
|
|
88
|
+
</label>
|
|
89
|
+
<label className="flex items-center justify-between gap-2.5 text-sm text-muted-foreground">
|
|
90
|
+
Small switch
|
|
91
|
+
<Switch size="sm" defaultChecked />
|
|
92
|
+
</label>
|
|
93
|
+
<Value>{`agree: ${agree}, notify: ${notify}`}</Value>
|
|
94
|
+
</DemoCard>
|
|
95
|
+
|
|
96
|
+
<DemoCard
|
|
97
|
+
title="Select"
|
|
98
|
+
description="The base select from shadcn/ui."
|
|
99
|
+
file="src/components/ui/select.jsx"
|
|
100
|
+
contentClassName="space-y-3"
|
|
101
|
+
>
|
|
102
|
+
<Select items={THEME_ITEMS} value={theme} onValueChange={setTheme}>
|
|
103
|
+
<SelectTrigger className="w-full">
|
|
104
|
+
<SelectValue />
|
|
105
|
+
</SelectTrigger>
|
|
106
|
+
<SelectContent>
|
|
107
|
+
{THEME_ITEMS.map((item) => (
|
|
108
|
+
<SelectItem key={item.value} value={item.value}>
|
|
109
|
+
{item.label}
|
|
110
|
+
</SelectItem>
|
|
111
|
+
))}
|
|
112
|
+
</SelectContent>
|
|
113
|
+
</Select>
|
|
114
|
+
<Value>{theme}</Value>
|
|
115
|
+
</DemoCard>
|
|
116
|
+
|
|
117
|
+
<DemoCard
|
|
118
|
+
title="SearchSelect"
|
|
119
|
+
description="Searchable single select with a radio indicator."
|
|
120
|
+
file="src/components/common/SearchSelect.jsx"
|
|
121
|
+
contentClassName="space-y-3"
|
|
122
|
+
>
|
|
123
|
+
<SearchSelect
|
|
124
|
+
options={CATEGORY_OPTIONS}
|
|
125
|
+
value={category}
|
|
126
|
+
onValueChange={setCategory}
|
|
127
|
+
searchPlaceholder="Search categories"
|
|
128
|
+
/>
|
|
129
|
+
<Value>{category}</Value>
|
|
130
|
+
</DemoCard>
|
|
131
|
+
|
|
132
|
+
<DemoCard
|
|
133
|
+
title="SearchSelect (multiple)"
|
|
134
|
+
description="Checkboxes and chips that scroll in a fixed height."
|
|
135
|
+
file="src/components/common/SearchSelect.jsx"
|
|
136
|
+
contentClassName="space-y-3"
|
|
137
|
+
>
|
|
138
|
+
<SearchSelect
|
|
139
|
+
multiple
|
|
140
|
+
options={TAG_OPTIONS}
|
|
141
|
+
value={tags}
|
|
142
|
+
onValueChange={setTags}
|
|
143
|
+
placeholder="Select tags"
|
|
144
|
+
searchPlaceholder="Search tags"
|
|
145
|
+
/>
|
|
146
|
+
<Value>{tags.join(", ")}</Value>
|
|
147
|
+
</DemoCard>
|
|
148
|
+
|
|
149
|
+
<DemoCard
|
|
150
|
+
title="ReactSelect"
|
|
151
|
+
description="react-select styled with the theme tokens."
|
|
152
|
+
file="src/components/common/ReactSelect.jsx"
|
|
153
|
+
contentClassName="space-y-3"
|
|
154
|
+
>
|
|
155
|
+
<ReactSelect
|
|
156
|
+
options={CATEGORY_OPTIONS}
|
|
157
|
+
value={reactSelectValue}
|
|
158
|
+
onChange={setReactSelectValue}
|
|
159
|
+
placeholder="Pick a category"
|
|
160
|
+
isClearable
|
|
161
|
+
/>
|
|
162
|
+
<Value>{reactSelectValue?.value}</Value>
|
|
163
|
+
</DemoCard>
|
|
164
|
+
|
|
165
|
+
<DemoCard
|
|
166
|
+
title="DatePicker"
|
|
167
|
+
description="Calendar with month and year views."
|
|
168
|
+
file="src/components/common/DatePicker.jsx"
|
|
169
|
+
contentClassName="space-y-3"
|
|
170
|
+
>
|
|
171
|
+
<DatePicker value={date} onValueChange={setDate} placeholder="Pick a release date" />
|
|
172
|
+
<Value>{date}</Value>
|
|
173
|
+
</DemoCard>
|
|
174
|
+
|
|
175
|
+
<DemoCard
|
|
176
|
+
title="PhoneInputComponent"
|
|
177
|
+
description="International phone input with validation."
|
|
178
|
+
file="src/components/common/PhoneInputComponent.jsx"
|
|
179
|
+
contentClassName="space-y-3"
|
|
180
|
+
>
|
|
181
|
+
<PhoneInputComponent value={phone} onChange={setPhone} />
|
|
182
|
+
<Value>{phone}</Value>
|
|
183
|
+
</DemoCard>
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export default FormsSection;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import axios, { CanceledError } from "axios";
|
|
3
|
+
import { toast } from "sonner";
|
|
4
|
+
import { Download, Loader2, Terminal } from "lucide-react";
|
|
5
|
+
import { Button } from "@/components/ui/button";
|
|
6
|
+
import { Input } from "@/components/ui/input";
|
|
7
|
+
import { ThemeToggle } from "@/components/common/theme-toggle";
|
|
8
|
+
import FullscreenToggle from "@/components/common/FullscreenToggle";
|
|
9
|
+
import DemoCard from "@/features/playground/DemoCard";
|
|
10
|
+
import { useApiHandler } from "@/hooks/useApiHandler";
|
|
11
|
+
import useDebounce from "@/hooks/useDebounce";
|
|
12
|
+
import { formatCurrency } from "@/utils/formatCurrency";
|
|
13
|
+
import { formatDateTime } from "@/utils/formatDateTime";
|
|
14
|
+
import { exportCsv } from "@/utils/exportCsv";
|
|
15
|
+
import logger from "@/utils/logger";
|
|
16
|
+
import { INITIAL_COMPONENTS } from "@/features/components/mockData";
|
|
17
|
+
|
|
18
|
+
const fakeRequest =
|
|
19
|
+
({ delay, fail, label }) =>
|
|
20
|
+
(signal) =>
|
|
21
|
+
new Promise((resolve, reject) => {
|
|
22
|
+
const timer = setTimeout(() => {
|
|
23
|
+
if (fail) reject("The server returned an error.");
|
|
24
|
+
else resolve({ label, count: INITIAL_COMPONENTS.length, at: new Date().toISOString() });
|
|
25
|
+
}, delay);
|
|
26
|
+
signal?.addEventListener("abort", () => {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
reject(new CanceledError());
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const Row = ({ label, children }) => (
|
|
33
|
+
<div className="flex items-center justify-between gap-3 py-2 text-sm">
|
|
34
|
+
<span className="text-muted-foreground">{label}</span>
|
|
35
|
+
<span className="truncate font-mono text-xs">{children}</span>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const ApiHandlerDemo = () => {
|
|
40
|
+
const { apiLoading, apiError, apiResponse, executeApi } = useApiHandler();
|
|
41
|
+
const [events, setEvents] = useState([]);
|
|
42
|
+
|
|
43
|
+
const addEvent = (text) => setEvents((prev) => [text, ...prev].slice(0, 5));
|
|
44
|
+
|
|
45
|
+
const run = async (options) => {
|
|
46
|
+
addEvent(`Started ${options.label}`);
|
|
47
|
+
try {
|
|
48
|
+
await executeApi({ key: "demo", apiFn: fakeRequest(options) });
|
|
49
|
+
addEvent(`Finished ${options.label}`);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (axios.isCancel(error)) addEvent(`Cancelled ${options.label}`);
|
|
52
|
+
else addEvent(`Failed ${options.label}`);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const fireThree = () => {
|
|
57
|
+
run({ delay: 1800, label: "request A" });
|
|
58
|
+
run({ delay: 1200, label: "request B" });
|
|
59
|
+
run({ delay: 600, label: "request C" });
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className="space-y-4">
|
|
64
|
+
<div className="flex flex-wrap gap-2">
|
|
65
|
+
<Button size="sm" onClick={() => run({ delay: 1200, label: "request" })}>
|
|
66
|
+
Load
|
|
67
|
+
</Button>
|
|
68
|
+
<Button size="sm" variant="outline" onClick={() => run({ delay: 900, fail: true, label: "failing request" })}>
|
|
69
|
+
Load with error
|
|
70
|
+
</Button>
|
|
71
|
+
<Button size="sm" variant="outline" onClick={fireThree}>
|
|
72
|
+
Fire 3 at once
|
|
73
|
+
</Button>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div className="divide-y divide-border rounded-lg border border-border px-3">
|
|
77
|
+
<Row label="apiLoading.demo">
|
|
78
|
+
{apiLoading.demo ? (
|
|
79
|
+
<span className="inline-flex items-center gap-1 text-primary">
|
|
80
|
+
<Loader2 className="h-3 w-3 animate-spin" /> true
|
|
81
|
+
</span>
|
|
82
|
+
) : (
|
|
83
|
+
"false"
|
|
84
|
+
)}
|
|
85
|
+
</Row>
|
|
86
|
+
<Row label="apiError.demo">{apiError.demo ? String(apiError.demo) : "null"}</Row>
|
|
87
|
+
<Row label="apiResponse.demo">{apiResponse.demo ? apiResponse.demo.label : "—"}</Row>
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
{events.length > 0 && (
|
|
91
|
+
<ul className="space-y-1 text-xs text-muted-foreground">
|
|
92
|
+
{events.map((event, idx) => (
|
|
93
|
+
<li key={`${event}-${idx}`}>• {event}</li>
|
|
94
|
+
))}
|
|
95
|
+
</ul>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const UtilitiesSection = () => {
|
|
102
|
+
const [query, setQuery] = useState("");
|
|
103
|
+
const debouncedQuery = useDebounce(query, 600);
|
|
104
|
+
const [amount, setAmount] = useState("1499.5");
|
|
105
|
+
const now = new Date().toISOString();
|
|
106
|
+
|
|
107
|
+
const handleExport = () => {
|
|
108
|
+
exportCsv({
|
|
109
|
+
filename: "components.csv",
|
|
110
|
+
columns: [
|
|
111
|
+
{ key: "name", label: "Name" },
|
|
112
|
+
{ key: "category", label: "Category" },
|
|
113
|
+
{ key: "path", label: "File path" },
|
|
114
|
+
],
|
|
115
|
+
rows: INITIAL_COMPONENTS,
|
|
116
|
+
});
|
|
117
|
+
toast.success("Exported components.csv.");
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const handleLog = () => {
|
|
121
|
+
logger.info("Playground", { components: INITIAL_COMPONENTS.length });
|
|
122
|
+
logger.table(INITIAL_COMPONENTS.slice(0, 5).map(({ name, category }) => ({ name, category })));
|
|
123
|
+
toast.info("Logged to the browser console.");
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3">
|
|
128
|
+
<DemoCard
|
|
129
|
+
title="useApiHandler"
|
|
130
|
+
description="Loading, error and response per key. A newer request cancels the older one."
|
|
131
|
+
file="src/hooks/useApiHandler.jsx"
|
|
132
|
+
className="md:col-span-2 xl:col-span-1 xl:row-span-2"
|
|
133
|
+
>
|
|
134
|
+
<ApiHandlerDemo />
|
|
135
|
+
</DemoCard>
|
|
136
|
+
|
|
137
|
+
<DemoCard
|
|
138
|
+
title="ThemeToggle and FullscreenToggle"
|
|
139
|
+
description="The same toggles used in the app header."
|
|
140
|
+
file="src/components/common/theme-toggle.jsx"
|
|
141
|
+
contentClassName="flex items-center gap-3"
|
|
142
|
+
>
|
|
143
|
+
<ThemeToggle />
|
|
144
|
+
<FullscreenToggle variant="outline" size="icon" />
|
|
145
|
+
<span className="text-xs text-muted-foreground">Switch theme or go fullscreen</span>
|
|
146
|
+
</DemoCard>
|
|
147
|
+
|
|
148
|
+
<DemoCard
|
|
149
|
+
title="useDebounce"
|
|
150
|
+
description="Waits until you stop typing."
|
|
151
|
+
file="src/hooks/useDebounce.js"
|
|
152
|
+
contentClassName="space-y-2"
|
|
153
|
+
>
|
|
154
|
+
<Input placeholder="Type quickly..." value={query} onChange={(e) => setQuery(e.target.value)} />
|
|
155
|
+
<Row label="Typed">{query || "—"}</Row>
|
|
156
|
+
<Row label="Debounced (600 ms)">{debouncedQuery || "—"}</Row>
|
|
157
|
+
</DemoCard>
|
|
158
|
+
|
|
159
|
+
<DemoCard
|
|
160
|
+
title="formatCurrency and formatDateTime"
|
|
161
|
+
description="Display helpers for money and dates."
|
|
162
|
+
file="src/utils/"
|
|
163
|
+
contentClassName="space-y-2"
|
|
164
|
+
>
|
|
165
|
+
<Input type="number" value={amount} onChange={(e) => setAmount(e.target.value)} />
|
|
166
|
+
<div className="divide-y divide-border">
|
|
167
|
+
<Row label="USD">{formatCurrency({ value: Number(amount) || 0 })}</Row>
|
|
168
|
+
<Row label="PKR">{formatCurrency({ value: Number(amount) || 0, currency: "PKR" })}</Row>
|
|
169
|
+
<Row label="date">{formatDateTime({ dateInput: now, type: "date" })}</Row>
|
|
170
|
+
<Row label="time">{formatDateTime({ dateInput: now, type: "time" })}</Row>
|
|
171
|
+
<Row label="datetime">{formatDateTime({ dateInput: now, type: "datetime" })}</Row>
|
|
172
|
+
</div>
|
|
173
|
+
</DemoCard>
|
|
174
|
+
|
|
175
|
+
<DemoCard
|
|
176
|
+
title="exportCsv and logger"
|
|
177
|
+
description="Download data as CSV or log it during development."
|
|
178
|
+
file="src/utils/exportCsv.js"
|
|
179
|
+
contentClassName="flex flex-wrap gap-2"
|
|
180
|
+
>
|
|
181
|
+
<Button variant="outline" onClick={handleExport}>
|
|
182
|
+
<Download />
|
|
183
|
+
Export catalog
|
|
184
|
+
</Button>
|
|
185
|
+
<Button variant="outline" onClick={handleLog}>
|
|
186
|
+
<Terminal />
|
|
187
|
+
Log to console
|
|
188
|
+
</Button>
|
|
189
|
+
</DemoCard>
|
|
190
|
+
|
|
191
|
+
<DemoCard
|
|
192
|
+
title="NetworkStatus"
|
|
193
|
+
description="Mounted once in App.jsx. Turn off your internet to see the banner, and on again to see it recover."
|
|
194
|
+
file="src/components/common/NetworkStatus.jsx"
|
|
195
|
+
/>
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export default UtilitiesSection;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import axios, { CanceledError } from "axios";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
|
|
4
|
+
export const useApiHandler = () => {
|
|
5
|
+
const [apiLoading, setApiLoading] = useState({});
|
|
6
|
+
const [apiError, setApiError] = useState({});
|
|
7
|
+
const [apiResponse, setApiResponse] = useState({});
|
|
8
|
+
|
|
9
|
+
const requestIdsRef = useRef({});
|
|
10
|
+
const controllersRef = useRef({});
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const controllers = controllersRef.current;
|
|
14
|
+
return () => {
|
|
15
|
+
Object.values(controllers).forEach((controller) => controller.abort());
|
|
16
|
+
Object.keys(controllers).forEach((key) => delete controllers[key]);
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
const executeApi = useCallback(async ({ key, apiFn }) => {
|
|
21
|
+
const requestId = (requestIdsRef.current[key] || 0) + 1;
|
|
22
|
+
requestIdsRef.current[key] = requestId;
|
|
23
|
+
|
|
24
|
+
controllersRef.current[key]?.abort();
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
controllersRef.current[key] = controller;
|
|
27
|
+
|
|
28
|
+
const isLatest = () => requestIdsRef.current[key] === requestId;
|
|
29
|
+
|
|
30
|
+
setApiLoading((prev) => ({
|
|
31
|
+
...prev,
|
|
32
|
+
[key]: true,
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
setApiError((prev) => ({
|
|
36
|
+
...prev,
|
|
37
|
+
[key]: null,
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const response = await apiFn(controller.signal);
|
|
42
|
+
|
|
43
|
+
if (controller.signal.aborted) {
|
|
44
|
+
throw new CanceledError();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setApiResponse((prev) => ({
|
|
48
|
+
...prev,
|
|
49
|
+
[key]: response,
|
|
50
|
+
}));
|
|
51
|
+
return response;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (axios.isCancel(error) || controller.signal.aborted) {
|
|
54
|
+
throw axios.isCancel(error) ? error : new CanceledError();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
setApiError((prev) => ({
|
|
58
|
+
...prev,
|
|
59
|
+
[key]: error,
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
throw error;
|
|
63
|
+
} finally {
|
|
64
|
+
if (isLatest()) {
|
|
65
|
+
setApiLoading((prev) => ({
|
|
66
|
+
...prev,
|
|
67
|
+
[key]: false,
|
|
68
|
+
}));
|
|
69
|
+
if (controllersRef.current[key] === controller) {
|
|
70
|
+
delete controllersRef.current[key];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, []);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
apiLoading,
|
|
78
|
+
apiError,
|
|
79
|
+
apiResponse,
|
|
80
|
+
executeApi,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export default function useDebounce(value, delay = 500) {
|
|
4
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const timer = setTimeout(() => setDebouncedValue(value), delay);
|
|
8
|
+
return () => clearTimeout(timer);
|
|
9
|
+
}, [value, delay]);
|
|
10
|
+
|
|
11
|
+
return debouncedValue;
|
|
12
|
+
}
|
package/src/lib/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { cn } from "cn";
|
package/src/main.jsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StrictMode } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import "@/assets/css/index.css";
|
|
4
|
+
import App from "./App.jsx";
|
|
5
|
+
import { ThemeProvider } from "./context/theme-provider.jsx";
|
|
6
|
+
import { Toaster } from "./components/ui/sonner.jsx";
|
|
7
|
+
import { IS_PRODUCTION } from "./constants/constant.js";
|
|
8
|
+
|
|
9
|
+
const AppRoot = (
|
|
10
|
+
<ThemeProvider defaultTheme="light" storageKey="theme">
|
|
11
|
+
<App />
|
|
12
|
+
<Toaster duration={3000} position="top-bottom" expand={false} />
|
|
13
|
+
</ThemeProvider>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
createRoot(document.getElementById("root")).render(IS_PRODUCTION ? AppRoot : <StrictMode>{AppRoot}</StrictMode>);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Link } from "react-router-dom";
|
|
3
|
+
import { toast } from "sonner";
|
|
4
|
+
import { ArrowLeft, CheckCircle2, Loader2, 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
|
+
|
|
10
|
+
const ForgotPasswordPage = () => {
|
|
11
|
+
const [email, setEmail] = useState("");
|
|
12
|
+
const [loading, setLoading] = useState(false);
|
|
13
|
+
const [sent, setSent] = useState(false);
|
|
14
|
+
|
|
15
|
+
const handleSubmit = (e) => {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
|
|
18
|
+
if (!email) {
|
|
19
|
+
toast.error("Enter your email address.");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setLoading(true);
|
|
24
|
+
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
setLoading(false);
|
|
27
|
+
setSent(true);
|
|
28
|
+
toast.success("Reset link sent.");
|
|
29
|
+
}, 800);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (sent) {
|
|
33
|
+
return (
|
|
34
|
+
<AuthLayout
|
|
35
|
+
title="Check your email"
|
|
36
|
+
footer={
|
|
37
|
+
<Link to="/login" className="inline-flex items-center gap-1.5 font-medium text-primary hover:underline">
|
|
38
|
+
<ArrowLeft className="h-3.5 w-3.5" />
|
|
39
|
+
Back to login
|
|
40
|
+
</Link>
|
|
41
|
+
}
|
|
42
|
+
>
|
|
43
|
+
<div className="flex flex-col items-center gap-4 rounded-xl border border-dashed border-border p-6 text-center">
|
|
44
|
+
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-muted">
|
|
45
|
+
<CheckCircle2 className="h-6 w-6 text-foreground" />
|
|
46
|
+
</div>
|
|
47
|
+
<p className="text-sm text-muted-foreground">
|
|
48
|
+
If an account exists for
|
|
49
|
+
<br />
|
|
50
|
+
<span className="font-medium text-foreground">{email}</span>
|
|
51
|
+
<br />
|
|
52
|
+
you'll receive a link to reset your password.
|
|
53
|
+
</p>
|
|
54
|
+
<Button variant="outline" size="sm" onClick={() => setSent(false)} className="mt-1">
|
|
55
|
+
Use a different email
|
|
56
|
+
</Button>
|
|
57
|
+
</div>
|
|
58
|
+
</AuthLayout>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<AuthLayout
|
|
64
|
+
title="Reset your password"
|
|
65
|
+
subtitle="Enter the email you log in with and we'll send you a reset link."
|
|
66
|
+
notice="Demo mode: no email is sent. Password reset is simulated until you connect your API."
|
|
67
|
+
footer={
|
|
68
|
+
<Link to="/login" className="inline-flex items-center gap-1.5 font-medium text-primary hover:underline">
|
|
69
|
+
<ArrowLeft className="h-3.5 w-3.5" />
|
|
70
|
+
Back to login
|
|
71
|
+
</Link>
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
<form className="space-y-4" onSubmit={handleSubmit}>
|
|
75
|
+
<div className="space-y-1.5">
|
|
76
|
+
<Label htmlFor="email">Email</Label>
|
|
77
|
+
<div className="relative">
|
|
78
|
+
<Mail className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
79
|
+
<Input
|
|
80
|
+
id="email"
|
|
81
|
+
name="email"
|
|
82
|
+
type="email"
|
|
83
|
+
autoComplete="email"
|
|
84
|
+
placeholder="Enter your email"
|
|
85
|
+
className="pl-8"
|
|
86
|
+
value={email}
|
|
87
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<Button type="submit" size="lg" className="w-full" disabled={loading}>
|
|
93
|
+
{loading && <Loader2 className="animate-spin" />}
|
|
94
|
+
{loading ? "Sending..." : "Send reset link"}
|
|
95
|
+
</Button>
|
|
96
|
+
</form>
|
|
97
|
+
</AuthLayout>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default ForgotPasswordPage;
|