Wizard: Remove redundant code, fix addItem
Removed redundant code and updated `addItem` to check for duplicate arguments in both required and non-required list.
This commit is contained in:
parent
1b21852518
commit
6a29f7f344
2 changed files with 8 additions and 12 deletions
|
|
@ -50,19 +50,19 @@ const ChippingInput = ({
|
|||
};
|
||||
|
||||
const addItem = (value: string) => {
|
||||
if (validator(value) && !list?.includes(value)) {
|
||||
dispatch(addAction(value));
|
||||
setInputValue('');
|
||||
setErrorText('');
|
||||
}
|
||||
|
||||
if (list?.includes(value)) {
|
||||
if (list?.includes(value) || requiredList?.includes(value)) {
|
||||
setErrorText(`${item} already exists.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validator(value)) {
|
||||
setErrorText('Invalid format.');
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(addAction(value));
|
||||
setInputValue('');
|
||||
setErrorText('');
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent, value: string) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue