@@ -12,11 +12,14 @@ import { SignInSocialButtons } from './SignInSocialButtons';
1212import { useResetPasswordFactor } from './useResetPasswordFactor' ;
1313import { withHavingTrouble } from './withHavingTrouble' ;
1414
15+ type AlternativeMethodsMode = 'forgot' | 'pwned' | 'default' ;
16+
1517export type AlternativeMethodsProps = {
1618 onBackLinkClick : React . MouseEventHandler | undefined ;
1719 onFactorSelected : ( factor : SignInFactor ) => void ;
1820 currentFactor : SignInFactor | undefined | null ;
1921 asForgotPassword ?: boolean ;
22+ mode ?: AlternativeMethodsMode ;
2023} ;
2124
2225export type AlternativeMethodListProps = AlternativeMethodsProps & { onHavingTroubleClick : React . MouseEventHandler } ;
@@ -28,45 +31,48 @@ export const AlternativeMethods = (props: AlternativeMethodsProps) => {
2831} ;
2932
3033const AlternativeMethodsList = ( props : AlternativeMethodListProps ) => {
31- const { onBackLinkClick, onHavingTroubleClick, onFactorSelected, asForgotPassword = false } = props ;
34+ const { onBackLinkClick, onHavingTroubleClick, onFactorSelected, mode = 'default' } = props ;
3235 const card = useCardState ( ) ;
3336 const resetPasswordFactor = useResetPasswordFactor ( ) ;
3437 const { firstPartyFactors, hasAnyStrategy } = useAlternativeStrategies ( {
3538 filterOutFactor : props ?. currentFactor ,
3639 } ) ;
3740
41+ const flowPart = determineFlowPart ( mode ) ;
42+ const cardTitleKey = determineTitle ( mode ) ;
43+ const isReset = determineIsReset ( mode ) ;
44+
3845 return (
39- < Flow . Part part = { asForgotPassword ? 'forgotPasswordMethods' : 'alternativeMethods' } >
46+ < Flow . Part part = { flowPart } >
4047 < Card >
4148 < CardAlert > { card . error } </ CardAlert >
4249 < Header . Root >
4350 { onBackLinkClick && < Header . BackLink onClick = { onBackLinkClick } /> }
44- < Header . Title
45- localizationKey = { localizationKeys (
46- asForgotPassword ? 'signIn.forgotPasswordAlternativeMethods.title' : 'signIn.alternativeMethods.title' ,
47- ) }
48- />
51+ < Header . Title localizationKey = { cardTitleKey } />
4952 </ Header . Root >
5053 { /*TODO: extract main in its own component */ }
5154 < Flex
5255 direction = 'col'
5356 elementDescriptor = { descriptors . main }
5457 gap = { 6 }
5558 >
56- { asForgotPassword && resetPasswordFactor && (
59+ { isReset && resetPasswordFactor && (
5760 < ArrowBlockButton
5861 leftIcon = { getButtonIcon ( resetPasswordFactor ) }
5962 textLocalizationKey = { getButtonLabel ( resetPasswordFactor ) }
6063 elementDescriptor = { descriptors . alternativeMethodsBlockButton }
6164 textElementDescriptor = { descriptors . alternativeMethodsBlockButtonText }
6265 arrowElementDescriptor = { descriptors . alternativeMethodsBlockButtonArrow }
6366 isDisabled = { card . isLoading }
64- onClick = { ( ) => onFactorSelected ( resetPasswordFactor ) }
67+ onClick = { ( ) => {
68+ card . setError ( undefined ) ;
69+ onFactorSelected ( resetPasswordFactor ) ;
70+ } }
6571 />
6672 ) }
6773 { hasAnyStrategy && (
6874 < >
69- { asForgotPassword && (
75+ { isReset && (
7076 < Text
7177 localizationKey = { localizationKeys (
7278 'signIn.forgotPasswordAlternativeMethods.label__alternativeMethods' ,
@@ -91,7 +97,10 @@ const AlternativeMethodsList = (props: AlternativeMethodListProps) => {
9197 arrowElementDescriptor = { descriptors . alternativeMethodsBlockButtonArrow }
9298 key = { i }
9399 isDisabled = { card . isLoading }
94- onClick = { ( ) => onFactorSelected ( factor ) }
100+ onClick = { ( ) => {
101+ card . setError ( undefined ) ;
102+ onFactorSelected ( factor ) ;
103+ } }
95104 />
96105 ) ) }
97106 </ Flex >
@@ -149,3 +158,35 @@ export function getButtonIcon(factor: SignInFactor) {
149158
150159 return icons [ factor . strategy as keyof typeof icons ] ;
151160}
161+
162+ function determineFlowPart ( mode : AlternativeMethodsMode ) {
163+ switch ( mode ) {
164+ case 'forgot' :
165+ return 'forgotPasswordMethods' ;
166+ case 'pwned' :
167+ return 'passwordPwnedMethods' ;
168+ default :
169+ return 'alternativeMethods' ;
170+ }
171+ }
172+
173+ function determineTitle ( mode : AlternativeMethodsMode ) : LocalizationKey {
174+ switch ( mode ) {
175+ case 'forgot' :
176+ return localizationKeys ( 'signIn.forgotPasswordAlternativeMethods.title' ) ;
177+ case 'pwned' :
178+ return localizationKeys ( 'signIn.passwordPwned.title' ) ;
179+ default :
180+ return localizationKeys ( 'signIn.alternativeMethods.title' ) ;
181+ }
182+ }
183+
184+ function determineIsReset ( mode : AlternativeMethodsMode ) : boolean {
185+ switch ( mode ) {
186+ case 'forgot' :
187+ case 'pwned' :
188+ return true ;
189+ default :
190+ return false ;
191+ }
192+ }
0 commit comments