@trii/components 2.0.33 → 2.0.34

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/cjs/index.js CHANGED
@@ -52182,7 +52182,7 @@ const StyledSaveCancelButton$1 = material.styled(material.IconButton)({
52182
52182
  },
52183
52183
  });
52184
52184
  const EntityInfoLabel = (props) => {
52185
- const { title, value, isNotEditable, displayValue, baseUrl, spaceId, minWidth, } = props;
52185
+ const { title, value, isNotEditable, displayValue, baseUrl, spaceId, minWidth, onEntityUpdated, } = props;
52186
52186
  const inputType = props.inputType ?? 'text';
52187
52187
  const [isEditing, setIsEditing] = React$1.useState(false);
52188
52188
  const [isSaving, setIsSaving] = React$1.useState(false);
@@ -52248,13 +52248,14 @@ const EntityInfoLabel = (props) => {
52248
52248
  if (!entityId) {
52249
52249
  throw new Error('Missing contactId for updateEntity');
52250
52250
  }
52251
- await updateEntity({
52251
+ const updated = await updateEntity({
52252
52252
  baseUrl,
52253
52253
  spaceId,
52254
52254
  entityType: 'contact',
52255
52255
  entityId,
52256
52256
  body: updatedContactData,
52257
52257
  });
52258
+ onEntityUpdated?.(updated);
52258
52259
  }
52259
52260
  else {
52260
52261
  const updatedBusinessData = props.constructUpdateObject(inputValue);
@@ -52262,13 +52263,14 @@ const EntityInfoLabel = (props) => {
52262
52263
  if (!entityId) {
52263
52264
  throw new Error('Missing businessId for updateEntity');
52264
52265
  }
52265
- await updateEntity({
52266
+ const updated = await updateEntity({
52266
52267
  baseUrl,
52267
52268
  spaceId,
52268
52269
  entityType: 'business',
52269
52270
  entityId,
52270
52271
  body: updatedBusinessData,
52271
52272
  });
52273
+ onEntityUpdated?.(updated);
52272
52274
  }
52273
52275
  }
52274
52276
  finally {
@@ -52299,12 +52301,12 @@ const EntityInfoLabel = (props) => {
52299
52301
  };
52300
52302
 
52301
52303
  const ContactInfoLabel = (props) => {
52302
- const { title, value, isNotEditable, options = [], displayValue, constructUpdateObject, businessId, baseUrl, spaceId, contactId, t, } = props;
52304
+ const { title, value, isNotEditable, options = [], displayValue, constructUpdateObject, businessId, baseUrl, spaceId, contactId, t, onEntityUpdated, } = props;
52303
52305
  if (props.inputType === 'birthday') {
52304
- return (jsxRuntimeExports.jsx(EntityInfoLabel, { entityType: "contact", entityId: contactId, title: title, value: value, isNotEditable: isNotEditable, inputType: "birthday", options: options, displayValue: displayValue, constructUpdateObject: constructUpdateObject, contact: props.contact, businessId: businessId, baseUrl: baseUrl, spaceId: spaceId, t: t, dateFormat: props.dateFormat }));
52306
+ return (jsxRuntimeExports.jsx(EntityInfoLabel, { entityType: "contact", entityId: contactId, title: title, value: value, isNotEditable: isNotEditable, inputType: "birthday", options: options, displayValue: displayValue, constructUpdateObject: constructUpdateObject, contact: props.contact, businessId: businessId, baseUrl: baseUrl, spaceId: spaceId, t: t, dateFormat: props.dateFormat, onEntityUpdated: onEntityUpdated }));
52305
52307
  }
52306
52308
  const inputType = props.inputType ?? 'text';
52307
- return (jsxRuntimeExports.jsx(EntityInfoLabel, { entityType: "contact", entityId: contactId, title: title, value: value, isNotEditable: isNotEditable, inputType: inputType, options: options, displayValue: displayValue, constructUpdateObject: constructUpdateObject, businessId: businessId, baseUrl: baseUrl, spaceId: spaceId, t: t }));
52309
+ return (jsxRuntimeExports.jsx(EntityInfoLabel, { entityType: "contact", entityId: contactId, title: title, value: value, isNotEditable: isNotEditable, inputType: inputType, options: options, displayValue: displayValue, constructUpdateObject: constructUpdateObject, businessId: businessId, baseUrl: baseUrl, spaceId: spaceId, t: t, onEntityUpdated: onEntityUpdated }));
52308
52310
  };
52309
52311
 
52310
52312
  const CustomPropertyInput = ({ nameKey, value, onChange, type, }) => {
@@ -54140,7 +54142,7 @@ const FieldValue = material.styled(material.Typography)(({ theme }) => ({
54140
54142
  overflow: 'auto',
54141
54143
  whiteSpace: 'break-spaces',
54142
54144
  }));
54143
- const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, customContactFields, userTrii, baseUrl, spaceId, t, }) => {
54145
+ const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, customContactFields, userTrii, baseUrl, spaceId, t, onEntityUpdated, }) => {
54144
54146
  const { customProperties } = entity.field;
54145
54147
  const { setCustomProperties } = entity.action;
54146
54148
  const [isEditing, setIsEditing] = React$1.useState(false);
@@ -54225,13 +54227,22 @@ const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, custom
54225
54227
  ],
54226
54228
  };
54227
54229
  try {
54228
- await updateEntity({
54230
+ const updated = await updateEntity({
54229
54231
  baseUrl,
54230
54232
  spaceId,
54231
54233
  entityType,
54232
54234
  entityId,
54233
54235
  body: updatedContactData,
54234
54236
  });
54237
+ const nextProperties = customProperties.map((p) => p.nameKey === nameKey
54238
+ ? {
54239
+ ...p,
54240
+ type: effectiveType,
54241
+ value: finalValue,
54242
+ }
54243
+ : p);
54244
+ setCustomProperties(nextProperties);
54245
+ onEntityUpdated?.(updated);
54235
54246
  }
54236
54247
  finally {
54237
54248
  setIsSaving(false);
@@ -54350,7 +54361,7 @@ const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, custom
54350
54361
  };
54351
54362
 
54352
54363
  const ContactGeneral = (props) => {
54353
- const { dateFormat, entityData, customContactFields, baseUrl, spaceId, t, currentUser } = props;
54364
+ const { dateFormat, entityData, customContactFields, baseUrl, spaceId, t, currentUser, onEntityUpdated } = props;
54354
54365
  const [users, setUsers] = React$1.useState([]);
54355
54366
  const [owner, setOwner] = React$1.useState(null);
54356
54367
  const [updatedBy, setUpdatedBy] = React$1.useState(null);
@@ -54432,9 +54443,9 @@ const ContactGeneral = (props) => {
54432
54443
  };
54433
54444
  return (jsxRuntimeExports.jsx(Section, { title: "General", children: jsxRuntimeExports.jsxs(SectionContent, { children: [jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('contactDetails.contactOwner'), displayValue: owner || '-', value: entityData.owner, inputType: "select", options: users, constructUpdateObject: (value) => ({
54434
54445
  owner: typeof value === 'string' ? value : '',
54435
- }), contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('contactDetails.business'), displayValue: entityData.businessName || '-', value: entityData.businessId, inputType: "selectBusiness", businessId: entityData.businessId, contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('contactDetails.createdBy'), value: createdBy || '-', isNotEditable: true, contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('contactDetails.modifiedBy'), value: updatedBy || '-', isNotEditable: true, contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('global.birthdate'), inputType: "birthday", displayValue: birthDate ? `${dateOnlyString} (${calculateAge(birthDate.toDate())})` : '-', value: birthDate ? birthDate.toISOString() : '', constructUpdateObject: (value) => ({
54446
+ }), contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t, onEntityUpdated: onEntityUpdated }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('contactDetails.business'), displayValue: entityData.businessName || '-', value: entityData.businessId, inputType: "selectBusiness", businessId: entityData.businessId, contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t, onEntityUpdated: onEntityUpdated }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('contactDetails.createdBy'), value: createdBy || '-', isNotEditable: true, contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('contactDetails.modifiedBy'), value: updatedBy || '-', isNotEditable: true, contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t }), jsxRuntimeExports.jsx(ContactInfoLabel, { title: t('global.birthdate'), inputType: "birthday", displayValue: birthDate ? `${dateOnlyString} (${calculateAge(birthDate.toDate())})` : '-', value: birthDate ? birthDate.toISOString() : '', constructUpdateObject: (value) => ({
54436
54447
  birthDate: value,
54437
- }), contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t, dateFormat: dateFormat }), editContact.field.customProperties.map((property) => (jsxRuntimeExports.jsx(EntityCustomFieldLabel, { property: property, entity: editContact, entityType: "contact", entityId: String(entityData.id), customContactFields: customContactFields, userTrii: currentUser, baseUrl: baseUrl, spaceId: spaceId, t: t }, property.nameKey)))] }) }));
54448
+ }), contact: editContact, baseUrl: baseUrl, spaceId: spaceId, contactId: entityData.id, t: t, dateFormat: dateFormat, onEntityUpdated: onEntityUpdated }), editContact.field.customProperties.map((property) => (jsxRuntimeExports.jsx(EntityCustomFieldLabel, { property: property, entity: editContact, entityType: "contact", entityId: String(entityData.id), customContactFields: customContactFields, userTrii: currentUser, baseUrl: baseUrl, spaceId: spaceId, t: t, onEntityUpdated: onEntityUpdated }, property.nameKey)))] }) }));
54438
54449
  };
