From cdd6dbe8aef0fa565504703f6a482548c1c270c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=9Al=C4=99zak?= Date: Mon, 22 Dec 2025 14:46:58 +0100 Subject: [PATCH 1/2] fix: location traffic toggle --- package.json | 1 + .../LocationCardRoute/LocationCardRoute.tsx | 40 +++++++++++-------- .../MfaMobileApprove/MfaMobileApprove.tsx | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index a8f0d967..e1a51434 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ ] }, "onlyBuiltDependencies": [ + "@parcel/watcher", "@swc/core", "esbuild" ], diff --git a/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx b/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx index fa2c6003..28131926 100644 --- a/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx +++ b/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx @@ -2,12 +2,12 @@ import './style.scss'; import { error } from '@tauri-apps/plugin-log'; import { useMemo } from 'react'; - import { useI18nContext } from '../../../../../../../../i18n/i18n-react'; import { Toggle } from '../../../../../../../../shared/defguard-ui/components/Layout/Toggle/Toggle'; import type { ToggleOption } from '../../../../../../../../shared/defguard-ui/components/Layout/Toggle/types'; import { clientApi } from '../../../../../../clientAPI/clientApi'; import { + ClientConnectionType, ClientTrafficPolicy, type CommonWireguardFields, type DefguardInstance, @@ -36,18 +36,19 @@ export const LocationCardRoute = ({ location, selectedDefguardInstance }: Props) }; const { LL } = useI18nContext(); + const toggleOptions = useMemo(() => { - const res: ToggleOption[] = [ + const res: ToggleOption[] = [ { text: LL.pages.client.pages.instancePage.controls.traffic.predefinedTraffic(), - value: 0, + value: false, disabled: selectedDefguardInstance?.client_traffic_policy === ClientTrafficPolicy.FORCE_ALL_TRAFFIC, }, { text: LL.pages.client.pages.instancePage.controls.traffic.allTraffic(), - value: 1, + value: true, disabled: selectedDefguardInstance?.client_traffic_policy === ClientTrafficPolicy.DISABLE_ALL_TRAFFIC, @@ -56,17 +57,24 @@ export const LocationCardRoute = ({ location, selectedDefguardInstance }: Props) return res; }, [LL.pages, selectedDefguardInstance?.client_traffic_policy]); - let selected: number; - if (selectedDefguardInstance?.client_traffic_policy === ClientTrafficPolicy.NONE) { - selected = Number(location?.route_all_traffic); - } else if ( - selectedDefguardInstance?.client_traffic_policy === - ClientTrafficPolicy.DISABLE_ALL_TRAFFIC - ) { - selected = 0; - } else { - selected = 1; - } + const selected = useMemo((): boolean => { + if (!selectedDefguardInstance || !location) return false; + + // tunnel + if (location.connection_type === ClientConnectionType.TUNNEL) + return location.route_all_traffic; + + // Defguard location + switch (selectedDefguardInstance.client_traffic_policy) { + case ClientTrafficPolicy.DISABLE_ALL_TRAFFIC: + return false; + case ClientTrafficPolicy.FORCE_ALL_TRAFFIC: + return true; + case ClientTrafficPolicy.NONE: + return location.route_all_traffic ?? false; + } + }, [location, selectedDefguardInstance]); + return ( { if (!location?.active) { - handleChange(Boolean(v)); + handleChange(v); } }} /> diff --git a/src/pages/client/pages/ClientInstancePage/components/LocationsList/modals/MFAModal/components/MfaMobileApprove/MfaMobileApprove.tsx b/src/pages/client/pages/ClientInstancePage/components/LocationsList/modals/MFAModal/components/MfaMobileApprove/MfaMobileApprove.tsx index b6670e84..a84da6b1 100644 --- a/src/pages/client/pages/ClientInstancePage/components/LocationsList/modals/MFAModal/components/MfaMobileApprove/MfaMobileApprove.tsx +++ b/src/pages/client/pages/ClientInstancePage/components/LocationsList/modals/MFAModal/components/MfaMobileApprove/MfaMobileApprove.tsx @@ -111,7 +111,7 @@ export const MfaMobileApprove = ({ socket?.close(); // go back to previous step onCancel(); - } + }; return (
From c0dbb4b265bab5daaf60d82dc06c432466ccda2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Tue, 23 Dec 2025 08:55:43 +0100 Subject: [PATCH 2/2] fix conditionals --- .../components/LocationCardRoute/LocationCardRoute.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx b/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx index 28131926..e4214320 100644 --- a/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx +++ b/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardRoute/LocationCardRoute.tsx @@ -58,13 +58,15 @@ export const LocationCardRoute = ({ location, selectedDefguardInstance }: Props) }, [LL.pages, selectedDefguardInstance?.client_traffic_policy]); const selected = useMemo((): boolean => { - if (!selectedDefguardInstance || !location) return false; + // handle undefined location + if (!location) return false; // tunnel if (location.connection_type === ClientConnectionType.TUNNEL) return location.route_all_traffic; // Defguard location + if (!selectedDefguardInstance) return false; switch (selectedDefguardInstance.client_traffic_policy) { case ClientTrafficPolicy.DISABLE_ALL_TRAFFIC: return false;