-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathOnboardingRegistrationForm.tsx
More file actions
181 lines (167 loc) · 5.49 KB
/
OnboardingRegistrationForm.tsx
File metadata and controls
181 lines (167 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import type { ReactElement } from 'react';
import React, { useEffect } from 'react';
import type { AuthFormProps } from './common';
import { providerMap } from './common';
import OrDivider from './OrDivider';
import { useLogContext } from '../../contexts/LogContext';
import type { AuthTriggersType } from '../../lib/auth';
import { AuthEventNames } from '../../lib/auth';
import type { ButtonProps } from '../buttons/Button';
import { Button, ButtonSize, ButtonVariant } from '../buttons/Button';
import { isIOSNative } from '../../lib/func';
import { MemberAlready } from '../onboarding/MemberAlready';
import SignupDisclaimer from './SignupDisclaimer';
import { FunnelTargetId } from '../../features/onboarding/types/funnelEvents';
interface ClassName {
onboardingSignup?: string;
onboardingForm?: string;
onboardingDivider?: string;
}
interface OnboardingRegistrationFormProps extends AuthFormProps {
onContinueWithEmail?: () => void;
onExistingEmail?: (email: string) => unknown;
onSignup?: (email: string) => unknown;
onProviderClick?: (provider: string, login?: boolean) => unknown;
targetId?: string;
isLoginFlow?: boolean;
logInTitle?: string;
signUpTitle?: string;
trigger: AuthTriggersType;
isReady: boolean;
className?: ClassName;
onboardingSignupButton?: ButtonProps<'button'>;
}
export const isWebView = (): boolean => {
const { userAgent } = navigator;
// Define patterns for detecting in-app browsers and devices
const inAppBrowserPatterns = [
/FBAN|FBAV/i, // Facebook
/Instagram/i, // Instagram
/Twitter/i, // Twitter
/Line/i, // LINE Messenger
/LinkedIn/i, // LinkedIn
/Snapchat/i, // Snapchat
/WhatsApp/i, // WhatsApp
/WeChat/i, // WeChat
/Messenger/i, // Facebook Messenger
/QQ/i, // QQ Browser
/Reddit/i, // Reddit
/Puffin/i, // Puffin Browser
/TikTok/i, // TikTok
/musical.ly/i, // TikTok (older)
/YouTube/i, // YouTube
/Pinterest/i, // Pinterest
/Discord/i, // Discord
/Telegram/i, // Telegram
/Viber/i, // Viber
/Slack/i, // Slack
/Signal/i, // Signal,
/KakaoTalk/i, // KakaoTalk (Popular in South Korea)
/Baidu/i, // Baidu (Popular in China)
];
// Advanced in-app detection (WebView or missing Safari)
const advancedInAppDetection = () => {
const rules = [
'WebView', // Generic WebView detection
'(iPhone|iPod|iPad)(?!.*Safari/)', // iOS WebView without Safari
'Android.*(wv)', // Android WebView
'(AppleWebKit)(?!.*Safari)', // iOS Safari WebView (missing Safari in UA)
];
const regex = new RegExp(`(${rules.join('|')})`, 'ig');
return !!userAgent.match(regex);
};
const isInAppBrowser = inAppBrowserPatterns.some((pattern) =>
pattern.test(userAgent),
);
return isInAppBrowser || advancedInAppDetection();
};
const getSignupProviders = () => {
if (isIOSNative()) {
return [providerMap.google, providerMap.apple];
}
if (isWebView()) {
return [providerMap.github];
}
return [providerMap.google, providerMap.github];
};
export const OnboardingRegistrationForm = ({
isReady,
onContinueWithEmail,
onExistingEmail,
onProviderClick,
targetId,
trigger,
}: OnboardingRegistrationFormProps): ReactElement => {
const { logEvent } = useLogContext();
const trackOpenSignup = () => {
logEvent({
event_name: 'click',
target_type: AuthEventNames.SignUpProvider,
target_id: 'email',
extra: JSON.stringify({ trigger }),
});
};
useEffect(() => {
logEvent({
event_name: AuthEventNames.OpenSignup,
extra: JSON.stringify({ trigger }),
target_id: targetId,
});
// Need to run only once on mount
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<div aria-label="Login/Register options" className="flex flex-col gap-4">
<ul aria-label="Social login buttons" className="flex flex-col gap-4">
{getSignupProviders().map((provider) => (
<li key={provider.value}>
<Button
aria-label={`Continue using ${provider.label}`}
className="w-full"
data-funnel-track={FunnelTargetId.SignupProvider}
icon={provider.icon}
loading={!isReady}
onClick={() => onProviderClick?.(provider.value, false)}
size={ButtonSize.Large}
type="button"
variant={ButtonVariant.Primary}
>
Continue with {provider.label}
</Button>
</li>
))}
</ul>
<OrDivider
className={{
text: 'text-text-tertiary typo-footnote',
}}
label="OR"
/>
<div className="flex flex-col-reverse text-center">
<MemberAlready
onLogin={() => onExistingEmail?.('')}
className={{
container:
'mx-auto mt-6 w-full justify-center border-t border-border-subtlest-tertiary pt-6 text-center text-text-secondary typo-callout',
login: '!text-inherit',
}}
/>
<SignupDisclaimer className="!text-text-tertiary tablet:!typo-footnote" />
<Button
aria-label="Signup using email"
className="mb-8"
data-funnel-track={FunnelTargetId.SignupProvider}
onClick={() => {
trackOpenSignup();
onContinueWithEmail?.();
}}
size={ButtonSize.Large}
variant={ButtonVariant.Float}
>
Continue with email
</Button>
</div>
</div>
);
};
export default OnboardingRegistrationForm;