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; + }, });