-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rename setSiteConfigAdmin to setSiteConfigByAdmin
- Loading branch information
Showing
3 changed files
with
35 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ import { useIsUserIsomerAdmin } from "~/hooks/useIsUserIsomerAdmin" | |
import { useQueryParse } from "~/hooks/useQueryParse" | ||
import { useZodForm } from "~/lib/form" | ||
import { type NextPageWithLayout } from "~/lib/types" | ||
import { setSiteConfigAdminSchema } from "~/schemas/site" | ||
import { setSiteConfigByAdminSchema } from "~/schemas/site" | ||
import { AdminSidebarOnlyLayout } from "~/templates/layouts/AdminSidebarOnlyLayout" | ||
import { trpc } from "~/utils/trpc" | ||
|
||
|
@@ -56,31 +56,6 @@ const SiteAdminPage: NextPageWithLayout = () => { | |
void router.push(`/sites/${siteId}`) | ||
} | ||
|
||
const { mutate, isLoading } = trpc.site.setSiteConfigAdmin.useMutation({ | ||
onSuccess: async () => { | ||
// reset({ config, theme, navbar, footer }) | ||
await trpcUtils.site.getConfig.invalidate({ id: siteId }) | ||
await trpcUtils.site.getTheme.invalidate({ id: siteId }) | ||
await trpcUtils.site.getNavbar.invalidate({ id: siteId }) | ||
await trpcUtils.site.getFooter.invalidate({ id: siteId }) | ||
toast({ | ||
title: "Saved site config!", | ||
description: "Check your site in 5-10 minutes to view it live.", | ||
status: "success", | ||
...BRIEF_TOAST_SETTINGS, | ||
}) | ||
}, | ||
onError: () => { | ||
toast({ | ||
title: "Error saving site config!", | ||
description: | ||
"If this persists, please report this issue at [email protected]", | ||
status: "error", | ||
...BRIEF_TOAST_SETTINGS, | ||
}) | ||
}, | ||
}) | ||
|
||
const [previousConfig] = trpc.site.getConfig.useSuspenseQuery({ | ||
id: siteId, | ||
}) | ||
|
@@ -94,13 +69,15 @@ const SiteAdminPage: NextPageWithLayout = () => { | |
id: siteId, | ||
}) | ||
|
||
// NOTE: Refining the setNotificationSchema here instead of in site.ts since omit does not work after refine | ||
// NOTE: Refining the setSiteConfigByAdminSchema here instead of in site.ts since omit does not work after refine | ||
const { | ||
reset, | ||
watch, | ||
register, | ||
handleSubmit, | ||
formState: { isDirty, errors }, | ||
} = useZodForm({ | ||
schema: setSiteConfigAdminSchema | ||
schema: setSiteConfigByAdminSchema | ||
.omit({ siteId: true }) | ||
.refine((data) => !!data.config, { | ||
message: "Site config must be present", | ||
|
@@ -126,6 +103,32 @@ const SiteAdminPage: NextPageWithLayout = () => { | |
}, | ||
}) | ||
|
||
const { mutate, isLoading } = trpc.site.setSiteConfigByAdmin.useMutation({ | ||
onSuccess: async () => { | ||
await trpcUtils.site.getConfig.invalidate({ id: siteId }) | ||
await trpcUtils.site.getTheme.invalidate({ id: siteId }) | ||
await trpcUtils.site.getNavbar.invalidate({ id: siteId }) | ||
await trpcUtils.site.getFooter.invalidate({ id: siteId }) | ||
// Reset the form's isDirty but use the latest values provided by the user | ||
reset(watch()) | ||
toast({ | ||
title: "Saved site config!", | ||
description: "Check your site in 5-10 minutes to view it live.", | ||
status: "success", | ||
...BRIEF_TOAST_SETTINGS, | ||
}) | ||
}, | ||
onError: () => { | ||
toast({ | ||
title: "Error saving site config!", | ||
description: | ||
"If this persists, please report this issue at [email protected]", | ||
status: "error", | ||
...BRIEF_TOAST_SETTINGS, | ||
}) | ||
}, | ||
}) | ||
|
||
const [nextUrl, setNextUrl] = useState("") | ||
const isOpen = !!nextUrl | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters