Skip to content

Commit 96b7a2d

Browse files
committed
fix(enterprise): allow clearing whitelabel fields and guard against empty update result
1 parent 4240b1c commit 96b7a2d

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

apps/sim/app/api/organizations/[id]/whitelabel/route.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ const logger = createLogger('WhitelabelAPI')
1414
const HEX_COLOR_REGEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i
1515

1616
const updateWhitelabelSchema = z.object({
17-
brandName: z.string().trim().max(64, 'Brand name must be 64 characters or fewer').optional(),
17+
brandName: z
18+
.string()
19+
.trim()
20+
.max(64, 'Brand name must be 64 characters or fewer')
21+
.nullable()
22+
.optional(),
1823
logoUrl: z.string().url('Logo URL must be a valid URL').nullable().optional(),
1924
primaryColor: z
2025
.string()
@@ -179,6 +184,10 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
179184
.where(eq(organization.id, organizationId))
180185
.returning({ whitelabelSettings: organization.whitelabelSettings })
181186

187+
if (!updated) {
188+
return NextResponse.json({ error: 'Organization not found' }, { status: 404 })
189+
}
190+
182191
recordAudit({
183192
workspaceId: null,
184193
actorId: session.user.id,

apps/sim/ee/whitelabeling/components/whitelabeling-settings.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import Image from 'next/image'
77
import { Button, Input, Label, Switch } from '@/components/emcn'
88
import { useSession } from '@/lib/auth/auth-client'
99
import { getSubscriptionAccessState } from '@/lib/billing/client/utils'
10-
import type { OrganizationWhitelabelSettings } from '@/lib/branding/types'
1110
import { isBillingEnabled } from '@/lib/core/config/feature-flags'
1211
import { cn } from '@/lib/core/utils/cn'
1312
import { getUserRole } from '@/lib/workspaces/organization/utils'
1413
import { useProfilePictureUpload } from '@/app/workspace/[workspaceId]/settings/hooks/use-profile-picture-upload'
1514
import {
1615
useUpdateWhitelabelSettings,
1716
useWhitelabelSettings,
17+
type WhitelabelSettingsPayload,
1818
} from '@/ee/whitelabeling/hooks/whitelabel'
1919
import { useOrganizations } from '@/hooks/queries/organization'
2020
import { useSubscriptionData } from '@/hooks/queries/subscription'
@@ -168,17 +168,17 @@ export function WhitelabelingSettings() {
168168
}
169169
}
170170

171-
const settings: OrganizationWhitelabelSettings = {
172-
brandName: brandName || undefined,
173-
logoUrl: previewUrl || undefined,
174-
primaryColor: primaryColor || undefined,
175-
primaryHoverColor: primaryHoverColor || undefined,
176-
accentColor: accentColor || undefined,
177-
accentHoverColor: accentHoverColor || undefined,
178-
supportEmail: supportEmail || undefined,
179-
documentationUrl: documentationUrl || undefined,
180-
termsUrl: termsUrl || undefined,
181-
privacyUrl: privacyUrl || undefined,
171+
const settings: WhitelabelSettingsPayload = {
172+
brandName: brandName || null,
173+
logoUrl: previewUrl || null,
174+
primaryColor: primaryColor || null,
175+
primaryHoverColor: primaryHoverColor || null,
176+
accentColor: accentColor || null,
177+
accentHoverColor: accentHoverColor || null,
178+
supportEmail: supportEmail || null,
179+
documentationUrl: documentationUrl || null,
180+
termsUrl: termsUrl || null,
181+
privacyUrl: privacyUrl || null,
182182
hidePoweredBySim,
183183
}
184184

apps/sim/ee/whitelabeling/hooks/whitelabel.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
44
import type { OrganizationWhitelabelSettings } from '@/lib/branding/types'
55
import { organizationKeys } from '@/hooks/queries/organization'
66

7+
/** PUT payload — string fields accept null to clear a previously-set value. */
8+
export type WhitelabelSettingsPayload = {
9+
[K in keyof OrganizationWhitelabelSettings]: OrganizationWhitelabelSettings[K] extends
10+
| string
11+
| undefined
12+
? string | null
13+
: OrganizationWhitelabelSettings[K]
14+
}
15+
716
/**
817
* Query key factories for whitelabel-related queries
918
*/
@@ -41,7 +50,7 @@ export function useWhitelabelSettings(orgId: string | undefined) {
4150

4251
interface UpdateWhitelabelVariables {
4352
orgId: string
44-
settings: OrganizationWhitelabelSettings
53+
settings: WhitelabelSettingsPayload
4554
}
4655

4756
/**

0 commit comments

Comments
 (0)