Fix: Cleanup unused onboarding FE code (#4645)
This commit is contained in:
@@ -1,104 +1,30 @@
|
||||
import { useApolloClient } from '@vue/apollo-composable'
|
||||
import { useMixpanel } from '~~/lib/core/composables/mp'
|
||||
import { UnsupportedEnvironmentError } from '~~/lib/core/errors/base'
|
||||
import type {
|
||||
OnboardingPlan,
|
||||
OnboardingRole,
|
||||
OnboardingSource,
|
||||
OnboardingState
|
||||
} from '@speckle/shared'
|
||||
import type { OnboardingState } from '@speckle/shared'
|
||||
import { useActiveUser } from '~~/lib/auth/composables/activeUser'
|
||||
import { OnboardingError } from '~~/lib/auth/errors/errors'
|
||||
import { finishOnboardingMutation } from '~~/lib/auth/graphql/mutations'
|
||||
import {
|
||||
convertThrowIntoFetchResult,
|
||||
getFirstErrorMessage,
|
||||
updateCacheByFilter
|
||||
} from '~~/lib/common/helpers/graphql'
|
||||
import { graphql } from '~~/lib/common/generated/gql'
|
||||
import { ToastNotificationType, useGlobalToast } from '~~/lib/common/composables/toast'
|
||||
import { useNavigateToHome } from '~~/lib/common/helpers/route'
|
||||
import { projectsDashboardQuery } from '~~/lib/projects/graphql/queries'
|
||||
|
||||
const ONBOARDING_PROP_ROLE = 'onboarding_v1_role'
|
||||
|
||||
export const FIRST_MODEL_NAME = 'base design'
|
||||
export const SECOND_MODEL_NAME = 'building wrapper'
|
||||
import { convertThrowIntoFetchResult } from '~~/lib/common/helpers/graphql'
|
||||
|
||||
export const useProcessOnboarding = () => {
|
||||
const mixpanel = useMixpanel()
|
||||
const { distinctId, activeUser } = useActiveUser()
|
||||
const { activeUser } = useActiveUser()
|
||||
const apollo = useApolloClient().client
|
||||
const { triggerNotification } = useGlobalToast()
|
||||
const goHome = useNavigateToHome()
|
||||
|
||||
const setMixpanelSegments = (segments: Partial<OnboardingState>) => {
|
||||
mixpanel.people.set(segments)
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the server-specified onboarding project for the (newly) logged in user.
|
||||
* Marks the current user as having completed the onboarding.
|
||||
*/
|
||||
const createOnboardingProject = async () => {
|
||||
const createOnboardingProjectMutation = graphql(`
|
||||
mutation CreateOnboardingProject {
|
||||
projectMutations {
|
||||
createForOnboarding {
|
||||
...ProjectPageProject
|
||||
...ProjectDashboardItem
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
const { data } = await apollo
|
||||
.mutate({
|
||||
mutation: createOnboardingProjectMutation,
|
||||
update: (cache, { data }) => {
|
||||
if (!data?.projectMutations.createForOnboarding.id) return
|
||||
|
||||
const newProjectData = data.projectMutations.createForOnboarding
|
||||
|
||||
// Update User.projects
|
||||
updateCacheByFilter(
|
||||
cache,
|
||||
{ query: { query: projectsDashboardQuery } },
|
||||
(cacheData) => {
|
||||
if (!cacheData.activeUser?.projects) return
|
||||
const newItems = [...cacheData.activeUser.projects.items, newProjectData]
|
||||
return {
|
||||
...cacheData,
|
||||
activeUser: {
|
||||
...cacheData.activeUser,
|
||||
projects: {
|
||||
...cacheData.activeUser.projects,
|
||||
items: newItems,
|
||||
totalCount: (cacheData.activeUser.projects.totalCount || 0) + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
.catch(convertThrowIntoFetchResult)
|
||||
|
||||
const newId = data?.projectMutations.createForOnboarding.id
|
||||
return {
|
||||
projectId: newId,
|
||||
project: data?.projectMutations.createForOnboarding
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the current user as having completed the onboarding - we're using this as a flag to
|
||||
* know that we've set up the sample project once. Also updates their Mailchimp tags.
|
||||
*/
|
||||
const setUserOnboardingComplete = async (onboardingData?: {
|
||||
role?: OnboardingRole
|
||||
plans?: OnboardingPlan[]
|
||||
source?: OnboardingSource
|
||||
}) => {
|
||||
const setUserOnboardingComplete = async (onboardingData?: OnboardingState) => {
|
||||
const user = activeUser.value
|
||||
|
||||
if (import.meta.server)
|
||||
throw new UnsupportedEnvironmentError("Can't process onboarding during SSR")
|
||||
|
||||
if (!user) throw new OnboardingError('Attempting to onboard unidentified user')
|
||||
|
||||
mixpanel.people.set_once({
|
||||
@@ -128,56 +54,8 @@ export const useProcessOnboarding = () => {
|
||||
.catch(convertThrowIntoFetchResult)
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
* @param state
|
||||
* @param goToDashboard
|
||||
*/
|
||||
const finishOnboarding = async (state: OnboardingState, goToDashboard = true) => {
|
||||
const user = activeUser.value
|
||||
|
||||
if (import.meta.server)
|
||||
throw new UnsupportedEnvironmentError("Can't process onboarding during SSR")
|
||||
|
||||
if (!distinctId.value || !user)
|
||||
throw new OnboardingError('Attempting to onboard unidentified user')
|
||||
|
||||
// Send data to mixpanel
|
||||
mixpanel.people.set_once(ONBOARDING_PROP_ROLE, state.role || null)
|
||||
|
||||
// Mark onboarding as finished
|
||||
const { data, errors } = await apollo
|
||||
.mutate({
|
||||
mutation: finishOnboardingMutation,
|
||||
update: (cache, { data }) => {
|
||||
if (!data?.activeUserMutations.finishOnboarding) return
|
||||
|
||||
// Mark onboarding as finished in the cache
|
||||
cache.modify({
|
||||
id: cache.identify(user),
|
||||
fields: {
|
||||
isOnboardingFinished: () => true
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(convertThrowIntoFetchResult)
|
||||
|
||||
if (data?.activeUserMutations.finishOnboarding) {
|
||||
if (goToDashboard) goHome()
|
||||
} else {
|
||||
const errMsg = getFirstErrorMessage(errors)
|
||||
triggerNotification({
|
||||
type: ToastNotificationType.Danger,
|
||||
title: errMsg
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
setMixpanelSegments,
|
||||
createOnboardingProject,
|
||||
setUserOnboardingComplete,
|
||||
finishOnboarding
|
||||
setUserOnboardingComplete
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,6 @@ type Documents = {
|
||||
"\n fragment WorkspaceWizardStepRegion_ServerInfo on ServerInfo {\n multiRegion {\n regions {\n id\n ...SettingsWorkspacesRegionsSelect_ServerRegionItem\n }\n }\n }\n": typeof types.WorkspaceWizardStepRegion_ServerInfoFragmentDoc,
|
||||
"\n query ActiveUserMainMetadata {\n activeUser {\n id\n email\n emails {\n id\n email\n verified\n }\n company\n bio\n name\n role\n avatar\n isOnboardingFinished\n createdAt\n verified\n notificationPreferences\n versions(limit: 0) {\n totalCount\n }\n }\n }\n": typeof types.ActiveUserMainMetadataDocument,
|
||||
"\n query ActiveUserProjectsToMove($filter: UserProjectsFilter) {\n activeUser {\n id\n projects(filter: $filter) {\n totalCount\n }\n }\n }\n": typeof types.ActiveUserProjectsToMoveDocument,
|
||||
"\n mutation CreateOnboardingProject {\n projectMutations {\n createForOnboarding {\n ...ProjectPageProject\n ...ProjectDashboardItem\n }\n }\n }\n ": typeof types.CreateOnboardingProjectDocument,
|
||||
"\n fragment FullPermissionCheckResult on PermissionCheckResult {\n authorized\n code\n message\n payload\n }\n": typeof types.FullPermissionCheckResultFragmentDoc,
|
||||
"\n mutation FinishOnboarding($input: OnboardingCompletionInput) {\n activeUserMutations {\n finishOnboarding(input: $input)\n }\n }\n": typeof types.FinishOnboardingDocument,
|
||||
"\n mutation RequestVerificationByEmail($email: String!) {\n requestVerificationByEmail(email: $email)\n }\n": typeof types.RequestVerificationByEmailDocument,
|
||||
@@ -564,7 +563,6 @@ const documents: Documents = {
|
||||
"\n fragment WorkspaceWizardStepRegion_ServerInfo on ServerInfo {\n multiRegion {\n regions {\n id\n ...SettingsWorkspacesRegionsSelect_ServerRegionItem\n }\n }\n }\n": types.WorkspaceWizardStepRegion_ServerInfoFragmentDoc,
|
||||
"\n query ActiveUserMainMetadata {\n activeUser {\n id\n email\n emails {\n id\n email\n verified\n }\n company\n bio\n name\n role\n avatar\n isOnboardingFinished\n createdAt\n verified\n notificationPreferences\n versions(limit: 0) {\n totalCount\n }\n }\n }\n": types.ActiveUserMainMetadataDocument,
|
||||
"\n query ActiveUserProjectsToMove($filter: UserProjectsFilter) {\n activeUser {\n id\n projects(filter: $filter) {\n totalCount\n }\n }\n }\n": types.ActiveUserProjectsToMoveDocument,
|
||||
"\n mutation CreateOnboardingProject {\n projectMutations {\n createForOnboarding {\n ...ProjectPageProject\n ...ProjectDashboardItem\n }\n }\n }\n ": types.CreateOnboardingProjectDocument,
|
||||
"\n fragment FullPermissionCheckResult on PermissionCheckResult {\n authorized\n code\n message\n payload\n }\n": types.FullPermissionCheckResultFragmentDoc,
|
||||
"\n mutation FinishOnboarding($input: OnboardingCompletionInput) {\n activeUserMutations {\n finishOnboarding(input: $input)\n }\n }\n": types.FinishOnboardingDocument,
|
||||
"\n mutation RequestVerificationByEmail($email: String!) {\n requestVerificationByEmail(email: $email)\n }\n": types.RequestVerificationByEmailDocument,
|
||||
@@ -1404,10 +1402,6 @@ export function graphql(source: "\n query ActiveUserMainMetadata {\n activeU
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n query ActiveUserProjectsToMove($filter: UserProjectsFilter) {\n activeUser {\n id\n projects(filter: $filter) {\n totalCount\n }\n }\n }\n"): (typeof documents)["\n query ActiveUserProjectsToMove($filter: UserProjectsFilter) {\n activeUser {\n id\n projects(filter: $filter) {\n totalCount\n }\n }\n }\n"];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n mutation CreateOnboardingProject {\n projectMutations {\n createForOnboarding {\n ...ProjectPageProject\n ...ProjectDashboardItem\n }\n }\n }\n "): (typeof documents)["\n mutation CreateOnboardingProject {\n projectMutations {\n createForOnboarding {\n ...ProjectPageProject\n ...ProjectDashboardItem\n }\n }\n }\n "];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user