fix(striker-ui): export input id and include previous value in AddUpsInputGroup

main
Tsu-ba-me 2 years ago committed by digimer
parent 130d70078d
commit f97463f2c4
  1. 32
      striker-ui/components/ManageUps/AddUpsInputGroup.tsx
  2. 1
      striker-ui/types/AddUpsInputGroup.d.ts

@ -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<AddUpsInputGroupProps> = ({
loading: isExternalLoading,
previous = {},
upsTemplate,
}) => {
const [inputUpsAgentValue, setInputUpsAgentValue] = useState<string>('');
const { upsTypeId: previousUpsTypeId = '' } = previous;
const [inputUpsTypeIdValue, setInputUpsTypeIdValue] =
useState<string>(previousUpsTypeId);
const upsAgentOptions = useMemo<SelectItem[]>(
const upsTypeOptions = useMemo<SelectItem[]>(
() =>
upsTemplate
? Object.entries(upsTemplate).map<SelectItem>(
@ -30,22 +36,22 @@ const AddUpsInputGroup: FC<AddUpsInputGroupProps> = ({
[upsTemplate],
);
const pickUpsAgentElement = useMemo(
const pickUpsTypeElement = useMemo(
() =>
upsTemplate && (
<SelectWithLabel
formControlProps={{ sx: { marginTop: '.3em' } }}
id="add-ups-select-agent"
id={INPUT_ID_UPS_TYPE_ID}
label="UPS type"
onChange={({ target: { value: rawNewValue } }) => {
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<AddUpsInputGroupProps> = ({
return brand;
},
}}
value={inputUpsAgentValue}
value={inputUpsTypeIdValue}
/>
),
[inputUpsAgentValue, upsAgentOptions, upsTemplate],
[inputUpsTypeIdValue, upsTypeOptions, upsTemplate],
);
const content = useMemo<ReactElement>(
() =>
@ -65,14 +71,16 @@ const AddUpsInputGroup: FC<AddUpsInputGroupProps> = ({
<Spinner />
) : (
<FlexBox>
{pickUpsAgentElement}
{inputUpsAgentValue && <CommonUpsInputGroup />}
{pickUpsTypeElement}
{inputUpsTypeIdValue && <CommonUpsInputGroup previous={previous} />}
</FlexBox>
),
[inputUpsAgentValue, isExternalLoading, pickUpsAgentElement],
[inputUpsTypeIdValue, isExternalLoading, pickUpsTypeElement, previous],
);
return content;
};
export { INPUT_ID_UPS_TYPE_ID };
export default AddUpsInputGroup;

@ -1,5 +1,6 @@
type AddUpsInputGroupOptionalProps = {
loading?: boolean;
previous?: CommonUpsInputGroupProps['previous'] & { upsTypeId?: string };
upsTemplate?: APIUpsTemplate;
};

Loading…
Cancel
Save