@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.
@@ -5,6 +5,7 @@ export type AddressInformationProps = {
5
5
  baseUrl?: string;
6
6
  spaceId?: string;
7
7
  t: (key: string) => string;
8
+ onEntityUpdated?: (entity: unknown) => void;
8
9
  };
9
- declare const AddressInformation: ({ entityType, entityData, baseUrl, spaceId, t }: AddressInformationProps) => import("react/jsx-runtime").JSX.Element;
10
+ declare const AddressInformation: ({ entityType, entityData, baseUrl, spaceId, t, onEntityUpdated, }: AddressInformationProps) => import("react/jsx-runtime").JSX.Element;
10
11
  export default AddressInformation;
@@ -9,6 +9,7 @@ export interface GeneralProps {
9
9
  spaceId?: string;
10
10
  t: (key: string) => string;
11
11
  currentUser?: UserTrii | null;
12
+ onEntityUpdated?: (entity: unknown) => void;
12
13
  }
13
14
  declare const General: (props: GeneralProps) => import("react/jsx-runtime").JSX.Element;
14
15
  export default General;
@@ -10,6 +10,7 @@ type Props = {
10
10
  baseUrl?: string;
11
11
  spaceId?: string;
12
12
  businessId?: string;
13
+ onEntityUpdated?: (entity: unknown) => void;
13
14
  };
14
- declare const BusinessInfoLabel: ({ title, value, isNotEditable, inputType, options, displayValue, constructUpdateObject, baseUrl, spaceId, businessId, }: Props) => import("react/jsx-runtime").JSX.Element;
15
+ declare const BusinessInfoLabel: ({ title, value, isNotEditable, inputType, options, displayValue, constructUpdateObject, baseUrl, spaceId, businessId, onEntityUpdated, }: Props) => import("react/jsx-runtime").JSX.Element;
15
16
  export default BusinessInfoLabel;
@@ -13,6 +13,7 @@ type BaseProps = {
13
13
  spaceId?: string;
14
14
  contactId?: string;
15
15
  t: (key: string) => string;
16
+ onEntityUpdated?: (entity: unknown) => void;
16
17
  };
17
18
  type BirthdayProps = BaseProps & {
18
19
  inputType: 'birthday';
@@ -13,6 +13,7 @@ type Props = {
13
13
  baseUrl?: string;
14
14
  spaceId?: string;
15
15
  t: (key: string) => string;
16
+ onEntityUpdated?: (entity: unknown) => void;
16
17
  };
17
- declare const EntityCustomFieldLabel: ({ property, entity, entityType, entityId, customContactFields, userTrii, baseUrl, spaceId, t, }: Props) => import("react/jsx-runtime").JSX.Element;
18
+ declare const EntityCustomFieldLabel: ({ property, entity, entityType, entityId, customContactFields, userTrii, baseUrl, spaceId, t, onEntityUpdated, }: Props) => import("react/jsx-runtime").JSX.Element;
18
19
  export default EntityCustomFieldLabel;
@@ -9,6 +9,7 @@ type SharedProps = {
9
9
  baseUrl?: string;
10
10
  spaceId?: string;
11
11
  minWidth?: string | number;
12
+ onEntityUpdated?: (entity: unknown) => void;
12
13
  };
13
14
  type ContactBaseProps = SharedProps & {
14
15
  entityType: 'contact';
package/dist/esm/index.js CHANGED
@@ -52162,7 +52162,7 @@ const StyledSaveCancelButton$1 = styled$4(IconButton$2)({
52162
52162
  },
52163
52163
  });
52164
52164
  const EntityInfoLabel = (props) => {
52165
- const { title, value, isNotEditable, displayValue, baseUrl, spaceId, minWidth, } = props;
52165
+ const { title, value, isNotEditable, displayValue, baseUrl, spaceId, minWidth, onEntityUpdated, } = props;
52166
52166
  const inputType = props.inputType ?? 'text';
52167
52167
  const [isEditing, setIsEditing] = useState(false);
52168
52168
  const [isSaving, setIsSaving] = useState(false);
@@ -52228,13 +52228,14 @@ const EntityInfoLabel = (props) => {
52228
52228
  if (!entityId) {
52229
52229
  throw new Error('Missing contactId for updateEntity');
52230
52230
  }
52231
- await updateEntity({
52231
+ const updated = await updateEntity({
52232
52232
  baseUrl,
52233
52233
  spaceId,
52234
52234
  entityType: 'contact',
52235
52235
  entityId,
52236
52236
  body: updatedContactData,
52237
52237
  });
52238
+ onEntityUpdated?.(updated);
52238
52239
  }
52239
52240
  else {
52240
52241
  const updatedBusinessData = props.constructUpdateObject(inputValue);
@@ -52242,13 +52243,14 @@ const EntityInfoLabel = (props) => {
52242
52243
  if (!entityId) {
52243
52244
  throw new Error('Missing businessId for updateEntity');
52244
52245
  }
52245
- await updateEntity({
52246
+ const updated = await updateEntity({
52246
52247
  baseUrl,
52247
52248
  spaceId,
52248
52249
  entityType: 'business',
52249
52250
  entityId,
52250
52251
  body: updatedBusinessData,
52251
52252
  });
52253
+ onEntityUpdated?.(updated);
52252
52254
  }
52253
52255
  }
52254
52256
  finally {
@@ -52279,12 +52281,12 @@ const EntityInfoLabel = (props) => {
52279
52281
  };
52280
52282
 
52281
52283
  const ContactInfoLabel = (props) => {
52282
- const { title, value, isNotEditable, options = [], displayValue, constructUpdateObject, businessId, baseUrl, spaceId, contactId, t, } = props;
52284
+ const { title, value, isNotEditable, options = [], displayValue, constructUpdateObject, businessId, baseUrl, spaceId, contactId, t, onEntityUpdated, } = props;
52283
52285
  if (props.inputType === 'birthday') {
52284
- 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 }));
52286
+ 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 }));
52285
52287
  }
52286
52288
  const inputType = props.inputType ?? 'text';
52287
- 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 }));
52289
+ 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 }));
52288
52290
  };
