From fd968bb2b545454e14ca261a56409417e8fe90ca Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 7 Mar 2026 14:05:23 +0000 Subject: [PATCH] Implemented better address handling. --- .../Dashboard/common/AddressDisplay.jsx | 110 ++++++++++++++++++ .../Dashboard/common/ObjectProperty.jsx | 20 ++++ src/database/models/Vendor.js | 48 +------- 3 files changed, 133 insertions(+), 45 deletions(-) create mode 100644 src/components/Dashboard/common/AddressDisplay.jsx diff --git a/src/components/Dashboard/common/AddressDisplay.jsx b/src/components/Dashboard/common/AddressDisplay.jsx new file mode 100644 index 0000000..1d4bf52 --- /dev/null +++ b/src/components/Dashboard/common/AddressDisplay.jsx @@ -0,0 +1,110 @@ +import PropTypes from 'prop-types' +import { Flex, Typography, Input } from 'antd' +import CountryDisplay from './CountryDisplay' +import CountrySelect from './CountrySelect' + +const { Text } = Typography + +const ADDRESS_FIELDS = [ + { key: 'building', label: 'Building' }, + { key: 'addressLine1', label: 'Line 1' }, + { key: 'addressLine2', label: 'Line 2' }, + { key: 'city', label: 'City' }, + { key: 'state', label: 'State' }, + { key: 'postcode', label: 'Postcode' }, + { key: 'country', label: 'Country', isCountry: true } +] + +const AddressDisplay = ({ + value, + isEditing = false, + onChange, + disabled = false +}) => { + const address = value && typeof value === 'object' ? value : {} + const hasAddress = ADDRESS_FIELDS.some( + (f) => address[f.key] != null && address[f.key] !== '' + ) + + const handleFieldChange = (field, fieldValue) => { + if (!onChange) return + onChange({ + ...address, + [field]: fieldValue + }) + } + + if (!isEditing) { + if (!hasAddress) { + return n/a + } + + return ( + + {ADDRESS_FIELDS.map(({ key, label, isCountry }) => { + const fieldValue = address[key] + if (fieldValue == null || fieldValue === '') return null + + return ( + + {isCountry ? ( + + ) : ( + + {fieldValue} + + )} + + ) + })} + + ) + } + + return ( + + {ADDRESS_FIELDS.map(({ key, label, isCountry }) => + isCountry ? ( + + handleFieldChange(key, v)} + disabled={disabled} + style={{ flex: 1 }} + alt={label} + /> + + ) : ( + + handleFieldChange(key, e.target.value)} + disabled={disabled} + style={{ flex: 1 }} + alt={label} + /> + + ) + )} + + ) +} + +AddressDisplay.propTypes = { + value: PropTypes.shape({ + building: PropTypes.string, + addressLine1: PropTypes.string, + addressLine2: PropTypes.string, + city: PropTypes.string, + state: PropTypes.string, + postcode: PropTypes.string, + country: PropTypes.string + }), + isEditing: PropTypes.bool, + onChange: PropTypes.func, + disabled: PropTypes.bool +} + +export default AddressDisplay diff --git a/src/components/Dashboard/common/ObjectProperty.jsx b/src/components/Dashboard/common/ObjectProperty.jsx index 0d8e4d0..8a7992b 100644 --- a/src/components/Dashboard/common/ObjectProperty.jsx +++ b/src/components/Dashboard/common/ObjectProperty.jsx @@ -46,6 +46,7 @@ import DataTree from './DataTree' import FileList from './FileList' import ObjectChildTable from './ObjectChildTable' import MiscId from './MiscId' +import AddressDisplay from './AddressDisplay' import { round } from '../utils/Utils' const { Text } = Typography @@ -521,6 +522,15 @@ const ObjectProperty = ({ ) } } + case 'address': { + return ( + + ) + } case 'operation': { if (value != null) { return @@ -777,6 +787,16 @@ const ObjectProperty = ({ return case 'tags': return + case 'address': + return ( + + ) case 'file': return (