2023-07-07 12:30:07 +08:00
import { Button } from "antd" ;
import i18next from "i18next" ;
import React , { useState } from "react" ;
import * as MfaBackend from "../../backend/MfaBackend" ;
2024-11-29 19:50:10 +08:00
export function MfaEnableForm ( { user , mfaType , secret , recoveryCodes , dest , countryCode , onSuccess , onFail } ) {
2023-07-07 12:30:07 +08:00
const [ loading , setLoading ] = useState ( false ) ;
const requestEnableMfa = ( ) => {
const data = {
mfaType ,
2024-11-29 19:50:10 +08:00
secret ,
dest ,
countryCode ,
2023-07-07 12:30:07 +08:00
... user ,
} ;
2025-01-21 22:56:02 +08:00
data [ "recoveryCodes" ] = recoveryCodes [ 0 ] ;
2023-07-07 12:30:07 +08:00
setLoading ( true ) ;
MfaBackend . MfaSetupEnable ( data ) . then ( res => {
if ( res . status === "ok" ) {
onSuccess ( res ) ;
} else {
onFail ( res ) ;
}
}
) . finally ( ( ) => {
setLoading ( false ) ;
} ) ;
} ;
return (
< div style = { { width : "400px" } } >
< p > { i18next . t ( "mfa:Please save this recovery code. Once your device cannot provide an authentication code, you can reset mfa authentication by this recovery code" ) } < / p >
< br / >
< code style = { { fontStyle : "solid" } } > { recoveryCodes [ 0 ] } < / c o d e >
< Button style = { { marginTop : 24 } } loading = { loading } onClick = { ( ) => {
requestEnableMfa ( ) ;
} } block type = "primary" >
{ i18next . t ( "general:Enable" ) }
< / B u t t o n >
< / d i v >
) ;
}
export default MfaEnableForm ;