Update team and client when updating custom field on invoice.

This commit is contained in:
HenriT
2021-04-14 11:52:32 +03:00
parent e23e1f720e
commit 328e30e874
8 changed files with 34 additions and 30 deletions

View File

@ -14,8 +14,10 @@ export default {
});
},
async updateClientField({ dispatch }, payload) {
await dispatch('clientFieldProps', payload);
return dispatch('clients/updateClient', null, { root: true }); // TODO: pass clientId to make generic
const field = await dispatch('clientFieldProps', payload);
return dispatch('clients/updateClient', {
clientId: field.client_id,
}, { root: true });
},
async addNewField(store, clientId) {
const field = await ClientField.createNew();
@ -38,8 +40,10 @@ export default {
}));
},
async deleteClientField({ dispatch }, fieldId) {
await ClientField.delete(fieldId);
return dispatch('clients/updateClient', null, { root: true }); // TODO: pass clientId to make generic
const field = await ClientField.delete(fieldId);
return dispatch('clients/updateClient', {
clientId: field.client_id,
}, { root: true }); // TODO: pass clientId to make generic
},
},
};

View File

@ -48,22 +48,17 @@ export default {
await Client.insert({ data: res });
return getClientById(res.id);
},
clientProps({ state }, props) {
clientProps(store, payload) {
return Client.update({
where: state.clientId,
data: props,
where: payload.clientId,
data: payload.props,
});
},
async updateClient({ getters, dispatch }, props) {
if (props) {
await dispatch('clientProps', props);
async updateClient({ dispatch }, payload) {
if (payload.props) {
await dispatch('clientProps', payload.props);
}
return ClientService.updateClient(getters.client);
},
async updateClientById(store, payload) {
const client = getClientById(payload.clientId);
client.$update(payload.props);
return ClientService.updateClient(client);
return ClientService.updateClient(getClientById(payload.clientId));
},
async openNewClientModal({ commit }) {
const client = await Client.createNew();

View File

@ -82,7 +82,7 @@ export default {
const invoice = getInvoice(payload.invoiceId);
if (Object.keys(clientProps).length > 0 && invoice.client_id) {
dispatch('clients/updateClientById', {
dispatch('clients/updateClient', {
props: clientProps,
clientId: invoice.client_id,
}, { root: true });
@ -189,6 +189,7 @@ export default {
props: {
label: field.label,
value: field.value,
team_field_id: field.id,
},
}, { root: true });
});

View File

@ -9,6 +9,7 @@ export default class InvoiceTeamField extends Model {
return {
id: this.attr(() => uuidv4()),
invoice_id: this.attr(null),
team_field_id: this.attr(null),
label: this.attr(''),
value: this.attr(''),
};