mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
♻️ getDocuments
This commit is contained in:
@ -19,6 +19,7 @@ import { DocumentStatus } from "@prisma/client";
|
||||
import { Tooltip as ReactTooltip } from "react-tooltip";
|
||||
import { Button, IconButton, SelectBox } from "@documenso/ui";
|
||||
import { NextPageContext } from "next";
|
||||
import { getDocuments } from "@documenso/lib/api";
|
||||
|
||||
const DocumentsPage: NextPageWithLayout = (props: any) => {
|
||||
const router = useRouter();
|
||||
@ -48,15 +49,10 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
|
||||
createdFilter[0]
|
||||
);
|
||||
|
||||
const getDocuments = async () => {
|
||||
const loadDocuments = async () => {
|
||||
if (!documents.length) setLoading(true);
|
||||
// todo encapsulate
|
||||
fetch("/api/documents", {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then((res) => {
|
||||
res.json().then((j) => {
|
||||
getDocuments().then((res: any) => {
|
||||
res.json().then((j: any) => {
|
||||
setDocuments(j);
|
||||
setLoading(false);
|
||||
});
|
||||
@ -64,7 +60,7 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getDocuments().finally(() => {
|
||||
loadDocuments().finally(() => {
|
||||
setSelectedStatusFilter(
|
||||
statusFilters.filter(
|
||||
(status) => status.value === props.filter.toUpperCase()
|
||||
@ -368,7 +364,7 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
|
||||
setDocuments(documentsWithoutIndex);
|
||||
})
|
||||
.then(() => {
|
||||
getDocuments();
|
||||
loadDocuments();
|
||||
});
|
||||
}
|
||||
}}
|
||||
|
||||
7
packages/lib/api/getDocuments.ts
Normal file
7
packages/lib/api/getDocuments.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export const getDocuments = (): any => {
|
||||
return fetch("/api/documents", {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -3,3 +3,4 @@ export { deleteField } from "./deleteField";
|
||||
export { signDocument } from "./signDocument";
|
||||
export { getUser } from "./getUser";
|
||||
export { signup } from "./signup";
|
||||
export { getDocuments } from "./getDocuments";
|
||||
|
||||
Reference in New Issue
Block a user