54439
54450
 
54440
54451
  const useEditBusiness = ({ business, customContactFields, baseUrl, spaceId }) => {
@@ -54617,12 +54628,12 @@ const useEditBusiness = ({ business, customContactFields, baseUrl, spaceId }) =>
54617
54628
  };
54618
54629
  };
54619
54630
 
54620
- const BusinessInfoLabel = ({ title, value, isNotEditable, inputType = 'text', options = [], displayValue, constructUpdateObject, baseUrl, spaceId, businessId, }) => {
54621
- return (jsxRuntimeExports.jsx(EntityInfoLabel, { entityType: "business", entityId: businessId, title: title, value: value, isNotEditable: isNotEditable, inputType: inputType, options: options, displayValue: displayValue, constructUpdateObject: constructUpdateObject, baseUrl: baseUrl, spaceId: spaceId }));
54631
+ const BusinessInfoLabel = ({ title, value, isNotEditable, inputType = 'text', options = [], displayValue, constructUpdateObject, baseUrl, spaceId, businessId, onEntityUpdated, }) => {
54632
+ return (jsxRuntimeExports.jsx(EntityInfoLabel, { entityType: "business", entityId: businessId, title: title, value: value, isNotEditable: isNotEditable, inputType: inputType, options: options, displayValue: displayValue, constructUpdateObject: constructUpdateObject, baseUrl: baseUrl, spaceId: spaceId, onEntityUpdated: onEntityUpdated }));
54622
54633
  };
54623
54634
 
54624
54635
  const BusinessGeneral = (props) => {
54625
- const { entityData, customContactFields, baseUrl, spaceId, t, currentUser } = props;
54636
+ const { entityData, customContactFields, baseUrl, spaceId, t, currentUser, onEntityUpdated } = props;
54626
54637
  const [users, setUsers] = React$1.useState([]);
54627
54638
  const [owner, setOwner] = React$1.useState(null);
54628
54639
  const [updatedBy, setUpdatedBy] = React$1.useState(null);
@@ -54692,7 +54703,7 @@ const BusinessGeneral = (props) => {
54692
54703
  }, [entityData, users, currentUser, baseUrl, spaceId]);
54693
54704
  return (jsxRuntimeExports.jsx(Section, { title: "General", children: jsxRuntimeExports.jsxs(SectionContent, { children: [jsxRuntimeExports.jsx(BusinessInfoLabel, { title: t('businessDetails.businessOwner'), value: entityData.owner, displayValue: owner || '-', inputType: "select", options: users, constructUpdateObject: (value) => ({
54694
54705
  owner: typeof value === 'string' ? value : '',
54695
- }), baseUrl: baseUrl, spaceId: spaceId, businessId: entityData.id }), jsxRuntimeExports.jsx(BusinessInfoLabel, { title: t('contactDetails.createdBy'), value: createdBy || '-', isNotEditable: true }), jsxRuntimeExports.jsx(BusinessInfoLabel, { title: t('contactDetails.modifiedBy'), value: updatedBy || '-', isNotEditable: true }), editBusiness.field.customProperties.map((property) => (jsxRuntimeExports.jsx(EntityCustomFieldLabel, { property: property, entity: editBusiness, entityType: "business", entityId: String(entityData.id), customContactFields: customContactFields, userTrii: currentUser, baseUrl: baseUrl, spaceId: spaceId, t: t }, property.nameKey)))] }) }));
54706
+ }), baseUrl: baseUrl, spaceId: spaceId, businessId: entityData.id, onEntityUpdated: onEntityUpdated }), jsxRuntimeExports.jsx(BusinessInfoLabel, { title: t('contactDetails.createdBy'), value: createdBy || '-', isNotEditable: true }), jsxRuntimeExports.jsx(BusinessInfoLabel, { title: t('contactDetails.modifiedBy'), value: updatedBy || '-', isNotEditable: true }), editBusiness.field.customProperties.map((property) => (jsxRuntimeExports.jsx(EntityCustomFieldLabel, { property: property, entity: editBusiness, entityType: "business", entityId: String(entityData.id), customContactFields: customContactFields, userTrii: currentUser, baseUrl: baseUrl, spaceId: spaceId, t: t, onEntityUpdated: onEntityUpdated }, property.nameKey)))] }) }));
54696
54707
  };
