Added notification generation on SMS. Added FCM Token saving on login.

This commit is contained in:
Patrick Fic
2020-05-01 12:32:40 -07:00
parent 92aeb419a9
commit 636e979fd0
21 changed files with 3810 additions and 45 deletions

View File

@@ -0,0 +1,60 @@
import { notification } from "antd";
import React, { Component } from "react";
import { messaging } from "../../firebase/firebase.utils";
import { withApollo } from "react-apollo";
import { UPDATE_FCM_TOKEN } from "../../graphql/user.queries";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectCurrentUser } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
class FcmNotificationComponent extends Component {
async componentDidMount() {
const { client, currentUser } = this.props;
messaging
.requestPermission()
.then(async function () {
const token = await messaging.getToken();
client.mutate({
mutation: UPDATE_FCM_TOKEN,
variables: { authEmail: currentUser.email, token: { [token]: true } },
});
})
.catch(function (err) {
console.log("Unable to get permission to notify.", err);
});
navigator.serviceWorker.addEventListener("message", (message) => {
const { payload } = message.data.firebaseMessaging;
// notification["info"]({ message: JSON.stringify(payload) });
navigator.serviceWorker.getRegistration().then((registration) =>
registration.showNotification(payload.notification.title, {
body: payload.notification.body,
icon: "logo240.png",
badge: "logo240.png",
actions: [
{
action: "respond",
title: "Respond",
},
],
})
);
});
}
render() {
return <div></div>;
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(withApollo(FcmNotificationComponent));