Skip to content

Commit

Permalink
Committing before modifying architeture
Browse files Browse the repository at this point in the history
  • Loading branch information
jaison080 committed Jan 1, 2023
1 parent b76bb04 commit 6eff5cb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 70 deletions.
6 changes: 3 additions & 3 deletions src/Components/InviteEmail/InviteEmail.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function InviteEmail({ data, member, id }) {
function InviteEmail({ data, member }) {
return (
<>
<div>
Expand All @@ -16,8 +16,8 @@ function InviteEmail({ data, member, id }) {
<i>
<a
href={
id
? `https://iedc-collab-frontend.pages.dev/projects/${id}`
data.id
? `https://iedc-collab-frontend.pages.dev/projects/${data.id}`
: `https://iedc-collab-frontend.pages.dev/projects/`
}
target="_blank"
Expand Down
54 changes: 5 additions & 49 deletions src/Components/ProjectModal/ProjectModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import "./ProjectModal.scss";
import { ProjectContext } from "../../contexts/ProjectContext";
import { toast } from "react-toastify";
import Compress from "compress.js";
import axios from "axios";
import { emailUrl } from "../../Utils/urls";
import { renderEmail } from "react-html-email";
import InviteEmail from "../InviteEmail/InviteEmail";
import { FormControlLabel, Radio, RadioGroup } from "@mui/material";

const compress = new Compress();
Expand All @@ -27,7 +23,7 @@ const NewProjectForm = ({ onClose, project, setVariable, variable }) => {
const [projectPhoto, setProjectPhoto] = useState(
project?.projectPhoto || null
);
const { fetchData, developers } = useContext(ProjectContext);
const { fetchData, developers, projects } = useContext(ProjectContext);
const initialValue = {
name: project?.name || "",
desc: project?.desc || "",
Expand Down Expand Up @@ -81,56 +77,16 @@ const NewProjectForm = ({ onClose, project, setVariable, variable }) => {
projectPhotoName,
};
if (!project) {
doCreateProject(formValues, () => {
formValues.teamMembers.forEach((member) => {
let sent = false;
developers.forEach((dev) => {
if (dev.email === member) {
sent = true;
}
});

if (sent === false) {
axios.post(emailUrl, {
toEmail: member,
subject: "New Project",
content: renderEmail(
<InviteEmail data={formValues} member={member} />
),
});
} else {
}
});
doCreateProject(formValues, developers, () => {
fetchData();
console.log(projects);

toast("Project created successfully", {
autoClose: 3000,
});
});
} else {
doEditProject(formValues, project.id, () => {
formValues.teamMembers.forEach((member) => {
let sent = false;
developers.forEach((dev) => {
if (dev.email === member) {
sent = true;
}
});

if (sent === false) {
axios.post(emailUrl, {
toEmail: member,
subject: "Invitation to join IEDC Collab",
content: renderEmail(
<InviteEmail
data={formValues}
member={member}
id={project.id}
/>
),
});
} else {
}
});
doEditProject(formValues, project.id, developers, () => {
fetchData();
setVariable(!variable);
toast("Project edited successfully", {
Expand Down
98 changes: 80 additions & 18 deletions src/Firebase/firebase.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import axios from "axios";
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/database";
import { renderEmail } from "react-html-email";
import InviteEmail from "../Components/InviteEmail/InviteEmail";
import { emailUrl } from "../Utils/urls";

const config = {
apiKey: process.env.REACT_APP_FB_API_KEY,
Expand Down Expand Up @@ -75,8 +79,9 @@ export const signOut = () => {
});
};

export const doCreateProject = (obj, onSuccess = () => {}) => {
export const doCreateProject = (obj, developers, onSuccess = () => {}) => {
const user = firebase.auth().currentUser;

if (!user) {
alert("Please login to add a project");
return;
Expand All @@ -93,6 +98,7 @@ export const doCreateProject = (obj, onSuccess = () => {}) => {
var projectData = {
...obj,
projectPhoto: photoUrl,
id: newProjectID,
projectPhotoName: obj.projectPhotoName || "",
available: true,
createdAt,
Expand All @@ -110,6 +116,22 @@ export const doCreateProject = (obj, onSuccess = () => {}) => {
.then(function () {
console.log("Project added sucessfully");
onSuccess("ADD");
projectData.teamMembers.forEach((member) => {
let sent = false;
developers.forEach((dev) => {
if (dev.email === member) {
sent = true;
}
});
if (sent === false)
axios.post(emailUrl, {
toEmail: member,
subject: "Invitation to join IEDC Collab",
content: renderEmail(
<InviteEmail data={projectData} member={member} />
),
});
});
})
.catch(function (error) {
alert("Something went wrong");
Expand All @@ -124,6 +146,7 @@ export const doCreateProject = (obj, onSuccess = () => {}) => {
projectPhoto: defaultPhotoUrl,
projectPhotoName: "Default Image",
available: true,
id: newProjectID,
createdAt,
updatedAt: createdAt,
leader_id: user.uid,
Expand All @@ -140,6 +163,22 @@ export const doCreateProject = (obj, onSuccess = () => {}) => {
.then(function () {
console.log("Project added sucessfully");
onSuccess("ADD");
projectData.teamMembers.forEach((member) => {
let sent = false;
developers.forEach((dev) => {
if (dev.email === member) {
sent = true;
}
});
if (sent === false)
axios.post(emailUrl, {
toEmail: member,
subject: "Invitation to join IEDC Collab",
content: renderEmail(
<InviteEmail data={projectData} member={member} />
),
});
});
})
.catch(function (error) {
alert("Something went wrong");
Expand Down Expand Up @@ -178,7 +217,12 @@ export const doDeleteProject = (project_id, onSuccess = () => {}) => {
});
};

export const doEditProject = async (obj, project_id, onSuccess = () => {}) => {
export const doEditProject = async (
obj,
project_id,
developers,
onSuccess = () => {}
) => {
const user = firebase.auth().currentUser;
if (!user) {
alert("Please login to add a project");
Expand Down Expand Up @@ -210,18 +254,36 @@ export const doEditProject = async (obj, project_id, onSuccess = () => {}) => {
photoUrl = obj.projectPhoto;
}
try {
await projectRef.set({
var projectData = {
...obj,
projectPhoto: photoUrl,
id: project_id,
available: true,
updatedAt: new Date(),
leader_id: user.uid,
leader_name: user.displayName,
leaderEmail: user.email,
leaderImg: user.providerData[0]?.photoURL || null,
});
};
await projectRef.set(projectData);
console.log("Project edited sucessfully");
onSuccess("EDIT");
projectData.teamMembers.forEach((member) => {
let sent = false;
developers.forEach((dev) => {
if (dev.email === member) {
sent = true;
}
});
if (sent === false)
axios.post(emailUrl, {
toEmail: member,
subject: "Invitation to join IEDC Collab",
content: renderEmail(
<InviteEmail data={projectData} member={member} />
),
});
});
} catch (error) {
alert(
"Something went wrong during edit. Please try againg after some time"
Expand Down Expand Up @@ -479,19 +541,19 @@ export const getSkills = () => {
return firebase.database().ref("skills/").once("value");
};

export const addSkills = async (skill)=>{
export const addSkills = async (skill) => {
// var skillId = firebase.database().ref().child("skills").push().key;
let skills = await getSkills();
let skillsArray = skills.val();
if(!skillsArray){
skillsArray = []
}
skillsArray.push(skill);
let skills = await getSkills();
let skillsArray = skills.val();
if (!skillsArray) {
skillsArray = [];
}
skillsArray.push(skill);

return firebase
.database()
.ref("skills/")
.set({
...skillsArray,
})
}
.database()
.ref("skills/")
.set({
...skillsArray,
});
};

0 comments on commit 6eff5cb

Please sign in to comment.