diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2023-12-28 10:46:34 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2024-01-05 16:51:02 +0100 |
| commit | 2601bf96f2b6524d5dc5c86c4bddd3e19b4b1988 (patch) | |
| tree | 1c3b604ebc02c4155dd02265f1d356ea620a6a17 /gui/src | |
| parent | 1b97311392a0a5b7f52c813c17ef69740054ffe3 (diff) | |
| download | mullvadvpn-2601bf96f2b6524d5dc5c86c4bddd3e19b4b1988.tar.xz mullvadvpn-2601bf96f2b6524d5dc5c86c4bddd3e19b4b1988.zip | |
Prevent creating custom lists with empty names
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/components/select-location/CustomLists.tsx | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/gui/src/renderer/components/select-location/CustomLists.tsx b/gui/src/renderer/components/select-location/CustomLists.tsx index 7fb66f630e..6799a34867 100644 --- a/gui/src/renderer/components/select-location/CustomLists.tsx +++ b/gui/src/renderer/components/select-location/CustomLists.tsx @@ -52,7 +52,11 @@ const StyledAddListCellButton = styled(StyledCellButton)({ const StyledSideButtonIcon = styled(Cell.Icon)({ padding: '3px', - [`${StyledCellButton}:hover &&, ${StyledAddListCellButton}:hover &&`]: { + [`${StyledCellButton}:disabled &&, ${StyledAddListCellButton}:disabled &&`]: { + backgroundColor: colors.white40, + }, + + [`${StyledCellButton}:not(:disabled):hover &&, ${StyledAddListCellButton}:not(:disabled):hover &&`]: { backgroundColor: colors.white, }, }); @@ -117,6 +121,7 @@ interface AddListFormProps { function AddListForm(props: AddListFormProps) { const [name, setName] = useState(''); + const nameValid = name.trim() !== ''; const [error, setError, unsetError] = useBoolean(); const containerRef = useStyledRef<HTMLDivElement>(); const inputRef = useStyledRef<HTMLInputElement>(); @@ -128,16 +133,18 @@ function AddListForm(props: AddListFormProps) { }, []); const createList = useCallback(async () => { - try { - const result = await props.onCreateList(name); - if (result) { - setError(); + if (nameValid) { + try { + const result = await props.onCreateList(name); + if (result) { + setError(); + } + } catch (e) { + const error = e as Error; + log.error('Failed to create list:', error.message); } - } catch (e) { - const error = e as Error; - log.error('Failed to create list:', error.message); } - }, [name, props.onCreateList]); + }, [name, props.onCreateList, nameValid]); const onBlur = useCallback( (event: React.FocusEvent<HTMLInputElement>) => { @@ -180,6 +187,7 @@ function AddListForm(props: AddListFormProps) { <StyledAddListCellButton $backgroundColor={colors.blue} $backgroundColorHover={colors.blue80} + disabled={!nameValid} onClick={createList}> <StyledSideButtonIcon source="icon-check" tintColor={colors.white60} width={18} /> </StyledAddListCellButton> |
