@awell-health/ui-library 0.1.130 → 0.1.133

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.
Files changed (2) hide show
  1. package/dist/index.js +104 -53
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -48142,6 +48142,20 @@ var Kr=[{
48142
48142
  error: undefined } :
48143
48143
 
48144
48144
  undefined),selectedFile = _h[0],setSelectedFile = _h[1];
48145
+ React.useEffect(function () {
48146
+ var _a, _b, _c, _d, _e;
48147
+ if (!lodash.exports.isNil(value) && !lodash.exports.isEmpty(value) && !selectedFile) {
48148
+ setSelectedFile({
48149
+ id: (_a = value.filename) !== null && _a !== void 0 ? _a : 'untitled',
48150
+ name: (_b = value.filename) !== null && _b !== void 0 ? _b : 'untitled',
48151
+ size: (_c = value.size) !== null && _c !== void 0 ? _c : 0,
48152
+ type: (_d = value.contentType) !== null && _d !== void 0 ? _d : '',
48153
+ url: (_e = value.url) !== null && _e !== void 0 ? _e : '',
48154
+ progress: 100,
48155
+ error: undefined });
48156
+
48157
+ }
48158
+ }, [value]);
48145
48159
  var convertErrorMessage = function (error) {
48146
48160
  if (error === 'Failed to fetch') {
48147
48161
  return 'File upload failed. Please remove this file and try again.';
@@ -48471,12 +48485,12 @@ var Kr=[{
48471
48485
  } },
48472
48486
  render: function (_a) {
48473
48487
  var _b, _c, _d;
48474
- var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value;
48488
+ var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value,fieldError = _a.fieldState.error;
48475
48489
  return jsxRuntime.exports.jsx(SingleFileInputField, { id: question.id, value: custom_json_parser(value, ''), onChange: function (attachment) {
48476
48490
  console.log('attachment', attachment === null || attachment === void 0 ? void 0 : attachment.contentType);
48477
- onControllerChange(JSON.stringify(attachment));
48491
+ onControllerChange(attachment ? JSON.stringify(attachment) : '');
48478
48492
  onAnswerChange();
48479
- }, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : undefined, configSlug: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_config_slug, onFileUpload: onFileUpload, label: question.title, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
48493
+ }, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : undefined, configSlug: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_config_slug, onFileUpload: onFileUpload, label: question.title, mandatory: config === null || config === void 0 ? void 0 : config.mandatory, error: fieldError === null || fieldError === void 0 ? void 0 : fieldError.message });
48480
48494
  } });
48481
48495
  case exports.UserQuestionType.Image:
48482
48496
  return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: [], rules: {
@@ -48491,11 +48505,11 @@ var Kr=[{
48491
48505
  } },
48492
48506
  render: function (_a) {
48493
48507
  var _b, _c, _d;
48494
- var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value;
48508
+ var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value,fieldError = _a.fieldState.error;
48495
48509
  return jsxRuntime.exports.jsx(SingleFileInputField, { id: question.id, value: custom_json_parser(value, ''), onChange: function (attachment) {
48496
- onControllerChange(JSON.stringify(attachment));
48510
+ onControllerChange(attachment ? JSON.stringify(attachment) : '');
48497
48511
  onAnswerChange();
48498
- }, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : ['image/*'], configSlug: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_config_slug, onFileUpload: onFileUpload, label: question.title, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
48512
+ }, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : ['image/*'], configSlug: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_config_slug, onFileUpload: onFileUpload, label: question.title, mandatory: config === null || config === void 0 ? void 0 : config.mandatory, error: fieldError === null || fieldError === void 0 ? void 0 : fieldError.message });
48499
48513
  } });
48500
48514
  case exports.UserQuestionType.Description:
48501
48515
  return jsxRuntime.exports.jsx(Description, { content: question.title });
