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: add hubspot component in shared web #5286
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8f8c2da
feat: add hubspot component in shared web
jainpawan21 fe0ce39
fix: cspell issue
jainpawan21 91cad96
fix: user jobtitle update
jainpawan21 c24be3f
feat: role to job title mapping
jainpawan21 01814bd
fix: founder enum value
jainpawan21 a78cc78
Merge branch 'next' into feature/sign-up-question-form-hubspot
jainpawan21 4734248
fix: add color scheme
jainpawan21 4ae7867
fix: Add Vonage to cspell
rifont 565872f
feat: update prod form value
jainpawan21 3966e87
Merge branch 'feature/sign-up-question-form-hubspot' of github.com:no…
jainpawan21 8d5bcf8
fix: change hubspot portal env
jainpawan21 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const HUBSPOT_FORM_IDS = { | ||
SIGN_UP: 'ae2194a3-2b9d-4625-9c64-454187c42e8b', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
apps/web/src/pages/auth/components/HubspotSignupForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import decode from 'jwt-decode'; | ||
import { useMantineColorScheme } from '@mantine/core'; | ||
|
||
import { JobTitleEnum } from '@novu/shared'; | ||
import type { ProductUseCases, IResponseError, ICreateOrganizationDto, IJwtPayload } from '@novu/shared'; | ||
import { HubspotForm } from '@novu/shared-web'; | ||
|
||
import { api } from '../../../api/api.client'; | ||
import { useAuthContext } from '../../../components/providers/AuthProvider'; | ||
import { useVercelIntegration, useVercelParams } from '../../../hooks'; | ||
import { ROUTES } from '../../../constants/routes.enum'; | ||
import { HUBSPOT_FORM_IDS } from '../../../constants/hubspotForms'; | ||
import SetupLoader from './SetupLoader'; | ||
|
||
export function HubspotSignupForm() { | ||
jainpawan21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const [loading, setLoading] = useState<boolean>(); | ||
const navigate = useNavigate(); | ||
const { setToken, token, currentUser } = useAuthContext(); | ||
const { startVercelSetup } = useVercelIntegration(); | ||
const { isFromVercel } = useVercelParams(); | ||
const { colorScheme } = useMantineColorScheme(); | ||
|
||
const { mutateAsync: createOrganizationMutation } = useMutation< | ||
{ _id: string }, | ||
IResponseError, | ||
ICreateOrganizationDto | ||
>((data: ICreateOrganizationDto) => api.post(`/v1/organizations`, data)); | ||
|
||
useEffect(() => { | ||
if (token) { | ||
const userData = decode<IJwtPayload>(token); | ||
|
||
if (userData.environmentId) { | ||
if (isFromVercel) { | ||
startVercelSetup(); | ||
|
||
return; | ||
} | ||
|
||
navigate(ROUTES.HOME); | ||
} | ||
} | ||
}, [token, navigate, isFromVercel, startVercelSetup]); | ||
|
||
async function createOrganization(data: IOrganizationCreateForm) { | ||
const { organizationName, jobTitle, ...rest } = data; | ||
const createDto: ICreateOrganizationDto = { ...rest, name: organizationName, jobTitle }; | ||
const organization = await createOrganizationMutation(createDto); | ||
const organizationResponseToken = await api.post(`/v1/auth/organizations/${organization._id}/switch`, {}); | ||
|
||
setToken(organizationResponseToken); | ||
} | ||
|
||
function jwtHasKey(key: string) { | ||
if (!token) return false; | ||
const jwt = decode<IJwtPayload>(token); | ||
|
||
return jwt && jwt[key]; | ||
} | ||
|
||
const handleCreateOrganization = async (data: IOrganizationCreateForm) => { | ||
if (!data?.organizationName) return; | ||
|
||
setLoading(true); | ||
|
||
if (!jwtHasKey('organizationId')) { | ||
await createOrganization({ ...data }); | ||
} | ||
|
||
setLoading(false); | ||
if (isFromVercel) { | ||
startVercelSetup(); | ||
|
||
return; | ||
} | ||
|
||
navigate(ROUTES.GET_STARTED); | ||
}; | ||
|
||
if (!currentUser || loading) { | ||
return <SetupLoader title="Loading..." />; | ||
} else { | ||
return ( | ||
<HubspotForm | ||
formId={HUBSPOT_FORM_IDS.SIGN_UP} | ||
properties={{ | ||
firstname: currentUser?.firstName as string, | ||
lastname: currentUser?.lastName as string, | ||
email: currentUser?.email as string, | ||
|
||
company: '', | ||
role___onboarding: '', | ||
heard_about_novu: '', | ||
use_case___onboarding: '', | ||
role___onboarding__other_: '', | ||
heard_about_novu__other_: '', | ||
}} | ||
readonlyProperties={['email', 'firstname', 'lastname']} | ||
focussedProperty="company" | ||
onFormSubmitted={($form, values) => { | ||
const submissionValues = values?.submissionValues as unknown as { | ||
company: string; | ||
role___onboarding: string; | ||
}; | ||
|
||
handleCreateOrganization({ | ||
organizationName: submissionValues?.company, | ||
jobTitle: hubspotRoleToJobTitleMapping[submissionValues?.role___onboarding], | ||
}); | ||
}} | ||
colorScheme={colorScheme} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
interface IOrganizationCreateForm { | ||
organizationName: string; | ||
jobTitle: JobTitleEnum; | ||
domain?: string; | ||
productUseCases?: ProductUseCases; | ||
} | ||
|
||
const hubspotRoleToJobTitleMapping: Record<string, JobTitleEnum> = { | ||
'Engineer/developer': JobTitleEnum.ENGINEER, | ||
Product: JobTitleEnum.PRODUCT_MANAGER, | ||
Architect: JobTitleEnum.ARCHITECT, | ||
'Engineering Manager': JobTitleEnum.ENGINEERING_MANAGER, | ||
Designer: JobTitleEnum.DESIGNER, | ||
'CxO/Founder': JobTitleEnum.FOUNDER, | ||
Marketing: JobTitleEnum.MARKETING_MANAGER, | ||
'Other (specify)': JobTitleEnum.OTHER, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 one, I think this is a suitable approach to dealing with local development, it will ensure we serve the Questionnaire form that does not require an internet connection in local.
For the no internet case in Prod, the User would not be able to reach the Novu API to complete the Organization creation anyway, so no further action needed on this path.