From a211e64f0e4ed22dcc4f92e05b639f8f47209579 Mon Sep 17 00:00:00 2001 From: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com> Date: Thu, 30 May 2024 17:30:14 +0530 Subject: [PATCH] fix: product styling form (#2696) --- .../edit/components/BackgroundStylingCard.tsx | 134 +++--- .../edit/components/CardStylingSettings.tsx | 426 +++++++++--------- .../edit/components/FormStylingSettings.tsx | 203 +++++---- .../edit/components/StylingView.tsx | 252 +++++++---- .../edit/components/SurveyBgSelectorTab.tsx | 23 +- .../components/EditProductNameForm.tsx | 4 +- .../components/EditWaitingTimeForm.tsx | 4 +- .../product/look/components/ThemeStyling.tsx | 363 ++++++++------- .../components/ThemeStylingPreviewSurvey.tsx | 4 +- apps/web/playwright/onboarding.spec.ts | 1 + .../surveys/src/components/general/Survey.tsx | 1 - packages/types/styling.ts | 23 +- packages/ui/CardArrangementTabs/index.tsx | 56 +++ packages/ui/ColorSelector/index.tsx | 18 + packages/ui/Form/index.tsx | 17 +- .../ui/Styling/components/CardArrangement.tsx | 80 ---- .../components/ColorSelectorWithLabel.tsx | 37 -- .../ui/Styling/components/DarkModeColors.tsx | 108 ----- packages/ui/Styling/index.tsx | 3 - packages/ui/Tabs/index.tsx | 80 ++++ .../CasualCardArrangementIcon.tsx} | 20 +- .../ui/icons/SimpleCardArrangementIcon.tsx | 7 + .../ui/icons/StraightCardArrangementIcon.tsx | 9 + 23 files changed, 938 insertions(+), 935 deletions(-) create mode 100644 packages/ui/CardArrangementTabs/index.tsx create mode 100644 packages/ui/ColorSelector/index.tsx delete mode 100644 packages/ui/Styling/components/CardArrangement.tsx delete mode 100644 packages/ui/Styling/components/ColorSelectorWithLabel.tsx delete mode 100644 packages/ui/Styling/components/DarkModeColors.tsx delete mode 100644 packages/ui/Styling/index.tsx create mode 100644 packages/ui/Tabs/index.tsx rename packages/ui/{Styling/components/CardArrangementIcons.tsx => icons/CasualCardArrangementIcon.tsx} (52%) create mode 100644 packages/ui/icons/SimpleCardArrangementIcon.tsx create mode 100644 packages/ui/icons/StraightCardArrangementIcon.tsx diff --git a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/BackgroundStylingCard.tsx b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/BackgroundStylingCard.tsx index 18ff948e007..c2588782d67 100644 --- a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/BackgroundStylingCard.tsx +++ b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/BackgroundStylingCard.tsx @@ -2,11 +2,13 @@ import * as Collapsible from "@radix-ui/react-collapsible"; import { CheckIcon } from "lucide-react"; +import { UseFormReturn } from "react-hook-form"; import { cn } from "@formbricks/lib/cn"; import { TProductStyling } from "@formbricks/types/product"; -import { TSurveyBackgroundBgType, TSurveyStyling } from "@formbricks/types/surveys"; +import { TSurveyStyling } from "@formbricks/types/surveys"; import { Badge } from "@formbricks/ui/Badge"; +import { FormControl, FormDescription, FormField, FormItem, FormLabel } from "@formbricks/ui/Form"; import { Slider } from "@formbricks/ui/Slider"; import { SurveyBgSelectorTab } from "./SurveyBgSelectorTab"; @@ -14,52 +16,24 @@ import { SurveyBgSelectorTab } from "./SurveyBgSelectorTab"; interface BackgroundStylingCardProps { open: boolean; setOpen: React.Dispatch>; - styling: TSurveyStyling | TProductStyling | null; - setStyling: React.Dispatch>; colors: string[]; isSettingsPage?: boolean; disabled?: boolean; environmentId: string; isUnsplashConfigured: boolean; + form: UseFormReturn; } export const BackgroundStylingCard = ({ open, setOpen, - styling, - setStyling, colors, isSettingsPage = false, disabled, environmentId, isUnsplashConfigured, + form, }: BackgroundStylingCardProps) => { - const { bgType, brightness } = styling?.background ?? {}; - - const handleBgChange = (color: string, type: TSurveyBackgroundBgType) => { - const { background } = styling ?? {}; - - setStyling({ - ...styling, - background: { - ...background, - bg: color, - bgType: type, - brightness: 100, - }, - }); - }; - - const handleBrightnessChange = (percent: number) => { - setStyling((prev) => ({ - ...prev, - background: { - ...prev.background, - brightness: percent, - }, - })); - }; - return ( -
-
- {/* Background */} -
-
-

Change background

-

- Pick a background from our library or upload your own. -

-
- -
+
+
+ ( + +
+ Change background + Pick a background from our library or upload your own. +
- {/* Overlay */} -
-
-

Background overlay

-

- Darken or lighten background of your choice. -

-
+ + { + field.onChange({ + ...field.value, + bg, + bgType, + brightness: 100, + }); + }} + colors={colors} + bgType={field.value?.bgType ?? "color"} + environmentId={environmentId} + isUnsplashConfigured={isUnsplashConfigured} + /> + + + )} + /> -
-
-
-
- { - handleBrightnessChange(value[0]); - }} - /> -
-
+
+
+
+ ( + +
+ Brightness + Darken or lighten background of your choice. +
+ + +
+ { + field.onChange(value[0]); + }} + /> +
+
+
+ )} + />
diff --git a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/CardStylingSettings.tsx b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/CardStylingSettings.tsx index 8053719b4b5..fb2b3b7e7a0 100644 --- a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/CardStylingSettings.tsx +++ b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/CardStylingSettings.tsx @@ -2,157 +2,47 @@ import * as Collapsible from "@radix-ui/react-collapsible"; import { CheckIcon } from "lucide-react"; -import React, { useMemo } from "react"; +import React from "react"; +import { UseFormReturn } from "react-hook-form"; import { cn } from "@formbricks/lib/cn"; import { COLOR_DEFAULTS } from "@formbricks/lib/styling/constants"; import { TProduct, TProductStyling } from "@formbricks/types/product"; -import { TCardArrangementOptions } from "@formbricks/types/styling"; import { TSurveyStyling, TSurveyType } from "@formbricks/types/surveys"; import { Badge } from "@formbricks/ui/Badge"; +import { CardArrangementTabs } from "@formbricks/ui/CardArrangementTabs"; import { ColorPicker } from "@formbricks/ui/ColorPicker"; -import { Label } from "@formbricks/ui/Label"; +import { ColorSelector } from "@formbricks/ui/ColorSelector"; +import { FormControl, FormDescription, FormField, FormItem, FormLabel } from "@formbricks/ui/Form"; import { Slider } from "@formbricks/ui/Slider"; -import { CardArrangement, ColorSelectorWithLabel } from "@formbricks/ui/Styling"; import { Switch } from "@formbricks/ui/Switch"; type CardStylingSettingsProps = { open: boolean; setOpen: React.Dispatch>; - styling: TSurveyStyling | TProductStyling | null; - setStyling: React.Dispatch>; isSettingsPage?: boolean; surveyType?: TSurveyType; disabled?: boolean; - localProduct: TProduct; + product: TProduct; + form: UseFormReturn; }; export const CardStylingSettings = ({ - setStyling, - styling, isSettingsPage = false, surveyType, disabled, open, - localProduct, + product, setOpen, + form, }: CardStylingSettingsProps) => { const isAppSurvey = surveyType === "app" || surveyType === "website"; - const cardBgColor = styling?.cardBackgroundColor?.light || COLOR_DEFAULTS.cardBackgroundColor; + const surveyTypeDerived = isAppSurvey ? "App / Website" : "Link"; + const isLogoVisible = !!product.logo?.url; - const isLogoHidden = styling?.isLogoHidden ?? false; - - const isLogoVisible = !!localProduct.logo?.url; - - const linkSurveyCardArrangement = styling?.cardArrangement?.linkSurveys ?? "straight"; - - const inAppSurveyCardArrangement = styling?.cardArrangement?.appSurveys ?? "straight"; - - const setCardBgColor = (color: string) => { - setStyling((prev) => ({ - ...prev, - cardBackgroundColor: { - ...(prev.cardBackgroundColor ?? {}), - light: color, - }, - })); - }; - - const cardBorderColor = styling?.cardBorderColor?.light || COLOR_DEFAULTS.cardBorderColor; - const setCardBorderColor = (color: string) => { - setStyling((prev) => ({ - ...prev, - cardBorderColor: { - ...(prev.cardBorderColor ?? {}), - light: color, - }, - })); - }; - - const cardShadowColor = styling?.cardShadowColor?.light || COLOR_DEFAULTS.cardShadowColor; - const setCardShadowColor = (color: string) => { - setStyling((prev) => ({ - ...prev, - cardShadowColor: { - ...(prev.cardShadowColor ?? {}), - light: color, - }, - })); - }; - - const isHighlightBorderAllowed = !!styling?.highlightBorderColor; - const setIsHighlightBorderAllowed = (open: boolean) => { - if (!open) { - const { highlightBorderColor, ...rest } = styling ?? {}; - - setStyling({ - ...rest, - }); - } else { - setStyling((prev) => ({ - ...prev, - highlightBorderColor: { - ...(prev.highlightBorderColor ?? {}), - light: COLOR_DEFAULTS.highlightBorderColor, - }, - })); - } - }; - - const highlightBorderColor = styling?.highlightBorderColor?.light || COLOR_DEFAULTS.highlightBorderColor; - const setHighlightBorderColor = (color: string) => { - setStyling((prev) => ({ - ...prev, - highlightBorderColor: { - ...(prev.highlightBorderColor ?? {}), - light: color, - }, - })); - }; - - const roundness = styling?.roundness ?? 8; - const setRoundness = (value: number) => { - setStyling((prev) => ({ - ...prev, - roundness: value, - })); - }; - - const setCardArrangement = (arrangement: TCardArrangementOptions, surveyType: TSurveyType) => { - const newCardArrangement = { - linkSurveys: linkSurveyCardArrangement, - appSurveys: inAppSurveyCardArrangement, - }; - - if (surveyType === "link") { - newCardArrangement.linkSurveys = arrangement; - } else if (surveyType === "app" || surveyType === "website") { - newCardArrangement.appSurveys = arrangement; - } - - setStyling((prev) => ({ - ...prev, - cardArrangement: newCardArrangement, - })); - }; - - const toggleProgressBarVisibility = (hideProgressBar: boolean) => { - setStyling({ - ...styling, - hideProgressBar, - }); - }; - - const toggleLogoVisibility = () => { - setStyling((prev) => ({ - ...prev, - isLogoHidden: !prev.isLogoHidden, - })); - }; - - const hideProgressBar = useMemo(() => { - return styling?.hideProgressBar; - }, [styling]); + const linkCardArrangement = form.watch("cardArrangement.linkSurveys") ?? "simple"; + const appCardArrangement = form.watch("cardArrangement.appSurveys") ?? "simple"; + const roundness = form.watch("roundness") ?? 8; return (
-
-
-

Roundness

-

Change the border radius of the card and the inputs.

-
-
- setRoundness(value[0])} /> -
+
+ ( + +
+ Roundness + Change the border radius of the card and the inputs. +
+ + +
+ { + form.setValue("roundness", value[0]); + }} + /> +
+
+
+ )} + />
- + ( + +
+ Card background color + Change the background color of the card. +
- + field.onChange(color)} + /> + +
+ )} /> - + ( + +
+ Card border color + Change the border color of the card. +
- + field.onChange(color)} + /> + +
+ )} /> - <> -
- toggleProgressBarVisibility(checked)} - /> -