Skip to content

Commit

Permalink
O3-2495 Add required attributes to address hierarchy fields (#846)
Browse files Browse the repository at this point in the history
* O3-2495 Add required attributes to address hierarchy fields

* (fix) fix broken unit test

---------

Co-authored-by: Donald Kibet <[email protected]>
  • Loading branch information
CynthiaKamau and donaldkibet authored Oct 14, 2023
1 parent b4e5b07 commit af7f7b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ export const AddressComponent: React.FC = () => {
if (!addressTemplate?.lines) {
return [];
}

const allFields = addressTemplate?.lines?.flat();
const fields = allFields?.filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN');

return fields.map(({ displayText, codeName }) => ({
id: codeName,
name: codeName,
label: displayText,
}));
const allRequiredFields = Object.fromEntries(addressTemplate?.requiredElements?.map((curr) => [curr, curr]) || []);
return fields.map(({ displayText, codeName }) => {
return {
id: codeName,
name: codeName,
label: displayText,
required: Boolean(allRequiredFields[codeName]),
};
});
}, [addressTemplate]);

const { t } = useTranslation();
Expand Down Expand Up @@ -83,6 +87,7 @@ export const AddressComponent: React.FC = () => {
labelText={t(attributes.label)}
id={attributes.name}
selected={selected}
required={attributes.required}
/>
))}
</AddressComponentContainer>
Expand Down Expand Up @@ -123,6 +128,7 @@ export const AddressComponent: React.FC = () => {
labelText={t(attributes.label)}
id={attributes.name}
selected={selected}
required={attributes.required}
/>
))
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface AddressComboBoxProps {
name: string;
value: string;
label: string;
required?: boolean;
};
}

Expand All @@ -36,6 +37,7 @@ const AddressComboBox: React.FC<AddressComboBoxProps> = ({ attribute }) => {
const [field, meta, { setValue }] = useField(`address.${attribute.name}`);
const { fetchEntriesForField, searchString, updateChildElements } = useAddressEntryFetchConfig(attribute.name);
const { entries } = useAddressEntries(fetchEntriesForField, searchString);
const label = t(attribute.label) + (attribute?.required ? '' : ` (${t('optional', 'optional')})`);

const handleInputChange = useCallback(
(newValue) => {
Expand All @@ -62,7 +64,8 @@ const AddressComboBox: React.FC<AddressComboBoxProps> = ({ attribute }) => {
fieldProps={{
...field,
id: attribute.name,
labelText: `${t(attribute.label)} (${t('optional', 'optional')})`,
labelText: label,
required: attribute?.required,
}}
handleInputChange={handleInputChange}
/>
Expand Down

0 comments on commit af7f7b6

Please sign in to comment.