mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-27 07:51:08 -04:00
Update team and client when updating custom field on invoice.
This commit is contained in:
@ -123,11 +123,17 @@ export default {
|
||||
},
|
||||
updateProp(props) {
|
||||
if (this.isNew) {
|
||||
return this.$store.dispatch('clients/clientProps', props);
|
||||
return this.$store.dispatch('clients/clientProps', {
|
||||
props,
|
||||
clientId: this.client.id,
|
||||
});
|
||||
}
|
||||
this.errors.clear();
|
||||
|
||||
this.$store.dispatch('clients/updateClient', props)
|
||||
this.$store.dispatch('clients/updateClient', {
|
||||
props,
|
||||
clientId: this.client.id,
|
||||
})
|
||||
.then(() => {
|
||||
NotificationService.success('Updated');
|
||||
})
|
||||
|
||||
@ -24,6 +24,10 @@ export default {
|
||||
fieldId: field.id,
|
||||
invoiceId: this.invoice.id,
|
||||
});
|
||||
this.$store.dispatch('clientFields/updateClientField', {
|
||||
fieldId: field.client_field_id,
|
||||
props,
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -24,6 +24,10 @@ export default {
|
||||
fieldId: field.id,
|
||||
invoiceId: this.invoice.id,
|
||||
});
|
||||
this.$store.dispatch('teamFields/updateTeamField', {
|
||||
fieldId: field.team_field_id,
|
||||
props,
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -27,11 +27,6 @@ export default {
|
||||
AppEditable,
|
||||
AppInput,
|
||||
},
|
||||
computed: {
|
||||
isNew() {
|
||||
return this.team && this.team.$isNew;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
addNewField() {
|
||||
this.$store.dispatch('teamFields/addNewField', this.team.id);
|
||||
@ -54,12 +49,6 @@ export default {
|
||||
}
|
||||
},
|
||||
updateFieldProp(props, field) {
|
||||
if (this.isNew) {
|
||||
return this.$store.dispatch('teamFields/teamFieldProps', {
|
||||
props,
|
||||
fieldId: field.id,
|
||||
});
|
||||
}
|
||||
this.$store.dispatch('teamFields/updateTeamField', {
|
||||
props,
|
||||
fieldId: field.id,
|
||||
|
||||
@ -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
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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 });
|
||||
});
|
||||
|
||||
@ -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(''),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user