52289
52291
 
52290
52292
  const CustomPropertyInput = ({ nameKey, value, onChange, type, }) => {
@@ -54120,7 +54122,7 @@ const FieldValue = styled$4(Typography$2)(({ theme }) => ({
54120
54122
  overflow: 'auto',
54121
54123
  whiteSpace: 'break-spaces',
54122
54124
  }));
54123
- const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, customContactFields, userTrii, baseUrl, spaceId, t, }) => {
54125
+ const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, customContactFields, userTrii, baseUrl, spaceId, t, onEntityUpdated, }) => {
54124
54126
  const { customProperties } = entity.field;
54125
54127
  const { setCustomProperties } = entity.action;
54126
54128
  const [isEditing, setIsEditing] = useState(false);
@@ -54205,13 +54207,22 @@ const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, custom
54205
54207
  ],
54206
54208
  };
54207
54209
  try {
54208
- await updateEntity({
54210
+ const updated = await updateEntity({
54209
54211
  baseUrl,
54210
54212
  spaceId,
54211
54213
  entityType,
54212
54214
  entityId,
54213
54215
  body: updatedContactData,
54214
54216
  });
54217
+ const nextProperties = customProperties.map((p) => p.nameKey === nameKey
54218
+ ? {
54219
+ ...p,
54220
+ type: effectiveType,
54221
+ value: finalValue,
54222
+ }
54223
+ : p);
54224
+ setCustomProperties(nextProperties);
54225
+ onEntityUpdated?.(updated);
54215
54226
  }
54216
54227
  finally {
54217
54228
  setIsSaving(false);
@@ -54330,7 +54341,7 @@ const EntityCustomFieldLabel = ({ property, entity, entityType, entityId, custom
54330
54341
  };
54331
54342
 
54332
54343
  const ContactGeneral = (props) => {
54333
- const { dateFormat, entityData, customContactFields, baseUrl, spaceId, t, currentUser } = props;
54344
+ const { dateFormat, entityData, customContactFields, baseUrl, spaceId, t, currentUser, onEntityUpdated } = props;
54334
54345
  const [users, setUsers] = useState([]);
54335
54346
  const [owner, setOwner] = useState(null);
54336
54347
  const [updatedBy, setUpdatedBy] = useState(null);
@@ -54412,9 +54423,9 @@ const ContactGeneral = (props) => {
54412
54423
  };
54413
54424
  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) => ({
54414
54425
  owner: typeof value === 'string' ? value : '',
54415
- }), 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) => ({
54426
+ }), 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) => ({
54416
54427
  birthDate: value,
54417
- }), 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)))] }) }));
54428
+ }), 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)))] }) }));
54418
54429
  };
54419
54430
 
54420
54431
  const useEditBusiness = ({ business, customContactFields, baseUrl, spaceId }) => {
@@ -54597,12 +54608,12 @@ const useEditBusiness = ({ business, customContactFields, baseUrl, spaceId }) =>
54597
54608
  };
54598
54609
  };
54599
54610
 
54600
- const BusinessInfoLabel = ({ title, value, isNotEditable, inputType = 'text', options = [], displayValue, constructUpdateObject, baseUrl, spaceId, businessId, }) => {
54601
- 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 }));
54611
+ const BusinessInfoLabel = ({ title, value, isNotEditable, inputType = 'text', options = [], displayValue, constructUpdateObject, baseUrl, spaceId, businessId, onEntityUpdated, }) => {
54612
+ 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 }));
54602
54613
  };
54603
54614
 
54604
54615
  const BusinessGeneral = (props) => {
54605
- const { entityData, customContactFields, baseUrl, spaceId, t, currentUser } = props;
54616
+ const { entityData, customContactFields, baseUrl, spaceId, t, currentUser, onEntityUpdated } = props;
54606
54617
  const [users, setUsers] = useState([]);
54607
54618
  const [owner, setOwner] = useState(null);
54608
54619
  const [updatedBy, setUpdatedBy] = useState(null);
@@ -54672,7 +54683,7 @@ const BusinessGeneral = (props) => {
54672
54683
  }, [entityData, users, currentUser, baseUrl, spaceId]);
