Skip to content

Commit 1e883e4

Browse files
committed
fix(media-tab): improve validation and error handling for brand kit flow
1 parent 0e113d2 commit 1e883e4

File tree

7 files changed

+21
-11
lines changed

7 files changed

+21
-11
lines changed

apps/pro-web/app/api/organizations/[id]/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export async function PATCH(
6868
}
6969

7070
// Validate brandKit if provided
71-
if (body.brandKit !== undefined && typeof body.brandKit !== 'object') {
71+
if (
72+
body.brandKit !== undefined &&
73+
(typeof body.brandKit !== 'object' || body.brandKit === null)
74+
) {
7275
return NextResponse.json(
7376
{ error: 'Brand Kit must be an object' },
7477
{ status: 422 },

apps/pro-web/components/routes/workspace/media-tab/ui/brand-kit/brand-kit-dialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export function BrandKitDialog({ open, onOpenChange }: BrandKitDialogProps) {
1919

2020
const subtitle = useMemo(() => {
2121
if (currentView === 'wizard') {
22-
return activeOrganization
23-
? `${activeOrganization}' Logo & Style`
24-
: 'Logo & Style'
22+
if (!activeOrganization) return 'Logo & Style'
23+
const endsWithS = activeOrganization.endsWith('s')
24+
return `${activeOrganization}${endsWithS ? "'" : "'s"} Logo & Style`
2525
}
2626
return 'Brand Kit'
2727
}, [currentView, activeOrganization])

apps/pro-web/components/routes/workspace/media-tab/ui/brand-kit/wizard/steps/checkpoint-step.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export function CheckpointStep({ next, close }: WizardStepProps) {
3535
throw new Error('Palette is required')
3636
}
3737

38+
if (!selectedFonts || selectedFonts.length === 0) {
39+
throw new Error('At least one font must be selected')
40+
}
41+
3842
return {
3943
vibes: selectedVibes,
4044
fonts: {
@@ -153,7 +157,8 @@ export function CheckpointStep({ next, close }: WizardStepProps) {
153157
className="bg-accent text-accent-foreground hover:bg-accent hover:text-accent-foreground hover:opacity-90 px-3 py-1 text-xs font-normal whitespace-nowrap"
154158
>
155159
<span className="font-bold">
156-
{activeOrganization || 'Organization'}'s Vibe:
160+
{activeOrganization || 'Organization'}
161+
{activeOrganization?.endsWith('s') ? "'" : "'s"} Vibe:
157162
</span>
158163
<span className="ml-1">{vibeLabel}</span>
159164
</Badge>

apps/pro-web/components/routes/workspace/media-tab/ui/brand-kit/wizard/steps/fonts-step.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export function FontsStep({ next, prev }: WizardStepProps) {
284284
{/* Header */}
285285
<div className="space-y-2 mb-6">
286286
<h2 className="text-lg sm:text-xl font-semibold leading-snug">
287-
Which font family you look for?
287+
Which font family are you looking for?
288288
</h2>
289289
<p className="text-sm text-muted-foreground max-w-2xl leading-snug">
290290
Headlines show personality; body text should be effortless to

apps/pro-web/components/routes/workspace/media-tab/ui/brand-kit/wizard/steps/vibe-step.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const vibes: Vibe[] = [
3535
},
3636
{
3737
name: 'Bold',
38-
description: 'Loud & campaing-ready',
38+
description: 'Loud & campaign-ready',
3939
colors: ['#E32A27', '#020202', '#FEFEFE', '#1845F5'],
4040
},
4141
{

apps/pro-web/lib/hooks/use-workspace-media.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export function WorkspaceMediaProvider({ children }: { children: ReactNode }) {
381381
// Invalidate and refetch - merge will prioritize IDB data (most recent updatedAt)
382382
const userId = session?.user?.id || 'anonymous'
383383
queryClient.invalidateQueries({
384-
queryKey: ['workspace', userId, 'structure'],
384+
queryKey: workspaceKeys.structure(userId),
385385
})
386386
},
387387
onError: (error) => {

apps/pro-web/lib/queries/use-workspace-structure.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,19 @@ export function useWorkspaceStructure(
239239

240240
// Merge organizations and their data (IDB/Cache might be ahead of server)
241241
if (sourceToMerge.organizationList && sourceToMerge.organizationData) {
242-
const existingOrgNames = new Set(finalStructure.organizationList)
242+
const existingOrgIds = new Set(
243+
finalStructure.organizationData.map((org) => org.id),
244+
)
243245
const orgDataMap = new Map(
244246
finalStructure.organizationData.map((org) => [org.id, org]),
245247
)
246248

247249
for (const orgData of sourceToMerge.organizationData) {
248-
if (!existingOrgNames.has(orgData.name)) {
250+
if (!existingOrgIds.has(orgData.id)) {
249251
// New organization - add it
250252
finalStructure.organizationList.push(orgData.name)
251253
finalStructure.organizationData.push(orgData)
252-
existingOrgNames.add(orgData.name)
254+
existingOrgIds.add(orgData.id)
253255
} else {
254256
// Existing organization - update its data (especially brandKit)
255257
const existingOrg = orgDataMap.get(orgData.id)

0 commit comments

Comments
 (0)