-
-
Notifications
You must be signed in to change notification settings - Fork 506
✨ Add option to enable custom branding #2321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| "use client"; | ||
|
|
||
| import { usePostHog } from "@rallly/posthog/client"; | ||
| import { Button } from "@rallly/ui/button"; | ||
| import { ColorPicker, parseColor } from "@rallly/ui/color-picker"; | ||
| import { Field, FieldGroup, FieldLabel } from "@rallly/ui/field"; | ||
| import { Switch } from "@rallly/ui/switch"; | ||
| import React from "react"; | ||
| import { | ||
| PageSection, | ||
| PageSectionContent, | ||
| PageSectionDescription, | ||
| PageSectionHeader, | ||
| PageSectionTitle, | ||
| } from "@/app/components/page-layout"; | ||
| import { ProBadge } from "@/components/pro-badge"; | ||
| import { useBilling } from "@/features/billing/client"; | ||
| import { DEFAULT_PRIMARY_COLOR } from "@/features/branding/constants"; | ||
| import { useSpace } from "@/features/space/client"; | ||
| import { Trans } from "@/i18n/client"; | ||
| import { useToastProgress } from "@/lib/use-toast-progress"; | ||
| import { trpc } from "@/trpc/client"; | ||
|
|
||
| export function CustomBrandingSection({ | ||
| disabled = false, | ||
| }: { | ||
| disabled?: boolean; | ||
| }) { | ||
| const { data: space } = useSpace(); | ||
| const { isFree, showPayWall } = useBilling(); | ||
| const toastProgress = useToastProgress(); | ||
| const utils = trpc.useUtils(); | ||
| const posthog = usePostHog(); | ||
|
|
||
| const currentColor = space.primaryColor ?? DEFAULT_PRIMARY_COLOR; | ||
| const [color, setColor] = React.useState(() => parseColor(currentColor)); | ||
| const hexColor = color.toString("hex"); | ||
| const isDirty = hexColor !== currentColor; | ||
|
|
||
| const updateShowBranding = trpc.spaces.updateShowBranding.useMutation({ | ||
| onMutate: async ({ showBranding }) => { | ||
| await utils.spaces.getCurrent.cancel(); | ||
| const previousData = utils.spaces.getCurrent.getData(); | ||
| utils.spaces.getCurrent.setData(undefined, (old) => | ||
| old ? { ...old, showBranding } : old, | ||
| ); | ||
| return { previousData }; | ||
| }, | ||
| onError: (_err, _vars, context) => { | ||
| utils.spaces.getCurrent.setData(undefined, context?.previousData); | ||
| }, | ||
| }); | ||
|
|
||
| const updateSpace = trpc.spaces.update.useMutation(); | ||
|
|
||
| const handleToggle = (newChecked: boolean) => { | ||
| if (isFree) { | ||
| posthog?.capture("branding_settings:paywall_trigger"); | ||
| showPayWall(); | ||
| return; | ||
| } | ||
| toastProgress(updateShowBranding.mutateAsync({ showBranding: newChecked })); | ||
| }; | ||
|
|
||
| const handleSave = async () => { | ||
| const value = hexColor === DEFAULT_PRIMARY_COLOR ? null : hexColor; | ||
| toastProgress(updateSpace.mutateAsync({ primaryColor: value })); | ||
| }; | ||
|
|
||
| return ( | ||
| <PageSection variant="card"> | ||
| <PageSectionHeader> | ||
| <PageSectionTitle> | ||
| <Trans i18nKey="branding" defaults="Branding" /> | ||
| </PageSectionTitle> | ||
| <PageSectionDescription> | ||
| <Trans | ||
| i18nKey="showBrandingDescription" | ||
| defaults="Show your brand identity on your public pages and emails" | ||
| /> | ||
| </PageSectionDescription> | ||
| </PageSectionHeader> | ||
| <PageSectionContent> | ||
| <FieldGroup> | ||
| <Field orientation="horizontal"> | ||
| <Switch | ||
| checked={space.showBranding} | ||
| onCheckedChange={handleToggle} | ||
| disabled={disabled || updateShowBranding.isPending} | ||
| /> | ||
| <FieldLabel> | ||
| <Trans | ||
| i18nKey="useCustomBranding" | ||
| defaults="Enable Custom Branding" | ||
| /> | ||
| {space.tier !== "pro" && <ProBadge />} | ||
| </FieldLabel> | ||
| </Field> | ||
| <div | ||
| className={ | ||
| !space.showBranding || disabled | ||
| ? "pointer-events-none opacity-50" | ||
| : undefined | ||
| } | ||
| > | ||
| <FieldGroup> | ||
| <Field> | ||
| <FieldLabel> | ||
| <Trans i18nKey="primaryColor" defaults="Primary Color" /> | ||
| </FieldLabel> | ||
| <ColorPicker value={color} onChange={setColor} /> | ||
| </Field> | ||
| <Field orientation="horizontal"> | ||
| <Button | ||
| onClick={handleSave} | ||
| disabled={!space.showBranding || !isDirty || disabled} | ||
| loading={updateSpace.isPending} | ||
| > | ||
| <Trans i18nKey="save" defaults="Save" /> | ||
| </Button> | ||
| </Field> | ||
| </FieldGroup> | ||
| </div> | ||
| </FieldGroup> | ||
| </PageSectionContent> | ||
| </PageSection> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Free-tier guard currently blocks turning branding off.
Line 55 applies the paywall guard regardless of target state, so free users with
showBranding=truecannot disable it.💡 Suggested fix
const handleToggle = (newChecked: boolean) => { - if (isFree) { + if (newChecked && isFree) { showPayWall(); return; } toastProgress(updateShowBranding.mutateAsync({ showBranding: newChecked })); };📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a space gets downgraded we disable show branding so this shouldn't happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukevella, that makes sense — since downgrading automatically disablesshowBranding, a free-tier space can never have it enabled in the first place, so the guard is correctly placed. Thanks for the clarification!✏️ Learnings added