Skip to content
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

Fixed missing utmSource on YPP signup #4548

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/atlas/src/providers/ypp/ypp.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type YppStoreState = {
* 'state' param passed to Google auth URL
*/
ytStateParam: string | null
utmSource: string | null
yppModalOpenName: YppModalStep
shouldContinueYppFlowAfterLogin: boolean
shouldContinueYppFlowAfterCreatingChannel: boolean
Expand All @@ -22,6 +23,7 @@ type YppStoreActions = {
* sets 'state' param passed to Google auth URL
*/
setYtStateParam: (authState: string | null) => void
setUtmSource: (utmSource: string | null) => void
setYppModalOpenName: (modal: YppModalStep) => void
setShouldContinueYppFlowAfterLogin: (shouldContinueYppFlow: boolean) => void
setShouldContinueYppFlowAfterCreatingChannel: (shouldContinueYppFlow: boolean) => void
Expand All @@ -34,6 +36,7 @@ export const useYppStore = createStore<YppStoreState, YppStoreActions>(
referrerId: null,
selectedChannelId: null,
ytStateParam: null,
utmSource: null,
yppModalOpenName: null,
shouldContinueYppFlowAfterLogin: false,
shouldContinueYppFlowAfterCreatingChannel: false,
Expand All @@ -55,6 +58,11 @@ export const useYppStore = createStore<YppStoreState, YppStoreActions>(
state.ytStateParam = authState
})
},
setUtmSource: (utmSource) => {
set((state) => {
state.utmSource = utmSource
})
},
setYppModalOpenName: (modal) => {
set((state) => {
state.yppModalOpenName = modal
Expand All @@ -80,7 +88,7 @@ export const useYppStore = createStore<YppStoreState, YppStoreActions>(
{
persist: {
key: 'ypp',
whitelist: ['referrerId', 'ytStateParam'],
whitelist: ['referrerId', 'ytStateParam', 'utmSource'],
version: 0,
migrate: (oldState) => oldState,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const DEFAULT_LANGUAGE = atlasConfig.derived.popularLanguagesSelectValues[0].val
export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSyncedChannels }) => {
const { memberId, refetchUserMemberships, setActiveChannel, channelId, isLoggedIn } = useUser()
const [searchParams] = useSearchParams()
const [utmSource, setUtmSource] = useState<string | null>(null)
const navigate = useNavigate()
const [isSubmitting, setIsSubmitting] = useState(false)
const createdChannelId = useRef<string | null>(null)
Expand All @@ -98,7 +97,8 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
const {
referrerId,
ytResponseData,
actions: { setYtResponseData },
utmSource,
actions: { setYtResponseData, setUtmSource },
} = useYppStore((store) => store, shallow)
const setReferrerId = useYppStore((store) => store.actions.setReferrerId)
const setShouldContinueYppFlowAfterLogin = useYppStore((store) => store.actions.setShouldContinueYppFlowAfterLogin)
Expand Down Expand Up @@ -155,7 +155,7 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
if (searchParams.get('utm_source')) {
setUtmSource(searchParams.get('utm_source'))
}
}, [searchParams])
}, [searchParams, setUtmSource])

useEffect(() => {
contentRef.current?.scrollTo({ top: 0 })
Expand Down