Closed andresgutgon closed 7 years ago
@andresgutgon to create a producer you'll need this https://github.com/coopdevs/katuma-web/pull/19
Ehm... I didn't close this GitHub... I was just removing my commits...
Rebased with the new develop
, so you can start from a balnk slate. Sorry for the noise!
@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({});
});
});
});
}
TODO
Dependency
https://github.com/coopdevs/katuma/pull/92