Skip to content

Commit 4e06732

Browse files
authored
Revert "corrected the CV upload issue"
1 parent dd39734 commit 4e06732

File tree

3 files changed

+85
-94
lines changed
  • jobsdoor360-website/src/main/ejs/main-files/myaccount/cv_upload
  • staticfiles/mainfiles

3 files changed

+85
-94
lines changed
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<title>CV Upload</title>
5-
<link rel="stylesheet" href="/staticfiles/mainfiles/myaccount/cv_upload/style.css">
4+
<title>Cv upload</title>
5+
<link
6+
rel="stylesheet"
7+
href="/staticfiles/mainfiles/myaccount/cv_upload/style.css"
8+
/>
69
<%- include('../../../partials/head.ejs') %>
7-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
10+
<link
11+
rel="stylesheet"
12+
type="text/css"
13+
href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css"
14+
/>
815
</head>
916
<body>
1017
<%- include('../../../partials/navbar.ejs') %>
11-
<div class="d-flex justify-content-center align-items-center flex-column gap-4" style="margin-block: 100px">
18+
<div
19+
class="d-flex justify-content-center align-items-center flex-column gap-4"
20+
style="margin-block: 100px"
21+
>
1222
<h2>UPLOAD YOUR RESUME</h2>
13-
<form class="d-flex flex-column justify-content-center gap-3" onsubmit="return false;">
23+
<form action="" class="d-flex flex-column justify-content-center gap-3">
1424
<div class="d-flex justify-content-center flex-column">
1525
<input
1626
id="cv"
1727
type="file"
1828
class="form-control cv"
19-
accept=".pdf,.doc,.docx"
29+
accept="cv/*"
2030
required
2131
/>
2232
<span class="form-text"></span>
@@ -33,9 +43,13 @@
3343
</form>
3444
</div>
3545
<%- include('../../../partials/footer.ejs') %>
36-
37-
<!-- Firebase -->
38-
<script type="module" src="/staticfiles/mainfiles/myaccount/cv_upload/script.js"></script>
39-
<script src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
46+
<script
47+
type="module"
48+
src="/staticfiles/mainfiles/myaccount/cv_upload/script.js"
49+
></script>
50+
<script
51+
type="text/javascript"
52+
src="https://cdn.jsdelivr.net/npm/toastify-js"
53+
></script>
4054
</body>
4155
</html>
Lines changed: 60 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,72 @@
1-
import {
2-
getAuth,
3-
onAuthStateChanged
4-
} from "firebase/auth";
1+
let userEmail;
2+
// Check if the user is signed in
3+
auth.onAuthStateChanged((user) => {
4+
if (user) {
5+
userEmail = user.email;
6+
} else {
7+
// No user is signed in
8+
console.log("No user is signed in");
9+
window.location.href = `/login/?redirect_url=${encodeURIComponent(window.location.href)}`;
510

6-
import {
7-
getFirestore,
8-
doc,
9-
getDoc,
10-
setDoc,
11-
updateDoc
12-
} from "firebase/firestore";
13-
14-
import {
15-
getStorage,
16-
ref,
17-
uploadBytes,
18-
getDownloadURL
19-
} from "firebase/storage";
20-
21-
const auth = getAuth();
22-
const db = getFirestore();
23-
const storage = getStorage();
11+
}
12+
});
2413

25-
let userEmail = null;
14+
const email = localStorage.getItem("email");
2615

27-
// Auth check
28-
onAuthStateChanged(auth, (user) => {
29-
if (user) {
30-
userEmail = user.email;
31-
} else {
32-
console.log("No user is signed in");
33-
window.location.href = `/login/?redirect_url=${encodeURIComponent(window.location.href)}`;
34-
}
35-
});
16+
let cvUrl = "";
3617