54673
54684
  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) => ({
54674
54685
  owner: typeof value === 'string' ? value : '',
54675
- }), 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)))] }) }));
54686
+ }), 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)))] }) }));
54676
54687
  };
54677
54688
 
54678
54689
  const General = (props) => {
@@ -54685,11 +54696,12 @@ const General = (props) => {
54685
54696
  return normalizedEntityType === 'contact' ? (jsxRuntimeExports.jsx(ContactGeneral, { ...props, entityData: entityData, entityType: "contact" })) : (jsxRuntimeExports.jsx(BusinessGeneral, { ...props, entityData: entityData, entityType: "business" }));
54686
54697
  };
54687
54698
 
54688
- const AddressInformation = ({ entityType, entityData, baseUrl, spaceId, t }) => {
54699
+ const AddressInformation = ({ entityType, entityData, baseUrl, spaceId, t, onEntityUpdated, }) => {
54689
54700
  const commonProps = {
54690
54701
  baseUrl,
54691
54702
  spaceId,
54692
54703
  entityId: String(entityData.id),
54704
+ onEntityUpdated,
54693
54705
  };
54694
54706
  const maybeTitle = t('contactDetails.addressInformation');
54695
54707
  const sectionTitle = maybeTitle === 'contactDetails.addressInformation' ? 'Address Information' : maybeTitle;
@@ -54753,6 +54765,18 @@ const EditContactModal = ({ open, onClose, baseUrl, spaceId, contactId, sx, t, }
54753
54765
  setTagsEditorInitialized(false);
54754
54766
  setIsSavingTags(false);
54755
54767
  }, []);
54768
+ const handleEntityUpdated = useCallback((entity) => {
54769
+ if (!entity || typeof entity !== 'object')
54770
+ return;
54771
+ const hasId = 'id' in entity;
54772
+ if (hasId) {
54773
+ actions.setContactData(entity);
54774
+ return;
54775
+ }
54776
+ if (state.contactData) {
54777
+ actions.setContactData({ ...state.contactData, ...entity });
54778
+ }
54779
+ }, [actions, state.contactData]);
54756
54780
  const image = useImage({
54757
54781
  baseUrl,
54758
54782
  spaceId,
@@ -54761,13 +54785,7 @@ const EditContactModal = ({ open, onClose, baseUrl, spaceId, contactId, sx, t, }
54761
54785
  : undefined,
54762
54786
  entityId: state.contactData ? String(state.contactData.id) : undefined,
54763
54787
  initialImageUrl: state.contactData?.imageUrl,
54764
- onEntityUpdated: (entity) => {
54765
- if (!entity || typeof entity !== 'object')
54766
- return;
54767
- if (!state.contactData)
54768
- return;
54769
- actions.setContactData({ ...state.contactData, ...entity });
54770
- },
54788
+ onEntityUpdated: handleEntityUpdated,
54771
54789
  });
54772
54790
  useEffect(() => {
54773
54791
  if (!open) {
@@ -54858,9 +54876,9 @@ const EditContactModal = ({ open, onClose, baseUrl, spaceId, contactId, sx, t, }
54858
54876
  setView('tags');
54859
54877
  }, onUploadPhoto: image.action.uploadImage, onPhotoFileChange: image.inputAtributes.onChange, photoInputRef: image.inputAtributes.ref, isUploadingPhoto: image.isUploading, onDeletePhoto: image.action.deleteImage, isDeletingPhoto: image.isDeleting }), jsxRuntimeExports.jsxs(Box$2, { sx: { px: 1, pb: 2 }, children: [jsxRuntimeExports.jsx(General, { dateFormat: selectors.userTrii?.regCon_dateFormat || 'MM/dd/yyyy', entityType: selectors.contactType === 'contact' || selectors.contactType === 'business'
54860
54878
  ? selectors.contactType
54861
- : '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'
54879
+ : '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'
54862
54880
  ? selectors.contactType
54863
- : 'contact', entityData: state.contactData, baseUrl: baseUrl, spaceId: spaceId, t: t }), jsxRuntimeExports.jsx(Section, { title: "Contact Information", children: "C" })] })] }) }), jsxRuntimeExports.jsx(Fade$2, { in: view === 'tags', timeout: 200, mountOnEnter: true, unmountOnExit: true, children: jsxRuntimeExports.jsx(Box$2, { 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 }) }) }));
54881
+ : 'contact', entityData: state.contactData, baseUrl: baseUrl, spaceId: spaceId, onEntityUpdated: handleEntityUpdated, t: t }), jsxRuntimeExports.jsx(Section, { title: "Contact Information", children: "C" })] })] }) }), jsxRuntimeExports.jsx(Fade$2, { in: view === 'tags', timeout: 200, mountOnEnter: true, unmountOnExit: true, children: jsxRuntimeExports.jsx(Box$2, { 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 }) }) }));
54864
54882
  };
54865
54883
 
54866
54884
  export { ContactInfoPopup, EditContactModal };