@openlettermarketing/olc-react-sdk 2.1.6-beta.2 → 2.1.6-beta.4
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/build/index.js +77 -77
- package/build/index.js.map +1 -1
- package/build/types/src/assets/images/modal-icons/checkbox-checked.d.ts +3 -0
- package/build/types/src/assets/images/modal-icons/checkbox-unchecked.d.ts +3 -0
- package/build/types/src/assets/images/modal-icons/warning.d.ts +3 -0
- package/build/types/src/components/GenericUIBlocks/Dialog/V2/index.d.ts +2 -0
- package/build/types/src/components/GenericUIBlocks/Dialog/index.d.ts +1 -0
- package/build/types/src/components/TopNavigation/FieldValidationModal/index.d.ts +12 -0
- package/build/types/src/utils/message.d.ts +8 -0
- package/build/types/src/utils/template-builder.d.ts +26 -0
- package/build/types/src/utils/templateIdentifierArea/triFold.d.ts +0 -2
- package/build/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/assets/images/modal-icons/checkbox-checked.tsx +24 -0
- package/src/assets/images/modal-icons/checkbox-unchecked.tsx +13 -0
- package/src/assets/images/modal-icons/warning.tsx +15 -0
- package/src/components/GenericUIBlocks/Dialog/V2/index.tsx +8 -4
- package/src/components/GenericUIBlocks/Dialog/V2/styles.scss +10 -1
- package/src/components/GenericUIBlocks/Dialog/index.tsx +4 -2
- package/src/components/TopNavigation/FieldValidationModal/index.tsx +116 -0
- package/src/components/TopNavigation/FieldValidationModal/styles.scss +48 -0
- package/src/components/TopNavigation/index.tsx +68 -1
- package/src/utils/message.ts +9 -1
- package/src/utils/products.ts +1 -1
- package/src/utils/template-builder.ts +105 -3
- package/src/utils/templateIdentifierArea/triFold.ts +8 -26
- package/src/utils/templateRestrictedArea/triFold.ts +6 -8
- package/src/utils/templateSafetyBorders/triFold.ts +20 -27
- package/version.js +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './styles.scss';
|
|
3
|
+
interface FieldValidationModalProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
invalidFields: string[];
|
|
6
|
+
currentTheme?: string | null | undefined;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
handleClose: () => void;
|
|
9
|
+
handleContinue: (acknowledged: boolean) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const FieldValidationModal: React.FC<FieldValidationModalProps>;
|
|
12
|
+
export default FieldValidationModal;
|
|
@@ -136,6 +136,14 @@ export declare const MESSAGES: {
|
|
|
136
136
|
readonly DOWNLOAD_ENVELOPE_BUTTON: "Download Envelope Proof";
|
|
137
137
|
readonly CANCEL_BUTTON: "Cancel";
|
|
138
138
|
readonly SUBMIT_BUTTON: "Save";
|
|
139
|
+
readonly FIELD_VALIDATION: {
|
|
140
|
+
readonly TITLE: "Invalid Fields";
|
|
141
|
+
readonly HEADING: "The following fields are not recognized";
|
|
142
|
+
readonly DESCRIPTION: "The following field(s) used in this template are not recognized by the system. You can save the template as is, but these fields will not populate with data. To resolve this, remove or replace them with valid field names.";
|
|
143
|
+
readonly ACKNOWLEDGE_LABEL: "I understand that saving now will preserve these invalid fields, but they will not be populated with data.";
|
|
144
|
+
readonly CONTINUE_BUTTON: "Continue Saving";
|
|
145
|
+
readonly CANCEL_BUTTON: "Cancel";
|
|
146
|
+
};
|
|
139
147
|
};
|
|
140
148
|
readonly QR_CODE_MODAL: {
|
|
141
149
|
readonly CREATE_TITLE: "Create New QR Code";
|
|
@@ -72,3 +72,29 @@ export declare const extractCustomRistrictedBoxColor: (jsonData: any) => null;
|
|
|
72
72
|
export declare const validateGSV: (pages: any) => boolean;
|
|
73
73
|
export declare const validateEmoji: (pages: any) => boolean;
|
|
74
74
|
export declare const isValidQR: (pages: any) => boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Interface for invalid field validation results
|
|
77
|
+
*/
|
|
78
|
+
export interface InvalidField {
|
|
79
|
+
field: string;
|
|
80
|
+
issue: 'INVALID_FORMAT' | 'NOT_UPPERCASE';
|
|
81
|
+
pageIndex: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validates template fields for correct format and capitalization
|
|
85
|
+
* Returns array of invalid fields found in the template
|
|
86
|
+
*
|
|
87
|
+
* @param pages - Template pages array from store.toJSON()
|
|
88
|
+
* @returns Array of objects containing invalid fields and their issues
|
|
89
|
+
*/
|
|
90
|
+
export declare const validateTemplateFields: (pages: any) => InvalidField[];
|
|
91
|
+
/**
|
|
92
|
+
* Validates that all dynamic field tokens used in the template exist in the allowed keys list.
|
|
93
|
+
* Scans the entire serialized template JSON for {{...}} patterns and returns any tokens
|
|
94
|
+
* that are not present in the provided allowedKeys list.
|
|
95
|
+
*
|
|
96
|
+
* @param templateJSON - Full template JSON object from store.toJSON()
|
|
97
|
+
* @param allowedKeys - Array of allowed {{...}} token strings (predefined + custom fields)
|
|
98
|
+
* @returns Array of unrecognized token strings; empty array means all fields are valid
|
|
99
|
+
*/
|
|
100
|
+
export declare const validateAllowedTemplateFields: (templateJSON: any, allowedKeys: string[]) => string[];
|
package/build/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION: "2.1.6-beta.
|
|
1
|
+
export const SDK_VERSION: "2.1.6-beta.4";
|
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const CheckboxChecked = (props: any) => {
|
|
4
|
+
const { fill = 'var(--primary-color)' } = props;
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<svg width="18" height="18" viewBox="0 0 14 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<rect y="0.5" width="14" height="14" rx="2" fill={fill} />
|
|
9
|
+
<g clipPath="url(#clip0_checkbox_checked)">
|
|
10
|
+
<path
|
|
11
|
+
d="M11.7909 4.97078C11.5124 4.69194 11.0602 4.69212 10.7814 4.97078L6.23808 9.51428L4.21877 7.49498C3.93994 7.21615 3.48796 7.21615 3.20912 7.49498C2.93029 7.77381 2.93029 8.2258 3.20912 8.50463L5.73315 11.0287C5.87248 11.168 6.05518 11.2378 6.23789 11.2378C6.4206 11.2378 6.60347 11.1682 6.7428 11.0287L11.7909 5.98041C12.0697 5.70177 12.0697 5.24959 11.7909 4.97078Z"
|
|
12
|
+
fill="white"
|
|
13
|
+
/>
|
|
14
|
+
</g>
|
|
15
|
+
<defs>
|
|
16
|
+
<clipPath id="clip0_checkbox_checked">
|
|
17
|
+
<rect width="9" height="9" fill="white" transform="translate(3 3.5)" />
|
|
18
|
+
</clipPath>
|
|
19
|
+
</defs>
|
|
20
|
+
</svg>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default CheckboxChecked;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const CheckboxUnchecked = (props: any) => {
|
|
4
|
+
const { stroke = '#303030' } = props;
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<svg width="18" height="18" viewBox="0 0 14 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<rect x="0.25" y="0.75" width="13.5" height="13.5" rx="1.75" stroke={stroke} strokeWidth="0.5" />
|
|
9
|
+
</svg>
|
|
10
|
+
);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default CheckboxUnchecked;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const WarningIcon = (props: any) => {
|
|
4
|
+
const { fill = 'var(--primary-color)' } = props;
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<svg width="34" height="34" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<path d="M24 4L4 44H44L24 4Z" stroke={fill} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
|
9
|
+
<path d="M24 18V28" stroke={fill} strokeWidth="2" strokeLinecap="round"/>
|
|
10
|
+
<circle cx="24" cy="36" r="2" fill={fill}/>
|
|
11
|
+
</svg>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default WarningIcon;
|
|
@@ -27,6 +27,8 @@ interface DialogProps {
|
|
|
27
27
|
isGallery?: boolean;
|
|
28
28
|
currentTheme?: string | null | undefined;
|
|
29
29
|
isQRCode?: boolean;
|
|
30
|
+
hideButtons?: boolean;
|
|
31
|
+
submitDisabled?: boolean;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
const buttonStyles: CSSProperties = {
|
|
@@ -80,7 +82,9 @@ const DialogV2: React.FC<DialogProps> = ({
|
|
|
80
82
|
children = [],
|
|
81
83
|
isGallery = false,
|
|
82
84
|
currentTheme = "default",
|
|
83
|
-
isQRCode = false
|
|
85
|
+
isQRCode = false,
|
|
86
|
+
hideButtons = false,
|
|
87
|
+
submitDisabled = false,
|
|
84
88
|
}) => {
|
|
85
89
|
const contentAdjust = submitText.length > 6 ? "fit-content" : "100px";
|
|
86
90
|
|
|
@@ -162,7 +166,7 @@ const DialogV2: React.FC<DialogProps> = ({
|
|
|
162
166
|
<div className="modal-footer">
|
|
163
167
|
{(!isGallery || isQRCode) &&
|
|
164
168
|
<>
|
|
165
|
-
<button onClick={onSubmit} disabled={loading}>
|
|
169
|
+
<button onClick={onSubmit} disabled={loading || submitDisabled}>
|
|
166
170
|
{loading ? <CircularProgress style={progressStyles} /> : submitText}
|
|
167
171
|
</button>
|
|
168
172
|
<button onClick={onCancel}>
|
|
@@ -204,9 +208,9 @@ const DialogV2: React.FC<DialogProps> = ({
|
|
|
204
208
|
)}
|
|
205
209
|
{children}
|
|
206
210
|
<div className="confirm-modal-footer">
|
|
207
|
-
{!isGallery &&
|
|
211
|
+
{!isGallery && !hideButtons &&
|
|
208
212
|
<>
|
|
209
|
-
<button onClick={onSubmit} disabled={loading}>
|
|
213
|
+
<button onClick={onSubmit} disabled={loading || submitDisabled}>
|
|
210
214
|
{loading ? <CircularProgress style={progressStyles} /> : submitText}
|
|
211
215
|
</button>
|
|
212
216
|
<button onClick={onCancel}>
|
|
@@ -223,6 +223,10 @@
|
|
|
223
223
|
gap: 12px;
|
|
224
224
|
margin-top: 16px;
|
|
225
225
|
|
|
226
|
+
&:empty {
|
|
227
|
+
margin-top: 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
226
230
|
button{
|
|
227
231
|
min-height: 50px;
|
|
228
232
|
font-size: 16px;
|
|
@@ -245,9 +249,14 @@
|
|
|
245
249
|
justify-content: center;
|
|
246
250
|
align-items: center;
|
|
247
251
|
|
|
248
|
-
&:hover{
|
|
252
|
+
&:hover:not(:disabled){
|
|
249
253
|
background-color: var(--primary-color-btn-hover);
|
|
250
254
|
}
|
|
255
|
+
|
|
256
|
+
&:disabled{
|
|
257
|
+
opacity: 0.45;
|
|
258
|
+
cursor: not-allowed;
|
|
259
|
+
}
|
|
251
260
|
}
|
|
252
261
|
|
|
253
262
|
&:last-child{
|
|
@@ -28,6 +28,7 @@ interface DialogProps {
|
|
|
28
28
|
children?: ReactNode;
|
|
29
29
|
isGallery?: boolean;
|
|
30
30
|
currentTheme?: string | null | undefined;
|
|
31
|
+
submitDisabled?: boolean;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
const buttonStyles: CSSProperties = {
|
|
@@ -73,7 +74,8 @@ const Dialog: React.FC<DialogProps> = ({
|
|
|
73
74
|
submitText = "",
|
|
74
75
|
children = [],
|
|
75
76
|
isGallery = false,
|
|
76
|
-
currentTheme = "default"
|
|
77
|
+
currentTheme = "default",
|
|
78
|
+
submitDisabled = false,
|
|
77
79
|
}) => {
|
|
78
80
|
const contentAdjust = submitText.length > 6 ? "fit-content" : "100px";
|
|
79
81
|
|
|
@@ -170,7 +172,7 @@ const Dialog: React.FC<DialogProps> = ({
|
|
|
170
172
|
<Button
|
|
171
173
|
style={{ ...buttonStyles, border: 'none', maxWidth: contentAdjust }}
|
|
172
174
|
onClick={onSubmit}
|
|
173
|
-
disabled={loading}
|
|
175
|
+
disabled={loading || submitDisabled}
|
|
174
176
|
>
|
|
175
177
|
{loading ? <CircularProgress style={progressStyles} /> : submitText}
|
|
176
178
|
</Button>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// Utils
|
|
4
|
+
import { MESSAGES } from '../../../utils/message';
|
|
5
|
+
|
|
6
|
+
// Components
|
|
7
|
+
import Dialog from '../../GenericUIBlocks/Dialog';
|
|
8
|
+
import DialogV2 from '../../GenericUIBlocks/Dialog/V2';
|
|
9
|
+
|
|
10
|
+
// Icons
|
|
11
|
+
import Warning from '../../../assets/images/modal-icons/warning';
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import CheckboxChecked from '../../../assets/images/modal-icons/checkbox-checked';
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import CheckboxUnchecked from '../../../assets/images/modal-icons/checkbox-unchecked';
|
|
16
|
+
|
|
17
|
+
// Styles
|
|
18
|
+
import './styles.scss';
|
|
19
|
+
|
|
20
|
+
interface FieldValidationModalProps {
|
|
21
|
+
open: boolean;
|
|
22
|
+
invalidFields: string[];
|
|
23
|
+
currentTheme?: string | null | undefined;
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
handleClose: () => void;
|
|
26
|
+
handleContinue: (acknowledged: boolean) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const modalStyles = {
|
|
30
|
+
maxWidth: '600px',
|
|
31
|
+
minHeight: '300px',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const modalStylesV2 = {
|
|
35
|
+
maxWidth: '600px',
|
|
36
|
+
minHeight: '300px',
|
|
37
|
+
padding: '40px',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const FieldValidationModal: React.FC<FieldValidationModalProps> = ({
|
|
41
|
+
open,
|
|
42
|
+
invalidFields,
|
|
43
|
+
currentTheme,
|
|
44
|
+
loading = false,
|
|
45
|
+
handleClose,
|
|
46
|
+
handleContinue,
|
|
47
|
+
}) => {
|
|
48
|
+
const [acknowledged, setAcknowledged] = useState(false);
|
|
49
|
+
|
|
50
|
+
// Reset checkbox whenever the modal opens with a new set of fields
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (open) {
|
|
53
|
+
setAcknowledged(false);
|
|
54
|
+
}
|
|
55
|
+
}, [open]);
|
|
56
|
+
|
|
57
|
+
const content = (
|
|
58
|
+
<div className="field-validation-content">
|
|
59
|
+
<p className="field-validation-description">
|
|
60
|
+
{MESSAGES.TEMPLATE.FIELD_VALIDATION.DESCRIPTION}
|
|
61
|
+
</p>
|
|
62
|
+
<ol className="field-validation-list">
|
|
63
|
+
{invalidFields.map((field, index) => (
|
|
64
|
+
<li key={index}>{field}</li>
|
|
65
|
+
))}
|
|
66
|
+
</ol>
|
|
67
|
+
<label
|
|
68
|
+
className="field-validation-acknowledge"
|
|
69
|
+
onClick={() => setAcknowledged((prev) => !prev)}
|
|
70
|
+
>
|
|
71
|
+
{acknowledged ? <CheckboxChecked /> : <CheckboxUnchecked />}
|
|
72
|
+
{MESSAGES.TEMPLATE.FIELD_VALIDATION.ACKNOWLEDGE_LABEL}
|
|
73
|
+
</label>
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return currentTheme === 'v2' ? (
|
|
78
|
+
<DialogV2
|
|
79
|
+
icon={<Warning fill="var(--primary-color)" />}
|
|
80
|
+
customStyles={modalStylesV2}
|
|
81
|
+
open={open}
|
|
82
|
+
loading={loading}
|
|
83
|
+
handleClose={handleClose}
|
|
84
|
+
title={MESSAGES.TEMPLATE.FIELD_VALIDATION.TITLE}
|
|
85
|
+
subHeading=""
|
|
86
|
+
currentTheme="v2"
|
|
87
|
+
isGallery={false}
|
|
88
|
+
onSubmit={() => handleContinue(acknowledged)}
|
|
89
|
+
submitText={MESSAGES.TEMPLATE.FIELD_VALIDATION.CONTINUE_BUTTON}
|
|
90
|
+
submitDisabled={!acknowledged}
|
|
91
|
+
onCancel={handleClose}
|
|
92
|
+
cancelText={MESSAGES.TEMPLATE.FIELD_VALIDATION.CANCEL_BUTTON}
|
|
93
|
+
>
|
|
94
|
+
{content}
|
|
95
|
+
</DialogV2>
|
|
96
|
+
) : (
|
|
97
|
+
<Dialog
|
|
98
|
+
icon={<Warning fill="var(--primary-color)" />}
|
|
99
|
+
customStyles={modalStyles}
|
|
100
|
+
open={open}
|
|
101
|
+
loading={loading}
|
|
102
|
+
handleClose={handleClose}
|
|
103
|
+
title={MESSAGES.TEMPLATE.FIELD_VALIDATION.TITLE}
|
|
104
|
+
subHeading=""
|
|
105
|
+
onSubmit={() => handleContinue(acknowledged)}
|
|
106
|
+
submitText={MESSAGES.TEMPLATE.FIELD_VALIDATION.CONTINUE_BUTTON}
|
|
107
|
+
submitDisabled={!acknowledged}
|
|
108
|
+
onCancel={handleClose}
|
|
109
|
+
cancelText={MESSAGES.TEMPLATE.FIELD_VALIDATION.CANCEL_BUTTON}
|
|
110
|
+
>
|
|
111
|
+
{content}
|
|
112
|
+
</Dialog>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default FieldValidationModal;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
.field-validation-content {
|
|
2
|
+
width: 100%;
|
|
3
|
+
margin-top: 12px;
|
|
4
|
+
text-align: left;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.field-validation-description {
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
font-weight: 400;
|
|
10
|
+
color: var(--text-color);
|
|
11
|
+
line-height: 20px;
|
|
12
|
+
font-family: var(--font-family);
|
|
13
|
+
margin: 0 0 12px 0;
|
|
14
|
+
padding: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.field-validation-list {
|
|
18
|
+
margin: 0 0 16px 0;
|
|
19
|
+
padding-left: 20px;
|
|
20
|
+
|
|
21
|
+
li {
|
|
22
|
+
font-size: 16px;
|
|
23
|
+
font-weight: 400;
|
|
24
|
+
color: var(--text-color);
|
|
25
|
+
line-height: 20px;
|
|
26
|
+
margin-bottom: 6px;
|
|
27
|
+
word-break: break-all;
|
|
28
|
+
font-family: var(--font-family);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.field-validation-acknowledge {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: flex-start;
|
|
35
|
+
gap: 8px;
|
|
36
|
+
font-size: 16px;
|
|
37
|
+
font-weight: 400;
|
|
38
|
+
color: var(--text-color);
|
|
39
|
+
line-height: 20px;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
user-select: none;
|
|
42
|
+
font-family: var(--font-family);
|
|
43
|
+
|
|
44
|
+
svg {
|
|
45
|
+
flex-shrink: 0;
|
|
46
|
+
margin-top: 1px;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -20,6 +20,7 @@ import { searchAndAdvanceChange } from '../../redux/actions/templateActions';
|
|
|
20
20
|
import SaveTemplateModel from './SaveTemplateModel';
|
|
21
21
|
import ConfirmNavigateDialog from './ConfirmNavigateDialog';
|
|
22
22
|
import EditTemplateNameModel from './EditTemplateNameModel';
|
|
23
|
+
import FieldValidationModal from './FieldValidationModal';
|
|
23
24
|
|
|
24
25
|
// Utils
|
|
25
26
|
import {
|
|
@@ -31,6 +32,8 @@ import {
|
|
|
31
32
|
removeBracketsFromRPL,
|
|
32
33
|
validateEmoji,
|
|
33
34
|
validateGSV,
|
|
35
|
+
validateTemplateFields,
|
|
36
|
+
validateAllowedTemplateFields,
|
|
34
37
|
} from '../../utils/template-builder';
|
|
35
38
|
import { addSafetyBordersToNonWindowProfessioanl } from '../../utils/templateSafetyBorders/professional';
|
|
36
39
|
import { addIdentifierAreaToProfessionalNonWindow } from '../../utils/templateIdentifierArea/professional';
|
|
@@ -142,6 +145,7 @@ const TopNavigation: React.FC<TopNavigationProps> = ({
|
|
|
142
145
|
const [downloadingProof, setDownloaingProof] = useState<boolean>(false);
|
|
143
146
|
const [downloadingEnvelope, setDownloaingEnvelope] = useState<boolean>(false);
|
|
144
147
|
const [templateTitle, setTemplateTitle] = useState('');
|
|
148
|
+
const [invalidFields, setInvalidFields] = useState<string[]>([]);
|
|
145
149
|
|
|
146
150
|
const { id } = useParams<{ id: string }>();
|
|
147
151
|
|
|
@@ -426,9 +430,10 @@ const TopNavigation: React.FC<TopNavigationProps> = ({
|
|
|
426
430
|
}
|
|
427
431
|
};
|
|
428
432
|
|
|
429
|
-
const handleSave = async () => {
|
|
433
|
+
const handleSave = async (invalidFieldsAcknowledged: boolean = false) => {
|
|
430
434
|
try {
|
|
431
435
|
const formData = new FormData();
|
|
436
|
+
formData.append('invalidFieldsAcknowledged', String(invalidFieldsAcknowledged));
|
|
432
437
|
const allFields = [
|
|
433
438
|
...defaultFields,
|
|
434
439
|
...customFields,
|
|
@@ -572,10 +577,61 @@ const TopNavigation: React.FC<TopNavigationProps> = ({
|
|
|
572
577
|
}
|
|
573
578
|
};
|
|
574
579
|
|
|
580
|
+
const handleContinueAnyway = (acknowledged: boolean) => {
|
|
581
|
+
setIsShowModel((prev) => ({ ...prev, loading: true }));
|
|
582
|
+
handleSave(acknowledged);
|
|
583
|
+
};
|
|
584
|
+
|
|
575
585
|
const handleChangeModel = (
|
|
576
586
|
model: string = '',
|
|
577
587
|
loading: string | null = null
|
|
578
588
|
) => {
|
|
589
|
+
// When opening the save modal, validate all {{...}} tokens against the allowed list
|
|
590
|
+
// and also catch any malformed/incomplete brace patterns (e.g. {{C.ZIP_COD without closing }})
|
|
591
|
+
if (model === 'save' && templateType === 'json') {
|
|
592
|
+
const tokenPattern = /\{\{[^{}]+\}\}/g;
|
|
593
|
+
|
|
594
|
+
// Flatten v2 custom field sections (each section has a .fields array)
|
|
595
|
+
const flattenedCustomFieldsV2 = (customFieldsV2 as any[]).length > 0
|
|
596
|
+
? (customFieldsV2 as any[]).flatMap((section: { fields: any }) => section.fields)
|
|
597
|
+
: [];
|
|
598
|
+
|
|
599
|
+
const allAllowedFields = [
|
|
600
|
+
...defaultFields,
|
|
601
|
+
...customFields, // v1 custom fields from API
|
|
602
|
+
...flattenedCustomFieldsV2, // v2 custom fields from API (flattened)
|
|
603
|
+
...Object.values(dynamicFields),
|
|
604
|
+
...defaultSenderFields,
|
|
605
|
+
...defaultPropertyFields,
|
|
606
|
+
...defaultMiscFields,
|
|
607
|
+
];
|
|
608
|
+
const allowedKeys = Array.from(new Set(
|
|
609
|
+
allAllowedFields.flatMap((field: any) =>
|
|
610
|
+
(field?.key || '').match(tokenPattern) || []
|
|
611
|
+
)
|
|
612
|
+
));
|
|
613
|
+
|
|
614
|
+
const jsonData = store.toJSON();
|
|
615
|
+
|
|
616
|
+
// Catch complete tokens not in the allowed list
|
|
617
|
+
const unrecognizedFields = validateAllowedTemplateFields(jsonData, allowedKeys);
|
|
618
|
+
|
|
619
|
+
// Catch malformed/incomplete patterns (e.g. {{C.ZIP_COD with no closing }})
|
|
620
|
+
const formatErrors = validateTemplateFields(jsonData.pages).map((f) => f.field);
|
|
621
|
+
|
|
622
|
+
const allInvalid = Array.from(new Set([...unrecognizedFields, ...formatErrors]));
|
|
623
|
+
|
|
624
|
+
if (allInvalid.length > 0) {
|
|
625
|
+
setInvalidFields(allInvalid);
|
|
626
|
+
setIsShowModel({
|
|
627
|
+
open: true,
|
|
628
|
+
model: 'field-validation',
|
|
629
|
+
loading: false,
|
|
630
|
+
});
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
579
635
|
setIsShowModel((prev) => ({
|
|
580
636
|
...prev,
|
|
581
637
|
open: !prev.open,
|
|
@@ -913,6 +969,17 @@ const TopNavigation: React.FC<TopNavigationProps> = ({
|
|
|
913
969
|
currentTheme={currentTheme}
|
|
914
970
|
/>
|
|
915
971
|
)}
|
|
972
|
+
{/* Field Validation Modal */}
|
|
973
|
+
{isShowModel.open && isShowModel.model === 'field-validation' && (
|
|
974
|
+
<FieldValidationModal
|
|
975
|
+
open={isShowModel.open}
|
|
976
|
+
invalidFields={invalidFields}
|
|
977
|
+
loading={isShowModel.loading}
|
|
978
|
+
currentTheme={currentTheme}
|
|
979
|
+
handleClose={() => handleChangeModel()}
|
|
980
|
+
handleContinue={handleContinueAnyway}
|
|
981
|
+
/>
|
|
982
|
+
)}
|
|
916
983
|
{/* Duplicate Template Modal */}
|
|
917
984
|
<DuplicateTemplateModal
|
|
918
985
|
open={isShowModel.open && isShowModel.model === 'duplicate'}
|
package/src/utils/message.ts
CHANGED
|
@@ -142,7 +142,15 @@ export const MESSAGES = {
|
|
|
142
142
|
DOWNLOAD_PROOF_BUTTON: "Download Mailer Proof",
|
|
143
143
|
DOWNLOAD_ENVELOPE_BUTTON: "Download Envelope Proof",
|
|
144
144
|
CANCEL_BUTTON: "Cancel",
|
|
145
|
-
SUBMIT_BUTTON: "Save"
|
|
145
|
+
SUBMIT_BUTTON: "Save",
|
|
146
|
+
FIELD_VALIDATION: {
|
|
147
|
+
TITLE: "Invalid Fields",
|
|
148
|
+
HEADING: "The following fields are not recognized",
|
|
149
|
+
DESCRIPTION: "The following field(s) used in this template are not recognized by the system. You can save the template as is, but these fields will not populate with data. To resolve this, remove or replace them with valid field names.",
|
|
150
|
+
ACKNOWLEDGE_LABEL: "I understand that saving now will preserve these invalid fields, but they will not be populated with data.",
|
|
151
|
+
CONTINUE_BUTTON: "Continue Saving",
|
|
152
|
+
CANCEL_BUTTON: "Cancel",
|
|
153
|
+
},
|
|
146
154
|
},
|
|
147
155
|
QR_CODE_MODAL: {
|
|
148
156
|
CREATE_TITLE: "Create New QR Code",
|