-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:thisyahlen-deriv/deriv-app into t…
…hisyahlen/WALL-2622/close_on_escape_key_by_default
- Loading branch information
Showing
15 changed files
with
1,295 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/cfd/src/features/Containers/cfd-password-modal/cfd-create-password-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { TCFDPasswordFormReusedProps, TCFDPasswordFormValues, TOnSubmitPassword } from './types'; | ||
import ChangePasswordConfirmation from '../../../Containers/cfd-change-password-confirmation'; | ||
import { CreatePassword } from './create-password'; | ||
import { CFD_PLATFORMS } from '../../../Helpers/cfd-config'; | ||
|
||
import { FormikHelpers } from 'formik'; | ||
import { MultiStep } from '@deriv/components'; | ||
|
||
type TCFDCreatePasswordFormProps = TCFDPasswordFormReusedProps & { | ||
has_mt5_account: boolean; | ||
submitPassword: TOnSubmitPassword; | ||
is_real_financial_stp: boolean; | ||
}; | ||
|
||
type TMultiStepRefProps = { | ||
goNextStep: () => void; | ||
goPrevStep: () => void; | ||
}; | ||
|
||
export const CFDCreatePasswordForm = ({ | ||
has_mt5_account, | ||
platform, | ||
error_message, | ||
validatePassword, | ||
submitPassword, | ||
is_real_financial_stp, | ||
}: TCFDCreatePasswordFormProps) => { | ||
const multi_step_ref = React.useRef<TMultiStepRefProps>(); | ||
const [password, setPassword] = React.useState(''); | ||
|
||
const onSubmit: TOnSubmitPassword = (values, actions) => { | ||
if (platform === CFD_PLATFORMS.MT5 && has_mt5_account) { | ||
setPassword(values.password); | ||
multi_step_ref.current?.goNextStep(); | ||
} else { | ||
submitPassword(values, actions); | ||
} | ||
}; | ||
|
||
const steps = [ | ||
{ | ||
component: ( | ||
<CreatePassword | ||
password={password} | ||
platform={platform} | ||
error_message={error_message} | ||
validatePassword={validatePassword} | ||
onSubmit={onSubmit} | ||
is_real_financial_stp={is_real_financial_stp} | ||
/> | ||
), | ||
}, | ||
{ | ||
component: ( | ||
<ChangePasswordConfirmation | ||
className='cfd-password-modal__change-password-confirmation' | ||
platform={platform} | ||
onConfirm={(_values: TCFDPasswordFormValues, actions: FormikHelpers<TCFDPasswordFormValues>) => | ||
submitPassword({ password }, actions) | ||
} | ||
onCancel={() => multi_step_ref.current?.goPrevStep()} | ||
/> | ||
), | ||
}, | ||
]; | ||
|
||
return <MultiStep ref={multi_step_ref} steps={steps} />; | ||
}; |
Oops, something went wrong.