Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
]
},
"onlyBuiltDependencies": [
"@parcel/watcher",
"@swc/core",
"esbuild"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -36,18 +36,19 @@ export const LocationCardRoute = ({ location, selectedDefguardInstance }: Props)
};

const { LL } = useI18nContext();

const toggleOptions = useMemo(() => {
const res: ToggleOption<number>[] = [
const res: ToggleOption<boolean>[] = [
{
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,
Expand All @@ -56,17 +57,26 @@ 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 => {
// 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;
case ClientTrafficPolicy.FORCE_ALL_TRAFFIC:
return true;
case ClientTrafficPolicy.NONE:
return location.route_all_traffic ?? false;
}
}, [location, selectedDefguardInstance]);

return (
<Toggle
className="location-traffic-toggle"
Expand All @@ -75,7 +85,7 @@ export const LocationCardRoute = ({ location, selectedDefguardInstance }: Props)
disabled={location?.active}
onChange={(v) => {
if (!location?.active) {
handleChange(Boolean(v));
handleChange(v);
}
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const MfaMobileApprove = ({
socket?.close();
// go back to previous step
onCancel();
}
};

return (
<div id="mobile-approve-mfa">
Expand Down