Skip to content

Commit 714b191

Browse files
committed
add tRPC route for resumes (progress)
1 parent 0a916e6 commit 714b191

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

apps/blade/src/app/member/application/_components/member-application-form.tsx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ export function MemberApplicationForm() {
5050
},
5151
});
5252

53-
const uploadResume = async (file: File): Promise<string> => {
54-
if (!file) throw new Error("No file provided");
55-
56-
const resumeUrl = await api.resume.uploadResume.useMutation().mutateAsync({
57-
fileName: file.name,
58-
fileContent: file,
59-
});
60-
61-
return resumeUrl;
62-
}
53+
const uploadResume = api.resume.uploadResume.useMutation({
54+
onSuccess() {
55+
toast.success("Resume sent to bucket!");
56+
},
57+
onError() {
58+
toast.error("There was a problem storing your resume, please try again!");
59+
}
60+
});
6361

6462
const form = useForm({
6563
schema: InsertMemberSchema.extend({
@@ -171,9 +169,22 @@ export function MemberApplicationForm() {
171169
<form
172170
className="space-y-4"
173171
noValidate
174-
onSubmit={form.handleSubmit((values) => {
175-
const resumeUrl = uploadResume(values.resumeUpload[0]);
176-
createMember.mutate(values);
172+
onSubmit={form.handleSubmit(async (values) => {
173+
try {
174+
let resumeUrl = "";
175+
if (values.resumeUpload?.length) {
176+
const file = values.resumeUpload[0];
177+
resumeUrl = await uploadResume.mutateAsync(file);
178+
}
179+
180+
createMember.mutate({
181+
...values,
182+
resumeUrl, // Include uploaded resume URL
183+
});
184+
} catch (error) {
185+
console.error("Error uploading resume or creating member:", error);
186+
toast.error("Something went wrong while processing your application.");
187+
}
177188
})}
178189
>
179190
<h1 className="text-2xl font-bold">Application Form</h1>

packages/api/src/routers/resume-upload.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,27 @@ import { z } from "zod";
44
import { env } from "../env";
55

66
const s3Client = new Client({
7-
endPoint: "",
7+
endPoint: env.MINIO_ENDPOINT,
88
accessKey: env.MINIO_ACCESS_KEY,
99
secretKey: env.MINIO_SECRET_KEY,
1010
});
1111

1212
export const resumeUploadRouter = {
1313
uploadResume: protectedProcedure.input(
14-
z.object({
15-
fileName: z.string(),
16-
fileContent: z.instanceof(File),
17-
})
14+
z.instanceof(File)
1815
)
1916
.mutation(async ({ input, ctx }) => {
20-
const { fileName, fileContent } = input;
21-
2217
const bucketName = "member-resumes";
23-
const objectName = `${ctx.session.user.id}/${fileName}`;
24-
const fileStream = fileContent.stream;
18+
const objectName = `${ctx.session.user.id}/${input.name}`;
2519

2620
// Ensure bucket exists
2721
const bucketExists = await s3Client.bucketExists(bucketName);
2822
if (!bucketExists) {
2923
await s3Client.makeBucket(bucketName, "us-east-1");
3024
}
3125

32-
await s3Client.putObject(bucketName, objectName, fileStream);
33-
const resumeUrl = `${env.MINIO_PUBLIC_URL}/${bucketName}/${objectName}`;
26+
await s3Client.putObject(bucketName, objectName, file);
27+
const resumeUrl = `https://${env.MINIO_ENDPOINT}/${bucketName}/${objectName}`;
3428
})
3529
};
3630

0 commit comments

Comments
 (0)