3718
async function uploadCV(file) {
38-
const fileName = `${userEmail.replace(/[^a-zA-Z0-9]/g, "_")}_${file.name}`;
39-
const cvRef = ref(storage, "user_cv/" + fileName);
40-
await uploadBytes(cvRef, file);
41-
return await getDownloadURL(cvRef);
19+
const cvRef = ref(storage, "user_cv/" + file.name);
20+
await uploadBytes(cvRef, file);
21+
22+
const url = await getDownloadURL(cvRef);
23+
return url; // Return empty string if URL is undefined
4224
}
4325

4426
async function saveCVToDatabase() {
45-
const uploadButton = document.getElementById("btn");
46-
uploadButton.innerHTML = "Uploading...";
47-
uploadButton.disabled = true;
48-
49-
const cvFile = document.getElementById("cv").files[0];
50-
if (!cvFile) {
51-
Toastify({ text: "Please select a file", duration: 3000, style: { background: "red" } }).showToast();
27+
const uploadButton = document.getElementById("btn");
28+
uploadButton.innerHTML = "Uploading...";
29+
uploadButton.disabled = true;
30+
const cvFile = document.getElementById("cv").files[0];
31+
if (cvFile) {
32+
cvUrl = await uploadCV(cvFile);
33+
34+
const userProfileRef = doc(db, "user_profile", userEmail);
35+
36+
// Ensure the user profile document exists before updating it
37+
const docSnap = await getDoc(userProfileRef);
38+
if (!docSnap.exists()) {
39+
await setDoc(userProfileRef, { "about": {} });
40+
}
41+
42+
await updateDoc(userProfileRef, { "about.cv": cvUrl })
43+
.then(() => {
44+
Toastify({
45+
text: "CV Successfully Submitted",
46+
duration: 3000,
47+
newWindow: true,
48+
close: true,
49+
gravity: "top",
50+
position: "right",
51+
stopOnFocus: true,
52+
style: {
53+
background: "linear-gradient(to right, #0d6efd, #586ba6)",
54+
borderRadius: "10px"
55+
}
56+
}).showToast();
57+
setTimeout(() => {
58+
window.location.href = "/myaccount/";
59+
}, 3000);
60+
})
61+
.catch((error) => {
62+
console.error("Error writing document: ", error);
63+
});
64+
}
65+
5266
uploadButton.innerHTML = "UPLOAD RESUME";
5367
uploadButton.disabled = false;
54-
return;
55-
}
56-
57-
try {
58-
const cvUrl = await uploadCV(cvFile);
59-
const userProfileRef = doc(db, "user_profile", userEmail);
60-
61-
const docSnap = await getDoc(userProfileRef);
62-
if (!docSnap.exists()) {
63-
await setDoc(userProfileRef, { about: {} });
64-
}
65-
66-
await updateDoc(userProfileRef, {
67-
"about.cv": cvUrl
68-
});
69-
70-
Toastify({
71-
text: "CV Successfully Submitted",
72-
duration: 3000,
73-
close: true,
74-
gravity: "top",
75-
position: "right",
76-
style: {
77-
background: "linear-gradient(to right, #0d6efd, #586ba6)",
78-
borderRadius: "10px"
79-
}
80-
}).showToast();
81-
82-
setTimeout(() => {
83-
window.location.href = "/myaccount/";
84-
}, 3000);
85-
86-
} catch (error) {
87-
console.error("Upload error:", error);
88-
Toastify({ text: "Upload failed", duration: 3000, style: { background: "red" } }).showToast();
89-
}
90-
91-
uploadButton.innerHTML = "UPLOAD RESUME";
92-
uploadButton.disabled = false;
9368
}
9469

95-
document.getElementById("btn").addEventListener("click", saveCVToDatabase);
70+
$("#btn").on("click", function () {
71+
saveCVToDatabase();
72+
});

staticfiles/mainfiles/signup/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ signupForm.addEventListener("submit", async (e) => {
4848
await sendEmailVerification(auth.currentUser);
4949

5050
window.location.href = "/resend_email_verification/";
51-
} catch (error) {.
51+
} catch (error) {
5252
alert("Error signing up: " + error.message);
5353
} finally {
5454
signupButton.innerHTML = "Sign Up";

0 commit comments

Comments
 (0)