Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: change on missing folder

Marc Seitzad7e2b169779
diff --git a/lib/swr/use-documents.ts b/lib/swr/use-documents.ts
index 5e6d6493..6e5b953d 100644
--- a/lib/swr/use-documents.ts
+++ b/lib/swr/use-documents.ts
@@ -86,7 +86,8 @@ export type FolderWithCount = Folder & {
};
export function useFolder({ name }: { name: string[] }) {
- const teamInfo = useTeam();
+ const { currentTeamId } = useTeam();
+ const router = useRouter();
const { data: folders, error } = useSWR<FolderWithCount[]>(
teamInfo?.currentTeam?.id &&
@@ -96,6 +97,11 @@ export function useFolder({ name }: { name: string[] }) {
{
revalidateOnFocus: false,
dedupingInterval: 30000,
+ onError: (err) => {
+ if (err.status === 404) {
+ router.replace("/documents");
+ }
+ },
},
);