示例#1
0
  componentDidMount() {
    const { id } = this.state;

    const promises = [
      this.partnersService.fetchAllData()
    ];

    // Add the dashboard promise if the id exists
    if (id) {
      promises.push(this.service.fetchData(id));
    }

    Promise.all(promises)
      .then((response) => {
        const partners = response[0];
        const current = response[1];

        this.setState({
          // CURRENT DASHBOARD
          form: (id) ? this.setFormFromParams(current) : this.state.form,
          loading: false,
          // OPTIONS
          partners: partners.map(p => ({ label: p.name, value: p.id }))
        });
      })
      .catch((err) => {
        console.error(err);
      });
  }
示例#2
0
  return (dispatch) => {
    dispatch({ type: GET_PARTNERS_LOADING });

    service.fetchAllData()
      .then((data) => {
        dispatch({ type: GET_PARTNERS_SUCCESS, payload: data });
      })
      .catch((err) => {
        dispatch({ type: GET_PARTNERS_ERROR, payload: err.message });
      });
  };