import { CustomField, CustomFieldType } from '@wix/bex-core'; import { Text, TextProps, Layout, Cell, Box, Heading, TextButton, } from '@wix/design-system'; import React from 'react'; import { useWixPatternsContainer } from '@wix/bex-core/react'; import { observer } from 'mobx-react-lite'; import { FileCardList } from '../FileCard/FileCardList'; import { getDateWithoutTimezone } from '../../utils/datesUtil'; interface CustomFieldsViewWidgetSectionProps { customFields: CustomField[]; fieldValues: Record; namespace: string; title?: string; } const _CustomFieldsViewWidgetSection = ({ customFields, fieldValues, namespace, title, }: CustomFieldsViewWidgetSectionProps) => { const container = useWixPatternsContainer(); const { translate: t, dateFormatters } = container; const valueWrapper = (value: any, props: TextProps) => { if (typeof value === 'string' && !/\s/.test(value)) { // if there are no space symbols we apply ellipsis (e.g. for links, emails, etc.) return ( {value} ); } if (typeof value !== 'string' && React.isValidElement(value)) { return value; } return {value}; }; const getViewValue = ( value: any, type: CustomFieldType, valueDataHook: string, ) => { const textProps: TextProps = { dataHook: valueDataHook, size: 'small', secondary: true, }; // It is relevant only to app sections. User fields that are null/undefined will be filtered before and won't be displayed if (value === undefined || value === null) { return valueWrapper('-', textProps); } let newValue = value; switch (type) { case 'dropdown': { newValue = value; break; } case 'multiSelect': { newValue = value.join(', '); break; } case 'files': { const files = Array.isArray(value) ? value : [value]; return ; } case 'date': newValue = dateFormatters.medium.format(getDateWithoutTimezone(value)); break; case 'dateTime': newValue = dateFormatters.mediumTime.format(new Date(value)); break; case 'checkbox': newValue = value ? t('cairo.customFields.booleanValue.true') : t('cairo.customFields.booleanValue.false'); break; case 'url': newValue = ( {value} ); break; default: break; } return valueWrapper(newValue, textProps); }; return ( {title && ( {title} )} {customFields.map((field) => ( ))} ); }; export const CustomFieldsViewWidgetSection = observer( _CustomFieldsViewWidgetSection, ); const CustomFieldCell = ({ field, value, labelDataHook, }: { field: CustomField; value: JSX.Element; labelDataHook: string; }) => { return ( {field.label || field.id}: {value} ); };