@@ -48816,29 +48830,11 @@ var Kr=[{
48816
48830
  };
48817
48831
  var validateAttachmentsResponse = function (questionConfig, value) {
48818
48832
  var inputRequired = questionConfig === null || questionConfig === void 0 ? void 0 : questionConfig.mandatory;
48819
- var parseAttachments = function (val) {
48820
- try {
48821
- return JSON.parse(val);
48822
- }
48823
- catch (error) {
48824
- return [];
48825
- }
48826
- };
48827
- var attachments = parseAttachments(value);
48828
- if (inputRequired === false && lodash.exports.isEmpty(attachments)) {
48829
- return {
48830
- isValid: true };
48831
-
48833
+ var hasValue = !lodash.exports.isNil(value) && !lodash.exports.isEmpty(value);
48834
+ if (inputRequired && !hasValue) {
48835
+ return { isValid: false, errorType: 'REQUIRED' };
48832
48836
  }
48833
- if (attachments.length === 0) {
48834
- return {
48835
- isValid: false,
48836
- errorType: 'REQUIRED' };
48837
-
48838
- }
48839
- return {
48840
- isValid: true };
48841
-
48837
+ return { isValid: true };
48842
48838
  };
48843
48839
  var validateInputValidationResponse = function (questionConfig, value) {
48844
48840
  if (!questionConfig || !questionConfig.input_validation) {
@@ -48966,9 +48962,15 @@ var Kr=[{
48966
48962
  }
48967
48963
  };
48968
48964
  var isEmpty = function (value) {
48969
- return typeof Array.isArray(value) && value.length === 0 ||
48970
- typeof value === 'string' && value.length === 0 ||
48971
- typeof value === 'object' && Object.keys(value).length === 0;
48965
+ if (lodash.exports.isNil(value))
48966
+ return true;
48967
+ if (Array.isArray(value))
48968
+ return value.length === 0;
48969
+ if (typeof value === 'string')
48970
+ return value.length === 0;
48971
+ if (typeof value === 'object')
48972
+ return Object.keys(value).length === 0;
48973
+ return false;
48972
48974
  };
48973
48975
  var calculatePercentageCompleted = function (_a) {
48974
48976
  var currentQuestionId = _a.currentQuestionId,allQuestions = _a.allQuestions;
@@ -49181,6 +49183,7 @@ var Kr=[{
49181
49183
  }
49182
49184
  }, []);
49183
49185
  var handleConvertAndSubmitForm = function (formResponse) {return __awaiter(void 0, void 0, void 0, function () {
49186
+ var error_1;
49184
49187
  return __generator(this, function (_a) {
49185
49188
  switch (_a.label) {
49186
49189
  case 0:
@@ -49188,28 +49191,54 @@ var Kr=[{
49188
49191
  return [2];
49189
49192
  }
49190
49193
  setIsSubmittingForm(true);
49191
- return [4, onSubmit(convertToAwellInput(formResponse))];
49194
+ _a.label = 1;
49192
49195
  case 1:
49196
+ _a.trys.push([1, 3, 4, 5]);
49197
+ return [4, onSubmit(convertToAwellInput(formResponse))];
49198
+ case 2:
49193
49199
  _a.sent();
49200
+ return [3, 5];
49201
+ case 3:
49202
+ error_1 = _a.sent();
49203
+ console.error('Form submission failed:', error_1);
49204
+ setFormHasErrors(true);
49205
+ return [3, 5];
49206
+ case 4:
49194
49207
  setIsSubmittingForm(false);
49195
- return [2];}
49208
+ return [7];
49209
+ case 5:return [2];}
49196
49210
 
49197
49211
  });
49198
49212
  });};
49199
49213
  var submitForm = function () {return __awaiter(void 0, void 0, void 0, function () {
49200
- var formErrors;
49214
+ var currentVisibleQuestions, error_2, formErrors;
49201
49215
  return __generator(this, function (_a) {
49202
49216
  switch (_a.label) {
49203
- case 0:return [4, updateQuestionVisibility()];
49217
+ case 0:
49218
+ currentVisibleQuestions = visibleQuestions;
49219
+ _a.label = 1;
49204
49220
  case 1:
49205
- _a.sent();
49206
- formErrors = visibleQuestions.flatMap(function (vq) {
49221
+ _a.trys.push([1, 3,, 4]);
49222
+ return [4, updateQuestionVisibility()];
49223
+ case 2:
49224
+ currentVisibleQuestions = _a.sent();
49225
+ return [3, 4];
49226
+ case 3:
49227
+ error_2 = _a.sent();
49228
+ console.error('Failed to evaluate display conditions:', error_2);
49229
+ setFormHasErrors(true);
49230
+ return [2];
49231
+ case 4:
49232
+ formErrors = currentVisibleQuestions.flatMap(function (vq) {
49207
49233
  return getErrorsForQuestion(vq, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse, validateAttachmentsResponse, validateInputValidationResponse);
49208
49234
  });
49209
49235
  setErrors(formErrors);
49210
49236
  if (formErrors.length === 0) {
49211
49237
  setFormHasErrors(false);
49212
- formMethods.handleSubmit(handleConvertAndSubmitForm)();
49238
+ formMethods.handleSubmit(handleConvertAndSubmitForm, function (rhfErrors) {
49239
+ console.error('Form validation errors:', rhfErrors);
49240
+ setFormHasErrors(true);
49241
+ })();
49213
49242
  } else
49214
49243
  {
49215
49244
  setFormHasErrors(true);
@@ -49320,7 +49349,9 @@ var Kr=[{
49320
49349
  updatedQuestions = _a.sent();
49321
49350
  isLastVisibleQuestion = current === updatedQuestions.length - 1;
49322
49351
  if (isLastVisibleQuestion) {
49323
- formMethods.handleSubmit(handleConvertAndSubmitForm)();
49352
+ formMethods.handleSubmit(handleConvertAndSubmitForm, function (rhfErrors) {
49353
+ console.error('Form validation errors:', rhfErrors);
49354
+ })();
49324
49355
  return [2];
49325
49356
  }
49326
49357
  return [3, 4];
@@ -49361,6 +49392,7 @@ var Kr=[{
49361
49392
  });
49362
49393
  });};
49363
49394
  var handleConvertAndSubmitForm = function (formResponse) {return __awaiter(void 0, void 0, void 0, function () {
49395
+ var error_1;
49364
49396
  return __generator(this, function (_a) {
49365
49397
  switch (_a.label) {
49366
49398
  case 0:
@@ -49368,30 +49400,49 @@ var Kr=[{
49368
49400
  return [2];
49369
49401
  }
49370
49402
  setIsSubmittingForm(true);
49371
- return [4, onSubmit(convertToAwellInput(formResponse))];
49403
+ _a.label = 1;
49372
49404
  case 1:
49405
+ _a.trys.push([1, 3, 4, 5]);
49406
+ return [4, onSubmit(convertToAwellInput(formResponse))];
49407
+ case 2:
49373
49408
  _a.sent();
49409
+ return [3, 5];
49410
+ case 3:
49411
+ error_1 = _a.sent();
49412
+ console.error('Form submission failed:', error_1);
49413
+ return [3, 5];
49414
+ case 4:
49374
49415
  setIsSubmittingForm(false);
49375
- return [2];}
49416
+ return [7];
49417
+ case 5:return [2];}
49376
49418
 
49377
49419
  });
49378
49420
  });};
49379
49421
  var submitForm = function () {return __awaiter(void 0, void 0, void 0, function () {
49422
+ var updatedQuestions, doNextQuestionExist, hasErrors, error_2;
49380
49423
  return __generator(this, function (_a) {
49381
49424
  switch (_a.label) {
49382
- case 0:return [4, updateQuestionVisibility().then(function (updatedQuestions) {
49383
- var doNextQuestionExist = current !== updatedQuestions.length - 1;
49384
- if (doNextQuestionExist) {
49385
- return handleGoToNextQuestion();
49386
- }
49387
- var hasErrors = handleCheckForErrors(visibleQuestions === null || visibleQuestions === void 0 ? void 0 : visibleQuestions[current]);
49388
- if (!hasErrors) {
49389
- formMethods.handleSubmit(handleConvertAndSubmitForm)();
49390
- }
49391
- })];
49425
+ case 0:
49426
+ _a.trys.push([0, 2,, 3]);
49427
+ return [4, updateQuestionVisibility()];
49392
49428
  case 1:
49393
- _a.sent();
49394
- return [2];}
49429
+ updatedQuestions = _a.sent();
49430
+ doNextQuestionExist = current !== updatedQuestions.length - 1;
49431
+ if (doNextQuestionExist) {
49432
+ return [2, handleGoToNextQuestion()];
49433
+ }
49434
+ hasErrors = handleCheckForErrors(updatedQuestions === null || updatedQuestions === void 0 ? void 0 : updatedQuestions[current]);
49435
+ if (!hasErrors) {
49436
+ formMethods.handleSubmit(handleConvertAndSubmitForm, function (rhfErrors) {
49437
+ console.error('Form validation errors:', rhfErrors);
49438
+ })();
49439
+ }
49440
+ return [3, 3];
49441
+ case 2:
49442
+ error_2 = _a.sent();
49443
+ console.error('Failed to evaluate display conditions:', error_2);
49444
+ return [3, 3];
49445
+ case 3:return [2];}
49395
49446
 
49396
49447
  });
49397
49448
  });};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awell-health/ui-library",
3
- "version": "0.1.130",
3
+ "version": "0.1.133",
4
4
  "description": "UI components to integrate with Awell Health",
5
5
  "repository": {
6
6
  "type": "git",