diff --git a/striker-ui/components/ManageUps/AddUpsInputGroup.tsx b/striker-ui/components/ManageUps/AddUpsInputGroup.tsx index 43e4c749..476d3310 100644 --- a/striker-ui/components/ManageUps/AddUpsInputGroup.tsx +++ b/striker-ui/components/ManageUps/AddUpsInputGroup.tsx @@ -6,13 +6,19 @@ import SelectWithLabel from '../SelectWithLabel'; import Spinner from '../Spinner'; import { BodyText } from '../Text'; +const INPUT_ID_UPS_TYPE_ID = 'add-ups-select-ups-type-id'; + const AddUpsInputGroup: FC = ({ loading: isExternalLoading, + previous = {}, upsTemplate, }) => { - const [inputUpsAgentValue, setInputUpsAgentValue] = useState(''); + const { upsTypeId: previousUpsTypeId = '' } = previous; + + const [inputUpsTypeIdValue, setInputUpsTypeIdValue] = + useState(previousUpsTypeId); - const upsAgentOptions = useMemo( + const upsTypeOptions = useMemo( () => upsTemplate ? Object.entries(upsTemplate).map( @@ -30,22 +36,22 @@ const AddUpsInputGroup: FC = ({ [upsTemplate], ); - const pickUpsAgentElement = useMemo( + const pickUpsTypeElement = useMemo( () => upsTemplate && ( { const newValue = String(rawNewValue); - setInputUpsAgentValue(newValue); + setInputUpsTypeIdValue(newValue); }} - selectItems={upsAgentOptions} + selectItems={upsTypeOptions} selectProps={{ onClearIndicatorClick: () => { - setInputUpsAgentValue(''); + setInputUpsTypeIdValue(''); }, renderValue: (rawValue) => { const upsTypeId = String(rawValue); @@ -54,10 +60,10 @@ const AddUpsInputGroup: FC = ({ return brand; }, }} - value={inputUpsAgentValue} + value={inputUpsTypeIdValue} /> ), - [inputUpsAgentValue, upsAgentOptions, upsTemplate], + [inputUpsTypeIdValue, upsTypeOptions, upsTemplate], ); const content = useMemo( () => @@ -65,14 +71,16 @@ const AddUpsInputGroup: FC = ({ ) : ( - {pickUpsAgentElement} - {inputUpsAgentValue && } + {pickUpsTypeElement} + {inputUpsTypeIdValue && } ), - [inputUpsAgentValue, isExternalLoading, pickUpsAgentElement], + [inputUpsTypeIdValue, isExternalLoading, pickUpsTypeElement, previous], ); return content; }; +export { INPUT_ID_UPS_TYPE_ID }; + export default AddUpsInputGroup; diff --git a/striker-ui/types/AddUpsInputGroup.d.ts b/striker-ui/types/AddUpsInputGroup.d.ts index 03a891ec..76e43636 100644 --- a/striker-ui/types/AddUpsInputGroup.d.ts +++ b/striker-ui/types/AddUpsInputGroup.d.ts @@ -1,5 +1,6 @@ type AddUpsInputGroupOptionalProps = { loading?: boolean; + previous?: CommonUpsInputGroupProps['previous'] & { upsTypeId?: string }; upsTemplate?: APIUpsTemplate; };