54697
54708
 
54698
54709
  const General = (props) => {
@@ -54705,11 +54716,12 @@ const General = (props) => {
54705
54716
  return normalizedEntityType === 'contact' ? (jsxRuntimeExports.jsx(ContactGeneral, { ...props, entityData: entityData, entityType: "contact" })) : (jsxRuntimeExports.jsx(BusinessGeneral, { ...props, entityData: entityData, entityType: "business" }));
54706
54717
  };
54707
54718
 
54708
- const AddressInformation = ({ entityType, entityData, baseUrl, spaceId, t }) => {
54719
+ const AddressInformation = ({ entityType, entityData, baseUrl, spaceId, t, onEntityUpdated, }) => {
54709
54720
  const commonProps = {
54710
54721
  baseUrl,
54711
54722
  spaceId,
54712
54723
  entityId: String(entityData.id),
54724
+ onEntityUpdated,
54713
54725
  };
54714
54726
  const maybeTitle = t('contactDetails.addressInformation');
54715
54727
  const sectionTitle = maybeTitle === 'contactDetails.addressInformation' ? 'Address Information' : maybeTitle;
@@ -54773,6 +54785,18 @@ const EditContactModal = ({ open, onClose, baseUrl, spaceId, contactId, sx, t, }
54773
54785
  setTagsEditorInitialized(false);
54774
54786
  setIsSavingTags(false);
54775
54787
  }, []);
54788
+ const handleEntityUpdated = React$1.useCallback((entity) => {
54789
+ if (!entity || typeof entity !== 'object')
54790
+ return;
54791
+ const hasId = 'id' in entity;
54792
+ if (hasId) {
54793
+ actions.setContactData(entity);
54794
+ return;
54795
+ }
54796
+ if (state.contactData) {
54797
+ actions.setContactData({ ...state.contactData, ...entity });
54798
+ }
54799
+ }, [actions, state.contactData]);
54776
54800
  const image = useImage({
54777
54801
  baseUrl,
54778
54802
  spaceId,
@@ -54781,13 +54805,7 @@ const EditContactModal = ({ open, onClose, baseUrl, spaceId, contactId, sx, t, }
54781
54805
  : undefined,
54782
54806
  entityId: state.contactData ? String(state.contactData.id) : undefined,
54783
54807
  initialImageUrl: state.contactData?.imageUrl,
54784
- onEntityUpdated: (entity) => {
54785
- if (!entity || typeof entity !== 'object')
54786
- return;
54787
- if (!state.contactData)
54788
- return;
54789
- actions.setContactData({ ...state.contactData, ...entity });
54790
- },
54808
+ onEntityUpdated: handleEntityUpdated,
54791
54809
  });
54792
54810
  React$1.useEffect(() => {
54793
54811
  if (!open) {
@@ -54878,9 +54896,9 @@ const EditContactModal = ({ open, onClose, baseUrl, spaceId, contactId, sx, t, }
54878
54896
  setView('tags');
54879
54897
  }, onUploadPhoto: image.action.uploadImage, onPhotoFileChange: image.inputAtributes.onChange, photoInputRef: image.inputAtributes.ref, isUploadingPhoto: image.isUploading, onDeletePhoto: image.action.deleteImage, isDeletingPhoto: image.isDeleting }), jsxRuntimeExports.jsxs(material.Box, { sx: { px: 1, pb: 2 }, children: [jsxRuntimeExports.jsx(General, { dateFormat: selectors.userTrii?.regCon_dateFormat || 'MM/dd/yyyy', entityType: selectors.contactType === 'contact' || selectors.contactType === 'business'
54880
54898
  ? selectors.contactType
54881
- : 'contact', entityData: state.contactData, customContactFields: selectors.contactFields, baseUrl: baseUrl, spaceId: spaceId, t: t, currentUser: selectors.userTrii }), jsxRuntimeExports.jsx(AddressInformation, { entityType: selectors.contactType === 'contact' || selectors.contactType === 'business'
54899
+ : 'contact', entityData: state.contactData, customContactFields: selectors.contactFields, baseUrl: baseUrl, spaceId: spaceId, onEntityUpdated: handleEntityUpdated, t: t, currentUser: selectors.userTrii }), jsxRuntimeExports.jsx(AddressInformation, { entityType: selectors.contactType === 'contact' || selectors.contactType === 'business'
54882
54900
  ? selectors.contactType
54883
- : 'contact', entityData: state.contactData, baseUrl: baseUrl, spaceId: spaceId, t: t }), jsxRuntimeExports.jsx(Section, { title: "Contact Information", children: "C" })] })] }) }), jsxRuntimeExports.jsx(material.Fade, { in: view === 'tags', timeout: 200, mountOnEnter: true, unmountOnExit: true, children: jsxRuntimeExports.jsx(material.Box, { sx: { pt: 0.5, position: 'absolute', inset: 0, overflowY: 'auto' }, children: jsxRuntimeExports.jsx(TagsEditor, { value: draftLabels, options: selectors.labels, onChange: setDraftLabels, onBack: () => setView('main'), onSave: handleSaveTags, isSaving: isSavingTags, t: t }) }) })] }) })) : null }) }) }));
54901
+ : 'contact', entityData: state.contactData, baseUrl: baseUrl, spaceId: spaceId, onEntityUpdated: handleEntityUpdated, t: t }), jsxRuntimeExports.jsx(Section, { title: "Contact Information", children: "C" })] })] }) }), jsxRuntimeExports.jsx(material.Fade, { in: view === 'tags', timeout: 200, mountOnEnter: true, unmountOnExit: true, children: jsxRuntimeExports.jsx(material.Box, { sx: { pt: 0.5, position: 'absolute', inset: 0, overflowY: 'auto' }, children: jsxRuntimeExports.jsx(TagsEditor, { value: draftLabels, options: selectors.labels, onChange: setDraftLabels, onBack: () => setView('main'), onSave: handleSaveTags, isSaving: isSavingTags, t: t }) }) })] }) })) : null }) }) }));
54884
54902
  };
54885
54903
 
54886
54904
  exports.ContactInfoPopup = ContactInfoPopup;