Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(site): Update the template form when a value is changed
  • Loading branch information
BrunoQuaresma committed Jun 6, 2023
commit 86805697ebb5e813f8519101527a23a283b31bd5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from "@tanstack/react-query"
import { useMutation, useQueryClient } from "@tanstack/react-query"
import { updateTemplateMeta } from "api/api"
import { UpdateTemplateMeta } from "api/typesGenerated"
import { displaySuccess } from "components/GlobalSnackbar/utils"
Expand All @@ -7,14 +7,18 @@ import { Helmet } from "react-helmet-async"
import { useTranslation } from "react-i18next"
import { useNavigate, useParams } from "react-router-dom"
import { pageTitle } from "utils/page"
import { useTemplateSettingsContext } from "../TemplateSettingsLayout"
import {
getTemplateQuery,
useTemplateSettingsContext,
} from "../TemplateSettingsLayout"
import { TemplateSettingsPageView } from "./TemplateSettingsPageView"

export const TemplateSettingsPage: FC = () => {
const { template: templateName } = useParams() as { template: string }
const { t } = useTranslation("templateSettingsPage")
const navigate = useNavigate()
const { template } = useTemplateSettingsContext()
const queryClient = useQueryClient()
const {
mutate: updateTemplate,
isLoading: isSubmitting,
Expand All @@ -23,6 +27,9 @@ export const TemplateSettingsPage: FC = () => {
(data: UpdateTemplateMeta) => updateTemplateMeta(template.id, data),
{
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: getTemplateQuery(templateName),
})
displaySuccess("Template updated successfully")
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ const fetchTemplateSettings = async (orgId: string, name: string) => {
}
}

export const getTemplateQuery = (name: string) => ["template", name, "settings"]

const useTemplate = (orgId: string, name: string) => {
return useQuery({
queryKey: ["template", name, "settings"],
queryKey: getTemplateQuery(name),
queryFn: () => fetchTemplateSettings(orgId, name),
keepPreviousData: true,
})
}

Expand Down