11import type { AddDeviceResponse , AddDeviceResponseConfig } from '../../api/types' ;
2+ import { LocationMfaMode } from '../../api/types' ;
23import './style.scss' ;
34import { ZipArchive } from '@shortercode/webzip' ;
45import { 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+
2630const configToFilename = ( item : AddDeviceResponseConfig ) : string =>
27- `${ item . network_name . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .txt ` ;
31+ `${ configToLocationName ( item ) } .conf ` ;
2832
2933type 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