@capillarytech/creatives-library 8.0.292-alpha.1 → 8.0.292-alpha.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "8.0.292-alpha.1",
4
+ "version": "8.0.292-alpha.3",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -97,12 +97,19 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
97
97
  componentWillReceiveProps = (nextProps) => {
98
98
  // Library mode: on Done click (transition to isGetFormData), run extractTags only when no existing validation errors (braces, personalization, etc.)
99
99
  if (nextProps.isGetFormData && !this.props.isGetFormData && !nextProps.isFullMode) {
100
- // If form already has validation errors (braces, personalization tags, etc.), do not call extractTags; just fail
101
- if (!this.state.isFormValid && nextProps.onValidationFail) {
102
- nextProps.onValidationFail();
100
+ // If form already has validation errors (braces, personalization tags, etc.), do not call extractTags or return payload; always return early
101
+ if (!this.state.isFormValid) {
102
+ if (typeof nextProps.onValidationFail === 'function') {
103
+ nextProps.onValidationFail();
104
+ }
103
105
  return;
104
106
  }
105
- if (nextProps.getLiquidTags && nextProps.showLiquidErrorInFooter && nextProps.onValidationFail) {
107
+ const hasAllValidationCallbacks =
108
+ typeof nextProps.getLiquidTags === 'function' &&
109
+ typeof nextProps.showLiquidErrorInFooter === 'function' &&
110
+ typeof nextProps.onValidationFail === 'function';
111
+
112
+ if (hasAllValidationCallbacks) {
106
113
  const formDataArr = [this.state.formData?.[0], this.state.formData?.[1]];
107
114
  validateMobilePushContent(formDataArr, {
108
115
  currentTab: this.state.currentTab,
@@ -115,21 +122,28 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
115
122
  const toArray = (v) => (Array.isArray(v) ? v : (v && typeof v === 'object' ? [].concat(...Object.values(v)) : []));
116
123
  const STANDARD_ERROR_MSG = toArray(standardErrors);
117
124
  const LIQUID_ERROR_MSG = toArray(liquidErrors);
118
- nextProps.showLiquidErrorInFooter(
119
- { STANDARD_ERROR_MSG, LIQUID_ERROR_MSG },
120
- this.state.currentTab
121
- );
125
+ if (typeof nextProps.showLiquidErrorInFooter === 'function') {
126
+ nextProps.showLiquidErrorInFooter(
127
+ { STANDARD_ERROR_MSG, LIQUID_ERROR_MSG },
128
+ this.state.currentTab
129
+ );
130
+ }
122
131
  // Only trigger onValidationFail when there are actual errors; skip when helper called onError with empty arrays (reset case)
123
- if (STANDARD_ERROR_MSG.length > 0 || LIQUID_ERROR_MSG.length > 0) {
132
+ if ((STANDARD_ERROR_MSG.length > 0 || LIQUID_ERROR_MSG.length > 0) && typeof nextProps.onValidationFail === 'function') {
124
133
  nextProps.onValidationFail();
125
134
  }
126
135
  },
127
136
  onSuccess: () => {
128
- nextProps.getFormLibraryData(this.getFormData());
137
+ if (this.state.isFormValid && typeof nextProps.getFormLibraryData === 'function') {
138
+ nextProps.getFormLibraryData(this.getFormData());
139
+ }
129
140
  },
130
141
  });
131
142
  } else {
132
- nextProps.getFormLibraryData(this.getFormData());
143
+ // Fail closed: require full validation callback set; treat any missing callback as validation failure
144
+ if (typeof nextProps.onValidationFail === 'function') {
145
+ nextProps.onValidationFail();
146
+ }
133
147
  }
134
148
  } else if (nextProps.isGetFormData && this.props.isGetFormData !== nextProps.isGetFormData && this.props.isFullMode && !this.props.Create.createTemplateInProgress) {
135
149
  this.startValidation();
@@ -69,6 +69,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
69
69
  schema: {},
70
70
  currentTab: 1,
71
71
  editData: {},
72
+ errorData: [],
72
73
  loading: false,
73
74
  isFormValid: true,
74
75
  injectedTags: {},
@@ -133,11 +134,11 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
133
134
  // Library mode: on Done click (transition to isGetFormData), run extractTags only when no existing validation errors (braces, personalization, etc.)
134
135
  if (nextProps.isGetFormData && !this.props.isGetFormData && !nextProps.isFullMode) {
135
136
  // If form already has validation errors (braces, personalization tags, etc.), do not call extractTags; just fail
136
- if (!this.state.isFormValid && nextProps.onValidationFail) {
137
- nextProps.onValidationFail();
137
+ if (!this.state.isFormValid) {
138
+ nextProps.onValidationFail?.();
138
139
  return;
139
140
  }
140
- if (nextProps.getLiquidTags && nextProps.showLiquidErrorInFooter && nextProps.onValidationFail) {
141
+ if (nextProps.getLiquidTags && nextProps.showLiquidErrorInFooter) {
141
142
  const formDataArr = [this.state.formData?.[0], this.state.formData?.[1]];
142
143
  validateMobilePushContent(formDataArr, {
143
144
  currentTab: this.state.currentTab,
@@ -156,8 +157,8 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
156
157
  );
157
158
  // Only treat as validation failure when there are actual errors; skip when helper called onError with empty reset payload
158
159
  const hasErrors = STANDARD_ERROR_MSG.length > 0 || LIQUID_ERROR_MSG.length > 0;
159
- if (hasErrors && nextProps.onValidationFail) {
160
- nextProps.onValidationFail();
160
+ if (hasErrors) {
161
+ nextProps.onValidationFail?.();
161
162
  }
162
163
  },
163
164
  onSuccess: () => {
@@ -745,8 +746,8 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
745
746
  const errorMessage = {key: 'validation-error', message: intl.formatMessage(messages.validationError)};
746
747
  if (!_.isEmpty(this.state.formData) && !this.state.isFormValid) {
747
748
  let tab = this.state.currentTab;
748
- const isAndroidInvalid = Object.values(errorData[0] || {}).includes(true);
749
- const isIosInvalid = Object.values(errorData[1] || {}).includes(true);
749
+ const isAndroidInvalid = Object.values(errorData?.[0] || {}).includes(true);
750
+ const isIosInvalid = Object.values(errorData?.[1] || {}).includes(true);
750
751
  const isIosTabVisible = get(schema, 'containers[0].panes[1].isSupported', true) !== false;
751
752
  if (isAndroidInvalid) {
752
753
  tab = 1;