Skip to content

Commit

Permalink
fix(strip-undefined): strip undefined value from referralCode
Browse files Browse the repository at this point in the history
  • Loading branch information
49659410+tx0c committed Dec 19, 2023
1 parent 19c724d commit a6154c1
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/common/utils/oauth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from 'vitest'

import { signupCallbackUrl } from './oauth'

describe('utils/oauth', () => {
it('should get signupCallbackUrl correctly', () => {
expect(signupCallbackUrl('email', 'code')).toEqual('https://undefined/callback/email-signup?email=email&referral=code')
expect(signupCallbackUrl('email')).toEqual('https://undefined/callback/email-signup?email=email')

Check failure on line 8 in src/common/utils/oauth.test.ts

View workflow job for this annotation

GitHub Actions / build

Expected 2 arguments, but got 1.
})
})
9 changes: 6 additions & 3 deletions src/common/utils/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ export const facebookOauthUrl = async (type: OauthType) => {
export const signupCallbackUrl = (email: string, referralCode: string) => {
return `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/callback/${
CALLBACK_PROVIDERS.EmailSignup
}?email=${encodeURIComponent(
email
)}&${REFERRAL_QUERY_REFERRAL_KEY}=${encodeURIComponent(referralCode)}`
}?${new URLSearchParams({
email: encodeURIComponent(email),
...(referralCode
? { [REFERRAL_QUERY_REFERRAL_KEY]: encodeURIComponent(referralCode) }
: null),
}).toString()}`
}

export const signinCallbackUrl = (email: string) => {
Expand Down
9 changes: 8 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/Douban.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useContext } from 'react'
import { FormattedMessage } from 'react-intl'

import { ReactComponent as IconShareDouban } from '@/public/static/icons/16px/share-douban.svg'
import { ReactComponent as IconShareDoubanCircle } from '@/public/static/icons/40px/share-douban-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { analytics, dom } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const Douban = ({
title,
Expand All @@ -14,10 +16,15 @@ const Douban = ({
link: string
circle?: boolean
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_douban'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
9 changes: 8 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/Email.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useContext } from 'react'
import { FormattedMessage } from 'react-intl'

import { ReactComponent as IconShareEmail } from '@/public/static/icons/16px/share-email.svg'
import { ReactComponent as IconShareEmailCircle } from '@/public/static/icons/40px/share-email-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { analytics, dom } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const Email = ({
title,
Expand All @@ -14,10 +16,15 @@ const Email = ({
link: string
circle?: boolean
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_email'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
10 changes: 9 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/Facebook.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useContext } from 'react'

import { ReactComponent as IconShareFacebook } from '@/public/static/icons/16px/share-facebook.svg'
import { ReactComponent as IconShareFacebookCircle } from '@/public/static/icons/40px/share-facebook-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { analytics } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const Facebook = ({
title,
Expand All @@ -12,10 +15,15 @@ const Facebook = ({
link: string
circle?: boolean
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_facebook'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
10 changes: 9 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/LINE.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useContext } from 'react'

import { ReactComponent as IconShareLINE } from '@/public/static/icons/16px/share-line.svg'
import { ReactComponent as IconShareLINECircle } from '@/public/static/icons/40px/share-line-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { analytics } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const LINE = ({
title,
Expand All @@ -12,10 +15,15 @@ const LINE = ({
link: string
circle?: boolean
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_line'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
10 changes: 9 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/Telegram.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useContext } from 'react'

import { ReactComponent as IconShareTelegram } from '@/public/static/icons/16px/share-telegram.svg'
import { ReactComponent as IconShareTelegramCircle } from '@/public/static/icons/40px/share-telegram-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { analytics } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const Telegram = ({
title,
Expand All @@ -12,10 +15,15 @@ const Telegram = ({
link: string
circle?: boolean
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_telegram'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
10 changes: 9 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/Twitter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useContext } from 'react'

import { ReactComponent as IconShareTwitter } from '@/public/static/icons/16px/share-twitter.svg'
import { ReactComponent as IconShareTwitterCircle } from '@/public/static/icons/40px/share-twitter-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { analytics, stripNonEnglishUrl } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const Twitter = ({
title,
Expand All @@ -14,10 +17,15 @@ const Twitter = ({
circle?: boolean
tags?: string[]
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_twitter'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
9 changes: 8 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/Weibo.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useContext } from 'react'
import { FormattedMessage } from 'react-intl'

import { ReactComponent as IconShareWeibo } from '@/public/static/icons/16px/share-weibo.svg'
import { ReactComponent as IconShareWeiboCircle } from '@/public/static/icons/40px/share-weibo-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { dom } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const Weibo = ({
title,
Expand All @@ -14,10 +16,15 @@ const Weibo = ({
link: string
circle?: boolean
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_weibo'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
10 changes: 9 additions & 1 deletion src/components/Dialogs/ShareDialog/Buttons/WhatsApp.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useContext } from 'react'

import { ReactComponent as IconShareWhatsApp } from '@/public/static/icons/16px/share-whatsapp.svg'
import { ReactComponent as IconShareWhatsAppCircle } from '@/public/static/icons/40px/share-whatsapp-circle.svg'
import { REFERRAL_QUERY_REFERRAL_KEY } from '~/common/enums'
import { analytics } from '~/common/utils'
import { TextIcon, withIcon } from '~/components'
import { TextIcon, ViewerContext, withIcon } from '~/components'

const Whatsapp = ({
title,
Expand All @@ -12,10 +15,15 @@ const Whatsapp = ({
link: string
circle?: boolean
}) => {
const viewer = useContext(ViewerContext)

// append utm_source to link
const utm_source = 'share_whatsapp'
const url = new URL(link)
url.searchParams.append('utm_source', utm_source)
if (viewer.userName) {
url.searchParams.append(REFERRAL_QUERY_REFERRAL_KEY, viewer.userName)
}
link = url.toString()

return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/Forms/EmailLoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export const EmailLoginForm: React.FC<FormProps> = ({
email,
passwordOrCode: password,
language: lang,
referralCode,
// referralCode,
...(referralCode ? { referralCode } : null),
},
},
})
Expand Down
7 changes: 6 additions & 1 deletion src/components/Forms/WalletAuthForm/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ const Connect: React.FC<FormProps> = ({
// confirm auth
const { data: loginData } = await walletLogin({
variables: {
input: { ...variables.input, language: lang, referralCode },
input: {
...variables.input,
language: lang,
// referralCode,
...(referralCode ? { referralCode } : null),
},
},
})

Expand Down
2 changes: 1 addition & 1 deletion src/views/Callback/LoginCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const LoginCallback = () => {
email,
passwordOrCode: code,
language: lang,
referralCode,
...(referralCode ? { referralCode } : null),
},
},
})
Expand Down
3 changes: 2 additions & 1 deletion src/views/Callback/SocialCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ const SocialCallback = ({ type }: Props) => {
type,
language: lang,
...input,
referralCode,
// referralCode,
...(referralCode ? { referralCode } : null),
},
},
})
Expand Down

0 comments on commit a6154c1

Please sign in to comment.