@awell-health/ui-library 0.1.92 → 0.1.93

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/dist/index.css CHANGED
@@ -5956,10 +5956,34 @@ html {
5956
5956
  display: flex;
5957
5957
  flex-direction: column;
5958
5958
  gap: 12px;
5959
+ /* Higher specificity to override Tailwind */
5960
+ }
5961
+ .awell__FileInputField_file_input_field_container.awell__FileInputField_file_input_field_container {
5962
+ width: 100%;
5963
+ }
5964
+
5965
+ .awell__FileInputField_error_message {
5966
+ color: #e53e3e; /* Red for error */
5967
+ font-size: 14px;
5968
+ margin-bottom: 4px;
5969
+ }
5970
+
5971
+ .awell__FileInputField_file_upload_wrapper {
5972
+ /* Isolate FileUpload component styles */
5973
+ }
5974
+ .awell__FileInputField_file_upload_wrapper .awell-file-upload {
5975
+ width: 100%;
5959
5976
  }
5960
5977
 
5961
- .awell__FileInputField_file_list {
5978
+ .awell__FileInputField_file_list_wrapper {
5979
+ /* Isolate FileList component styles */
5980
+ width: 100%;
5981
+ /* Override Tailwind with higher specificity if needed */
5982
+ }
5983
+ .awell__FileInputField_file_list_wrapper .awell-file-list {
5984
+ width: 100%;
5962
5985
  display: flex;
5986
+ flex-direction: column;
5963
5987
  }
5964
5988
  @import 'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap';
5965
5989
  :root {
package/dist/index.js CHANGED
@@ -48050,41 +48050,100 @@ var Kr=[{
48050
48050
  .styles-module_tooltip__mnnfp{padding:8px 16px;border-radius:3px;font-size:90%;width:max-content}.styles-module_arrow__K0L3T{width:8px;height:8px}[class*='react-tooltip__place-top']>.styles-module_arrow__K0L3T{transform:rotate(45deg)}[class*='react-tooltip__place-right']>.styles-module_arrow__K0L3T{transform:rotate(135deg)}[class*='react-tooltip__place-bottom']>.styles-module_arrow__K0L3T{transform:rotate(225deg)}[class*='react-tooltip__place-left']>.styles-module_arrow__K0L3T{transform:rotate(315deg)}.styles-module_dark__xNqje{background:var(--rt-color-dark);color:var(--rt-color-white)}.styles-module_light__Z6W-X{background-color:var(--rt-color-white);color:var(--rt-color-dark)}.styles-module_success__A2AKt{background-color:var(--rt-color-success);color:var(--rt-color-white)}.styles-module_warning__SCK0X{background-color:var(--rt-color-warning);color:var(--rt-color-white)}.styles-module_error__JvumD{background-color:var(--rt-color-error);color:var(--rt-color-white)}.styles-module_info__BWdHW{background-color:var(--rt-color-info);color:var(--rt-color-white)}`,type:"base"});
48051
48051
  });
48052
48052
 
48053
- var classes$9 = {"file_input_field_container":"awell__FileInputField_file_input_field_container","file_list":"awell__FileInputField_file_list"};
48053
+ var classes$9 = {"file_input_field_container":"awell__FileInputField_file_input_field_container","error_message":"awell__FileInputField_error_message","file_upload_wrapper":"awell__FileInputField_file_upload_wrapper","file_list_wrapper":"awell__FileInputField_file_list_wrapper"};
48054
48054
 
48055
48055
  var FileInputField = function (_a) {
48056
- _a.id;var label = _a.label;_a.description;var accept = _a.accept;_a.maxSize;var _b = _a.multiple,multiple = _b === void 0 ? false : _b,error = _a.error;_a.disabled;_a.required;var onChange = _a.onChange,onError = _a.onError,_e = _a.className,className = _e === void 0 ? '' : _e,dataCy = _a.dataCy;_a.value;_a.loading;var fileUploadErrors = _a.fileUploadErrors;
48057
- var _g = React.useState([]),selectedFiles = _g[0],setSelectedFiles = _g[1];
48056
+ var id = _a.id,label = _a.label,accept = _a.accept,_b = _a.multiple,multiple = _b === void 0 ? true : _b,error = _a.error,onChange = _a.onChange,onError = _a.onError,_c = _a.className,className = _c === void 0 ? '' : _c,dataCy = _a.dataCy,onFileUpload = _a.onFileUpload,configId = _a.configId,value = _a.value;
48057
+ var _d = React.useState(Array.isArray(value) ?
48058
+ value === null || value === void 0 ? void 0 : value.map(function (attachment) {
48059
+ var _a, _b, _c, _d;
48060
+ return {
48061
+ name: (_a = attachment.filename) !== null && _a !== void 0 ? _a : '',
48062
+ size: (_b = attachment.size) !== null && _b !== void 0 ? _b : 0,
48063
+ type: (_c = attachment.contentType) !== null && _c !== void 0 ? _c : '',
48064
+ url: (_d = attachment.url) !== null && _d !== void 0 ? _d : '',
48065
+ progress: 100,
48066
+ error: undefined };
48067
+
48068
+ }) :
48069
+ []),selectedFiles = _d[0],setSelectedFiles = _d[1];
48058
48070
  React.useEffect(function () {
48059
- if (fileUploadErrors && fileUploadErrors.length > 0) {
48060
- console.log('fileUploadErrors', fileUploadErrors);
48061
- setSelectedFiles(function (prev) {
48062
- return prev.map(function (file) {
48063
- var fileId = file.name;
48064
- var error = fileUploadErrors.find(function (f) {return f.id === fileId;});
48065
- if (error) {
48066
- return __assign(__assign({}, file), { error: error.error });
48067
- }
48068
- return file;
48069
- });
48070
- });
48071
- }
48072
- }, [fileUploadErrors]);
48073
- var handleFileChange = function (files) {
48074
- var updatedFiles = files;
48075
- var filesAsListItems = updatedFiles.map(function (file) {return {
48076
- name: file.name,
48077
- size: file.size,
48078
- type: file.type };
48071
+ var attachments = selectedFiles.
48072
+ filter(function (file) {return file.url;}).
48073
+ map(function (file) {return {
48074
+ url: file.url,
48075
+ filename: file.name,
48076
+ contentType: file.type,
48077
+ size: file.size };
48079
48078
  });
48080
- setSelectedFiles(function (prev) {return __spreadArray(__spreadArray([], prev, true), filesAsListItems, true);});
48081
- onChange(__spreadArray(__spreadArray([], selectedFiles, true), updatedFiles, true));
48082
- };
48079
+ onChange(attachments);
48080
+ }, [selectedFiles]);
48081
+ var uploadFilesToStorage = function (files) {return __awaiter(void 0, void 0, void 0, function () {
48082
+ var fileListWithUrls;
48083
+ return __generator(this, function (_a) {
48084
+ switch (_a.label) {
48085
+ case 0:return [4, Promise.all(Array.from(files).map(function (file) {return __awaiter(void 0, void 0, void 0, function () {
48086
+ var fileUrl, error_1;
48087
+ return __generator(this, function (_a) {
48088
+ switch (_a.label) {
48089
+ case 0:
48090
+ _a.trys.push([0, 2,, 3]);
48091
+ return [4, onFileUpload === null || onFileUpload === void 0 ? void 0 : onFileUpload(file, configId)];
48092
+ case 1:
48093
+ fileUrl = _a.sent();
48094
+ return [2, {
48095
+ name: file.name,
48096
+ size: file.size,
48097
+ type: file.type,
48098
+ progress: 100,
48099
+ error: undefined,
48100
+ url: fileUrl }];
48101
+
48102
+ case 2:
48103
+ error_1 = _a.sent();
48104
+ return [2, {
48105
+ name: file.name,
48106
+ size: file.size,
48107
+ type: file.type,
48108
+ progress: 0,
48109
+ error: error_1 instanceof Error ? error_1.message : 'File upload failed',
48110
+ url: undefined }];
48111
+
48112
+ case 3:return [2];}
48113
+
48114
+ });
48115
+ });}))];
48116
+ case 1:
48117
+ fileListWithUrls = _a.sent();
48118
+ return [2, fileListWithUrls];}
48119
+
48120
+ });
48121
+ });};
48122
+ var handleFilesChange = function (files) {return __awaiter(void 0, void 0, void 0, function () {
48123
+ var fileList, fileListWithUrls;
48124
+ return __generator(this, function (_a) {
48125
+ switch (_a.label) {
48126
+ case 0:
48127
+ fileList = Array.from(files).map(function (file) {return {
48128
+ name: "".concat(file.name, " (uploading...)"),
48129
+ size: file.size,
48130
+ type: file.type,
48131
+ progress: 0,
48132
+ error: undefined };
48133
+ });
48134
+ setSelectedFiles(fileList);
48135
+ return [4, uploadFilesToStorage(files)];
48136
+ case 1:
48137
+ fileListWithUrls = _a.sent();
48138
+ setSelectedFiles(fileListWithUrls);
48139
+ return [2];}
48140
+
48141
+ });
48142
+ });};
48083
48143
  var handleRemoveFile = function (file) {
48084
- setSelectedFiles(function (prev) {return prev.filter(function (f) {return f.name !== file.name;});});
48085
- onChange(selectedFiles.filter(function (f) {return f.name !== file.name;}));
48144
+ setSelectedFiles(selectedFiles.filter(function (f) {return f.name !== file.name;}));
48086
48145
  };
48087
- return jsxRuntime.exports.jsx("div", __assign({ className: className, "data-cy": dataCy }, { children: jsxRuntime.exports.jsxs("div", __assign({ className: classes$9.file_input_field_container }, { children: [error && jsxRuntime.exports.jsx("div", __assign({ className: classes$9.error_message }, { children: error })), jsxRuntime.exports.jsx(ag, { onChange: handleFileChange, onError: onError, isMultiple: multiple, accept: accept, label: label, error: error }), selectedFiles.length > 0 && jsxRuntime.exports.jsx("div", __assign({ className: classes$9.file_list }, { children: jsxRuntime.exports.jsx(og, { files: selectedFiles, onDelete: handleRemoveFile }) }))] })) }));
48146
+ return jsxRuntime.exports.jsxs("div", __assign({ className: "".concat(classes$9.file_input_field_container, " ").concat(className), "data-cy": dataCy }, { children: [error && jsxRuntime.exports.jsx("div", __assign({ className: classes$9.error_message }, { children: error })), jsxRuntime.exports.jsx("div", __assign({ className: classes$9.file_upload_wrapper }, { children: jsxRuntime.exports.jsx(ag, { onChange: handleFilesChange, onError: onError, isMultiple: multiple, accept: accept, label: label, error: error }) })), selectedFiles.length > 0 && jsxRuntime.exports.jsx("div", __assign({ className: classes$9.file_list_wrapper }, { children: jsxRuntime.exports.jsx(og, { files: selectedFiles, onDelete: handleRemoveFile }) }))] }), id);
48088
48147
  };
48089
48148
 
48090
48149
  var custom_json_parser = function (blob) {
@@ -48109,53 +48168,6 @@ var Kr=[{
48109
48168
  var question = _a.question,control = _a.control,getValues = _a.getValues,labels = _a.labels,_g = _a.inputAutoFocus,inputAutoFocus = _g === void 0 ? false : _g,_h = _a.submitAndMoveToNextQuestion,submitAndMoveToNextQuestion = _h === void 0 ? lodash.exports.noop : _h,_j = _a.onAnswerChange,onAnswerChange = _j === void 0 ? lodash.exports.noop : _j,_k = _a.shouldAutoProgress,shouldAutoProgress = _k === void 0 ? function () {return false;} : _k,onFileUpload = _a.onFileUpload;
48110
48169
  var config = question === null || question === void 0 ? void 0 : question.questionConfig;
48111
48170
  var _l = useICDClassificationList(question.id),icdClassificationOptions = _l.options,optionsLoading = _l.loading,onIcdClassificationSearchChange = _l.onIcdClassificationSearchChange;
48112
- var _m = React.useState([]),fileUploadErrors = _m[0],setFileUploadErrors = _m[1];
48113
- var handleFilesUpload = function (files, onControllerChange) {return __awaiter(void 0, void 0, void 0, function () {
48114
- var attachments;
48115
- return __generator(this, function (_a) {
48116
- switch (_a.label) {
48117
- case 0:
48118
- if (!onFileUpload) return [3, 2];
48119
- setFileUploadErrors([]);
48120
- return [4, Promise.all(files.map(function (file) {return __awaiter(void 0, void 0, void 0, function () {
48121
- var configId, fileUrl, attachment, error_1, errorMessage_1;
48122
- var _a;
48123
- return __generator(this, function (_b) {
48124
- switch (_b.label) {
48125
- case 0:
48126
- _b.trys.push([0, 2,, 3]);
48127
- configId = (_a = config === null || config === void 0 ? void 0 : config.file_storage) === null || _a === void 0 ? void 0 : _a.file_storage_destination_id;
48128
- return [4, onFileUpload(file, configId)];
48129
- case 1:
48130
- fileUrl = _b.sent();
48131
- attachment = {
48132
- url: fileUrl,
48133
- filename: file.name,
48134
- contentType: file.type,
48135
- size: file.size };
48136
-
48137
- return [2, attachment];
48138
- case 2:
48139
- error_1 = _b.sent();
48140
- errorMessage_1 = error_1 instanceof Error ?
48141
- error_1.message :
48142
- 'This file could not be uploaded';
48143
- setFileUploadErrors(function (prev) {return __spreadArray(__spreadArray([], prev, true), [
48144
- { id: file.name, error: errorMessage_1 }],
48145
- false);});
48146
- return [3, 3];
48147
- case 3:return [2];}
48148
-
48149
- });
48150
- });}))];
48151
- case 1:
48152
- attachments = _a.sent();
48153
- onControllerChange(JSON.stringify(attachments.filter(function (attachment) {return !lodash.exports.isNil(attachment);})));
48154
- _a.label = 2;
48155
- case 2:return [2];}
48156
-
48157
- });
48158
- });};
48159
48171
  switch (question.userQuestionType) {
48160
48172
  case exports.UserQuestionType.YesNo:
48161
48173
  return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: "", rules: { required: config === null || config === void 0 ? void 0 : config.mandatory }, render: function (_a) {
@@ -48328,29 +48340,21 @@ var Kr=[{
48328
48340
  } });
48329
48341
  case exports.UserQuestionType.File:
48330
48342
  return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: [], rules: { required: config === null || config === void 0 ? void 0 : config.mandatory }, render: function (_a) {
48331
- var _b, _c;
48332
- var _d = _a.field,onControllerChange = _d.onChange,onBlur = _d.onBlur,value = _d.value;
48333
- return jsxRuntime.exports.jsx(FileInputField, { onChange: function (files) {
48334
- void handleFilesUpload(files, onControllerChange);
48335
- }, value: custom_json_parser(value), 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 : [
48343
+ var _b, _c, _d;
48344
+ var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value;
48345
+ return jsxRuntime.exports.jsx(FileInputField, { id: question.id, value: custom_json_parser(value), onChange: function (attachments) {
48346
+ onControllerChange(JSON.stringify(attachments));
48347
+ }, 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 : [
48336
48348
  'application/pdf'],
48337
- fileUploadErrors: fileUploadErrors, onError: function (error) {
48338
- setFileUploadErrors(function (prev) {return __spreadArray(__spreadArray([], prev, true), [
48339
- { id: error, error: error }],
48340
- false);});
48341
- } });
48349
+ configId: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_destination_id, onFileUpload: onFileUpload });
48342
48350
  } });
48343
48351
  case exports.UserQuestionType.Image:
48344
48352
  return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: [], rules: { required: config === null || config === void 0 ? void 0 : config.mandatory }, render: function (_a) {
48345
- var _b, _c;
48346
- var _d = _a.field,onControllerChange = _d.onChange,onBlur = _d.onBlur,value = _d.value;
48347
- return jsxRuntime.exports.jsx(FileInputField, { value: custom_json_parser(value), onChange: function (files) {
48348
- void handleFilesUpload(files, onControllerChange);
48349
- }, 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/*'], fileUploadErrors: fileUploadErrors, onError: function (error) {
48350
- setFileUploadErrors(function (prev) {return __spreadArray(__spreadArray([], prev, true), [
48351
- { id: error, error: error }],
48352
- false);});
48353
- } });
48353
+ var _b, _c, _d;
48354
+ var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value;
48355
+ return jsxRuntime.exports.jsx(FileInputField, { id: question.id, value: custom_json_parser(value), onChange: function (attachments) {
48356
+ onControllerChange(JSON.stringify(attachments));
48357
+ }, 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/*'], configId: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_destination_id, onFileUpload: onFileUpload });
48354
48358
  } });
48355
48359
  case exports.UserQuestionType.Description:
48356
48360
  return jsxRuntime.exports.jsx(Description, { content: question.title });
@@ -1,25 +1,19 @@
1
1
  import React from 'react';
2
+ import { Attachment } from '../../molecules/question/types';
2
3
  interface Props {
3
4
  id?: string;
4
5
  label?: string;
5
- description?: string;
6
6
  accept?: Array<string>;
7
- maxSize?: number;
8
7
  multiple?: boolean;
9
8
  error?: string;
10
- disabled?: boolean;
11
- required?: boolean;
12
- onChange: (files: Array<File>) => void;
9
+ onChange: (attachments: Array<Attachment>) => void;
13
10
  onError?: (error: string) => void;
14
11
  className?: string;
15
12
  onBlur?: () => void;
16
13
  dataCy?: string;
17
- value?: Array<string>;
18
- loading?: boolean;
19
- fileUploadErrors?: Array<{
20
- id: string;
21
- error: string;
22
- }>;
14
+ onFileUpload?: (file: File, configId?: string) => Promise<string | undefined>;
15
+ configId?: string;
16
+ value?: Array<Attachment>;
23
17
  }
24
18
  export declare const FileInputField: React.FC<Props>;
25
19
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awell-health/ui-library",
3
- "version": "0.1.92",
3
+ "version": "0.1.93",
4
4
  "description": "UI components to integrate with Awell Health",
5
5
  "repository": {
6
6
  "type": "git",