From ecc41845208220df7b9c717f54287c1ff4d66675 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 25 Jun 2024 15:33:55 +0100 Subject: [PATCH 1/7] add new planx-core ref and fetched values to form inputs --- .../src/components/Header.test.tsx | 12 +-- .../Settings/DesignSettings/index.tsx | 1 - .../Settings/GeneralSettings/ContactForm.tsx | 86 +++++++++++-------- .../Settings/GeneralSettings/index.tsx | 21 ++--- .../src/pages/FlowEditor/lib/store/team.ts | 4 + 5 files changed, 68 insertions(+), 56 deletions(-) diff --git a/editor.planx.uk/src/components/Header.test.tsx b/editor.planx.uk/src/components/Header.test.tsx index 94e370320e..488b269936 100644 --- a/editor.planx.uk/src/components/Header.test.tsx +++ b/editor.planx.uk/src/components/Header.test.tsx @@ -85,7 +85,7 @@ describe("Header Component - Editor Route", () => { id: 123, email: "test@example.com", }, - }), + }) ); jest.spyOn(ReactNavi, "useCurrentRoute").mockImplementation( @@ -98,7 +98,7 @@ describe("Header Component - Editor Route", () => { data: { flow: "test-flow", }, - }) as any, + }) as any ); }); @@ -139,7 +139,7 @@ for (const route of ["/published", "/preview", "/draft", "/pay", "/invite"]) { data: { flow: "test-flow", }, - }) as any, + }) as any ); }); @@ -148,7 +148,7 @@ for (const route of ["/published", "/preview", "/draft", "/pay", "/invite"]) { expect(screen.queryByText("Plan✕")).not.toBeInTheDocument(); expect(screen.getByAltText(`${mockTeam1.name} Logo`)).toHaveAttribute( "src", - "logo.jpg", + "logo.jpg" ); }); @@ -156,7 +156,7 @@ for (const route of ["/published", "/preview", "/draft", "/pay", "/invite"]) { act(() => setState({ teamTheme: mockTeam2.theme })); setup(
); expect( - screen.queryByAltText(`${mockTeam2.name} Logo`), + screen.queryByAltText(`${mockTeam2.name} Logo`) ).not.toBeInTheDocument(); expect(screen.getByText("Plan✕")).toBeInTheDocument(); act(() => setState({ teamTheme: mockTeam1.theme })); @@ -190,7 +190,7 @@ describe("Section navigation bar", () => { data: { flow: "test-flow", }, - }) as any, + }) as any ); }); 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 a5071ba261..0fcaebad06 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 @@ -42,7 +42,6 @@ const DesignSettings: React.FC = () => { try { const fetchedTeam = await useStore.getState().fetchCurrentTeam(); if (!fetchedTeam) throw Error("Unable to find team"); - setFormikConfig({ initialValues: fetchedTeam.theme, // This value will be set per form section diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx index 5b8c8c4047..b7ba13669f 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx @@ -41,43 +41,55 @@ export default function ContactForm({ formikConfig, onSuccess }: FormProps) { } input={ <> - - { - onChangeFn("homepage", event); - }} - id="homepageUrl" - /> - - - { - onChangeFn("helpEmail", event); - }} - id="helpEmail" - /> - - - { - onChangeFn("helpPhone", event); - }} - id="helpPhone" - /> - - - { - onChangeFn("helpOpeningHours", event); - }} - id="helpOpeningHours" - /> - + + + Homepage URL + { + onChangeFn("homepage", event); + }} + /> + + + + + Contact email address + { + onChangeFn("helpEmail", event); + }} + /> + + + + + Phone number + { + onChangeFn("helpPhone", event); + }} + /> + + + + + Opening hours + { + onChangeFn("helpOpeningHours", event); + }} + /> + + } /> diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx index a2fec53d73..e50c94f700 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx @@ -2,7 +2,9 @@ import Alert from "@mui/material/Alert"; import Box from "@mui/material/Box"; import Snackbar from "@mui/material/Snackbar"; import Typography from "@mui/material/Typography"; +import { GeneralTeamSettings } from "@opensystemslab/planx-core/types"; import { FormikConfig } from "formik"; +import { useStore } from "pages/FlowEditor/lib/store"; import React, { useEffect, useState } from "react"; import SettingsSection from "ui/editor/SettingsSection"; @@ -18,28 +20,23 @@ export interface GeneralSettings { } export interface FormProps { - formikConfig: FormikConfig; + formikConfig: FormikConfig; onSuccess: () => void; } const GeneralSettings: React.FC = () => { const [formikConfig, setFormikConfig] = useState< - FormikConfig | undefined + FormikConfig | undefined >(undefined); - const initialValues = { - boundaryUrl: "", - helpEmail: "", - helpPhone: "", - helpOpeningHours: "", - homepage: "", - }; - useEffect(() => { const fetchTeam = async () => { try { + const fetchedTeam = await useStore.getState().fetchCurrentTeam(); + console.log(fetchedTeam); + if (!fetchedTeam) throw Error("Unable to find team"); setFormikConfig({ - initialValues: initialValues, + initialValues: fetchedTeam.team_settings, onSubmit: () => {}, validateOnBlur: false, validateOnChange: false, @@ -58,7 +55,7 @@ const GeneralSettings: React.FC = () => { const handleClose = ( _event?: React.SyntheticEvent | Event, - reason?: string, + reason?: string ) => { if (reason === "clickaway") { return; diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts index 884b4e5cb9..86ec2c85af 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts @@ -18,6 +18,7 @@ export interface TeamStore { teamSettings: TeamSettings; teamSlug: string; teamTheme: TeamTheme; + teamGeneralSettings: GeneralTeamSettings; setTeam: (team: Team) => void; getTeam: () => Team; @@ -40,6 +41,7 @@ export const teamStore: StateCreator< teamSettings: {} as TeamSettings, teamSlug: "", teamTheme: {} as TeamTheme, + teamGeneralSettings: {} as GeneralTeamSettings, setTeam: (team) => { set({ @@ -50,6 +52,7 @@ export const teamStore: StateCreator< teamSettings: team.teamSettings, teamSlug: team.slug, teamTheme: team.theme, + teamGeneralSettings: team.team_settings, }); if (team.theme?.favicon) { @@ -66,6 +69,7 @@ export const teamStore: StateCreator< teamSettings: get().teamSettings, slug: get().teamSlug, theme: get().teamTheme, + team_settings: get().teamGeneralSettings, }), initTeamStore: async (slug) => { From 0509d4a24d5eafc4d7f58d3cdc4f120be77d259e Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 26 Jun 2024 11:23:37 +0100 Subject: [PATCH 2/7] add update general settings to store and forms --- .../Settings/GeneralSettings/BoundaryForm.tsx | 14 +++++++++++--- .../Settings/GeneralSettings/ContactForm.tsx | 15 ++++++++++++--- .../src/pages/FlowEditor/lib/store/team.ts | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx index dbd93e3f0b..33d562e289 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx @@ -1,4 +1,5 @@ import { useFormik } from "formik"; +import { useStore } from "pages/FlowEditor/lib/store"; import React, { ChangeEvent } from "react"; import InputLabel from "ui/editor/InputLabel"; import Input from "ui/shared/Input"; @@ -9,9 +10,16 @@ import { FormProps } from "."; export default function BoundaryForm({ formikConfig, onSuccess }: FormProps) { const formik = useFormik({ ...formikConfig, - onSubmit(values, { resetForm }) { - onSuccess(); - resetForm({ values }); + onSubmit: async (values, { resetForm }) => { + const isSuccess = await useStore.getState().updateGeneralSettings({ + boundaryUrl: values.boundaryUrl, + }); + console.log("button pressed"); + console.log({ successBool: isSuccess }); + if (isSuccess) { + onSuccess(); + resetForm({ values }); + } }, }); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx index b7ba13669f..051f6fc11c 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx @@ -1,4 +1,5 @@ import { useFormik } from "formik"; +import { useStore } from "pages/FlowEditor/lib/store"; import React, { ChangeEvent } from "react"; import InputLabel from "ui/editor/InputLabel"; import Input from "ui/shared/Input"; @@ -20,9 +21,17 @@ export default function ContactForm({ formikConfig, onSuccess }: FormProps) { const formik = useFormik({ ...formikConfig, validationSchema: formSchema, - onSubmit(values, { resetForm }) { - onSuccess(); - resetForm({ values }); + onSubmit: async (values, { resetForm }) => { + const isSuccess = await useStore.getState().updateGeneralSettings({ + homepage: values.homepage, + helpEmail: values.helpEmail, + helpPhone: values.helpPhone, + helpOpeningHours: values.helpOpeningHours, + }); + if (isSuccess) { + onSuccess(); + resetForm({ values }); + } }, }); diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts index 86ec2c85af..2f1254840b 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts @@ -26,6 +26,9 @@ export interface TeamStore { clearTeamStore: () => void; fetchCurrentTeam: () => Promise; updateTeamTheme: (theme: Partial) => Promise; + updateGeneralSettings: ( + generalSettings: Partial, + ) => Promise; } export const teamStore: StateCreator< @@ -132,4 +135,16 @@ export const teamStore: StateCreator< const isSuccess = await $client.team.updateTheme(teamId, theme); return isSuccess; }, + + updateGeneralSettings: async ( + generalSettings: Partial, + ) => { + const { teamId, $client } = get(); + console.log(generalSettings); + const isSuccess = await $client.team.updateGeneralSettings( + teamId, + generalSettings, + ); + return isSuccess; + }, }); From f1c70fcc408ed316a79960596cb84c52fa0178a2 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 26 Jun 2024 12:08:52 +0100 Subject: [PATCH 3/7] remove comment out of general settings inherited from main --- editor.planx.uk/src/routes/teamSettings.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/editor.planx.uk/src/routes/teamSettings.tsx b/editor.planx.uk/src/routes/teamSettings.tsx index 27fcb11715..48afba1a8d 100644 --- a/editor.planx.uk/src/routes/teamSettings.tsx +++ b/editor.planx.uk/src/routes/teamSettings.tsx @@ -28,7 +28,7 @@ const teamSettingsRoutes = compose( if (!isAuthorised) throw new NotFoundError( - `User does not have access to ${req.originalUrl}`, + `User does not have access to ${req.originalUrl}` ); return route(async (req) => ({ @@ -47,17 +47,17 @@ const teamSettingsRoutes = compose( route: "design", Component: DesignSettings, }, - // { - // name: "General", - // route: "general", - // Component: GeneralSettings, - // }, + { + name: "General", + route: "general", + Component: GeneralSettings, + }, ]} /> ), })); }), - }), + }) ); export default teamSettingsRoutes; From dd4787755fbcd972620ca54e0e3fb9d8c778b6aa Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 3 Jul 2024 09:27:25 +0100 Subject: [PATCH 4/7] import input and input label --- .../components/Settings/GeneralSettings/ContactForm.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx index 051f6fc11c..604039692b 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx @@ -3,6 +3,8 @@ import { useStore } from "pages/FlowEditor/lib/store"; import React, { ChangeEvent } from "react"; import InputLabel from "ui/editor/InputLabel"; import Input from "ui/shared/Input"; +import InputRow from "ui/shared/InputRow"; +import InputRowLabel from "ui/shared/InputRowLabel"; import * as Yup from "yup"; import { SettingsForm } from "../shared/SettingsForm"; From 140baa71670e5b2d81e4a71aa7448ab1483bb763 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 3 Jul 2024 09:34:39 +0100 Subject: [PATCH 5/7] adjust store settings --- .../Settings/GeneralSettings/BoundaryForm.tsx | 2 +- .../Settings/GeneralSettings/ContactForm.tsx | 2 +- .../Settings/GeneralSettings/index.tsx | 18 +++++---------- .../src/pages/FlowEditor/lib/store/team.ts | 22 ++++++------------- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx index 33d562e289..67d34b2fdc 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx @@ -11,7 +11,7 @@ export default function BoundaryForm({ formikConfig, onSuccess }: FormProps) { const formik = useFormik({ ...formikConfig, onSubmit: async (values, { resetForm }) => { - const isSuccess = await useStore.getState().updateGeneralSettings({ + const isSuccess = await useStore.getState().updateTeamSettings({ boundaryUrl: values.boundaryUrl, }); console.log("button pressed"); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx index 604039692b..21f0328b44 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx @@ -24,7 +24,7 @@ export default function ContactForm({ formikConfig, onSuccess }: FormProps) { ...formikConfig, validationSchema: formSchema, onSubmit: async (values, { resetForm }) => { - const isSuccess = await useStore.getState().updateGeneralSettings({ + const isSuccess = await useStore.getState().updateTeamSettings({ homepage: values.homepage, helpEmail: values.helpEmail, helpPhone: values.helpPhone, diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx index e50c94f700..d5685f9054 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx @@ -2,7 +2,7 @@ import Alert from "@mui/material/Alert"; import Box from "@mui/material/Box"; import Snackbar from "@mui/material/Snackbar"; import Typography from "@mui/material/Typography"; -import { GeneralTeamSettings } from "@opensystemslab/planx-core/types"; +import { TeamSettings } from "@opensystemslab/planx-core/types"; import { FormikConfig } from "formik"; import { useStore } from "pages/FlowEditor/lib/store"; import React, { useEffect, useState } from "react"; @@ -11,22 +11,14 @@ import SettingsSection from "ui/editor/SettingsSection"; import BoundaryForm from "./BoundaryForm"; import ContactForm from "./ContactForm"; -export interface GeneralSettings { - boundaryUrl: string; - helpEmail: string; - helpPhone: string; - helpOpeningHours: string; - homepage: string; -} - export interface FormProps { - formikConfig: FormikConfig; + formikConfig: FormikConfig; onSuccess: () => void; } const GeneralSettings: React.FC = () => { const [formikConfig, setFormikConfig] = useState< - FormikConfig | undefined + FormikConfig | undefined >(undefined); useEffect(() => { @@ -36,7 +28,7 @@ const GeneralSettings: React.FC = () => { console.log(fetchedTeam); if (!fetchedTeam) throw Error("Unable to find team"); setFormikConfig({ - initialValues: fetchedTeam.team_settings, + initialValues: fetchedTeam.teamSettings, onSubmit: () => {}, validateOnBlur: false, validateOnChange: false, @@ -55,7 +47,7 @@ const GeneralSettings: React.FC = () => { const handleClose = ( _event?: React.SyntheticEvent | Event, - reason?: string + reason?: string, ) => { if (reason === "clickaway") { return; diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts index 2f1254840b..6a6b15f780 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts @@ -15,10 +15,9 @@ export interface TeamStore { teamId: number; teamIntegrations: TeamIntegrations; teamName: string; - teamSettings: TeamSettings; teamSlug: string; teamTheme: TeamTheme; - teamGeneralSettings: GeneralTeamSettings; + teamSettings: TeamSettings; setTeam: (team: Team) => void; getTeam: () => Team; @@ -26,9 +25,7 @@ export interface TeamStore { clearTeamStore: () => void; fetchCurrentTeam: () => Promise; updateTeamTheme: (theme: Partial) => Promise; - updateGeneralSettings: ( - generalSettings: Partial, - ) => Promise; + updateTeamSettings: (teamSettings: Partial) => Promise; } export const teamStore: StateCreator< @@ -41,10 +38,9 @@ export const teamStore: StateCreator< teamId: 0, teamIntegrations: {} as TeamIntegrations, teamName: "", - teamSettings: {} as TeamSettings, teamSlug: "", teamTheme: {} as TeamTheme, - teamGeneralSettings: {} as GeneralTeamSettings, + teamSettings: {} as TeamSettings, setTeam: (team) => { set({ @@ -52,10 +48,9 @@ export const teamStore: StateCreator< teamId: team.id, teamIntegrations: team.integrations, teamName: team.name, - teamSettings: team.teamSettings, teamSlug: team.slug, teamTheme: team.theme, - teamGeneralSettings: team.team_settings, + teamSettings: team.teamSettings, }); if (team.theme?.favicon) { @@ -69,10 +64,9 @@ export const teamStore: StateCreator< id: get().teamId, integrations: get().teamIntegrations, name: get().teamName, - teamSettings: get().teamSettings, slug: get().teamSlug, theme: get().teamTheme, - team_settings: get().teamGeneralSettings, + teamSettings: get().teamSettings, }), initTeamStore: async (slug) => { @@ -136,12 +130,10 @@ export const teamStore: StateCreator< return isSuccess; }, - updateGeneralSettings: async ( - generalSettings: Partial, - ) => { + updateTeamSettings: async (generalSettings: Partial) => { const { teamId, $client } = get(); console.log(generalSettings); - const isSuccess = await $client.team.updateGeneralSettings( + const isSuccess = await $client.team.updateTeamSettings( teamId, generalSettings, ); From 54964dc98094ca78cf29b9943d6f280a47dc2d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 3 Jul 2024 09:24:22 +0100 Subject: [PATCH 6/7] chore: Only open dependabot PRs for major versions (#3361) --- .github/dependabot.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2758fd20d0..f8baa88533 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -24,7 +24,7 @@ updates: - "theopensystemslab/planx" ignore: - dependency-name: "*" - update-types: ["version-update:semver-patch"] + update-types: ["version-update:semver-patch", "version-update:semver-minor"] # Hasura - package-ecosystem: "npm" @@ -38,7 +38,7 @@ updates: - "theopensystemslab/planx" ignore: - dependency-name: "*" - update-types: ["version-update:semver-patch"] + update-types: ["version-update:semver-patch", "version-update:semver-minor"] - package-ecosystem: "docker" directory: "/hasura.planx.uk" @@ -76,7 +76,7 @@ updates: - "theopensystemslab/planx" ignore: - dependency-name: "*" - update-types: ["version-update:semver-patch"] + update-types: ["version-update:semver-patch", "version-update:semver-minor"] # ShareDB - package-ecosystem: "npm" @@ -90,7 +90,7 @@ updates: - "theopensystemslab/planx" ignore: - dependency-name: "*" - update-types: ["version-update:semver-patch"] + update-types: ["version-update:semver-patch", "version-update:semver-minor"] - package-ecosystem: "docker" directory: "/sharedb.planx.uk" @@ -115,7 +115,7 @@ updates: - "theopensystemslab/planx" ignore: - dependency-name: "*" - update-types: ["version-update:semver-patch"] + update-types: ["version-update:semver-patch", "version-update:semver-minor"] - package-ecosystem: "docker" directory: "/api.planx.uk" @@ -142,7 +142,7 @@ updates: - "theopensystemslab/planx" ignore: - dependency-name: "*" - update-types: ["version-update:semver-patch"] + update-types: ["version-update:semver-patch", "version-update:semver-minor"] # Infrastructure # - package-ecosystem: "npm" From 85b8164ad66c029d06e4ab97ed3fae97125184bb Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 3 Jul 2024 10:34:08 +0100 Subject: [PATCH 7/7] Revert "adjust store settings" This reverts commit 140baa71670e5b2d81e4a71aa7448ab1483bb763. --- .../Settings/GeneralSettings/BoundaryForm.tsx | 2 +- .../Settings/GeneralSettings/ContactForm.tsx | 2 +- .../Settings/GeneralSettings/index.tsx | 16 ++++++++++---- .../src/pages/FlowEditor/lib/store/team.ts | 22 +++++++++++++------ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx index 67d34b2fdc..33d562e289 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/BoundaryForm.tsx @@ -11,7 +11,7 @@ export default function BoundaryForm({ formikConfig, onSuccess }: FormProps) { const formik = useFormik({ ...formikConfig, onSubmit: async (values, { resetForm }) => { - const isSuccess = await useStore.getState().updateTeamSettings({ + const isSuccess = await useStore.getState().updateGeneralSettings({ boundaryUrl: values.boundaryUrl, }); console.log("button pressed"); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx index 21f0328b44..604039692b 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ContactForm.tsx @@ -24,7 +24,7 @@ export default function ContactForm({ formikConfig, onSuccess }: FormProps) { ...formikConfig, validationSchema: formSchema, onSubmit: async (values, { resetForm }) => { - const isSuccess = await useStore.getState().updateTeamSettings({ + const isSuccess = await useStore.getState().updateGeneralSettings({ homepage: values.homepage, helpEmail: values.helpEmail, helpPhone: values.helpPhone, diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx index d5685f9054..bc7ea75ee2 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/index.tsx @@ -2,7 +2,7 @@ import Alert from "@mui/material/Alert"; import Box from "@mui/material/Box"; import Snackbar from "@mui/material/Snackbar"; import Typography from "@mui/material/Typography"; -import { TeamSettings } from "@opensystemslab/planx-core/types"; +import { GeneralTeamSettings } from "@opensystemslab/planx-core/types"; import { FormikConfig } from "formik"; import { useStore } from "pages/FlowEditor/lib/store"; import React, { useEffect, useState } from "react"; @@ -11,14 +11,22 @@ import SettingsSection from "ui/editor/SettingsSection"; import BoundaryForm from "./BoundaryForm"; import ContactForm from "./ContactForm"; +export interface GeneralSettings { + boundaryUrl: string; + helpEmail: string; + helpPhone: string; + helpOpeningHours: string; + homepage: string; +} + export interface FormProps { - formikConfig: FormikConfig; + formikConfig: FormikConfig; onSuccess: () => void; } const GeneralSettings: React.FC = () => { const [formikConfig, setFormikConfig] = useState< - FormikConfig | undefined + FormikConfig | undefined >(undefined); useEffect(() => { @@ -28,7 +36,7 @@ const GeneralSettings: React.FC = () => { console.log(fetchedTeam); if (!fetchedTeam) throw Error("Unable to find team"); setFormikConfig({ - initialValues: fetchedTeam.teamSettings, + initialValues: fetchedTeam.team_settings, onSubmit: () => {}, validateOnBlur: false, validateOnChange: false, diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts index 6a6b15f780..2f1254840b 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts @@ -15,9 +15,10 @@ export interface TeamStore { teamId: number; teamIntegrations: TeamIntegrations; teamName: string; + teamSettings: TeamSettings; teamSlug: string; teamTheme: TeamTheme; - teamSettings: TeamSettings; + teamGeneralSettings: GeneralTeamSettings; setTeam: (team: Team) => void; getTeam: () => Team; @@ -25,7 +26,9 @@ export interface TeamStore { clearTeamStore: () => void; fetchCurrentTeam: () => Promise; updateTeamTheme: (theme: Partial) => Promise; - updateTeamSettings: (teamSettings: Partial) => Promise; + updateGeneralSettings: ( + generalSettings: Partial, + ) => Promise; } export const teamStore: StateCreator< @@ -38,9 +41,10 @@ export const teamStore: StateCreator< teamId: 0, teamIntegrations: {} as TeamIntegrations, teamName: "", + teamSettings: {} as TeamSettings, teamSlug: "", teamTheme: {} as TeamTheme, - teamSettings: {} as TeamSettings, + teamGeneralSettings: {} as GeneralTeamSettings, setTeam: (team) => { set({ @@ -48,9 +52,10 @@ export const teamStore: StateCreator< teamId: team.id, teamIntegrations: team.integrations, teamName: team.name, + teamSettings: team.teamSettings, teamSlug: team.slug, teamTheme: team.theme, - teamSettings: team.teamSettings, + teamGeneralSettings: team.team_settings, }); if (team.theme?.favicon) { @@ -64,9 +69,10 @@ export const teamStore: StateCreator< id: get().teamId, integrations: get().teamIntegrations, name: get().teamName, + teamSettings: get().teamSettings, slug: get().teamSlug, theme: get().teamTheme, - teamSettings: get().teamSettings, + team_settings: get().teamGeneralSettings, }), initTeamStore: async (slug) => { @@ -130,10 +136,12 @@ export const teamStore: StateCreator< return isSuccess; }, - updateTeamSettings: async (generalSettings: Partial) => { + updateGeneralSettings: async ( + generalSettings: Partial, + ) => { const { teamId, $client } = get(); console.log(generalSettings); - const isSuccess = await $client.team.updateTeamSettings( + const isSuccess = await $client.team.updateGeneralSettings( teamId, generalSettings, );