@visns-studio/visns-components 5.4.7 → 5.4.9

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/README.md CHANGED
@@ -1,67 +1,527 @@
1
- # Visns Components
2
-
3
- A list of components that is used by the Visns Studio team on all their CRM and CMS Projects.
4
-
5
- # Modules
6
-
7
- There are multiple components that are shared between the CRM and CMS but there are also unique components for both the CRM and CMS
8
-
9
- ## CRM
10
-
11
- - Authentication UI
12
- - Login
13
- - Profile
14
- - Reset
15
- - Verify
16
- - DataGrid
17
- - Form
18
- - Generic Pages
19
- - Detail Page
20
- - Index Page
21
- - Notification Page
22
-
23
- ## CMS
24
-
25
- - DataGrid
26
- - DropZone
27
- - Field
28
- - Form
29
- - Generic Pages
30
- - Detail Page
31
- - Index Page
32
- - Sorting Page
33
-
34
- ## Shared
35
-
36
- - Asynchronous React Select
37
- - Autocomplete (Mapbox)
38
- - Call Popup
39
- - Download (Axios)
40
- - Fetch (Axios)
41
- - Loader
42
- - Multi React Select
43
- - Navigation / Header
44
- - Notification
45
- - Select
46
- - Sub Navigati
47
-
48
- # Usage
49
-
50
- Detail list of the usage for each components.
51
-
52
- ## CRM
53
-
54
- ### DataGrid
55
-
56
- #### Prop List
57
-
58
- | Prop | Description | Default |
59
- | ------------- | ----------- | ------- |
60
- | ajaxSetting | | |
61
- | columns | | |
62
- | form | | |
63
- | gridHeight | | |
64
- | settings | | |
65
- | setFilterData | | |
66
- | setConfig | | |
67
- | style | | |
1
+ # VISNS Components
2
+
3
+ A comprehensive React component library used by the VISNS Studio team for CRM and CMS projects, featuring authentication, data visualization, form handling, and more.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/visns-components.svg)](https://www.npmjs.com/package/visns-components)
6
+ [![license](https://img.shields.io/npm/l/visns-components.svg)](https://github.com/yourusername/visns-components/blob/master/LICENSE)
7
+
8
+ ## Overview
9
+
10
+ VISNS Components is a React-based UI component library that provides a set of reusable, consistent, and customizable components for building web applications. It includes components for authentication, data grids, forms, navigation, and more, designed to work seamlessly together.
11
+
12
+ ## Features
13
+
14
+ ### Authentication System
15
+
16
+ - **Login** - Email/password authentication
17
+ - **Two-Factor Authentication (2FA)** - Additional security layer (optional)
18
+ - **Password Reset** - Secure password recovery flow
19
+ - **Profile Management** - User profile editing
20
+ - **SSO Integration** - Support for Microsoft Azure
21
+
22
+ ### Data Visualization
23
+
24
+ - **DataGrid** - Powerful data table with sorting, filtering, and pagination
25
+ - **Charts** - Various chart types for data visualization
26
+
27
+ ### Form Components
28
+
29
+ - **Form Builder** - Dynamic form creation and validation
30
+ - **Field Components** - Text inputs, selects, checkboxes, etc.
31
+ - **Multi-select** - Enhanced select with multiple selection support
32
+ - **Autocomplete** - Mapbox integration for location selection
33
+ - **Dropzone** - File upload with drag and drop support
34
+
35
+ ### Navigation
36
+
37
+ - **Header/Navigation** - Application header with navigation
38
+ - **Sub Navigation** - Secondary navigation options
39
+
40
+ ### Utility Components
41
+
42
+ - **Fetch** - Axios-based data fetching with error handling
43
+ - **Download** - File download functionality
44
+ - **Loader** - Loading indicators
45
+ - **Notification** - Toast notifications
46
+ - **Call Popup** - Modal dialogs
47
+
48
+ ### Generic Pages
49
+
50
+ - **Index Pages** - List view templates
51
+ - **Detail Pages** - Item detail templates
52
+ - **Notification Pages** - User notification center
53
+ - **Sorting Pages** - Content ordering interfaces
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ npm install visns-components
59
+ # or
60
+ yarn add visns-components
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ ### Basic Setup
66
+
67
+ ```jsx
68
+ import React from 'react';
69
+ import { GenericAuth } from 'visns-components';
70
+
71
+ const App = () => {
72
+ return (
73
+ <GenericAuth
74
+ logo="/path/to/logo.png"
75
+ headerLogo="/path/to/header-logo.png"
76
+ providers={['azure']} // Optional SSO providers
77
+ themeType="primary"
78
+ navigation={navigationConfig}
79
+ routeConfig={routeConfig}
80
+ />
81
+ );
82
+ };
83
+
84
+ export default App;
85
+ ```
86
+
87
+ ## Component Documentation
88
+
89
+ ### Authentication Components
90
+
91
+ #### GenericAuth
92
+
93
+ The main component that handles authentication and routing.
94
+
95
+ ```jsx
96
+ <GenericAuth
97
+ layout="full" // 'full' or 'compact'
98
+ loginBg="/path/to/background.jpg" // Optional login background
99
+ logo="/path/to/logo.png" // Logo for login/auth screens
100
+ headerLogo="/path/to/header-logo.png" // Logo for header in main app
101
+ providers={['azure']} // Optional SSO providers
102
+ navigation={navigationConfig} // Navigation configuration
103
+ routeConfig={routeConfig} // Route configuration
104
+ themeType="primary" // Theme type: 'primary', 'secondary', etc.
105
+ />
106
+ ```
107
+
108
+ #### Login
109
+
110
+ Handles user login with email and password.
111
+
112
+ ```jsx
113
+ <Login
114
+ logo="/path/to/logo.png"
115
+ providers={['azure']} // Optional SSO providers
116
+ setSystemAuth={setAuthFunction}
117
+ setUserProfile={setUserProfileFunction}
118
+ />
119
+ ```
120
+
121
+ #### TwoFactorAuth
122
+
123
+ Handles 2FA verification.
124
+
125
+ ```jsx
126
+ <TwoFactorAuth
127
+ logo="/path/to/logo.png"
128
+ setSystemAuth={setAuthFunction}
129
+ setUserProfile={setUserProfileFunction}
130
+ />
131
+ ```
132
+
133
+ #### Reset
134
+
135
+ Password reset request form.
136
+
137
+ ```jsx
138
+ <Reset logo="/path/to/logo.png" setSystemAuth={setAuthFunction} />
139
+ ```
140
+
141
+ #### Verify
142
+
143
+ Password reset verification form.
144
+
145
+ ```jsx
146
+ <Verify logo="/path/to/logo.png" setSystemAuth={setAuthFunction} />
147
+ ```
148
+
149
+ #### Profile
150
+
151
+ User profile management.
152
+
153
+ ```jsx
154
+ <Profile
155
+ userProfile={userProfileData}
156
+ setUserProfile={setUserProfileFunction}
157
+ />
158
+ ```
159
+
160
+ ### DataGrid Component
161
+
162
+ A powerful data table component with sorting, filtering, and pagination.
163
+
164
+ ```jsx
165
+ <DataGrid
166
+ ajaxSetting={{
167
+ url: '/api/data',
168
+ method: 'GET',
169
+ params: {},
170
+ }}
171
+ columns={[
172
+ { field: 'id', headerName: 'ID', width: 90 },
173
+ { field: 'name', headerName: 'Name', width: 150 },
174
+ // More columns...
175
+ ]}
176
+ form={formConfig}
177
+ gridHeight={500}
178
+ settings={{
179
+ pagination: true,
180
+ pageSize: 25,
181
+ // More settings...
182
+ }}
183
+ setFilterData={setFilterFunction}
184
+ setConfig={setConfigFunction}
185
+ style={
186
+ {
187
+ /* Custom styles */
188
+ }
189
+ }
190
+ />
191
+ ```
192
+
193
+ #### DataGrid Props
194
+
195
+ | Prop | Description | Type | Default |
196
+ | ------------- | ---------------------------------- | -------- | ------- |
197
+ | ajaxSetting | Configuration for data fetching | Object | - |
198
+ | columns | Column definitions | Array | - |
199
+ | form | Form configuration for editing | Object | - |
200
+ | gridHeight | Height of the grid | Number | 500 |
201
+ | settings | Grid settings (pagination, etc.) | Object | - |
202
+ | setFilterData | Callback for filter changes | Function | - |
203
+ | setConfig | Callback for configuration changes | Function | - |
204
+ | style | Custom styles | Object | - |
205
+
206
+ ### Form Components
207
+
208
+ #### Form
209
+
210
+ A flexible form component with validation.
211
+
212
+ ```jsx
213
+ <Form
214
+ fields={[
215
+ {
216
+ name: 'firstName',
217
+ label: 'First Name',
218
+ type: 'text',
219
+ required: true,
220
+ },
221
+ { name: 'email', label: 'Email', type: 'email', required: true },
222
+ // More fields...
223
+ ]}
224
+ onSubmit={handleSubmit}
225
+ initialValues={initialData}
226
+ validationSchema={validationSchema}
227
+ />
228
+ ```
229
+
230
+ #### AsyncSelect
231
+
232
+ Asynchronous select component with search functionality.
233
+
234
+ ```jsx
235
+ <AsyncSelect
236
+ url="/api/options"
237
+ valueKey="id"
238
+ labelKey="name"
239
+ placeholder="Select an option"
240
+ onChange={handleChange}
241
+ value={selectedValue}
242
+ />
243
+ ```
244
+
245
+ #### MultiSelect
246
+
247
+ Select component with multiple selection support.
248
+
249
+ ```jsx
250
+ <MultiSelect
251
+ options={options}
252
+ value={selectedValues}
253
+ onChange={handleChange}
254
+ placeholder="Select options"
255
+ />
256
+ ```
257
+
258
+ #### Autocomplete
259
+
260
+ Location autocomplete with Mapbox integration.
261
+
262
+ ```jsx
263
+ <Autocomplete
264
+ apiKey="your-mapbox-api-key"
265
+ placeholder="Enter a location"
266
+ onChange={handleLocationChange}
267
+ value={location}
268
+ />
269
+ ```
270
+
271
+ #### DropZone
272
+
273
+ File upload component with drag and drop support.
274
+
275
+ ```jsx
276
+ <DropZone
277
+ onDrop={handleFileDrop}
278
+ accept=".jpg,.png,.pdf"
279
+ maxSize={5242880} // 5MB
280
+ multiple={true}
281
+ />
282
+ ```
283
+
284
+ ### Utility Components
285
+
286
+ #### CustomFetch
287
+
288
+ Data fetching utility with error handling.
289
+
290
+ ```jsx
291
+ CustomFetch(
292
+ '/api/data',
293
+ 'GET',
294
+ { param1: 'value1' },
295
+ (result) => {
296
+ // Success callback
297
+ console.log(result);
298
+ },
299
+ (error) => {
300
+ // Error callback
301
+ console.error(error);
302
+ }
303
+ );
304
+ ```
305
+
306
+ #### Download
307
+
308
+ File download utility.
309
+
310
+ ```jsx
311
+ Download('/api/download', { fileId: 123 }, 'filename.pdf');
312
+ ```
313
+
314
+ #### Loader
315
+
316
+ Loading indicator component.
317
+
318
+ ```jsx
319
+ <Loader />
320
+ ```
321
+
322
+ #### Notification
323
+
324
+ Toast notification component.
325
+
326
+ ```jsx
327
+ <Notification
328
+ message="Operation successful"
329
+ type="success" // 'success', 'error', 'warning', 'info'
330
+ duration={3000}
331
+ />
332
+ ```
333
+
334
+ ## Two-Factor Authentication (2FA)
335
+
336
+ ### How 2FA Works
337
+
338
+ 1. User enters email and password on the login screen
339
+ 2. If credentials are valid and 2FA is required, the backend returns `requires_2fa: true`
340
+ 3. The user is redirected to the 2FA verification screen
341
+ 4. User enters the verification code
342
+ 5. If the code is valid, the user is authenticated and redirected to the main application
343
+
344
+ ### API Integration for 2FA
345
+
346
+ #### Login Endpoint Response (when 2FA is required)
347
+
348
+ ```json
349
+ {
350
+ "error": "",
351
+ "requires_2fa": true,
352
+ "user": {
353
+ "id": "user_id",
354
+ "email": "user@example.com",
355
+ "name": "User Name"
356
+ }
357
+ }
358
+ ```
359
+
360
+ #### 2FA Verification Endpoint
361
+
362
+ Request:
363
+
364
+ ```json
365
+ {
366
+ "user_id": "user_id",
367
+ "verification_code": "123456",
368
+ "previous_url": "/optional-redirect-url"
369
+ }
370
+ ```
371
+
372
+ Response:
373
+
374
+ ```json
375
+ {
376
+ "error": "",
377
+ "user": {
378
+ "id": "user_id",
379
+ "email": "user@example.com",
380
+ "name": "User Name",
381
+ "roles": ["admin"]
382
+ },
383
+ "previous": "/optional-redirect-url"
384
+ }
385
+ ```
386
+
387
+ ## Customization
388
+
389
+ ### Theming
390
+
391
+ The components use CSS variables for theming. You can override these variables in your CSS:
392
+
393
+ ```css
394
+ :root {
395
+ --primary-color: #007bff;
396
+ --secondary-color: #6c757d;
397
+ --third-color: #ffffff;
398
+ --bg-color: #f8f9fa;
399
+ --paragraph-color: #212529;
400
+ --paragraph-rgb: 33, 37, 41;
401
+ --primary-rgb: 0, 123, 255;
402
+ --secondary-rgb: 108, 117, 125;
403
+ --radius: 4px;
404
+ --sidebar-width: 250px;
405
+ }
406
+ ```
407
+
408
+ ### Layout Customization
409
+
410
+ You can customize the layout by providing different configuration options:
411
+
412
+ ```jsx
413
+ <GenericAuth
414
+ layout="compact" // 'full' or 'compact'
415
+ // Other props...
416
+ />
417
+ ```
418
+
419
+ ## Navigation Configuration
420
+
421
+ The navigation system is highly configurable:
422
+
423
+ ```jsx
424
+ const navigationConfig = {
425
+ main: [
426
+ {
427
+ label: 'Dashboard',
428
+ icon: 'dashboard',
429
+ path: '/',
430
+ },
431
+ {
432
+ label: 'Users',
433
+ icon: 'users',
434
+ path: '/users',
435
+ children: [
436
+ {
437
+ label: 'List',
438
+ path: '/users',
439
+ },
440
+ {
441
+ label: 'Add New',
442
+ path: '/users/new',
443
+ },
444
+ ],
445
+ },
446
+ // More items...
447
+ ],
448
+ secondary: [
449
+ // Secondary navigation items...
450
+ ],
451
+ };
452
+ ```
453
+
454
+ ## Route Configuration
455
+
456
+ Define your application routes:
457
+
458
+ ```jsx
459
+ const routeConfig = [
460
+ {
461
+ path: '/',
462
+ component: Dashboard,
463
+ },
464
+ {
465
+ path: '/users',
466
+ component: UserList,
467
+ },
468
+ {
469
+ path: '/users/new',
470
+ component: UserForm,
471
+ },
472
+ {
473
+ path: '/users/:id',
474
+ component: UserDetail,
475
+ },
476
+ // More routes...
477
+ ];
478
+ ```
479
+
480
+ ## Development
481
+
482
+ ### Prerequisites
483
+
484
+ - Node.js (v14 or higher)
485
+ - npm or yarn
486
+
487
+ ### Setup
488
+
489
+ 1. Clone the repository
490
+ 2. Install dependencies:
491
+ ```bash
492
+ npm install
493
+ # or
494
+ yarn
495
+ ```
496
+ 3. Start the development server:
497
+ ```bash
498
+ npm run dev
499
+ # or
500
+ yarn dev
501
+ ```
502
+
503
+ ### Building
504
+
505
+ ```bash
506
+ npm run build
507
+ # or
508
+ yarn build
509
+ ```
510
+
511
+ ## Contributing
512
+
513
+ We welcome contributions! Please follow these steps:
514
+
515
+ 1. Fork the repository
516
+ 2. Create a feature branch: `git checkout -b feature/my-feature`
517
+ 3. Commit your changes: `git commit -m 'Add my feature'`
518
+ 4. Push to the branch: `git push origin feature/my-feature`
519
+ 5. Submit a pull request
520
+
521
+ ## License
522
+
523
+ [MIT License](LICENSE)
524
+
525
+ ## Support
526
+
527
+ For support, please contact the VISNS Studio team or open an issue on GitHub.
package/package.json CHANGED
@@ -26,6 +26,7 @@
26
26
  "motion": "^10.18.0",
27
27
  "numeral": "^2.0.6",
28
28
  "pluralize": "^8.0.0",
29
+ "qrcode.react": "^4.2.0",
29
30
  "quill-image-uploader": "^1.3.0",
30
31
  "react-big-calendar": "^1.18.0",
31
32
  "react-color": "^2.19.3",
@@ -55,7 +56,7 @@
55
56
  "truncate": "^3.0.0",
56
57
  "uuid": "^10.0.0",
57
58
  "validator": "^13.15.0",
58
- "vite": "^5.4.16",
59
+ "vite": "^5.4.17",
59
60
  "yarn": "^1.22.22"
60
61
  },
61
62
  "devDependencies": {
@@ -70,7 +71,7 @@
70
71
  "mini-css-extract-plugin": "^2.9.2",
71
72
  "react": "^18.3.1",
72
73
  "react-dom": "^18.3.1",
73
- "sass": "^1.86.2",
74
+ "sass": "^1.86.3",
74
75
  "sass-loader": "^16.0.5"
75
76
  },
76
77
  "peerDependencies": {
@@ -78,7 +79,7 @@
78
79
  "react-dom": "^17.0.0 || ^18.0.0"
79
80
  },
80
81
  "name": "@visns-studio/visns-components",
81
- "version": "5.4.7",
82
+ "version": "5.4.9",
82
83
  "description": "Various packages to assist in the development of our Custom Applications.",
83
84
  "main": "src/index.js",
84
85
  "files": [
@@ -197,10 +197,25 @@ function Navigation({
197
197
  const appNavClasses = styles['app-nav'];
198
198
 
199
199
  const handleLogout = () => {
200
- CustomFetch('/logout', 'GET', {}, () => {
201
- setSystemAuth(false);
202
- navigate('/login');
203
- });
200
+ // First navigate to login, then set auth state to false
201
+ // This prevents the race condition with updateAuthStatus
202
+ CustomFetch(
203
+ '/logout',
204
+ 'GET',
205
+ {},
206
+ // Success callback
207
+ () => {
208
+ // Use window.location for a full page refresh to ensure clean state
209
+ window.location.href = '/login';
210
+ // No need to call setSystemAuth as the page will refresh
211
+ },
212
+ // Error callback
213
+ (error) => {
214
+ console.error('Logout error:', error);
215
+ // Even if there's an error, force a page refresh to login
216
+ window.location.href = '/login';
217
+ }
218
+ );
204
219
  };
205
220
 
206
221
  const renderSetting = (n) => {