fix: limits syncing issue (#1195)

Exposes `refreshLimits()` to be able to keep the limit in sync when
deleting/creating a document.
This commit is contained in:
emmpaz
2024-07-31 07:57:27 -05:00
committed by GitHub
parent 5582f29bda
commit 1beb434a72
4 changed files with 24 additions and 11 deletions

View File

@ -4,6 +4,7 @@ import { useRouter } from 'next/navigation';
import { match } from 'ts-pattern';
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
import { DocumentStatus } from '@documenso/prisma/client';
import { trpc as trpcReact } from '@documenso/trpc/react';
import { Alert, AlertDescription } from '@documenso/ui/primitives/alert';
@ -41,6 +42,7 @@ export const DeleteDocumentDialog = ({
const router = useRouter();
const { toast } = useToast();
const { refreshLimits } = useLimits();
const [inputValue, setInputValue] = useState('');
const [isDeleteEnabled, setIsDeleteEnabled] = useState(status === DocumentStatus.DRAFT);
@ -48,6 +50,7 @@ export const DeleteDocumentDialog = ({
const { mutateAsync: deleteDocument, isLoading } = trpcReact.document.deleteDocument.useMutation({
onSuccess: () => {
router.refresh();
void refreshLimits();
toast({
title: 'Document deleted',

View File

@ -36,7 +36,7 @@ export const UploadDocument = ({ className, team }: UploadDocumentProps) => {
const { toast } = useToast();
const { quota, remaining } = useLimits();
const { quota, remaining, refreshLimits } = useLimits();
const [isLoading, setIsLoading] = useState(false);
@ -71,6 +71,8 @@ export const UploadDocument = ({ className, team }: UploadDocumentProps) => {
teamId: team?.id,
});
void refreshLimits();
toast({
title: 'Document uploaded',
description: 'Your document has been uploaded successfully.',