upload ux
This commit is contained in:
@@ -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}`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user