From 906333124713a170e80ce042f27f1faac1e39bd3 Mon Sep 17 00:00:00 2001
From: Ben Allfree
Date: Wed, 26 Nov 2025 08:49:06 -0800
Subject: [PATCH] refactor: update ProfileCard and ProfileEditor to use new
config structure and improve version handling
---
src/components/ProfileCard.tsx | 2 +-
src/components/ProfileEditor.tsx | 59 ++++++++++----------------------
2 files changed, 20 insertions(+), 41 deletions(-)
diff --git a/src/components/ProfileCard.tsx b/src/components/ProfileCard.tsx
index 2b30a51..679b3a1 100644
--- a/src/components/ProfileCard.tsx
+++ b/src/components/ProfileCard.tsx
@@ -45,7 +45,7 @@ export function ProfileCardContent({ profile }: ProfileCardContentProps) {
>
diff --git a/src/components/ProfileEditor.tsx b/src/components/ProfileEditor.tsx
index e27f2a8..6c27778 100644
--- a/src/components/ProfileEditor.tsx
+++ b/src/components/ProfileEditor.tsx
@@ -5,17 +5,19 @@ import { Checkbox } from '@/components/ui/checkbox'
import { Input } from '@/components/ui/input'
import { api } from '../../convex/_generated/api'
import modulesData from '../../convex/modules.json'
-import type { ProfileFields, ProfilesDoc } from '../../convex/schema'
+import type {
+ BuildConfigFields,
+ ProfileFields,
+ ProfilesDoc,
+} from '../../convex/schema'
import { VERSIONS } from '../constants/versions'
import { ModuleToggle } from './ModuleToggle'
// Form values use flattened config for UI, but will be transformed to nested on submit
type ProfileFormValues = Omit<
ProfileFields,
- '_id' | '_creationTime' | 'userId' | 'flashCount' | 'updatedAt' | 'config'
-> & {
- config: Record // Flattened: moduleId -> boolean
-}
+ '_id' | '_creationTime' | 'userId' | 'flashCount' | 'updatedAt'
+>
interface ProfileEditorProps {
initialData?: ProfilesDoc
@@ -30,27 +32,6 @@ export default function ProfileEditor({
}: ProfileEditorProps) {
const upsertProfile = useMutation(api.profiles.upsert)
- // Flatten config for UI: transform config.modulesExcluded to flat object
- const getFlattenedConfig = (
- config: ProfileFields['config'] | undefined
- ): Record => {
- if (!config || !config.modulesExcluded) return {}
- return { ...config.modulesExcluded }
- }
-
- // Transform flat config back to nested structure for database
- const getNestedConfig = (
- flatConfig: Record
- ): ProfileFields['config'] => {
- const modulesExcluded: Record = {}
- for (const [key, value] of Object.entries(flatConfig)) {
- if (value === true) {
- modulesExcluded[key] = true
- }
- }
- return { modulesExcluded }
- }
-
const {
register,
handleSubmit,
@@ -61,21 +42,22 @@ export default function ProfileEditor({
defaultValues: {
name: initialData?.name || '',
description: initialData?.description || '',
- config: getFlattenedConfig(initialData?.config),
- version: initialData?.version || VERSIONS[0],
+ config: {
+ version: VERSIONS[0],
+ modulesExcluded: {},
+ target: '',
+ ...initialData?.config,
+ },
isPublic: initialData?.isPublic ?? true,
},
})
const onSubmit = async (data: ProfileFormValues) => {
- // Transform flattened config back to nested structure
- const nestedConfig = getNestedConfig(data.config)
await upsertProfile({
id: initialData?._id,
name: data.name,
description: data.description,
- config: nestedConfig,
- version: data.version,
+ config: data.config,
isPublic: data.isPublic,
})
onSave()
@@ -107,7 +89,7 @@ export default function ProfileEditor({