diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/lookandfeel/components/UnifiedStyling.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/lookandfeel/components/UnifiedStyling.tsx index d4fc88ce08..741470a654 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/lookandfeel/components/UnifiedStyling.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/settings/lookandfeel/components/UnifiedStyling.tsx @@ -1,18 +1,139 @@ "use client"; -import React, { useState } from "react"; +import { RotateCcwIcon } from "lucide-react"; +import { useRouter } from "next/navigation"; +import React, { useEffect, useState } from "react"; +import toast from "react-hot-toast"; import { TProduct } from "@formbricks/types/product"; +import { Button } from "@formbricks/ui/Button"; import { ColorPicker } from "@formbricks/ui/ColorPicker"; +import { Slider } from "@formbricks/ui/Slider"; +import CardArrangement from "@formbricks/ui/Styling/CardArrangement"; +import DarkModeColors from "@formbricks/ui/Styling/DarkModeColors"; import { Switch } from "@formbricks/ui/Switch"; +import { updateProductAction } from "../actions"; + type UnifiedStylingProps = { product: TProduct; }; +const colorDefaults = { + brandColor: "#64748b", + questionColor: "#2b2524", + inputColor: "#efefef", + inputBorderColor: "#c0c0c0", + cardBackgroundColor: "#c0c0c0", + highlighBorderColor: "#64748b", +}; + const UnifiedStyling = ({ product }: UnifiedStylingProps) => { - // const [color, setColor] = useState("#333"); - const [color, setColor] = useState(product.styling?.brandColor?.light); + const router = useRouter(); + const [unifiedStyling, setUnifiedStyling] = useState(product.styling?.unifiedStyling ?? false); + const [allowStyleOverwrite, setAllowStyleOverwrite] = useState( + product.styling?.allowStyleOverwrite ?? false + ); + const [brandColor, setBrandColor] = useState( + product.styling?.brandColor?.light ?? colorDefaults.brandColor + ); + const [questionColor, setQuestionColor] = useState( + product.styling?.questionColor?.light ?? colorDefaults.questionColor + ); + const [inputColor, setInputColor] = useState( + product.styling?.inputColor?.light ?? colorDefaults.inputColor + ); + const [inputBorderColor, setInputBorderColor] = useState( + product.styling?.inputBorderColor?.light ?? colorDefaults.inputBorderColor + ); + const [cardBackgroundColor, setCardBackgroundColor] = useState( + product.styling?.cardBackgroundColor?.light ?? colorDefaults.cardBackgroundColor + ); + + // highlight border + const [allowHighlightBorder, setAllowHighlightBorder] = useState( + !!product.styling?.highlightBorderColor?.light ?? false + ); + const [highlightBorderColor, setHighlightBorderColor] = useState( + product.styling?.highlightBorderColor?.light ?? colorDefaults.highlighBorderColor + ); + + const [isDarkMode, setIsDarkMode] = useState(product.styling?.isDarkModeEnabled ?? false); + + const [brandColorDark, setBrandColorDark] = useState(product.styling?.brandColor?.dark); + + const [questionColorDark, setQuestionColorDark] = useState(product.styling?.questionColor?.dark); + + const [inputColorDark, setInputColorDark] = useState(product.styling?.inputColor?.dark); + + const [inputBorderColorDark, setInputBorderColorDark] = useState(product.styling?.inputBorderColor?.dark); + + const [cardBackgroundColorDark, setCardBackgroundColorDark] = useState( + product.styling?.cardBackgroundColor?.dark + ); + + const [highlightBorderColorDark, setHighlightBorderColorDark] = useState( + product.styling?.highlightBorderColor?.dark + ); + + const [roundness, setRoundness] = useState(product.styling?.roundness ?? 8); + + const [linkSurveysCardArrangement, setLinkSurveysCardArrangement] = useState( + product.styling?.cardArrangement?.linkSurveys ?? "casual" + ); + const [inAppSurveysCardArrangement, setInAppSurveysCardArrangement] = useState( + product.styling?.cardArrangement?.inAppSurveys ?? "casual" + ); + + useEffect(() => { + if (!unifiedStyling) { + setAllowStyleOverwrite(false); + } + }, [unifiedStyling]); + + const onSave = async () => { + await updateProductAction(product.id, { + styling: { + unifiedStyling, + allowStyleOverwrite, + brandColor: { + light: brandColor, + dark: brandColorDark, + }, + questionColor: { + light: questionColor, + dark: questionColorDark, + }, + inputColor: { + light: inputColor, + dark: inputColorDark, + }, + inputBorderColor: { + light: inputBorderColor, + dark: inputBorderColorDark, + }, + cardBackgroundColor: { + light: cardBackgroundColor, + dark: cardBackgroundColorDark, + }, + highlightBorderColor: allowHighlightBorder + ? { + light: highlightBorderColor, + dark: highlightBorderColorDark, + } + : undefined, + isDarkModeEnabled: isDarkMode, + roundness, + cardArrangement: { + linkSurveys: linkSurveysCardArrangement, + inAppSurveys: inAppSurveysCardArrangement, + }, + }, + }); + + toast.success("Styling updated successfully."); + router.refresh(); + }; return (
Set base styles for all surveys below
+Set base styles for all surveys below
+
Activate if you want some surveys to be styled differently
Change the text color of the survey questions.
+Change the text color of the survey questions.
Change the text color of the survey questions.
+Change the text color of the survey questions.
Change the text color of the survey questions.
+Change the text color of the survey questions.
Change the text color of the survey questions.
+Change the text color of the survey questions.
Change the text color of the survey questions.
+Change the text color of the survey questions.
Add on outer border to your survey card
+Change the border radius of the card and the inputs.
++ How funky do you want your cards in {surveyTypeDerived} Surveys +
+Your app has a dark mode? Set a different set of colors.
+