Files
BrowserOS/packages/browseros-agent/apps/agent/lib/onboarding/syncOnboardingProfile.ts
Dani Akash 290ee91a8b Add 'packages/browseros-agent/' from commit '90bd4be3008285bf3825aad3702aff98f872671a'
git-subtree-dir: packages/browseros-agent
git-subtree-mainline: 8f148d0918
git-subtree-split: 90bd4be300
2026-03-13 21:22:09 +05:30

35 lines
1.1 KiB
TypeScript

import { UpdateProfileByUserIdDocument } from '@/entrypoints/app/profile/graphql/profileDocument'
import { execute } from '@/lib/graphql/execute'
import { onboardingProfileStorage } from './onboardingStorage'
function splitName(name: string): { firstName: string; lastName: string } {
const parts = name.trim().split(/\s+/)
return {
firstName: parts[0] ?? '',
lastName: parts.slice(1).join(' '),
}
}
export async function syncOnboardingProfile(userId: string): Promise<void> {
const profile = await onboardingProfileStorage.getValue()
if (!profile) return
const { firstName, lastName } = splitName(profile.name)
const preferences: Record<string, string> = {}
if (profile.role) preferences.role = profile.role
if (profile.company) preferences.company = profile.company
if (profile.description) preferences.description = profile.description
await execute(UpdateProfileByUserIdDocument, {
userId,
patch: {
firstName,
...(lastName ? { lastName } : {}),
preferences,
},
})
await onboardingProfileStorage.removeValue()
}