-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(DIA-927): conditionally display email enrollment checkbox during sign-up #11020
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { useCountryCodeQuery } from "__generated__/useCountryCodeQuery.graphql" | ||
import { useClientQuery } from "app/utils/useClientQuery" | ||
import { useEffect, useState } from "react" | ||
import { getIpAddress } from "react-native-device-info" | ||
import { graphql } from "react-relay" | ||
|
||
const USE_COUNTRY_CODE_QUERY = graphql` | ||
query useCountryCodeQuery($ip: String!) { | ||
requestLocation(ip: $ip) { | ||
countryCode | ||
} | ||
} | ||
` | ||
|
||
export const useCountryCode = () => { | ||
const [ip, setIp] = useState("0.0.0.0") | ||
|
||
useEffect(() => { | ||
getIpAddress().then((ip) => { | ||
setIp(ip) | ||
}) | ||
}, []) | ||
|
||
const { data, loading, error } = useClientQuery<useCountryCodeQuery>({ | ||
query: USE_COUNTRY_CODE_QUERY, | ||
variables: { | ||
ip, | ||
}, | ||
cacheConfig: { | ||
networkCacheConfig: { | ||
force: false, | ||
}, | ||
}, | ||
}) | ||
|
||
const countryCode = data?.requestLocation?.countryCode | ||
|
||
const isAutomaticallySubscribed = !!(countryCode && !GDPR_COUNTRY_CODES.includes(countryCode)) | ||
|
||
return { | ||
countryCode, | ||
error, | ||
isAutomaticallySubscribed, | ||
loading, | ||
} | ||
} | ||
|
||
export const GDPR_COUNTRY_CODES = [ | ||
"AT", | ||
"BE", | ||
"BG", | ||
"CY", | ||
"CZ", | ||
"DE", | ||
"DK", | ||
"EE", | ||
"ES", | ||
"FI", | ||
"FR", | ||
"GB", | ||
"GR", | ||
"HR", | ||
"HU", | ||
"IE", | ||
"IT", | ||
"LT", | ||
"LU", | ||
"LV", | ||
"MT", | ||
"NL", | ||
"PL", | ||
"PT", | ||
"RO", | ||
"SE", | ||
"SI", | ||
"SK", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
useAuthNavigation, | ||
useAuthScreen, | ||
} from "app/Scenes/Onboarding/Auth2/hooks/useAuthNavigation" | ||
import { useCountryCode } from "app/Scenes/Onboarding/Auth2/hooks/useCountryCode" | ||
import { useInputAutofocus } from "app/Scenes/Onboarding/Auth2/hooks/useInputAutofocus" | ||
import { OnboardingNavigationStack } from "app/Scenes/Onboarding/Onboarding" | ||
import { EmailSubscriptionCheckbox } from "app/Scenes/Onboarding/OnboardingCreateAccount/EmailSubscriptionCheckbox" | ||
|
@@ -23,13 +24,19 @@ interface SignUpNameStepFormValues { | |
|
||
export const SignUpNameStep: React.FC = () => { | ||
const screen = useAuthScreen() | ||
const { loading, isAutomaticallySubscribed } = useCountryCode() | ||
|
||
// TODO: Show a skeleton loader | ||
if (loading) { | ||
return null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the sort of thing where we should avoid using a skeleton because its so conditional. For most users, this just wont appear and we can probably just have it pop in. But def play with it! might be able to make it nice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. Thanks! |
||
} | ||
|
||
return ( | ||
<Formik<SignUpNameStepFormValues> | ||
initialValues={{ | ||
name: "", | ||
acceptedTerms: false, | ||
agreedToReceiveEmails: false, | ||
agreedToReceiveEmails: isAutomaticallySubscribed, | ||
}} | ||
validationSchema={Yup.object().shape({ | ||
name: Yup.string().trim().required("Full name field is required"), | ||
|
@@ -84,6 +91,7 @@ const SignUpNameStepForm: React.FC = () => { | |
|
||
const navigation = useAuthNavigation() | ||
const parentNavigation = useNavigation<NavigationProp<OnboardingNavigationStack>>() | ||
const { isAutomaticallySubscribed } = useCountryCode() | ||
const { color } = useTheme() | ||
const nameRef = useRef<Input>(null) | ||
|
||
|
@@ -146,10 +154,14 @@ const SignUpNameStepForm: React.FC = () => { | |
error={highlightTerms} | ||
navigation={parentNavigation} | ||
/> | ||
<EmailSubscriptionCheckbox | ||
setChecked={() => setFieldValue("agreedToReceiveEmails", !values.agreedToReceiveEmails)} | ||
checked={values.agreedToReceiveEmails} | ||
/> | ||
{!isAutomaticallySubscribed ? ( | ||
<EmailSubscriptionCheckbox | ||
setChecked={() => setFieldValue("agreedToReceiveEmails", !values.agreedToReceiveEmails)} | ||
checked={values.agreedToReceiveEmails} | ||
/> | ||
) : ( | ||
<Spacer y={2} /> | ||
)} | ||
</Flex> | ||
|
||
<Button | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and simple 👍