Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. import React from 'react';
  2. import { Notifications } from 'expo';
  3. import { connect } from 'react-redux';
  4. // import { Text, View } from 'react-native';
  5. import { updateTicketList } from '../actions/ticket';
  6. import { get } from '../utils';
  7.  
  8. class NotificationContainer extends React.Component {
  9. state = {
  10. notification: {},
  11. };
  12.  
  13. componentDidMount() {
  14. this._notificationSubscription = Notifications.addListener(this._handleNotification);
  15. }
  16.  
  17. getTicket() {
  18. const { customerId } = this.props
  19. let url = '/api/customer/ticket/' + customerId;
  20. get(url)
  21. .then(response => {
  22. if (response.status >= 400) {
  23. throw new Error("Bad response from server");
  24. }
  25. this.props.updateTicketList(response)
  26. })
  27. .catch(err => {
  28. console.log(err.message)
  29. })
  30. }
  31.  
  32. _handleNotification = (notification) => {
  33. this.getTicket()
  34. this.setState({ notification: notification });
  35. };
  36.  
  37. render() {
  38. return null
  39. // return (
  40. // <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
  41. // <Text>Origin: {this.state.notification.origin}</Text>
  42. // <Text>Data: {JSON.stringify(this.state.notification.data)}</Text>
  43. // </View>
  44. // );
  45. }
  46. }
  47.  
  48. const mapStateToProps = (state) => ({
  49. customerId: state.login.id,
  50. })
  51.  
  52. const mapDispatchToProps = (dispatch) => ({
  53. updateTicketList: (payload) => dispatch(updateTicketList(payload))
  54. })
  55.  
  56. export default connect(mapStateToProps, mapDispatchToProps)(NotificationContainer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement