Skip to content

Commit

Permalink
feat: populate all dropdowns with picklists
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstefanequilobe committed Feb 9, 2022
1 parent 4c9373f commit 1bcbad3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
29 changes: 22 additions & 7 deletions src/components/forms/CreateUnitsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { FormattedMessage, useIntl } from 'react-intl';
import {
correspondingAdjustmentDeclarationValues,
correspondingAdjustmentStatusValues,
unitStatusValues,
} from '../../utils/pick-values';

const StyledFormContainer = styled('div')`
Expand Down Expand Up @@ -88,6 +87,15 @@ const CreateUnitsForm = withRouter(({ onClose, left, top, width, height }) => {
});
const { pickLists } = useSelector(store => store.climateWarehouse);

const selectUnitStatusOptions = useMemo(
() =>
pickLists.unitStatus.map(country => ({
value: country,
label: country,
})),
[pickLists],
);

const selectUnitTypeOptions = useMemo(
() =>
pickLists.unitType.map(country => ({
Expand Down Expand Up @@ -128,7 +136,7 @@ const CreateUnitsForm = withRouter(({ onClose, left, top, width, height }) => {
dataToSend.unitType = unitType;
}
if (!_.isEmpty(unitStatus)) {
dataToSend.unitStatus = unitStatus[0].value;
dataToSend.unitStatus = unitStatus;
}
if (!_.isEmpty(selectedCorrespondingAdjustmentDeclaration)) {
dataToSend.correspondingAdjustmentDeclaration =
Expand Down Expand Up @@ -703,11 +711,18 @@ const CreateUnitsForm = withRouter(({ onClose, left, top, width, height }) => {
<Select
size={SelectSizeEnum.large}
type={SelectTypeEnum.basic}
options={unitStatusValues}
onChange={value => setUnitStatus(value)}
placeholder={`-- ${intl.formatMessage({
id: 'select',
})} --`}
options={selectUnitStatusOptions}
selected={
unitStatus
? [{ label: unitStatus, value: unitStatus }]
: undefined
}
onChange={selectedOptions =>
setUnitStatus(selectedOptions[0].value)
}
placeholder={intl.formatMessage({
id: 'unit-status',
})}
/>
</InputContainer>
{errorMessage?.unitStatus && (
Expand Down
40 changes: 27 additions & 13 deletions src/components/forms/EditUnitsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { FormattedMessage, useIntl } from 'react-intl';
import {
correspondingAdjustmentDeclarationValues,
correspondingAdjustmentStatusValues,
unitStatusValues,
} from '../../utils/pick-values';

const EditUnitsForm = ({ onClose }) => {
Expand Down Expand Up @@ -76,6 +75,15 @@ const EditUnitsForm = ({ onClose }) => {
[pickLists],
);

const selectUnitStatusOptions = useMemo(
() =>
pickLists.unitStatus.map(country => ({
value: country,
label: country,
})),
[pickLists],
);

const handleTabChange = (event, newValue) => {
setTabValue(newValue);
};
Expand Down Expand Up @@ -173,7 +181,7 @@ const EditUnitsForm = ({ onClose }) => {
dataToSend.unitType = unitType;
}
if (!_.isEmpty(unitStatus)) {
dataToSend.unitStatus = unitStatus[0].value;
dataToSend.unitStatus = unitStatus;
}
if (!_.isEmpty(year)) {
dataToSend.vintageYear = year;
Expand Down Expand Up @@ -687,17 +695,23 @@ const EditUnitsForm = ({ onClose }) => {
<Select
size={SelectSizeEnum.large}
type={SelectTypeEnum.basic}
options={unitStatusValues}
onChange={value => setUnitStatus(value)}
placeholder={`-- ${intl.formatMessage({
id: 'select',
})} --`}
selected={[
{
label: climatewarehouseUnits.unitStatus,
value: climatewarehouseUnits.unitStatus,
},
]}
options={selectUnitStatusOptions}
onChange={selectedOptions =>
setUnitStatus(selectedOptions[0].value)
}
placeholder={intl.formatMessage({
id: 'unit-status',
})}
selected={
climatewarehouseUnits.unitStatus
? [
{
label: climatewarehouseUnits.unitStatus,
value: climatewarehouseUnits.unitStatus,
},
]
: undefined
}
/>
</InputContainer>
{errorMessageAlert('unitStatus')}
Expand Down

0 comments on commit 1bcbad3

Please sign in to comment.