Skip to content

Commit

Permalink
Merge pull request #27 from Kashyap1ankit/fix/hero
Browse files Browse the repository at this point in the history
added company logo image upload fucntion
  • Loading branch information
Kashyap1ankit authored Nov 13, 2024
2 parents a86caae + f18462b commit b91d0c7
Show file tree
Hide file tree
Showing 19 changed files with 273 additions and 208 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ next-env.d.ts
**/public/worker-*.js
**/public/sw.js.map
**/public/workbox-*.js.map
**/public/worker-*.js.map
**/public/worker-*.js.map

package-lock.json
67 changes: 67 additions & 0 deletions app/actions/posts/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
import { createJobSchema, createJobSchemaType } from "@/schema/jobs";
import { CheckUser } from "../users/checkUser";
import prisma from "@/db";
import { v2 as cloudinary } from "cloudinary";
import streamifier from "streamifier";
import { File } from "buffer";

cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});

// Create new Jobs

Expand All @@ -19,6 +28,8 @@ export async function CreateJob(postdata: createJobSchemaType) {
data: {
apply_link: postdata.apply_link,
company: postdata.company,
company_logo: postdata.company_logo,
company_website: postdata.company_website,
experience_level: postdata.experience_level,
job_type: postdata.job_type,
location: postdata.location,
Expand Down Expand Up @@ -69,6 +80,8 @@ export async function GetAllPost() {
id: true,
apply_link: true,
company: true,
company_logo: true,
company_website: true,
experience_level: true,
job_type: true,
location: true,
Expand Down Expand Up @@ -122,6 +135,8 @@ export async function GetPostByAuthorId(authorId: string) {
id: true,
apply_link: true,
company: true,
company_logo: true,
company_website: true,
experience_level: true,
job_type: true,
location: true,
Expand Down Expand Up @@ -202,3 +217,55 @@ export async function DestroyPost(postId: string, authorId: string) {
};
}
}

//Upload Image

export async function UploadImage(data: FormData) {
try {
const file = data.get("image");

if (!file || !(file instanceof File)) {
return {
status: 401,
message: "File is not provided",
};
}
//Converting the file instance to buffer
const bufferArr = await file.arrayBuffer();
const buffer = Buffer.from(bufferArr);

const uploadToCloud = new Promise<any>((resolve, reject) => {
const cld = cloudinary.uploader.upload_stream(
{
use_filename: true,
folder: "jobjunction",
overwrite: false,
},
(err: any, res: any) => {
if (err) {
reject(err);
}
resolve(res);
}
);

streamifier.createReadStream(buffer).pipe(cld);
});

const uploadedImageObject = await uploadToCloud;

return {
status: 200,
message: "File uploaded successfully",
public_id: uploadedImageObject.public_id,
secure_url: uploadedImageObject.secure_url,
};
} catch (error) {
return {
status: 200,
message: "File unot ploaded",
public_id: null,
secure_url: null,
};
}
}
18 changes: 1 addition & 17 deletions components/Admin/Users/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export default function AllUser() {
const session = useSession();
const [users, setUsers] = useState<GetAllUserType[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState({
status: false,
message: "",
});

useEffect(() => {
const getAllUsers = async () => {
Expand All @@ -27,17 +23,7 @@ export default function AllUser() {
if (response.status !== 200) throw new Error(response.message);
setUsers(response.data);
} catch (error) {
setError({
status: true,
message: (error as Error).message,
});

setTimeout(() => {
setError({
status: true,
message: (error as Error).message,
});
}, 1500);
toast((error as Error).message);
} finally {
setLoading(false);
}
Expand All @@ -51,8 +37,6 @@ export default function AllUser() {
}
return (
<div>
{error.status ? toast(error.message) : ""}

<div className="md:flex md:flex-col gap-8 py-6 h-screen max-h-screen overflow-y-scroll no-scrollbar ">
{loading ? (
<div className="w-full h-full flex items-center justify-center ">
Expand Down
16 changes: 3 additions & 13 deletions components/Auth/Signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ export default function SigninForm() {
});
const [submitting, setSubmitting] = useState<boolean>(false);
const [passwordClick, setPasswordClick] = useState<boolean>(false);
const [error, setError] = useState<boolean | null>(null);

async function onSubmit(data: any) {
setSubmitting(true);
setError(null);
try {
const res = await signIn("credentials", {
username: data.username,
Expand All @@ -39,18 +37,12 @@ export default function SigninForm() {
});

if (res?.error) {
setError(true);
setTimeout(() => {
setError(false);
}, 2000);
toast("Username / Password mismatched");
} else {
window.location.href = res?.url || "/jobs";
}
} catch (error: any) {
setError(true);
setTimeout(() => {
setError(false);
}, 2000);
} catch (error) {
toast("Username / Password mismatched");
} finally {
setSubmitting(false);
reset();
Expand All @@ -60,8 +52,6 @@ export default function SigninForm() {
return (
<div className="min-h-screen">
<div className="mx-auto rounded-lg p-4 md:p-6 w-11/12 sm:w-3/4 md:w-1/2 xl:w-1/3 bg-gradient-to-b from-secondaryTestimoanlBg to-primaryTestimonalBg mt-6 md:mt-8 lg:mt-20 md:mt-24 border-2 border-slate-800 flex flex-col gap-6">
{error && toast("Username / Password mismatched")}

<div>
<Link href={"/"} aria-label="go-back">
<IoArrowBack className="text-gray-400 size-6 cursor-pointer mb-4 hover:text-white" />
Expand Down
38 changes: 6 additions & 32 deletions components/Auth/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ export default function SignupForm() {
resolver: zodResolver(signupSchema),
});

const [error, setError] = useState<{
status: boolean;
message: string;
}>({
status: false,
message: "",
});
const [success, setSuccess] = useState(false);
const [passwordClick, setPasswordClick] = useState(false);
const [submitting, setSubmitting] = useState<boolean>(false);

Expand All @@ -58,24 +50,16 @@ export default function SignupForm() {
try {
const response = await CreateUser(data);
if (response.status !== 200) throw new Error(response.message);
setSuccess(true);
setTimeout(() => {
setSuccess(false);
}, 2000);
toast("Account created Successfully.", {
duration: 2000,
});
router.push("/signin");

setCurrentIndex(0);
} catch (error: any) {
setError({
status: true,
message: error.message,
} catch (error) {
toast((error as Error).message, {
duration: 2000,
});
setTimeout(() => {
setError({
status: false,
message: "",
});
}, 2000);
} finally {
setSubmitting(false);
reset();
Expand Down Expand Up @@ -114,16 +98,6 @@ export default function SignupForm() {

return (
<div className="min-h-screen">
{success &&
toast("Account created Successfully.", {
duration: 2000,
})}

{error.status &&
toast(error.message, {
duration: 2000,
})}

<div className="w-11/12 sm:w-3/4 md:w-1/2 xl:w-1/3 mx-auto rounded-lg p-4 md:p-6 bg-gradient-to-b from-secondaryTestimoanlBg to-primaryTestimonalBg mt-6 md:mt-8 lg:mt-20 md:mt-24 border-2 border-slate-800 mt-6 md:mt-8 mb-4 lg:mt-20 md:mt-24 text-white">
<Link href={"/"} aria-label="go-back">
<IoArrowBack className="text-gray-400 size-6 cursor-pointer mb-4 hover:text-white" />
Expand Down
Loading

0 comments on commit b91d0c7

Please sign in to comment.