Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🚧 Add primaryColor and showBranding to SpaceDTO and branding mutations (#2307)

Luke Vella34f9fdd10135
diff --git a/apps/web/src/auth/data.ts b/apps/web/src/auth/data.ts
index 4df6a80b3..cd675304f 100644
--- a/apps/web/src/auth/data.ts
+++ b/apps/web/src/auth/data.ts
@@ -42,14 +42,7 @@ export const getCurrentUserSpace = async () => {
lastSelectedAt: "desc",
},
include: {
- space: {
- select: {
- id: true,
- name: true,
- ownerId: true,
- tier: true,
- },
- },
+ space: true,
},
});
@@ -63,10 +56,7 @@ export const getCurrentUserSpace = async () => {
return {
user,
space: createSpaceDTO({
- id: spaceMember.space.id,
- ownerId: spaceMember.space.ownerId,
- name: spaceMember.space.name,
- tier: spaceMember.space.tier,
+ ...spaceMember.space,
role: spaceMember.role,
}),
};
diff --git a/apps/web/src/features/space/data.ts b/apps/web/src/features/space/data.ts
index 536bcd381..7b455dc92 100644
--- a/apps/web/src/features/space/data.ts
+++ b/apps/web/src/features/space/data.ts
@@ -50,6 +50,8 @@ export function createSpaceDTO(space: {
role: DBSpaceMemberRole;
image?: string | null;
tier: DBSpaceTier;
+ primaryColor?: string | null;
+ showBranding: boolean;
}): SpaceDTO {
return {
id: space.id,
@@ -58,6 +60,8 @@ export function createSpaceDTO(space: {
tier: isSelfHosted ? "pro" : space.tier,
role: fromDBRole(space.role),
image: space.image ?? undefined,
+ primaryColor: space.primaryColor ?? undefined,
+ showBranding: space.showBranding,
};
}
diff --git a/apps/web/src/features/space/types.ts b/apps/web/src/features/space/types.ts
index c889e39f7..f5a21427b 100644
--- a/apps/web/src/features/space/types.ts
+++ b/apps/web/src/features/space/types.ts
@@ -7,4 +7,6 @@ export type SpaceDTO = {
tier: "hobby" | "pro";
role: MemberRole;
image?: string;
+ primaryColor?: string;
+ showBranding: boolean;
};
diff --git a/apps/web/src/trpc/routers/spaces.ts b/apps/web/src/trpc/routers/spaces.ts
index 7abd86d0c..4acf81332 100644
--- a/apps/web/src/trpc/routers/spaces.ts
+++ b/apps/web/src/trpc/routers/spaces.ts
@@ -59,6 +59,8 @@ export const spaces = router({
image: true,
ownerId: true,
tier: true,
+ primaryColor: true,
+ showBranding: true,
},
},
},
@@ -295,6 +297,62 @@ export const spaces = router({
});
}),
+ updatePrimaryColor: spaceProcedure
+ .input(
+ z.object({
+ primaryColor: z
+ .string()
+ .regex(/^#[0-9a-fA-F]{6}$/, "Invalid hex color")
+ .nullable(),
+ }),
+ )
+ .mutation(async ({ ctx, input }) => {
+ const memberAbility = defineAbilityForMember({
+ user: ctx.user,
+ space: ctx.space,
+ });
+
+ if (memberAbility.cannot("update", subject("Space", ctx.space))) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "You do not have permission to update this space",
+ });
+ }
+
+ await prisma.space.update({
+ where: { id: ctx.space.id },
+ data: { primaryColor: input.primaryColor },
+ });
+ }),
+
+ updateShowBranding: spaceProcedure
+ .input(z.object({ showBranding: z.boolean() }))
+ .mutation(async ({ ctx, input }) => {
+ const memberAbility = defineAbilityForMember({
+ user: ctx.user,
+ space: ctx.space,
+ });
+
+ if (memberAbility.cannot("update", subject("Space", ctx.space))) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "You do not have permission to update this space",
+ });
+ }
+
+ if (input.showBranding && ctx.space.tier !== "pro") {
+ throw new TRPCError({
+ code: "PAYMENT_REQUIRED",
+ message: "You need a Pro subscription to enable custom branding",
+ });
+ }
+
+ await prisma.space.update({
+ where: { id: ctx.space.id },
+ data: { showBranding: input.showBranding },
+ });
+ }),
+
inviteMember: spaceProcedure
.input(z.object({ email: z.email(), role: memberRoleSchema }))
.mutation(async ({ ctx, input }) => {