Skip to content

Commit

Permalink
build(admin): ➕ added uploadthing
Browse files Browse the repository at this point in the history
  • Loading branch information
sahrohit committed Sep 25, 2023
1 parent 8006aed commit 5bedd2d
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 87 deletions.
2 changes: 2 additions & 0 deletions apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "^2.9.11",
"@tanstack/react-table": "^8.9.11",
"@uploadthing/react": "^5.6.1",
"framer-motion": "^6.5.1",
"next": "latest",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.45.4",
"react-icons": "^4.11.0",
"uploadthing": "^5.6.1",
"yup": "^0.32.11"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions apps/admin/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { AppProps } from "next/app";
import { useRouter } from "next/router";
import theme from "@/config/theme";
import SidebarLayout from "@/components/shared/sidebar";
import "@uploadthing/react/styles.css";

export const client = new ApolloClient({
uri: `${process.env.NEXT_PUBLIC_API_URL}/graphql`,
Expand Down
9 changes: 9 additions & 0 deletions apps/admin/src/pages/api/uploadthing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable import/namespace */
import { createNextPageApiHandler } from "uploadthing/next-legacy";
import { ourFileRouter } from "@/server/uploadthing";

const handler = createNextPageApiHandler({
router: ourFileRouter,
});

export default handler;
15 changes: 15 additions & 0 deletions apps/admin/src/server/uploadthing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createUploadthing, type FileRouter } from "uploadthing/next-legacy";

const f = createUploadthing();

export const ourFileRouter = {
// Router for uploading documents
kycDocumentUploader: f({
image: { maxFileCount: 5 },
pdf: { maxFileCount: 5 },
}).onUploadComplete(async ({ file }) => {
console.log("file url", file.url);
}),
} satisfies FileRouter;

export type OurFileRouter = typeof ourFileRouter;
6 changes: 6 additions & 0 deletions apps/admin/src/utils/uploadthing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/namespace */
import { generateComponents } from "@uploadthing/react";
import type { OurFileRouter } from "@/server/uploadthing";

export const { UploadButton, UploadDropzone, Uploader } =
generateComponents<OurFileRouter>();
Loading

0 comments on commit 5bedd2d

Please sign in to comment.