Skip to content

Commit 81b00bd

Browse files
Merge branch 'develop' into contribution
2 parents 41d1882 + 4b53989 commit 81b00bd

File tree

5 files changed

+85
-16
lines changed

5 files changed

+85
-16
lines changed

.github/pull_request_template.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# ✨ Codu Pull Request 💻
22

33
Fixes #(issue)
4+
45
<!-- for example `Fixes #1012` -->
56

67
## Pull Request details
78

8-
- INFO ABOUT YOUR PULL REQUEST GOES HERE (Please be as descriptive as possible) 🤜
9-
- Use bullet points to make it easy to read.
9+
<!-- - INFO ABOUT YOUR PULL REQUEST GOES HERE (Please be as descriptive as possible) 🤜
10+
- Use bullet points to make it easy to read. -->
1011

1112
## Any Breaking changes
1213

13-
- IF ANYTHING YOU'RE COMMITTING WOULD BREAK SOMETHING, INCLUDE HERE WHAT WOULD BREAK
14-
- IF YOU HAVE NO BREAKING CHANGES, ENTER 'None'
14+
<!-- - IF ANYTHING YOU'RE COMMITTING WOULD BREAK SOMETHING, INCLUDE HERE WHAT WOULD BREAK
15+
- IF YOU HAVE NO BREAKING CHANGES, ENTER 'None' --->
1516

1617
## Associated Screenshots
1718

18-
- IF YOU HAVE ANY SCREENSHOTS, INCLUDE THEM HERE. _( Welcome file extensions include gifs/png screenshots of your feature in action )_
19-
- IF YOU HAVE NO SCREENSHOTS, ENTER 'None'
19+
<!-- - IF YOU HAVE ANY SCREENSHOTS, INCLUDE THEM HERE. _( Welcome file extensions include gifs/png screenshots of your feature in action )_
20+
- IF YOU HAVE NO SCREENSHOTS, ENTER 'None' --->
2021

2122
## [Optional] What gif best describes this PR or how it makes you feel
2223

