mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-21 12:55:09 +00:00
git-subtree-dir: packages/browseros-agent git-subtree-mainline:8f148d0918git-subtree-split:90bd4be300
35 lines
1.1 KiB
TypeScript
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()
|
|
}
|