Skip to content

Commit 675dad7

Browse files
committed
can signout now
1 parent 3142287 commit 675dad7

10 files changed

+182
-248
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ dist-ssr
2323
*.sln
2424
*.sw?
2525

26-
# Ignore Firebase configuration file
27-
firebaseConfig.js
26+
# environment variables
27+
.env

firebase.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
import { initializeApp } from 'firebase/app';
2-
import { getAuth } from 'firebase/auth';
3-
import { getFirestore } from 'firebase/firestore';
4-
import { getStorage } from "firebase/storage";
5-
import firebaseConfig from './firebaseConfig';
1+
import { initializeApp } from "firebase/app";
2+
import { getAuth, signInWithEmailAndPassword, signOut } from "firebase/auth";
3+
import { getFirestore } from "firebase/firestore";
4+
// import { getStorage } from "firebase/storage";
5+
// import firebaseConfig from "./firebaseConfig";
6+
7+
const firebaseConfig = {
8+
apiKey : import.meta.env.VITE_REACT_APP_API_KEY,
9+
authDomain : import.meta.env.VITE_REACT_APP_AUTH_DOMAIN,
10+
projectId : import.meta.env.VITE_REACT_APP_PROJECT_ID,
11+
storageBucket : import.meta.env.VITE_REACT_APP_STORAGE_BUCKET,
12+
messagingSenderId : import.meta.env.VITE_REACT_APP_MESSAGING_SENDER_ID,
13+
appId : import.meta.env.VITE_REACT_APP_APP_ID,
14+
measurementId : import.meta.env.VITE_REACT_APP_MEASUREMENT_ID,
15+
};
616

717
const app = initializeApp(firebaseConfig);
818
const auth = getAuth(app);
919
const db = getFirestore(app);
10-
const storage = getStorage(app);
20+
// const storage = getStorage(app);
21+
22+
const logInWithEmailAndPassword = async (email, password) => {
23+
await signInWithEmailAndPassword(auth, email, password);
24+
};
25+
26+
const logout = () => {
27+
signOut(auth);
28+
};
1129

12-
export { auth, db, storage };
30+
export { auth, db, logInWithEmailAndPassword, logout };

package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"firebase": "^10.6.0",
1414
"react": "^18.2.0",
1515
"react-dom": "^18.2.0",
16+
"react-firebase-hooks": "^5.1.1",
1617
"react-router-dom": "^6.18.0",
1718
"react-select": "^5.8.0"
1819
},

src/pages/CreateTask/CreateTask.jsx

