From c7b1abe8f7823c02271fb5f05bc311ba8e6635f1 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Mon, 23 Jan 2023 17:57:50 +0100 Subject: [PATCH] upload file POC --- apps/web/pages/dashboard.tsx | 37 +++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx index d1f1529d0..fb0b95848 100644 --- a/apps/web/pages/dashboard.tsx +++ b/apps/web/pages/dashboard.tsx @@ -1,6 +1,6 @@ import { useSession } from "next-auth/react"; import Head from "next/head"; -import type { ReactElement } from "react"; +import { ReactElement, useEffect, useState } from "react"; import Layout from "../components/layout"; import Settings from "../components/settings"; import Link from "next/link"; @@ -13,9 +13,15 @@ import { SunIcon, XCircleIcon, } from "@heroicons/react/24/outline"; +import { FormProvider, useForm } from "react-hook-form"; +import Router from "next/router"; +import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib"; + +type FormValues = { + document: File; +}; const DashboardPage: NextPageWithLayout = () => { - const status = useSession(); const stats = [ { name: "Draft", @@ -54,6 +60,24 @@ const DashboardPage: NextPageWithLayout = () => { link: "/documents?filter=", }, ]; + const uploadToServer = async (event: any) => { + if (event.target.files && event.target.files[0]) { + 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: any) => { + Router.push( + `${NEXT_PUBLIC_WEBAPP_URL}/documents/${ + response.json().creadtedDocumentId + }` + ); + }); + } + }; + return ( <> @@ -108,7 +132,14 @@ const DashboardPage: NextPageWithLayout = () => { Upload a new PDF document - + { + uploadToServer(event); + }} + hidden + />