summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2024-01-31 11:45:41 +0100
committerOskar Nyberg <oskar@mullvad.net>2024-01-31 11:45:41 +0100
commit91da61996b0f42789983df924f71a7ead8a1af74 (patch)
tree63b30906ab15cd23c0863014b3ac3bd3d0edbc2e
parent16eea5fa0fcb3fb9e4052ce52e97c49e315e0ba4 (diff)
parentfc779b4ddad22658b95b262ff6e04396ebb6a0bc (diff)
downloadmullvadvpn-91da61996b0f42789983df924f71a7ead8a1af74.tar.xz
mullvadvpn-91da61996b0f42789983df924f71a7ead8a1af74.zip
Merge branch 'fix-api-access-method-gui-bugs-des-598'
-rw-r--r--gui/src/renderer/components/EditApiAccessMethod.tsx28
1 files changed, 22 insertions, 6 deletions
diff --git a/gui/src/renderer/components/EditApiAccessMethod.tsx b/gui/src/renderer/components/EditApiAccessMethod.tsx
index 578c8fe31a..c56329214b 100644
--- a/gui/src/renderer/components/EditApiAccessMethod.tsx
+++ b/gui/src/renderer/components/EditApiAccessMethod.tsx
@@ -88,8 +88,8 @@ function AccessMethodForm() {
}
}, [updatedMethod, save, history.pop]);
- const title = getTitle(id !== undefined);
- const subtitle = getSubtitle(id !== undefined);
+ const title = getTitle(id === undefined);
+ const subtitle = getSubtitle(id === undefined);
return (
<BackAction action={history.pop}>
@@ -280,15 +280,31 @@ function AccessMethodFormImpl(props: EditApiAccessMethodImplProps) {
// State for the name input.
const name = useRef(props.method?.name ?? '');
- const updateName = useCallback((value: string) => (name.current = value), []);
+ const method = useRef<AccessMethod | undefined>(props.method);
// When the form makes up a valid method the parent is updated.
- const updateMethod = useCallback((value: AccessMethod) => {
- if (name.current !== '') {
- props.updateMethod({ ...value, name: name.current, enabled: true });
+ const onUpdate = useCallback(() => {
+ if (method.current !== undefined && name.current !== '') {
+ props.updateMethod({ ...method.current, name: name.current, enabled: true });
}
}, []);
+ const updateName = useCallback(
+ (value: string) => {
+ name.current = value;
+ onUpdate();
+ },
+ [onUpdate],
+ );
+
+ const updateMethod = useCallback(
+ (value: AccessMethod) => {
+ method.current = value;
+ onUpdate();
+ },
+ [onUpdate],
+ );
+
return (
<>
<SettingsRow label={messages.gettext('Name')}>