Skip to content

Commit d2b1eca

Browse files
author
ayush221b
committed
Added notification trigger for new project
1 parent 2566a41 commit d2b1eca

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

functions/index.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
const functions = require('firebase-functions');
2+
const admin = require('firebase-admin');
23

3-
// // Create and Deploy Your First Cloud Functions
4-
// // https://firebase.google.com/docs/functions/write-firebase-functions
5-
//
6-
// exports.helloWorld = functions.https.onRequest((request, response) => {
7-
// response.send("Hello from Firebase!");
8-
// });
4+
admin.initializeApp(functions.config().firebase)
5+
6+
exports.helloWorld = functions.https.onRequest((request, response) => {
7+
response.send("Hello, amigos!");
8+
});
9+
10+
const createNotification = (notification => {
11+
12+
return admin.firestore().collection('notifications')
13+
.add(notification)
14+
.then(doc => {
15+
console.log('notofication added', doc)
16+
})
17+
})
18+
19+
exports.projectCreated =
20+
functions.firestore.document('projects/{projectId}').onCreate(doc => {
21+
22+
const project = doc.data();
23+
const notification = {
24+
content: 'Added a new Project',
25+
user: `${project.authorFirstName} ${project.authorLastName}`,
26+
time: admin.firestore.FieldValue.serverTimestamp()
27+
}
28+
29+
return createNotification(notification);
30+
})

src/Components/dashboard/Notifications.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
import React from 'react'
22

3-
const Notifications = () =>{
3+
const Notifications = (props) =>{
44

55
return(
6-
<div>
7-
<p>Notifications</p>
6+
<div className="section">
7+
<div className="card z-depth-0">
8+
<div className="card-content">
9+
<span className="card-title">
10+
Notifications
11+
</span>
12+
<ul className="notifications">
13+
<li>
14+
Notification
15+
</li>
16+
<li>
17+
Notification
18+
</li>
19+
<li>
20+
Notification
21+
</li>
22+
<li>
23+
Notification
24+
</li>
25+
</ul>
26+
</div>
27+
</div>
828
</div>
929
)
1030
}

0 commit comments

Comments
 (0)