Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { Notifications } from 'expo';
- import { connect } from 'react-redux';
- // import { Text, View } from 'react-native';
- import { updateTicketList } from '../actions/ticket';
- import { get } from '../utils';
- class NotificationContainer extends React.Component {
- state = {
- notification: {},
- };
- componentDidMount() {
- this._notificationSubscription = Notifications.addListener(this._handleNotification);
- }
- getTicket() {
- const { customerId } = this.props
- let url = '/api/customer/ticket/' + customerId;
- get(url)
- .then(response => {
- if (response.status >= 400) {
- throw new Error("Bad response from server");
- }
- this.props.updateTicketList(response)
- })
- .catch(err => {
- console.log(err.message)
- })
- }
- _handleNotification = (notification) => {
- this.getTicket()
- this.setState({ notification: notification });
- };
- render() {
- return null
- // return (
- // <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
- // <Text>Origin: {this.state.notification.origin}</Text>
- // <Text>Data: {JSON.stringify(this.state.notification.data)}</Text>
- // </View>
- // );
- }
- }
- const mapStateToProps = (state) => ({
- customerId: state.login.id,
- })
- const mapDispatchToProps = (dispatch) => ({
- updateTicketList: (payload) => dispatch(updateTicketList(payload))
- })
- export default connect(mapStateToProps, mapDispatchToProps)(NotificationContainer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement