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 Jul 3, 2024
1 parent ecc4184 commit 0509d4a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
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 InputLabel from "ui/editor/InputLabel";
import Input from "ui/shared/Input";
Expand All @@ -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 });
}
},
});

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 InputLabel from "ui/editor/InputLabel";
import Input from "ui/shared/Input";
Expand All @@ -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 });
}
},
});

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 @@ -26,6 +26,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 @@ -132,4 +135,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 0509d4a

Please sign in to comment.