Skip to content

Commit

Permalink
add update general settings to store and forms
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Jun 26, 2024
1 parent ff06241 commit 5a52e40
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@mui/material": "^5.15.2",
"@mui/utils": "^5.15.2",
"@opensystemslab/map": "^0.8.2",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#0e84ec2",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#77bfdb7",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
10 changes: 5 additions & 5 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useFormik } from "formik";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { ChangeEvent } from "react";
import InputDescription from "ui/editor/InputDescription";
import Input from "ui/shared/Input";
Expand All @@ -11,9 +12,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 });
}
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useFormik } from "formik";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { ChangeEvent } from "react";
import InputDescription from "ui/editor/InputDescription";
import Input from "ui/shared/Input";
Expand All @@ -22,9 +23,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 });
}
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ const GeneralSettings: React.FC = () => {
FormikConfig<GeneralTeamSettings> | undefined
>(undefined);

const initialValues = {
boundaryUrl: "",
helpEmail: "",
helpPhone: "",
helpOpeningHours: "",
homepage: "",
boundaryJson: {},
referenceCode: "",
emailReplyToId: "",
};

useEffect(() => {
const fetchTeam = async () => {
try {
Expand Down
15 changes: 15 additions & 0 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export interface TeamStore {
clearTeamStore: () => void;
fetchCurrentTeam: () => Promise<Team>;
updateTeamTheme: (theme: Partial<TeamTheme>) => Promise<boolean>;
updateGeneralSettings: (
generalSettings: Partial<GeneralTeamSettings>,
) => Promise<boolean>;
}

export const teamStore: StateCreator<
Expand Down Expand Up @@ -139,4 +142,16 @@ export const teamStore: StateCreator<
const isSuccess = await $client.team.updateTheme(teamId, theme);
return isSuccess;
},

updateGeneralSettings: async (
generalSettings: Partial<GeneralTeamSettings>,
) => {
const { teamId, $client } = get();
console.log(generalSettings);
const isSuccess = await $client.team.updateGeneralSettings(
teamId,
generalSettings,
);
return isSuccess;
},
});

0 comments on commit 5a52e40

Please sign in to comment.