diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/ButtonForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/ButtonForm.tsx index ddeb8d32c9..d621cffc8c 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/ButtonForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/ButtonForm.tsx @@ -1,23 +1,47 @@ import Button from "@mui/material/Button"; import Link from "@mui/material/Link"; +import { darken, useTheme } from "@mui/material/styles"; +import { Team, TeamTheme } from "@opensystemslab/planx-core/types"; import { useFormik } from "formik"; -import React from "react"; +import { useStore } from "pages/FlowEditor/lib/store"; +import React, { useEffect, useState } from "react"; +import { getContrastTextColor } from "styleUtils"; import ColorPicker from "ui/editor/ColorPicker"; import InputDescription from "ui/editor/InputDescription"; import InputRow from "ui/shared/InputRow"; import InputRowItem from "ui/shared/InputRowItem"; -import { DesignPreview, EXAMPLE_COLOUR, SettingsForm } from "."; +import { DesignPreview, SettingsForm } from "."; -export const ButtonForm: React.FC = () => { - const formik = useFormik<{ - buttonColor: string; - }>({ - initialValues: { - buttonColor: EXAMPLE_COLOUR, +type FormValues = Pick; + +export const ButtonForm: React.FC<{ team: Team; onSuccess: () => void }> = ({ + team, + onSuccess, +}) => { + const theme = useTheme(); + + useEffect(() => { + setInitialValues({ actionColour: team.theme?.actionColour }); + }, [team]); + + const [initialValues, setInitialValues] = useState({ + actionColour: "", + }); + + const formik = useFormik({ + initialValues, + onSubmit: async (values, { resetForm }) => { + const isSuccess = await useStore.getState().updateTeamTheme(values); + if (isSuccess) { + onSuccess(); + // Reset "dirty" status to disable Save & Reset buttons + resetForm({ values }); + } }, - onSubmit: () => {}, - validate: () => {}, + validateOnBlur: false, + validateOnChange: false, + enableReinitialize: true, }); return ( @@ -42,8 +66,8 @@ export const ButtonForm: React.FC = () => { formik.setFieldValue("buttonColor", color)} + color={formik.values.actionColour} + onChange={(color) => formik.setFieldValue("actionColour", color)} label="Button colour" /> @@ -51,7 +75,20 @@ export const ButtonForm: React.FC = () => { } preview={ - diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/index.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/index.tsx index 4bc13a3951..c31b0afc94 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/index.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/DesignSettings/index.tsx @@ -137,7 +137,7 @@ const DesignSettings: React.FC = () => { ) : ( <> setOpen(true)} /> - + setOpen(true)} />