Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Leeeef552 committed Apr 25, 2024
2 parents ae9ee66 + 0b21b7c commit 793dbf2
Show file tree
Hide file tree
Showing 19 changed files with 417 additions and 168 deletions.
188 changes: 105 additions & 83 deletions src/components/ErrorMessage.vue
Original file line number Diff line number Diff line change
@@ -1,96 +1,120 @@
<template>
<div class="modal">
<div class = "model-flexbox">
<span class="close" @click="toggleError">&times;</span>
<img id="errorImg" src="@/assets/close.png" alt="ErrorCross">
<p id = 'errorMessage'>Oops!</p>
<span id = "message">{{ displayMessage }}</span>
</div>
<div class="modal">
<div class="model-flexbox">
<span class="close" @click="toggleError">&times;</span>
<img id="errorImg" src="@/assets/close.png" alt="ErrorCross" />
<p id="errorMessage">Oops!</p>
<span id="message">{{ displayMessage }}</span>
</div>
</template>

<script>
export default {
name: "ErrorMessage",
data() {
return {
displayMessage: ""
};
</div>
</template>

<script>
export default {
name: "ErrorMessage",
data() {
return {
displayMessage: "",
};
},
props: {
condition: {
type: String,
required: true,
},
props: {
condition: {
type: String,
required: true
},
user_id: {
type: String,
},
user_id: {
type: String,
},
error: {
type: String,
}
error: {
type: String,
},
mounted() {
},
mounted() {
this.getMessage();
},
watch: {
condition: function (newCondition) {
this.getMessage();
},
watch: {
condition: function(newCondition) {
this.getMessage();
},
methods: {
getMessage() {
// login errors
if (
this.condition === "errorLogin" &&
this.error == "auth/invalid-email"
) {
this.displayMessage = "You entered an invalid email! Please try again";
} else if (
this.condition === "errorLogin" &&
this.error == "auth/invalid-credential"
) {
this.displayMessage = "Incorrect password or email! Please try again";
}
// registration errors
else if (
this.condition === "errorRegistration" &&
this.error == "Firebase: Error (auth/email-already-in-use)."
) {
this.displayMessage = "The email you entered is already in use";
} else if (
this.condition === "errorRegistration" &&
this.error == "Postal code invalid. Please try again."
) {
this.displayMessage = "Invalid postal code! Please try again.";
} else if (
this.condition === "errorRegistration" &&
this.error == "Firebase: Error (auth/invalid-email)."
) {
this.displayMessage = "The email entered is invalid! Please try again.";
} else if (
this.condition === "errorRegistration" &&
this.error == "Firebase: Error (auth/missing-password)."
) {
this.displayMessage = "You forgot to provide a password!";
} else if (
this.condition === "errorRegistration" &&
this.error == "Please make sure all fields are filled."
) {
this.displayMessage =
"You missed out some fields! Please fill them in.";
}
// google registration errors
else if (
this.condition === "errorRegistration" &&
this.error == "Account already exists."
) {
this.displayMessage = "The email you entered is already in use";
} else if (
this.condition === "errorLoginNotRegisteredGoogle" &&
this.error == "Login but not registered with google"
) {
this.displayMessage = "This google account is not registered.";
} else {
this.displayMessage = "Something went wrong! Please try again";
}
},
methods: {
getMessage() {
// login errors
if (this.condition === "errorLogin" && this.error == "auth/invalid-email") {
this.displayMessage = "You entered an invalid email! Please try again";
}
else if (this.condition === "errorLogin" && this.error == "auth/invalid-credential") {
this.displayMessage = "Incorrect password or email! Please try again";
}
// registration errors
else if (this.condition === "errorRegistration" && this.error == "Firebase: Error (auth/email-already-in-use).") {
this.displayMessage = "The email you entered is already in use";
}
else if (this.condition === "errorRegistration" && this.error == "Postal code invalid. Please try again.") {
this.displayMessage = "Invalid postal code! Please try again.";
}
else if (this.condition === "errorRegistration" && this.error == "Firebase: Error (auth/invalid-email).") {
this.displayMessage = "The email entered is invalid! Please try again.";
}
else if (this.condition === "errorRegistration" && this.error == "Firebase: Error (auth/missing-password).") {
this.displayMessage = "You forgot to provide a password!";
}
else if (this.condition === "errorRegistration" && this.error == "Please make sure all fields are filled.") {
this.displayMessage = "You missed out some fields! Please fill them in.";
}
// google registration errors
else if (this.condition === "errorRegistration" && this.error == "Account already exists.") {
this.displayMessage = "The email you entered is already in use";
}
else {
this.displayMessage = "Something went wrong! Please try again";
}
},
toggleError() {
if (this.condition === "errorLogin") {
this.$emit("close")
} else if (this.condition === "errorRegistration") {
this.$emit("close")
} else {
this.$emit("close")
}
toggleError() {
if (this.condition === "errorLogin") {
this.$emit("close");
} else if (this.condition === "errorRegistration") {
this.$emit("close");
} else {
this.$emit("close");
}
}
};
</script>

},
},
};
</script>

<style scoped>
.modal {
text-align: center;
Expand Down Expand Up @@ -141,6 +165,4 @@ img {
font-size: 20px;
margin-bottom: 0px;
}
</style>

7 changes: 7 additions & 0 deletions src/components/GroupEventsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import CreateEventForm from '@/components/CreateEventForm.vue';
</div>
</div>
<!-- need to include event -->
<div v-if="noEvents">
<p>There is currently no event.</p>
</div>
<div v-for="event in events" class="group">
<GroupEventListComponent :event="event" :group="groupId"/>
</div>
Expand Down Expand Up @@ -53,6 +56,7 @@ export default {
groupAdmin: "",
showSuccess: false,
message_passed: "createEvent",
noEvents: false
};
},
methods: {
Expand All @@ -63,6 +67,9 @@ export default {
if (documentSnapshot.exists()) {
this.events = documentSnapshot.data()["GroupEvents"];
console.log(this.events);
if (this.events.length == 0) {
this.noEvents = true;
}
} else {
console.log("No such document!");
}
Expand Down
45 changes: 35 additions & 10 deletions src/components/LoginAuth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@

<script setup>
import { ref } from "vue";
import firebaseApp from "@/firebase";
import firebaseApp, { firestore } from "@/firebase";
import {
getAuth,
signInWithEmailAndPassword,
signInWithPopup,
GoogleAuthProvider,
} from "firebase/auth";
import { getDoc, doc } from "firebase/firestore";
import { useRouter } from "vue-router";
import SuccessMessage from "@/components/SuccessMessage.vue";
import ErrorMessage from "@/components/ErrorMessage.vue";
Expand Down Expand Up @@ -116,16 +117,40 @@ const loginWithGoogle = async (event) => {
try {
const result = await signInWithPopup(auth, provider);
const user = result.user;
user_id.value = user.uid;
loginStatus.value = "success";
message_passed = "loginSuccess";
const userDocRef = doc(firestore, "users", user.uid);
// Get the document
const userDocSnap = await getDoc(userDocRef);
console.log("hi");
// Check if the document exists
if (userDocSnap.exists()) {
// Document exists, proceed with login
user_id.value = user.uid;
loginStatus.value = "success";
message_passed = "loginSuccess";
} else {
loginStatus.value = "error";
message_passed = "errorLoginNotRegisteredGoogle";
error.value = "Login but not registered with google";
showError.value = true;
try {
await user.delete();
console.log("User account deleted successfully");
} catch (error) {
console.error("Error deleting user account:", error);
}
}
} catch (error) {
loginStatus.value = "error";
message_passed = "errorLogin";
email.value = "";
password.value = "";
error.value = error.code;
showError.value = true;
if (error.code === "auth/popup-closed-by-user") {
console.log("Popup closed by user");
} else {
loginStatus.value = "error";
message_passed = "errorLogin";
email.value = "";
password.value = "";
error.value = error.code;
showError.value = true;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/MyGroupListComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h3 id="groupName">{{ group.GroupName }}</h3>
<!-- <p id="groupLocation">{{ group.GroupLocation }}</p> -->
<p id="groupDescription">{{ group.GroupDescription }}</p>
<button class="leave-group-btn" @click="leaveGroup">Leave Group</button>
<button v-if="!isAdmin" class="leave-group-btn" @click="leaveGroup">Leave Group</button>
<button v-if="isAdmin" class="delete-group-btn" @click="showWarning">
Delete Group
</button>
Expand Down
18 changes: 11 additions & 7 deletions src/components/RegisterAuth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,17 @@ export default {
// Set user info into firebase
await setDoc(userDocRef, userData);
} catch (error) {
console.error("Error during registration:", error);
this.registrationStatus = "error";
this.errorMessage = error.message;
this.showError = true;
this.showPopup = false;
this.message_passed = "errorRegistration";
console.log("hereeee -->", this.errorMessage, "lol");
if (error.code === "auth/popup-closed-by-user") {
console.log("Popup closed by user");
} else {
console.error("Error during registration:", error);
this.registrationStatus = "error";
this.errorMessage = error.message;
this.showError = true;
this.showPopup = false;
this.message_passed = "errorRegistration";
console.log("hereeee -->", this.errorMessage, "lol");
}
}
},
Expand Down
7 changes: 2 additions & 5 deletions src/mComponents/Approval.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@
this.updateBuyer()
this.updateItem()
this.updateSeller()
alert('approved')
this.$router.push({ name: 'MarketplaceDealReq'})
this.$emit('open')
},
async rejectReq() {
Expand All @@ -115,8 +113,7 @@
} else {
await updateDoc(itemDocRef, { buyerID: updatedListedItems })
}
console.log("rejected")
this.$router.push({ name: 'MarketplaceViewItems'})
this.$emit('rejected')
},
async getImage(fileID) {
Expand Down
2 changes: 1 addition & 1 deletion src/mComponents/CreateListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default {
this.updateUserDBItem(this.user, ItemID)
document.getElementById('myform').reset()
this.$emit("added")
this.$router.push({ name: 'MarketplaceViewItems'})
this.$emit("open")
} catch(error) {
console.log("Error when adding document: ", error)
}
Expand Down
9 changes: 7 additions & 2 deletions src/mComponents/DealReqListingComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ export default {
border-radius: 5px;
cursor: pointer;
}
.done-deal button:hover,
.buy-request button {
background-color: rgb(20, 163, 20);
}
.buy-request button:hover {
background-color: green;
}
.done-deal button:hover{
background-color: #0056b3;
}
</style>
2 changes: 1 addition & 1 deletion src/mComponents/EditListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default {
await updateDoc(doc(db, "Items", ItemID), ItemData)
document.getElementById('myform').reset()
this.$emit("added")
this.$router.push({ name: 'MarketplaceViewItems'})
this.$emit('open')
} catch(error) {
console.log("Error when adding document: ", error)
}
Expand Down
Loading

0 comments on commit 793dbf2

Please sign in to comment.