coopdevs / katuma-web

ABANDONED - Old Katuma's web interface
http://www.katuma.org
MIT License
7 stars 1 forks source link

Lets fix complete invitation and add create producer to onboarding #18

Closed andresgutgon closed 7 years ago

andresgutgon commented 7 years ago

TODO

https://github.com/coopdevs/katuma/pull/92

enricostano commented 7 years ago

@andresgutgon to create a producer you'll need this https://github.com/coopdevs/katuma-web/pull/19

enricostano commented 7 years ago

Ehm... I didn't close this GitHub... I was just removing my commits...

enricostano commented 7 years ago

Rebased with the new develop, so you can start from a balnk slate. Sorry for the noise!

enricostano commented 7 years ago

@andresgutgon one thing you'll need in the form that creates producers is the following chain of promises:

  handleSubmit(data) {
    const self = this;

    data.group_id = this.props.group.id;

    // First promise: create the producer
    return this.props.createProducer(data).then((responseData) => {
      const errors = self.props.createProducerErrors;

      if (Object.keys(errors).length) {
        return Promise.reject(errors);
      }

      return Promise.resolve(responseData);
    }).then((producerData) => {
      const supplierData = {
        group_id: data.group_id,
        producer_id: producerData.id,
      };

      // Second promise: create the supplier given the producer ID
      return this.props.createSupplier(supplierData).then(() => {
        const errors = self.props.createSupplierErrors;

        if (Object.keys(errors).length) {
          return Promise.reject(errors);
        }

        return Promise.resolve({});
      }).then(() => {
        // Third promise: load the producers to get latest state
        return this.props.loadProducers(data.group_id).then(() => {

          // TODO: what if the request fails?
          return Promise.resolve({});
        });
      });
    });
  }