tee3apps-cms-sdk-react 0.0.8 → 0.0.10

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
@@ -67,6 +67,85 @@ function App() {
67
67
  export default App;
68
68
  ```
69
69
 
70
+ ## 📝 Using PageForm Component
71
+
72
+ The `PageForm` component allows you to render dynamic forms based on JSON data. It includes built-in validation, form state management, toast notifications, and API submission support.
73
+
74
+ ### Basic PageForm Usage
75
+
76
+ ```jsx
77
+ import React, { useState, useEffect } from 'react';
78
+ import { PageForm } from 'tee3apps-cms-sdk-react';
79
+
80
+ function FormPage() {
81
+ const [formData, setFormData] = useState(null);
82
+ const [loading, setLoading] = useState(true);
83
+
84
+ useEffect(() => {
85
+ const fetchFormData = async () => {
86
+ try {
87
+ const response = await fetch('/api/form-data');
88
+ const data = await response.json();
89
+ const formElements = data?.data?.formElements;
90
+
91
+ setFormData(formElements);
92
+ } catch (error) {
93
+ console.error('Error fetching form data:', error);
94
+ } finally {
95
+ setLoading(false);
96
+ }
97
+ };
98
+
99
+ fetchFormData();
100
+ }, []);
101
+
102
+ const handleFormSubmit = (formValues) => {
103
+ console.log('Form submitted with values:', formValues);
104
+ // Handle form submission (e.g., send to API)
105
+ // Form values are automatically transformed to use field names instead of codes
106
+ };
107
+
108
+ if (loading) return <div>Loading...</div>;
109
+
110
+ return (
111
+ <div className="form-page">
112
+ <PageForm
113
+ jsonData={formData}
114
+ onSubmit={handleFormSubmit}
115
+ />
116
+ </div>
117
+ );
118
+ }
119
+
120
+ export default FormPage;
121
+ ```
122
+
123
+ ### PageForm with API Submission
124
+
125
+ You can configure the form to automatically submit to an API endpoint:
126
+
127
+ ```jsx
128
+ <PageForm
129
+ jsonData={formData}
130
+ isUrl={true}
131
+ method="POST"
132
+ url="https://api.example.com/submit"
133
+ onSubmit={(responseData) => {
134
+ // This callback is called after successful API submission
135
+ // responseData contains the API response
136
+ console.log('API Response:', responseData);
137
+ }}
138
+ />
139
+ ```
140
+
141
+ **API Submission Props:**
142
+ - `isUrl` (boolean): Set to `true` to enable API submission
143
+ - `method` ('POST' | 'GET'): HTTP method to use (defaults to 'POST')
144
+ - `url` (string): API endpoint URL
145
+ - `onSubmit` (function): Callback function called after submission (receives API response or error)
146
+
147
+ **Note:** When `isUrl` is `false` or not provided, the form uses the `onSubmit` callback with form data directly.
148
+
70
149
  ## 📊 Data Structure
71
150
 
72
151
  The package expects your `pageElements` data to follow this structure:
@@ -239,7 +318,304 @@ The package expects your `pageElements` data to follow this structure:
239
318
  ]
240
319
  ```
241
320
 
321
+ ## 📋 PageForm Component Data Structure
322
+
323
+ The `PageForm` component expects the same structure as `Page`, but with form-specific components. Here's an example with form fields:
324
+
325
+ ```json
326
+ [
327
+ {
328
+ "name": "Row",
329
+ "props": {
330
+ "minHeight": "auto",
331
+ "bgColor": "#ffffff",
332
+ "bgImage": "",
333
+ "align": "initial",
334
+ "justify": "flex-start",
335
+ "nowrap": false,
336
+ "bgsize": "cover",
337
+ "mode": {
338
+ "web": {
339
+ "isScroll": false,
340
+ "isVisible": true,
341
+ "top": "0px",
342
+ "bottom": "0px",
343
+ "flexView": true
344
+ },
345
+ "mobileweb": {
346
+ "isScroll": false,
347
+ "isVisible": true,
348
+ "top": "0px",
349
+ "bottom": "0px",
350
+ "flexView": true
351
+ },
352
+ "mobileapp": {
353
+ "isScroll": false,
354
+ "isVisible": true,
355
+ "top": "0px",
356
+ "bottom": "0px",
357
+ "flexView": true
358
+ },
359
+ "tablet": {
360
+ "isScroll": false,
361
+ "isVisible": true,
362
+ "top": "0px",
363
+ "bottom": "0px",
364
+ "flexView": true
365
+ }
366
+ }
367
+ },
368
+ "columns": [
369
+ {
370
+ "name": "Box",
371
+ "props": {
372
+ "bgColor": "#ffffff",
373
+ "align": "initial",
374
+ "justify": "flex-start",
375
+ "mode": {
376
+ "web": {
377
+ "colspan": 12,
378
+ "isVisible": true,
379
+ "height": "auto"
380
+ }
381
+ }
382
+ },
383
+ "components": [
384
+ {
385
+ "name": "InputField",
386
+ "props": {
387
+ "code": "email",
388
+ "name": {
389
+ "all": "Email Address"
390
+ },
391
+ "required": true,
392
+ "type": "email",
393
+ "placeholder": {
394
+ "all": "Enter your email"
395
+ }
396
+ },
397
+ "type": []
398
+ },
399
+ {
400
+ "name": "NumberField",
401
+ "props": {
402
+ "code": "age",
403
+ "name": {
404
+ "all": "Age"
405
+ },
406
+ "required": false,
407
+ "min": 18,
408
+ "max": 100
409
+ },
410
+ "type": []
411
+ },
412
+ {
413
+ "name": "SelectField",
414
+ "props": {
415
+ "code": "country",
416
+ "name": {
417
+ "all": "Country"
418
+ },
419
+ "required": true,
420
+ "multiSelect": false,
421
+ "lov": [
422
+ {
423
+ "id": "1",
424
+ "code": "us",
425
+ "name": "United States"
426
+ },
427
+ {
428
+ "id": "2",
429
+ "code": "uk",
430
+ "name": "United Kingdom"
431
+ }
432
+ ]
433
+ },
434
+ "type": []
435
+ },
436
+ {
437
+ "name": "DateField",
438
+ "props": {
439
+ "code": "birthdate",
440
+ "name": {
441
+ "all": "Date of Birth"
442
+ },
443
+ "required": true,
444
+ "format": "YYYY-MM-DD"
445
+ },
446
+ "type": []
447
+ },
448
+ {
449
+ "name": "RadioField",
450
+ "props": {
451
+ "code": "gender",
452
+ "name": {
453
+ "all": "Gender"
454
+ },
455
+ "required": true,
456
+ "lov": [
457
+ {
458
+ "id": "1",
459
+ "code": "male",
460
+ "name": "Male"
461
+ },
462
+ {
463
+ "id": "2",
464
+ "code": "female",
465
+ "name": "Female"
466
+ }
467
+ ]
468
+ },
469
+ "type": []
470
+ },
471
+ {
472
+ "name": "BooleanField",
473
+ "props": {
474
+ "code": "terms",
475
+ "name": {
476
+ "all": "I agree to the terms and conditions"
477
+ },
478
+ "required": true,
479
+ "onText": "Yes",
480
+ "offText": "No"
481
+ },
482
+ "type": []
483
+ }
484
+ ]
485
+ }
486
+ ]
487
+ }
488
+ ]
489
+ ```
490
+
491
+ ### Supported Form Field Types
492
+
493
+ - **InputField**: Text input fields (text, email, password, etc.) with postal code formatting support
494
+ - **NumberField**: Numeric input with min/max validation
495
+ - **DateField**: Date picker with format support
496
+ - **SelectField**: Dropdown select with single or multi-select
497
+ - **RadioField**: Radio button group
498
+ - **BooleanField**: Checkbox or toggle switch
499
+ - **TermsAndCondition**: Terms and conditions checkbox with modal popup for conditions
500
+ - **ButtonField**: Form buttons with submit, reset, and cancel types
501
+
502
+ ### Form Features
503
+
504
+ - **Automatic Validation**: Required fields are validated automatically
505
+ - **Toast Notifications**: Custom toast notifications for validation errors and form actions
506
+ - **Field Name Mapping**: Form values are automatically transformed from codes to field names
507
+ - **Responsive Design**: Forms adapt to different device modes (web, mobileweb, mobileapp, tablet)
508
+ - **Error Highlighting**: Invalid fields are visually highlighted
509
+ - **API Submission**: Built-in support for submitting forms directly to API endpoints
510
+ - **Button Types**: Support for submit, reset, and cancel button types
511
+ - **Form Reset/Cancel**: Built-in handlers for resetting or cancelling forms
512
+
513
+ ### Form Submission
514
+
515
+ #### Using Callback (Default)
516
+
517
+ The `onSubmit` callback receives form data with field names as keys:
518
+
519
+ ```jsx
520
+ const handleFormSubmit = (formValues) => {
521
+ // formValues will have field names as keys
522
+ // Example: { "Email Address": "user@example.com", "Country": "us" }
523
+ console.log(formValues);
524
+
525
+ // Submit to your API
526
+ fetch('/api/submit-form', {
527
+ method: 'POST',
528
+ headers: { 'Content-Type': 'application/json' },
529
+ body: JSON.stringify(formValues)
530
+ });
531
+ };
532
+ ```
533
+
534
+ #### Using API Submission
535
+
536
+ When `isUrl={true}`, the form automatically submits to the specified API:
537
+
538
+ ```jsx
539
+ <PageForm
540
+ jsonData={formData}
541
+ isUrl={true}
542
+ method="POST"
543
+ url="https://api.example.com/submit"
544
+ onSubmit={(responseData) => {
545
+ // Called after successful API submission
546
+ // responseData contains the API response
547
+ console.log('Success:', responseData);
548
+ }}
549
+ />
550
+ ```
551
+
552
+ **API Submission Behavior:**
553
+ - **POST requests**: Form data is sent in the request body as JSON
554
+ - **GET requests**: Form data is appended as query parameters
555
+ - **Success**: Shows success toast and calls `onSubmit` with response data
556
+ - **Error**: Shows error toast and calls `onSubmit` with error information
557
+
558
+ ### Button Types
559
+
560
+ Buttons support three types: `submit`, `reset`, and `cancel`:
561
+
562
+ ```json
563
+ {
564
+ "name": "ButtonField",
565
+ "props": {
566
+ "text": {
567
+ "all": "Submit",
568
+ "en-IN": "Submit"
569
+ },
570
+ "buttonType": "submit",
571
+ "disabled": false,
572
+ "mode": {
573
+ "web": {
574
+ "radius": "5px",
575
+ "bgColor": "#3498db",
576
+ "textstyle": {
577
+ "fontSize": 16,
578
+ "fontColor": "#ffffff",
579
+ "fontStyle": {
580
+ "isBold": false,
581
+ "isItalic": false,
582
+ "isUnderLine": false,
583
+ "isStrikeThrough": false
584
+ }
585
+ }
586
+ }
587
+ }
588
+ }
589
+ }
590
+ ```
591
+
592
+ **Button Types:**
593
+ - `submit`: Triggers form submission (shows "Submitting..." during API calls)
594
+ - `reset`: Resets all form fields and validation errors
595
+ - `cancel`: Cancels the form (same as reset, can be customized)
596
+
597
+ ### Field Component Props
598
+
599
+ #### InputField
600
+ - `helperText`: Used as placeholder text
601
+ - `format`: "Postalcode" for postal code formatting
602
+ - `postaltype`: "State" for US postal code formatting
603
+ - `textArea`: `true` to render as textarea
604
+ - `minLength` / `maxLength`: Length constraints
605
+
606
+ #### NumberField
607
+ - `helperText`: Used as placeholder text
608
+ - `termsandcondition`: HTML text displayed below input
609
+ - `onText` / `offText`: Status text displayed
610
+
611
+ #### RadioField
612
+ - `helperText`: Displayed in parentheses after the label (e.g., "Label (helperText)")
242
613
 
614
+ #### TermsAndCondition
615
+ - `termsText`: Clickable terms text (HTML supported)
616
+ - `conditionText`: Conditions displayed in modal popup (HTML supported)
617
+ - `isRequired`: Whether checkbox is required
618
+ - `checked`: Initial checked state
243
619
 
244
620
  ## 📄 License
245
621
 
@@ -251,5 +627,4 @@ If you encounter any issues or have questions, please create an issue on GitHub
251
627
 
252
628
  ---
253
629
 
254
- Built for developers who need dynamic page rendering capabilities.
255
- =======
630
+ Built for developers who need dynamic page rendering capabilities.
package/dist/index.d.ts CHANGED
@@ -109,6 +109,15 @@ type ComponentProps = {
109
109
  disabled?: boolean;
110
110
  bgColor?: string;
111
111
  radius?: string;
112
+ conditionText?: {
113
+ all?: string;
114
+ };
115
+ termsText?: {
116
+ all?: string;
117
+ };
118
+ isRequired?: boolean;
119
+ checked?: boolean;
120
+ buttonType?: 'submit' | 'reset' | 'cancel';
112
121
  };
113
122
  type Component = {
114
123
  name: string;
@@ -187,6 +196,9 @@ type Row = {
187
196
  interface PageFormProps {
188
197
  jsonData: Row[];
189
198
  onSubmit?: (data: Record<string, any>) => void;
199
+ isUrl?: boolean;
200
+ method?: 'POST' | 'GET' | 'post' | 'get';
201
+ url?: string;
190
202
  }
191
203
  declare const PageForm: React.FC<PageFormProps>;
192
204