+36-66
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import Select from "react-select";
2-
import { useEffect, useRef, useState } from "react";
2+
import { useEffect, useState } from "react";
3+
import { useAuthState } from "react-firebase-hooks/auth";
34
import {
45
addTask,
56
getTags,
67
getSegments,
78
getContributors,
8-
getProjects,
9-
uploadImage,
10-
logout
119
} from "../../utils/databaseOps";
12-
10+
import { auth, logout} from "../../../firebase";
1311
import styles from "./CreateTask.module.css";
1412
import { useNavigate, useLocation } from "react-router-dom";
1513
import SummaryEdit from './components/SummaryEdit';
@@ -18,6 +16,24 @@ export default function CreateTask() {
1816
const location = useLocation();
1917
const navigate = useNavigate();
2018

19+
function handleLogout(){
20+
if(!user){
21+
navigate('/');
22+
}
23+
logout();
24+
}
25+
26+
//If the user logs out redirect to login page
27+
const [user, loading] = useAuthState(auth);
28+
useEffect(() => {
29+
if(loading){
30+
return;
31+
}
32+
if (!user){
33+
navigate("/");
34+
}
35+
}, [user]);
36+
2137
// hardcoded values
2238
const priorities = [
2339
{ value: 1, label: "Low" },
@@ -46,7 +62,9 @@ export default function CreateTask() {
4662

4763
// values per project basis
4864
const [data, setData] = useState({
49-
projects: [],
65+
projects: location.state?.userData.PROJECTS.map((project) => {
66+
return {value : project, label : project}
67+
}),
5068
segments: [],
5169
sections: [],
5270
contributors: [],
@@ -75,35 +93,16 @@ export default function CreateTask() {
7593
version: 4,
7694
})
7795

78-
function logout(){
79-
navigate("/");
80-
}
81-
82-
// get projects on page load
83-
useEffect(() => {
84-
if(!location.state?.userData)
85-
logout();
86-
setData((prevData) => {
87-
return {...prevData, projects : location.state?.userData.PROJECTS.map((project) => {
88-
return {value : project, label : project}
89-
})}
90-
})
91-
// getProjects(task.assigner).then((projects) => {
92-
// setData((prevData) => {
93-
// return {...prevData, projects : projects ? projects.map((project) => {
94-
// return {value : project, label : project}
95-
// }) : [] }
96-
// })
97-
// })
98-
}, [location.state?.userData])
96+
// function logout(){
97+
// navigate("/");
98+
// }
9999

100100
// get project specific data when new project is selected
101101
useEffect(() => {
102102
if (!task.project_ID) return;
103103

104104
// get tags of the selected project
105105
getTags(task.project_ID).then((tagsData) => {
106-
console.log(tagsData);
107106
setData((prevData) => {
108107
return { ...prevData, tags: tagsData ? [...tagsData] : [] };
109108
});
@@ -172,7 +171,7 @@ export default function CreateTask() {
172171
// event handler for handling changes in select
173172
const handleSelectChange = (select, spec) => {
174173
setTask((prevTask) => ({ ...prevTask, [spec]: select.value }));
175-
console.log(`Option selected:`, select.value);
174+
// console.log(`Option selected:`, select.value);
176175
};
177176

178177
// event handler for handling project title and desc input
@@ -265,49 +264,20 @@ export default function CreateTask() {
265264
}));
266265
}
267266

268-
// Handler for handling the image drop
269-
function handleImageDrop(e) {
270-
e.preventDefault();
271-
setDragging(false);
272-
const file = e.dataTransfer.files[0];
273-
if ((task, file)) {
274-
setUploadMessage(`Uploading ${file.name}...`);
275-
console.log("File", file);
276-
uploadImage(task, file).then((url) => {
277-
console.log("IMAGE URL from store", url);
278-
const cursorPosition = descriptionRef.current.selectionStart;
279-
const newDescription =
280-
task.description.slice(0, cursorPosition) +
281-
`![Image](${url})` +
282-
task.description.slice(cursorPosition);
283-
284-
setTask((prevTask) => ({ ...prevTask, description: newDescription }));
285-
setUploadMessage(null);
286-
});
287-
}
288-
}
289-
290-
// event handler for handling drag enter
291-
function handleDragEnter(e) {
292-
e.preventDefault();
293-
setDragging(true);
294-
}
295-
296-
// event handler for handling drag leave
297-
function handleDragLeave(e) {
298-
e.preventDefault();
299-
setDragging(false);
300-
}
301-
302267
// render task form
303268
return (
304269
<>
305270
<form className={styles.form} onSubmit={handleTaskSubmit}>
306271
<div className={styles.header}>
307272
<h1>New Task</h1>
308-
<button type="submit" className={styles.taskSubmit}>
309-
Create Task
310-
</button>
273+
<div className={styles.btnCont}>
274+
<button type="submit" className={styles.taskSubmit}>
275+
Create Task
276+
</button>
277+
<button type="button" className={styles.logoutBtn} onClick={handleLogout}>
278+
Logout
279+
</button>
280+
</div>
311281
</div>
312282
<div className={styles.taskSpecs}>
313283

src/pages/CreateTask/CreateTask.module.css

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
.btnCont{
2+
display: flex;
3+
gap: 1rem;
4+
}
5+
16
.taskSubmit {
7+
background-color: rgb(0, 164, 11);
8+
color: rgb(255, 255, 255);
9+
border: none;
10+
font-size: 1rem;
11+
margin-top: 0.8rem;
12+
padding: 10px;
13+
font-weight: bold;
14+
border-radius: 4px;
15+
cursor: pointer;
16+
}
17+
18+
.taskSubmit:hover {
19+
background-color: rgb(0, 133, 9);
20+
}
21+
22+
.logoutBtn{
223
background-color: rgb(255, 94, 0);
324
color: #fff;
425
border: none;
@@ -10,8 +31,8 @@
1031
cursor: pointer;
1132
}
1233

13-
.taskSubmit:hover {
14-
background-color: #c1450b;
34+
.logoutBtn:hover {
35+
background-color: rgb(188, 69, 0);
1536
}
1637

1738
.selectElement{

src/pages/CreateTask/components/SummaryEdit.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function SummaryEdit({description, handleChange}){
1414
className={styles.summaryBox}
1515
name="description"
1616
onChange={handleChange}
17-
placeholder="Trivial Summary Editor, needs upgrade, styling upgrade required throughout the page, show label for different dropdowns"
17+
placeholder="Task Summary"
1818
rows="7"
1919
required
2020
/>

0 commit comments

Comments
 (0)