23-
- [HERES](https://stackoverflow.com/questions/34341808/is-there-a-way-to-add-an-animated-gif-to-a-markdown-file) HOW TO EASILY ADD GIFS TO A PR
24-
- IF NO GIF COMES TO MIND, ENTER 'None'
24+
<!-- - [HERES](https://stackoverflow.com/questions/34341808/is-there-a-way-to-add-an-animated-gif-to-a-markdown-file) HOW TO EASILY ADD GIFS TO A PR
25+
- IF NO GIF COMES TO MIND, ENTER 'None' -->

app/(app)/jobs/create/_client.tsx

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ import { Strong, Text } from "@/components/ui-components/text";
2424
import { Textarea } from "@/components/ui-components/textarea";
2525
import { saveJobsInput, saveJobsSchema } from "@/schema/job";
2626
import { FEATURE_FLAGS, isFlagEnabled } from "@/utils/flags";
27+
import { uploadFile } from "@/utils/s3helpers";
28+
import { getUploadUrl } from "@/app/actions/getUploadUrl";
2729
import { zodResolver } from "@hookform/resolvers/zod";
2830
import Image from "next/image";
2931
import { notFound } from "next/navigation";
3032
import React, { useRef, useState } from "react";
3133
import { Controller, SubmitHandler, useForm } from "react-hook-form";
34+
import * as Sentry from "@sentry/nextjs";
35+
import { toast } from "sonner";
3236

3337
export default function Content() {
3438
const {
@@ -54,8 +58,70 @@ export default function Content() {
5458
const flagEnabled = isFlagEnabled(FEATURE_FLAGS.JOBS);
5559
const fileInputRef = useRef<HTMLInputElement>(null);
5660
const [imgUrl, setImgUrl] = useState<string | null>(null);
61+
const [uploadStatus, setUploadStatus] = useState<
62+
"idle" | "loading" | "success" | "error"
63+
>("idle");
5764
const onSubmit: SubmitHandler<saveJobsInput> = (values) => {
58-
console.log(values);
65+
const formData = {
66+
...values,
67+
companyLogo: imgUrl || undefined,
68+
};
69+
console.log(formData);
70+
};
71+
72+
const handleLogoUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
73+
if (uploadStatus === "loading") {
74+
return toast.info("Upload in progress, please wait...");
75+
}
76+
77+
if (e.target.files && e.target.files.length > 0) {
78+
setUploadStatus("loading");
79+
80+
const file = e.target.files[0];
81+
const { size, type } = file;
82+
83+
if (size > 1048576) {
84+
setUploadStatus("error");
85+
return toast.error("File size too big (max 1MB).");
86+
}
87+
88+
try {
89+
const res = await getUploadUrl({
90+
size,
91+
type,
92+
uploadType: "uploads",
93+
});
94+
95+
const signedUrl = res?.data;
96+
97+
if (!signedUrl) {
98+
setUploadStatus("error");
99+
return toast.error(
100+
"Something went wrong uploading the logo, please retry.",
101+
);
102+
}
103+
104+
const { fileLocation } = await uploadFile(signedUrl, file);
105+
if (!fileLocation) {
106+
setUploadStatus("error");
107+
return toast.error(
108+
"Something went wrong uploading the logo, please retry.",
109+
);
110+
}
111+
112+
setUploadStatus("success");
113+
setImgUrl(fileLocation);
114+
toast.success("Company logo uploaded successfully!");
115+
} catch (error) {
116+
setUploadStatus("error");
117+
toast.error(
118+
error instanceof Error
119+
? error.message
120+
: "An error occurred while uploading the logo.",
121+
);
122+
Sentry.captureException(error);
123+
}
124+
}
59125
};
60126
if (!flagEnabled) {
61127
notFound();
@@ -89,15 +155,16 @@ export default function Content() {
89155
onClick={() => {
90156
fileInputRef.current?.click();
91157
}}
158+
disabled={uploadStatus === "loading"}
92159
>
93-
Change Logo
160+
{uploadStatus === "loading" ? "Uploading..." : "Change Logo"}
94161
</Button>
95162
<Input
96163
type="file"
97164
id="file-input"
98165
name="company-logo"
99166
accept="image/png, image/gif, image/jpeg"
100-
onChange={() => {}}
167+
onChange={handleLogoUpload}
101168
className="hidden"
102169
ref={fileInputRef}
103170
/>

app/(app)/my-posts/_client.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ const MyPosts = () => {
206206
<div className="dropdown-bg py-1">
207207
<MenuItem>
208208
<Link
209-
className="dropdown-item group flex items-center px-4 py-2 text-sm text-neutral-700 data-[focus]:bg-neutral-100 data-[focus]:text-black"
209+
className="dropdown-item group flex items-center px-4 py-2 text-sm text-neutral-700 data-[focus]:bg-neutral-100 data-[focus]:text-neutral-500"
210210
href={`/create/${id}`}
211211
>
212212
<PencilIcon
213-
className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500"
213+
className="mr-3 h-5 w-5 text-neutral-500 group-hover:text-neutral-400"
214214
aria-hidden="true"
215215
/>
216216
Edit
@@ -220,10 +220,10 @@ const MyPosts = () => {
220220
<MenuItem>
221221
<button
222222
onClick={() => setSelectedArticleToDelete(id)}
223-
className="dropdown-item group flex w-full items-center px-4 py-2 text-sm text-neutral-700 data-[focus]:bg-neutral-100 data-[focus]:text-black"
223+
className="dropdown-item group flex w-full items-center px-4 py-2 text-sm text-neutral-700 data-[focus]:bg-neutral-100 data-[focus]:text-neutral-500"
224224
>
225225
<TrashIcon
226-
className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500"
226+
className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-400"
227227
aria-hidden="true"
228228
/>
229229
Delete

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"isomorphic-dompurify": "^2.16.0",
8585
"lowlight": "^3.1.0",
8686
"lucide-react": "^0.451.0",
87-
"nanoid": "^5.0.7",
87+
"nanoid": "^5.0.9",
8888
"next": "^14.2.21",
8989
"next-auth": "^4.24.9",
9090
"next-safe-action": "^7.9.4",

schema/job.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const saveJobsSchema = z.object({
2323
.url("Provide a valid url")
2424
.optional()
2525
.or(z.literal("")),
26+
companyLogo: z.string().optional(),
2627
remote: z.boolean().optional().default(false),
2728
relocation: z.boolean().optional().default(false),
2829
visa_sponsorship: z.boolean().optional().default(false),

0 commit comments

Comments
 (0)