From f09375b447aba63cb45c00588dc5ee8ac3e9b071 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Mon, 20 Jan 2025 18:31:58 +0600 Subject: [PATCH] fix: name and label --- .../AuthenticationFlow/EmailLoginForm.tsx | 5 +- .../AuthenticationFlow/GitHubButton.tsx | 6 +-- .../AuthenticationFlow/GoogleButton.tsx | 5 +- .../AuthenticationFlow/LinkedInButton.tsx | 5 +- .../TriggerVerifyAccount.tsx | 6 +-- src/components/ShareIcons/ShareIcons.tsx | 48 +++++++++++-------- src/lib/jwt.ts | 1 + src/pages/[roadmapId]/index.astro | 2 + .../[bestPracticeId]/index.astro | 2 + 9 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/components/AuthenticationFlow/EmailLoginForm.tsx b/src/components/AuthenticationFlow/EmailLoginForm.tsx index a348921e8..2907433fb 100644 --- a/src/components/AuthenticationFlow/EmailLoginForm.tsx +++ b/src/components/AuthenticationFlow/EmailLoginForm.tsx @@ -2,8 +2,7 @@ import Cookies from 'js-cookie'; import type { FormEvent } from 'react'; import { useId, useState } from 'react'; import { httpPost } from '../../lib/http'; -import { TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; -import { FIRST_LOGIN_TAG } from './TriggerVerifyAccount'; +import { FIRST_LOGIN_PARAM, setAuthToken } from '../../lib/jwt'; type EmailLoginFormProps = { isDisabled?: boolean; @@ -40,7 +39,7 @@ export function EmailLoginForm(props: EmailLoginFormProps) { const currentLocation = window.location.href; const url = new URL(currentLocation, window.location.origin); if (response?.isNewUser) { - url.searchParams.set(FIRST_LOGIN_TAG, '1'); + url.searchParams.set(FIRST_LOGIN_PARAM, '1'); } window.location.href = url.toString(); return; diff --git a/src/components/AuthenticationFlow/GitHubButton.tsx b/src/components/AuthenticationFlow/GitHubButton.tsx index 2daf89a20..49fb7dd76 100644 --- a/src/components/AuthenticationFlow/GitHubButton.tsx +++ b/src/components/AuthenticationFlow/GitHubButton.tsx @@ -1,11 +1,9 @@ import { useEffect, useState } from 'react'; import { GitHubIcon } from '../ReactIcons/GitHubIcon.tsx'; -import Cookies from 'js-cookie'; -import { TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; +import { FIRST_LOGIN_PARAM, setAuthToken } from '../../lib/jwt'; import { httpGet } from '../../lib/http'; import { Spinner } from '../ReactIcons/Spinner.tsx'; import { triggerUtmRegistration } from '../../lib/browser.ts'; -import { FIRST_LOGIN_TAG } from './TriggerVerifyAccount.tsx'; type GitHubButtonProps = { isDisabled?: boolean; @@ -78,7 +76,7 @@ export function GitHubButton(props: GitHubButtonProps) { const url = new URL(redirectUrl, window.location.origin); if (response?.isNewUser) { - url.searchParams.set(FIRST_LOGIN_TAG, '1'); + url.searchParams.set(FIRST_LOGIN_PARAM, '1'); } window.location.href = url.toString(); }) diff --git a/src/components/AuthenticationFlow/GoogleButton.tsx b/src/components/AuthenticationFlow/GoogleButton.tsx index a3ef581d4..7f742b887 100644 --- a/src/components/AuthenticationFlow/GoogleButton.tsx +++ b/src/components/AuthenticationFlow/GoogleButton.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; import Cookies from 'js-cookie'; -import { TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; +import { FIRST_LOGIN_PARAM, TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; import { httpGet } from '../../lib/http'; import { Spinner } from '../ReactIcons/Spinner.tsx'; import { GoogleIcon } from '../ReactIcons/GoogleIcon.tsx'; @@ -8,7 +8,6 @@ import { getStoredUtmParams, triggerUtmRegistration, } from '../../lib/browser.ts'; -import { FIRST_LOGIN_TAG } from './TriggerVerifyAccount.tsx'; type GoogleButtonProps = { isDisabled?: boolean; @@ -82,7 +81,7 @@ export function GoogleButton(props: GoogleButtonProps) { const url = new URL(redirectUrl, window.location.origin); if (response?.isNewUser) { - url.searchParams.set(FIRST_LOGIN_TAG, '1'); + url.searchParams.set(FIRST_LOGIN_PARAM, '1'); } window.location.href = url.toString(); }) diff --git a/src/components/AuthenticationFlow/LinkedInButton.tsx b/src/components/AuthenticationFlow/LinkedInButton.tsx index 956cc573a..1bbda2f7c 100644 --- a/src/components/AuthenticationFlow/LinkedInButton.tsx +++ b/src/components/AuthenticationFlow/LinkedInButton.tsx @@ -1,11 +1,10 @@ import { useEffect, useState } from 'react'; import Cookies from 'js-cookie'; -import { TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; +import { FIRST_LOGIN_PARAM, TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; import { httpGet } from '../../lib/http'; import { Spinner } from '../ReactIcons/Spinner.tsx'; import { LinkedInIcon } from '../ReactIcons/LinkedInIcon.tsx'; import { triggerUtmRegistration } from '../../lib/browser.ts'; -import { FIRST_LOGIN_TAG } from './TriggerVerifyAccount.tsx'; type LinkedInButtonProps = { isDisabled?: boolean; @@ -77,7 +76,7 @@ export function LinkedInButton(props: LinkedInButtonProps) { const url = new URL(redirectUrl, window.location.origin); if (response?.isNewUser) { - url.searchParams.set(FIRST_LOGIN_TAG, '1'); + url.searchParams.set(FIRST_LOGIN_PARAM, '1'); } window.location.href = url.toString(); }) diff --git a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx index 87627a42d..2524645f6 100644 --- a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx +++ b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx @@ -1,13 +1,11 @@ import { useEffect, useState } from 'react'; import Cookies from 'js-cookie'; import { httpPost } from '../../lib/http'; -import { TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; +import { FIRST_LOGIN_PARAM, TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; import { Spinner } from '../ReactIcons/Spinner'; import { ErrorIcon2 } from '../ReactIcons/ErrorIcon2'; import { triggerUtmRegistration } from '../../lib/browser.ts'; -export const FIRST_LOGIN_TAG = 'fl' as const; - export function TriggerVerifyAccount() { const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(''); @@ -35,7 +33,7 @@ export function TriggerVerifyAccount() { const url = new URL('/', window.location.origin); if (response?.isNewUser) { - url.searchParams.set(FIRST_LOGIN_TAG, '1'); + url.searchParams.set(FIRST_LOGIN_PARAM, '1'); } window.location.href = url.toString(); }) diff --git a/src/components/ShareIcons/ShareIcons.tsx b/src/components/ShareIcons/ShareIcons.tsx index 09ce80589..edf161df7 100644 --- a/src/components/ShareIcons/ShareIcons.tsx +++ b/src/components/ShareIcons/ShareIcons.tsx @@ -6,12 +6,14 @@ import { RedditIcon } from '../ReactIcons/RedditIcon'; import { TwitterIcon } from '../ReactIcons/TwitterIcon'; type ShareIconsProps = { + resourceId: string; + resourceType: string; pageUrl: string; description: string; }; export function ShareIcons(props: ShareIconsProps) { - const { pageUrl, description } = props; + const { pageUrl, description, resourceType, resourceId } = props; const shareIconsRef = useRef(null); @@ -73,26 +75,30 @@ export function ShareIcons(props: ShareIconsProps) { ref={shareIconsRef} >
- {icons.map((icon, index) => ( - { - window.fireEvent({ - category: 'RoadmapShareLink', - action: 'Roadmap Share Link Clicked', - label: icon.url, - }); - }} - > - {icon.icon} - - ))} + {icons.map((icon, index) => { + const host = new URL(icon.url).host; + + return ( + { + window.fireEvent({ + category: 'RoadmapShareLink', + action: `Share Roadmap / ${resourceType} / ${resourceId} / ${host}`, + label: icon.url, + }); + }} + > + {icon.icon} + + ); + })}
); diff --git a/src/lib/jwt.ts b/src/lib/jwt.ts index 1d3aaa0af..f7cd3a77b 100644 --- a/src/lib/jwt.ts +++ b/src/lib/jwt.ts @@ -3,6 +3,7 @@ import Cookies from 'js-cookie'; import type { AllowedOnboardingStatus } from '../api/user'; export const TOKEN_COOKIE_NAME = '__roadmapsh_jt__'; +export const FIRST_LOGIN_PARAM = 'fl' as const; export type TokenPayload = { id: string; diff --git a/src/pages/[roadmapId]/index.astro b/src/pages/[roadmapId]/index.astro index 779e89430..ddc79a19d 100644 --- a/src/pages/[roadmapId]/index.astro +++ b/src/pages/[roadmapId]/index.astro @@ -134,6 +134,8 @@ const projects = await getProjectsByRoadmapId(roadmapId);