upload ux

This commit is contained in:
Timur Ercan
2023-01-24 18:31:35 +01:00
parent 65ea717ff4
commit d463c45f76
2 changed files with 49 additions and 28 deletions

View File

@@ -16,6 +16,7 @@ import {
import { FormProvider, useForm } from "react-hook-form";
import Router from "next/router";
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib";
import toast from "react-hot-toast";
type FormValues = {
document: File;
@@ -66,16 +67,25 @@ const DashboardPage: NextPageWithLayout = () => {
const body = new FormData();
const document = event.target.files[0];
body.append("document", document || "");
const response: any = await fetch("/api/documents", {
method: "POST",
body,
}).then((response: Response) => {
response.json().then((createdDocumentIdFromBody) => {
Router.push(
`${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}`
);
const response: any = await toast
.promise(
fetch("/api/documents", {
method: "POST",
body,
}),
{
loading: "Uploading document...",
success: "Document uploaded successfully.",
error: "Could not upload document :/",
}
)
.then((response: Response) => {
response.json().then((createdDocumentIdFromBody) => {
Router.push(
`${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}`
);
});
});
});
}
};