componentDidMount()

in src/CCPData/CCPData.js [91:159]


  componentDidMount() {
    // eslint-disable-next-line no-undef
    connect.agent(function(agent) {

      agent.onOffline(function(agent) {
        this.setState({phonenumber: '0'});
        this.setState({ items: '' })
      }.bind(this));

      agent.onRoutable(function(agent) {
        this.setState({phonenumber: '0'});
        this.setState({ items: '' })
      }.bind(this));

    }.bind(this))

    // eslint-disable-next-line no-undef
    connect.contact(function(contact) {

      contact.onIncoming(function(contact) {
      }.bind(this));

      contact.onRefresh(function(contact) {
      }.bind(this));

      contact.onAccepted(function(contact) {
      }.bind(this));

      // Call established
      contact.onConnected(function(contact) {
      }.bind(this));

      // call ended
      contact.onEnded(function() {
      }.bind(this));

      // Triggered for the normal inbound calls.
      contact.onConnecting(function(contact) {
      }.bind(this));

      // Triggered for the Queue callbacks.
      contact.onIncoming(async function() {
        console.log(`onConnected(${contact.getContactId()})`);
        var attributeMap = contact.getAttributes();
        var phone = JSON.stringify(attributeMap["IncomingNumber"]["value"]);
        phone = phone.replace(/"/g, '');
        console.log(phone);
        //window.alert("Customer's phone #: " + phone);
        this.setState({phonenumber: phone});

        // api call
        if (this.state.phonenumber !== 0){
          try {
            const items = await API.get('api604c21a1', ('/telephonenumber/' + this.state.phonenumber))
            console.log(items)
            this.setState({ items: items })
          } catch (error) {
            console.log(error)
            //if (error.response.status === 404)
            //{
              this.setState({ items: '' })
            //}
          }
        }
        
        console.log(this.state.phonenumber);
      }.bind(this));
    }.bind(this));
  }