-
-
Notifications
You must be signed in to change notification settings - Fork 507
✨ Add option to enable brand settings #2319
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 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
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
47 changes: 47 additions & 0 deletions
47
apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/custom-branding-alert.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,47 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| Alert, | ||
| AlertAction, | ||
| AlertDescription, | ||
| AlertTitle, | ||
| } from "@rallly/ui/alert"; | ||
| import { Button } from "@rallly/ui/button"; | ||
| import { PaletteIcon } from "lucide-react"; | ||
| import { usePoll } from "@/contexts/poll"; | ||
| import { useBilling } from "@/features/billing/client"; | ||
| import { Trans } from "@/i18n/client"; | ||
|
|
||
| export function CustomBrandingAlert() { | ||
| const poll = usePoll(); | ||
| const { isFree, showPayWall } = useBilling(); | ||
|
|
||
| if (!isFree || !poll.space || poll.space.showBranding) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Alert variant="primary"> | ||
| <PaletteIcon /> | ||
| <AlertTitle> | ||
| <Trans | ||
| i18nKey="customBrandingAlertTitle" | ||
| defaults="Show your brand to participants" | ||
| /> | ||
| </AlertTitle> | ||
| <AlertDescription> | ||
| <p className="text-sm"> | ||
| <Trans | ||
| i18nKey="pollAdminCustomBrandingAlertDescription" | ||
| defaults="Upgrade to Pro to show your logo and brand colors to participants." | ||
| /> | ||
| </p> | ||
| </AlertDescription> | ||
| <AlertAction> | ||
| <Button size="sm" variant="default" onClick={showPayWall}> | ||
| <Trans i18nKey="upgrade" defaults="Upgrade" /> | ||
| </Button> | ||
| </AlertAction> | ||
| </Alert> | ||
| ); | ||
| } |
101 changes: 101 additions & 0 deletions
101
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,101 @@ | ||
| "use client"; | ||
|
|
||
| import { Button } from "@rallly/ui/button"; | ||
| import { ColorPicker, parseColor } from "@rallly/ui/color-picker"; | ||
| import { Field, FieldGroup, FieldLabel } from "@rallly/ui/field"; | ||
| import { toast } from "@rallly/ui/sonner"; | ||
| import React from "react"; | ||
| import { | ||
| PageSection, | ||
| PageSectionContent, | ||
| PageSectionDescription, | ||
| PageSectionHeader, | ||
| PageSectionTitle, | ||
| } from "@/app/components/page-layout"; | ||
| import { ProBadge } from "@/components/pro-badge"; | ||
| import { DEFAULT_PRIMARY_COLOR } from "@/features/branding/constants"; | ||
| import { useSpace } from "@/features/space/client"; | ||
| import { Trans, useTranslation } from "@/i18n/client"; | ||
| import { trpc } from "@/trpc/client"; | ||
| import { CustomBrandingSwitch } from "./custom-branding-switch"; | ||
|
|
||
| export function CustomBrandingSection() { | ||
| const { data: space } = useSpace(); | ||
| const { t } = useTranslation(); | ||
| const currentColor = space.primaryColor ?? DEFAULT_PRIMARY_COLOR; | ||
| const [color, setColor] = React.useState(() => parseColor(currentColor)); | ||
| const hexColor = color.toString("hex"); | ||
| const isDirty = hexColor !== currentColor; | ||
|
|
||
| const updateSpace = trpc.spaces.update.useMutation(); | ||
| const utils = trpc.useUtils(); | ||
|
|
||
| const handleSave = async () => { | ||
| const value = hexColor === DEFAULT_PRIMARY_COLOR ? null : hexColor; | ||
| toast.promise( | ||
| updateSpace | ||
| .mutateAsync({ name: space.name, primaryColor: value }) | ||
| .then(() => utils.spaces.getCurrent.invalidate()), | ||
| { | ||
| loading: t("savingBranding", { defaultValue: "Saving..." }), | ||
| success: t("brandingSaved", { defaultValue: "Branding saved" }), | ||
| error: t("brandingSaveError", { | ||
| defaultValue: "Failed to save branding", | ||
| }), | ||
| }, | ||
| ); | ||
| }; | ||
|
|
||
| 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"> | ||
| <CustomBrandingSwitch checked={space.showBranding} /> | ||
| <FieldLabel> | ||
| <Trans | ||
| i18nKey="useCustomBranding" | ||
| defaults="Enable Custom Branding" | ||
| /> | ||
| {space.tier !== "pro" && <ProBadge />} | ||
| </FieldLabel> | ||
| </Field> | ||
| <div | ||
| className={ | ||
| !space.showBranding ? "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={!isDirty} | ||
| loading={updateSpace.isPending} | ||
| > | ||
| <Trans i18nKey="save" defaults="Save" /> | ||
| </Button> | ||
| </Field> | ||
| </FieldGroup> | ||
| </div> | ||
| </FieldGroup> | ||
| </PageSectionContent> | ||
| </PageSection> | ||
| ); | ||
| } |
50 changes: 50 additions & 0 deletions
50
apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-switch.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,50 @@ | ||
| "use client"; | ||
|
|
||
| import { toast } from "@rallly/ui/sonner"; | ||
| import { Switch } from "@rallly/ui/switch"; | ||
| import { useBilling } from "@/features/billing/client"; | ||
| import { useTranslation } from "@/i18n/client"; | ||
| import { trpc } from "@/trpc/client"; | ||
|
|
||
| export function CustomBrandingSwitch({ | ||
| checked, | ||
| onChange, | ||
| }: { | ||
| checked: boolean; | ||
| onChange?: (checked: boolean) => void; | ||
| }) { | ||
| const { t } = useTranslation(); | ||
| const { isFree, showPayWall } = useBilling(); | ||
| const updateShowBranding = trpc.spaces.updateShowBranding.useMutation(); | ||
| const utils = trpc.useUtils(); | ||
|
|
||
| const handleToggle = (checked: boolean) => { | ||
| if (isFree) { | ||
| showPayWall(); | ||
| return; | ||
| } | ||
| toast.promise( | ||
| updateShowBranding | ||
| .mutateAsync({ showBranding: checked }) | ||
| .then(() => utils.spaces.getCurrent.invalidate()), | ||
| { | ||
| loading: t("savingBranding", { defaultValue: "Saving..." }), | ||
| success: checked | ||
| ? t("brandingEnabled", { defaultValue: "Custom branding enabled" }) | ||
| : t("brandingDisabled", { defaultValue: "Custom branding disabled" }), | ||
| error: t("brandingSaveError", { | ||
| defaultValue: "Failed to save branding", | ||
| }), | ||
| }, | ||
| ); | ||
| onChange?.(checked); | ||
| }; | ||
|
|
||
| return ( | ||
| <Switch | ||
| checked={checked} | ||
| onCheckedChange={handleToggle} | ||
| disabled={updateShowBranding.isPending} | ||
| /> | ||
| ); | ||
| } | ||
56 changes: 56 additions & 0 deletions
56
apps/web/src/app/[locale]/(space)/settings/general/components/space-branding-form.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,56 @@ | ||
| "use client"; | ||
|
|
||
| import { Button } from "@rallly/ui/button"; | ||
| import { ColorPicker, parseColor } from "@rallly/ui/color-picker"; | ||
| import { toast } from "@rallly/ui/sonner"; | ||
| import React from "react"; | ||
| import { DEFAULT_PRIMARY_COLOR } from "@/features/branding/constants"; | ||
| import type { SpaceDTO } from "@/features/space/types"; | ||
| import { Trans, useTranslation } from "@/i18n/client"; | ||
| import { trpc } from "@/trpc/client"; | ||
|
|
||
| export function SpaceBrandingForm({ space }: { space: SpaceDTO }) { | ||
| const { t } = useTranslation(); | ||
| const currentColor = space.primaryColor ?? DEFAULT_PRIMARY_COLOR; | ||
| const [color, setColor] = React.useState(() => parseColor(currentColor)); | ||
| const hexColor = color.toString("hex"); | ||
| const isDirty = hexColor !== currentColor; | ||
|
|
||
| const updateSpace = trpc.spaces.update.useMutation(); | ||
| const utils = trpc.useUtils(); | ||
|
|
||
| const handleSave = async () => { | ||
| const value = hexColor === DEFAULT_PRIMARY_COLOR ? null : hexColor; | ||
| toast.promise( | ||
| updateSpace | ||
| .mutateAsync({ name: space.name, primaryColor: value }) | ||
| .then(() => utils.spaces.getCurrent.invalidate()), | ||
| { | ||
| loading: t("savingBranding", { defaultValue: "Saving..." }), | ||
| success: t("brandingSaved", { defaultValue: "Branding saved" }), | ||
| error: t("brandingSaveError", { | ||
| defaultValue: "Failed to save branding", | ||
| }), | ||
| }, | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| className={ | ||
| !space.showBranding ? "pointer-events-none opacity-50" : undefined | ||
| } | ||
| > | ||
| <div className="w-56 space-y-4"> | ||
| <ColorPicker value={color} onChange={setColor} /> | ||
| <Button | ||
| onClick={handleSave} | ||
| disabled={!space.showBranding || !isDirty} | ||
| loading={updateSpace.isPending} | ||
| > | ||
| <Trans i18nKey="save" defaults="Save" /> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
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.
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.
onChangecallback fires before mutation completes.onChange?.(checked)on line 40 executes immediately after starting the mutation, not after it succeeds. If the mutation fails, the parent component's state may be inconsistent with the server state.Consider moving
onChangeinto the.then()chain or removing it entirely sinceutils.spaces.getCurrent.invalidate()already refreshes the data.🐛 Proposed fix
const handleToggle = (checked: boolean) => { if (isFree) { showPayWall(); return; } toast.promise( updateShowBranding .mutateAsync({ showBranding: checked }) - .then(() => utils.spaces.getCurrent.invalidate()), + .then(() => { + utils.spaces.getCurrent.invalidate(); + onChange?.(checked); + }), { loading: t("savingBranding", { defaultValue: "Saving..." }), success: checked ? t("brandingEnabled", { defaultValue: "Custom branding enabled" }) : t("brandingDisabled", { defaultValue: "Custom branding disabled" }), error: t("brandingSaveError", { defaultValue: "Failed to save branding", }), }, ); - onChange?.(checked); };🤖 Prompt for AI Agents