Skip to content

Commit ab997d1

Browse files
committed
fix displaying configs for mfa locations, fix downloading configs
1 parent a0e6d79 commit ab997d1

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

web/src/shared/api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ export interface AddDeviceResponseConfig {
541541
network_id: number;
542542
network_name: string;
543543
config: string;
544+
location_mfa_mode: LocationMfaModeValue;
544545
}
545546

546547
export interface AddDeviceResponse {

web/src/shared/components/ModalDeviceConfigSection/ModalDeviceConfigSection.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AddDeviceResponse, AddDeviceResponseConfig } from '../../api/types';
2+
import { LocationMfaMode } from '../../api/types';
23
import './style.scss';
34
import { ZipArchive } from '@shortercode/webzip';
45
import { useCallback, useMemo, useState } from 'react';
@@ -23,8 +24,11 @@ const configToOption = (
2324
value: item,
2425
});
2526

27+
const configToLocationName = (item: AddDeviceResponseConfig): string =>
28+
item.network_name.toLowerCase().replaceAll(' ', '-');
29+
2630
const configToFilename = (item: AddDeviceResponseConfig): string =>
27-
`${item.network_name.toLowerCase().replaceAll(' ', '-')}.txt`;
31+
`${configToLocationName(item)}.conf`;
2832

2933
type Props = { data: AddDeviceResponse; privateKey?: string };
3034

@@ -33,9 +37,9 @@ export const ModalDeviceConfigSection = ({ data: response, privateKey }: Props)
3337
const { writeToClipboard } = useClipboard();
3438
const selectOptions = useMemo(
3539
() =>
36-
response.configs.map(
37-
(item): SelectOption<AddDeviceResponseConfig> => configToOption(item),
38-
),
40+
response.configs
41+
.filter((item) => item.location_mfa_mode === LocationMfaMode.Disabled)
42+
.map((item): SelectOption<AddDeviceResponseConfig> => configToOption(item)),
3943
[response.configs],
4044
);
4145
const [selectedOption, setSelected] =
@@ -58,19 +62,23 @@ export const ModalDeviceConfigSection = ({ data: response, privateKey }: Props)
5862
}, [selectedOption, privateKey]);
5963

6064
const handleDownloadSelected = useCallback(() => {
61-
downloadText(clipboardConfig, 'conf');
62-
}, [clipboardConfig]);
65+
if (!selectedOption) return;
66+
downloadText(clipboardConfig, configToLocationName(selectedOption.value), 'conf');
67+
}, [clipboardConfig, selectedOption]);
6368

6469
const handleDownloadAll = useCallback(async () => {
6570
if (!response) return;
71+
const nonMfaConfigs = response.configs.filter(
72+
(c) => c.location_mfa_mode === LocationMfaMode.Disabled,
73+
);
6674
let data: AddDeviceResponseConfig[] = [];
6775
if (isPresent(privateKey)) {
68-
data = response.configs.map((c) => ({
76+
data = nonMfaConfigs.map((c) => ({
6977
...c,
7078
config: c.config.replace('YOUR_PRIVATE_KEY', privateKey as string),
7179
}));
7280
} else {
73-
data = response.configs;
81+
data = nonMfaConfigs;
7482
}
7583
const zip = new ZipArchive();
7684
for (const item of data) {

0 commit comments

Comments
 (0)