({
loginFormProps,
onRegister,
isLoginFlow,
onProviderClick,
isProviderLoading,
simplified,
onShowLoginOptions,
isConnectedAccount,
}: AuthSignBackProps)
| 24 | } |
| 25 | |
| 26 | export const AuthSignBack = ({ |
| 27 | loginFormProps, |
| 28 | onRegister, |
| 29 | isLoginFlow, |
| 30 | onProviderClick, |
| 31 | isProviderLoading, |
| 32 | simplified, |
| 33 | onShowLoginOptions, |
| 34 | isConnectedAccount, |
| 35 | }: AuthSignBackProps): ReactElement | null => { |
| 36 | const { signBack, provider, isLoaded } = useSignBack(); |
| 37 | const socialProvider = |
| 38 | provider && provider !== 'password' |
| 39 | ? (provider as SocialProvider) |
| 40 | : undefined; |
| 41 | const providerItem = socialProvider ? providerMap[socialProvider] : undefined; |
| 42 | const isValid = signBack && (provider === 'password' || !!providerItem); |
| 43 | const handleShowLoginOptions = (): void => { |
| 44 | onShowLoginOptions?.(); |
| 45 | }; |
| 46 | const handleRegister = (): void => { |
| 47 | onRegister?.(); |
| 48 | }; |
| 49 | const handleProviderClick = (): void => { |
| 50 | if (!socialProvider || !onProviderClick) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | onProviderClick(socialProvider); |
| 55 | }; |
| 56 | |
| 57 | useEffect(() => { |
| 58 | if (!isLoaded || isValid) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if (isLoginFlow) { |
| 63 | onShowLoginOptions?.(); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | onRegister?.(); |
| 68 | // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM |
| 69 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 70 | }, [isLoaded, isValid]); |
| 71 | |
| 72 | if (!isLoaded || !signBack || !isValid) { |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | if (provider === 'password' && !loginFormProps) { |
| 77 | return null; |
| 78 | } |
| 79 | |
| 80 | const renderAuthAction = () => { |
| 81 | if (provider === 'password') { |
| 82 | if (!loginFormProps) { |
| 83 | return null; |
nothing calls this directly
no test coverage detected