Fixed website refresh after save.

This commit is contained in:
Mike Cao 2024-02-14 23:21:35 -08:00
parent f01073c46a
commit f50067e44f
4 changed files with 26 additions and 20 deletions

View file

@ -7,7 +7,6 @@ import {
Button,
Toggle,
LoadingButton,
useToasts,
} from 'react-basics';
import { useContext, useState } from 'react';
import { getRandomChars } from 'next-basics';
@ -18,6 +17,7 @@ const generateId = () => getRandomChars(16);
export function ShareUrl({
hostUrl,
onSave,
}: {
websiteId: string;
hostUrl?: string;
@ -27,7 +27,6 @@ export function ShareUrl({
const { domain, shareId } = website;
const { formatMessage, labels, messages } = useMessages();
const [id, setId] = useState(shareId);
const { showToast } = useToasts();
const { post, useMutation } = useApi();
const { mutate, error, isPending } = useMutation({
mutationFn: (data: any) => post(`/websites/${website.id}`, data),
@ -46,7 +45,8 @@ export function ShareUrl({
const data = { shareId: checked ? generateId() : null };
mutate(data, {
onSuccess: async () => {
showToast({ message: formatMessage(messages.saved), variant: 'success' });
touch(`website:${website.id}`);
onSave?.();
},
});
setId(data.shareId);
@ -57,8 +57,8 @@ export function ShareUrl({
{ shareId: id },
{
onSuccess: async () => {
showToast({ message: formatMessage(messages.saved), variant: 'success' });
touch(`website:${website?.id}`);
touch(`website:${website.id}`);
onSave?.();
},
},
);