mirror of
https://github.com/hanzoai/captable.git
synced 2026-10-16 14:21:29 +00:00
Merge pull request #352 from captableinc/fix-uploader-types
feat: make uploader component more type safe
This commit is contained in:
@@ -343,7 +343,7 @@ model EquityPlan {
|
||||
}
|
||||
|
||||
model Bucket {
|
||||
id String @id @default(cuid())
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
key String
|
||||
mimeType String
|
||||
|
||||
@@ -36,7 +36,7 @@ const DocumentUploadModal = ({
|
||||
<Uploader
|
||||
shouldUpload={true}
|
||||
identifier={companyPublicId}
|
||||
keyPrefix="generic-document"
|
||||
keyPrefix="generic-documents"
|
||||
tags={[TAG.GENERIC]}
|
||||
onSuccess={async (uploadedData: UploadReturn) => {
|
||||
await mutateAsync({
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ const DataRoomUploader = ({
|
||||
shouldUpload
|
||||
multiple={true}
|
||||
identifier={companyPublicId}
|
||||
keyPrefix={`data-room/${dataRoom.publicId}/file`}
|
||||
keyPrefix={`data-room/${dataRoom.publicId}`}
|
||||
tags={[TAG.DATA_ROOM]}
|
||||
onSuccess={async (upload: UploadReturn) => {
|
||||
const document = await documentMutation.mutateAsync({
|
||||
|
||||
@@ -69,7 +69,7 @@ export function AddRecipientStep({ companyPublicId }: AddRecipientStepProps) {
|
||||
}
|
||||
const { key, mimeType, name, size } = await uploadFile(document, {
|
||||
identifier: companyPublicId,
|
||||
keyPrefix: "EsignDocs",
|
||||
keyPrefix: "unsigned-esign-doc",
|
||||
});
|
||||
|
||||
const { id: bucketId, name: templateName } = await handleBucketUpload({
|
||||
|
||||
@@ -14,10 +14,8 @@ export function UploadDocumentStep() {
|
||||
<StepperStep title="Upload a document">
|
||||
<StepperModalContent>
|
||||
<Uploader
|
||||
identifier={""}
|
||||
shouldUpload={false}
|
||||
keyPrefix="equity-doc"
|
||||
onSuccess={async (file) => {
|
||||
onSuccess={(file) => {
|
||||
setValue({ document: file });
|
||||
next();
|
||||
}}
|
||||
|
||||
@@ -113,12 +113,15 @@ export const ProfileSettings = ({ memberProfile }: ProfileType) => {
|
||||
|
||||
async function handleImageUpload(file: File): Promise<{ imageUrl: string }> {
|
||||
if (session?.user.id) {
|
||||
const options = {
|
||||
expiresIn: 3600,
|
||||
keyPrefix: "profile-avatars",
|
||||
identifier: session.user.id,
|
||||
};
|
||||
const { fileUrl } = await uploadFile(file, options, "publicBucket");
|
||||
const { fileUrl } = await uploadFile(
|
||||
file,
|
||||
{
|
||||
expiresIn: 3600,
|
||||
keyPrefix: "profile-avatars",
|
||||
identifier: session.user.id,
|
||||
},
|
||||
"publicBucket",
|
||||
);
|
||||
|
||||
return { imageUrl: fileUrl };
|
||||
}
|
||||
|
||||
@@ -111,12 +111,15 @@ export const CompanyForm = ({ type, data }: CompanyFormProps) => {
|
||||
|
||||
async function handleLogoUpload(file: File): Promise<{ imageUrl: string }> {
|
||||
if (user?.user.id) {
|
||||
const options = {
|
||||
expiresIn: 3600,
|
||||
keyPrefix: "company-logo",
|
||||
identifier: user.user.id,
|
||||
};
|
||||
const { fileUrl } = await uploadFile(file, options, "publicBucket");
|
||||
const { fileUrl } = await uploadFile(
|
||||
file,
|
||||
{
|
||||
expiresIn: 3600,
|
||||
keyPrefix: "company-logos",
|
||||
identifier: user.user.id,
|
||||
},
|
||||
"publicBucket",
|
||||
);
|
||||
setImageUrl(fileUrl);
|
||||
|
||||
return { imageUrl: fileUrl };
|
||||
|
||||
@@ -68,8 +68,6 @@ export function SafeDocuments() {
|
||||
<div>
|
||||
<Uploader
|
||||
multiple={true}
|
||||
identifier={""}
|
||||
keyPrefix="existing-safes"
|
||||
shouldUpload={false}
|
||||
onSuccess={(bucketData) => {
|
||||
setDocumentsList(bucketData);
|
||||
|
||||
@@ -263,8 +263,6 @@ function CustomTemplateField({
|
||||
return (
|
||||
<div>
|
||||
<Uploader
|
||||
identifier={""}
|
||||
keyPrefix="new-safes"
|
||||
shouldUpload={false}
|
||||
onSuccess={(bucketData) => {
|
||||
setDocumentsList(bucketData);
|
||||
|
||||
@@ -50,7 +50,7 @@ export const Documents = () => {
|
||||
for (const document of documentsList) {
|
||||
const { key, mimeType, name, size } = await uploadFile(document, {
|
||||
identifier: session.user.companyPublicId,
|
||||
keyPrefix: "stockOptionDocs",
|
||||
keyPrefix: "stock-option-docs",
|
||||
});
|
||||
|
||||
const { id: bucketId, name: docName } = await handleBucketUpload({
|
||||
@@ -72,8 +72,6 @@ export const Documents = () => {
|
||||
<div>
|
||||
<Uploader
|
||||
multiple={true}
|
||||
identifier={""}
|
||||
keyPrefix="equity-doc"
|
||||
shouldUpload={false}
|
||||
onSuccess={(bucketData) => {
|
||||
setDocumentsList(bucketData);
|
||||
|
||||
@@ -46,7 +46,7 @@ export const Documents = () => {
|
||||
for (const document of documentsList) {
|
||||
const { key, mimeType, name, size } = await uploadFile(document, {
|
||||
identifier: session.user.companyPublicId,
|
||||
keyPrefix: "sharesDocs",
|
||||
keyPrefix: "shares-docs",
|
||||
});
|
||||
const { id: bucketId, name: docName } = await handleBucketUpload({
|
||||
key,
|
||||
@@ -64,8 +64,6 @@ export const Documents = () => {
|
||||
<div>
|
||||
<Uploader
|
||||
multiple={true}
|
||||
identifier={""}
|
||||
keyPrefix="equity-doc"
|
||||
shouldUpload={false}
|
||||
onSuccess={(bucketData) => {
|
||||
setDocumentsList(bucketData);
|
||||
|
||||
@@ -13,6 +13,7 @@ import { toast } from "sonner";
|
||||
import { Button } from "./button";
|
||||
|
||||
import type { TagType } from "@/lib/tags";
|
||||
import type { TypeKeyPrefixes } from "@/server/file-uploads";
|
||||
import type { RouterOutputs } from "@/trpc/shared";
|
||||
|
||||
export type UploadReturn = RouterOutputs["bucket"]["create"];
|
||||
@@ -26,22 +27,26 @@ type UploadProps =
|
||||
| {
|
||||
shouldUpload?: true;
|
||||
onSuccess?: (data: UploadReturn) => void | Promise<void>;
|
||||
identifier: string;
|
||||
keyPrefix: TypeKeyPrefixes;
|
||||
tags: TagType[];
|
||||
}
|
||||
| {
|
||||
shouldUpload: false;
|
||||
onSuccess?: (data: FileWithPath[]) => void | Promise<void>;
|
||||
identifier?: never;
|
||||
keyPrefix?: never;
|
||||
tags?: TagType[];
|
||||
};
|
||||
|
||||
type Props = {
|
||||
header?: React.ReactNode;
|
||||
// should be companyPublicId or memberId or userId
|
||||
identifier: string;
|
||||
keyPrefix: string;
|
||||
|
||||
multiple?: boolean;
|
||||
} & DocumentUploadDropzone &
|
||||
UploadProps;
|
||||
|
||||
export function Uploader({
|
||||
header,
|
||||
identifier,
|
||||
@@ -70,10 +75,11 @@ export function Uploader({
|
||||
toast.error("Please provide document tags.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const file of acceptedFiles) {
|
||||
const { key, mimeType, name, size } = await uploadFile(file, {
|
||||
identifier,
|
||||
keyPrefix,
|
||||
identifier: identifier as string,
|
||||
keyPrefix: keyPrefix as TypeKeyPrefixes,
|
||||
});
|
||||
|
||||
const data = await mutateAsync({
|
||||
|
||||
+1
-1
@@ -211,7 +211,7 @@ export async function uploadEsignDocuments({
|
||||
|
||||
const data = await uploadFile(file, {
|
||||
identifier: companyId,
|
||||
keyPrefix: "generic-document",
|
||||
keyPrefix: "signed-esign-doc",
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use server";
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
|
||||
import path from "node:path";
|
||||
import { customId } from "@/common/id";
|
||||
@@ -33,11 +31,23 @@ const S3 = new S3Client({
|
||||
: undefined,
|
||||
});
|
||||
|
||||
export type TypeKeyPrefixes =
|
||||
| "new-safes"
|
||||
| "existing-safes"
|
||||
| "signed-esign-doc"
|
||||
| "unsigned-esign-doc"
|
||||
| "stock-option-docs"
|
||||
| "company-logos"
|
||||
| "profile-avatars"
|
||||
| "generic-documents"
|
||||
| "shares-docs"
|
||||
| `data-room/${string}`;
|
||||
|
||||
export interface getPresignedUrlOptions {
|
||||
contentType: string;
|
||||
expiresIn?: number;
|
||||
fileName: string;
|
||||
keyPrefix: string;
|
||||
keyPrefix: TypeKeyPrefixes;
|
||||
// should be companyPublicId or memberId or userId
|
||||
identifier: string;
|
||||
bucketMode: "privateBucket" | "publicBucket";
|
||||
@@ -81,7 +91,7 @@ export const getPresignedGetUrl = async (key: string) => {
|
||||
Bucket: PrivateBucket,
|
||||
Key: key,
|
||||
// ResponseContentDisposition: `attachment; filename="${key}"`,
|
||||
ResponseContentDisposition: `inline`,
|
||||
ResponseContentDisposition: "inline",
|
||||
});
|
||||
|
||||
const url = await getSignedUrl(S3, getObjectCommand, {
|
||||
|
||||
@@ -45,7 +45,7 @@ export const createSafeProcedure = withAuth
|
||||
file,
|
||||
{
|
||||
identifier: "templates",
|
||||
keyPrefix: "new-safe",
|
||||
keyPrefix: "new-safes",
|
||||
},
|
||||
"privateBucket",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user