Skip to content

Commit

Permalink
Merge pull request #4089 from thematters/feat/email-sign-up-referral
Browse files Browse the repository at this point in the history
fix(referral): fix referral via email signup
  • Loading branch information
robertu7 authored Dec 14, 2023
2 parents 7c74c93 + 73d91eb commit 8110b3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/common/utils/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
OAUTH_SESSSION_STORAGE_OAUTH_TYPE,
OAUTH_TYPE,
PATHS,
REFERRAL_QUERY_REFERRAL_KEY,
} from '~/common/enums'

export const toReadableScope = ({
Expand Down Expand Up @@ -96,10 +97,12 @@ export const facebookOauthUrl = async (type: OauthType) => {
return url
}

export const signupCallbackUrl = (email: string) => {
export const signupCallbackUrl = (email: string, referralCode: string) => {
return `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/callback/${
CALLBACK_PROVIDERS.EmailSignup
}?email=${encodeURIComponent(email)}`
}?email=${encodeURIComponent(
email
)}&${REFERRAL_QUERY_REFERRAL_KEY}=${encodeURIComponent(referralCode)}`
}

export const signinCallbackUrl = (email: string) => {
Expand Down
16 changes: 14 additions & 2 deletions src/components/Forms/EmailSignUpForm/Init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import _pickBy from 'lodash/pickBy'
import { useContext, useRef, useState } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'

import { ERROR_CODES } from '~/common/enums'
import {
ERROR_CODES,
REFERRAL_QUERY_REFERRAL_KEY,
REFERRAL_STORAGE_REFERRAL_CODE,
} from '~/common/enums'
import {
parseFormSubmitErrors,
signupCallbackUrl,
storage,
validateEmail,
} from '~/common/utils'
import { WalletType } from '~/common/utils'
Expand All @@ -26,6 +31,7 @@ import {
// TURNSTILE_DEFAULT_SCRIPT_ID,
TurnstileInstance,
useMutation,
useRoute,
ViewerContext,
} from '~/components'
import SEND_CODE from '~/components/GQL/mutations/sendCode'
Expand Down Expand Up @@ -79,6 +85,12 @@ const Init: React.FC<FormProps> = ({
}
)
const intl = useIntl()
const { getQuery } = useRoute()
const referralCode =
getQuery(REFERRAL_QUERY_REFERRAL_KEY) ||
storage.get(REFERRAL_STORAGE_REFERRAL_CODE)?.referralCode ||
undefined

const {
values,
errors,
Expand All @@ -99,7 +111,7 @@ const Init: React.FC<FormProps> = ({
}),
onSubmit: async ({ email }, { setFieldError, setSubmitting }) => {
try {
const redirectUrl = signupCallbackUrl(email)
const redirectUrl = signupCallbackUrl(email, referralCode)
await sendCode({
variables: {
input: {
Expand Down

0 comments on commit 8110b3e

Please sign in to comment.