From 0d9d0c2816e72c8e183dd3e11e8a9a5014605994 Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Wed, 9 Feb 2022 10:57:21 +0200 Subject: [PATCH] feat: populate all dropdowns with picklists --- src/components/forms/CreateUnitsForm.js | 42 +++++++++++++++------ src/components/forms/EditUnitsForm.js | 50 +++++++++++++++---------- 2 files changed, 62 insertions(+), 30 deletions(-) diff --git a/src/components/forms/CreateUnitsForm.js b/src/components/forms/CreateUnitsForm.js index 16c13e9e..e1d193f2 100644 --- a/src/components/forms/CreateUnitsForm.js +++ b/src/components/forms/CreateUnitsForm.js @@ -36,10 +36,7 @@ import LabelsRepeater from './LabelsRepeater'; import IssuanceRepeater from './IssuanceRepeater'; import { postNewUnits } from '../../store/actions/climateWarehouseActions'; import { FormattedMessage, useIntl } from 'react-intl'; -import { - correspondingAdjustmentDeclarationValues, - correspondingAdjustmentStatusValues, -} from '../../utils/pick-values'; +import { correspondingAdjustmentDeclarationValues } from '../../utils/pick-values'; const StyledFormContainer = styled('div')` display: flex; @@ -105,6 +102,15 @@ const CreateUnitsForm = withRouter(({ onClose, left, top, width, height }) => { [pickLists], ); + const selectCorrespondingAdjustmentStatusOptions = useMemo( + () => + pickLists.correspondingAdjustmentStatus.map(country => ({ + value: country, + label: country, + })), + [pickLists], + ); + const handleEditUnits = async () => { setErrorMessage({}); const dataToSend = _.cloneDeep(newUnits); @@ -147,7 +153,7 @@ const CreateUnitsForm = withRouter(({ onClose, left, top, width, height }) => { } if (!_.isEmpty(selectedCorrespondingAdjustmentStatus)) { dataToSend.correspondingAdjustmentStatus = - selectedCorrespondingAdjustmentStatus[0].value; + selectedCorrespondingAdjustmentStatus; } await unitsSchema .validate(dataToSend, { abortEarly: false }) @@ -857,13 +863,27 @@ const CreateUnitsForm = withRouter(({ onClose, left, top, width, height }) => { - setSelectedCorrespondingAdjustmentStatus(value) + options={selectCorrespondingAdjustmentStatusOptions} + onChange={selectedOptions => + setSelectedCorrespondingAdjustmentStatus( + selectedOptions[0].value, + ) + } + placeholder={intl.formatMessage({ + id: 'corresponding-adjustment-status', + })} + selected={ + climatewarehouseUnits.correspondingAdjustmentStatus + ? [ + { + label: + climatewarehouseUnits.correspondingAdjustmentStatus, + value: + climatewarehouseUnits.correspondingAdjustmentStatus, + }, + ] + : undefined } - placeholder={`-- ${intl.formatMessage({ - id: 'select', - })} --`} - selected={[ - { - label: - climatewarehouseUnits.correspondingAdjustmentStatus, - value: - climatewarehouseUnits.correspondingAdjustmentStatus, - }, - ]} /> {errorMessageAlert('correspondingAdjustmentStatus')}