mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-28 08:21: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) {
|
updateProp(props) {
|
||||||
if (this.isNew) {
|
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.errors.clear();
|
||||||
|
|
||||||
this.$store.dispatch('clients/updateClient', props)
|
this.$store.dispatch('clients/updateClient', {
|
||||||
|
props,
|
||||||
|
clientId: this.client.id,
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
NotificationService.success('Updated');
|
NotificationService.success('Updated');
|
||||||
})
|
})
|
||||||
|
|||||||
@ -24,6 +24,10 @@ export default {
|
|||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
invoiceId: this.invoice.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,
|
fieldId: field.id,
|
||||||
invoiceId: this.invoice.id,
|
invoiceId: this.invoice.id,
|
||||||
});
|
});
|
||||||
|
this.$store.dispatch('teamFields/updateTeamField', {
|
||||||
|
fieldId: field.team_field_id,
|
||||||
|
props,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -27,11 +27,6 @@ export default {
|
|||||||
AppEditable,
|
AppEditable,
|
||||||
AppInput,
|
AppInput,
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
isNew() {
|
|
||||||
return this.team && this.team.$isNew;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
addNewField() {
|
addNewField() {
|
||||||
this.$store.dispatch('teamFields/addNewField', this.team.id);
|
this.$store.dispatch('teamFields/addNewField', this.team.id);
|
||||||
@ -54,12 +49,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateFieldProp(props, field) {
|
updateFieldProp(props, field) {
|
||||||
if (this.isNew) {
|
|
||||||
return this.$store.dispatch('teamFields/teamFieldProps', {
|
|
||||||
props,
|
|
||||||
fieldId: field.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.$store.dispatch('teamFields/updateTeamField', {
|
this.$store.dispatch('teamFields/updateTeamField', {
|
||||||
props,
|
props,
|
||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
|
|||||||
@ -14,8 +14,10 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
async updateClientField({ dispatch }, payload) {
|
async updateClientField({ dispatch }, payload) {
|
||||||
await dispatch('clientFieldProps', payload);
|
const field = await dispatch('clientFieldProps', payload);
|
||||||
return dispatch('clients/updateClient', null, { root: true }); // TODO: pass clientId to make generic
|
return dispatch('clients/updateClient', {
|
||||||
|
clientId: field.client_id,
|
||||||
|
}, { root: true });
|
||||||
},
|
},
|
||||||
async addNewField(store, clientId) {
|
async addNewField(store, clientId) {
|
||||||
const field = await ClientField.createNew();
|
const field = await ClientField.createNew();
|
||||||
@ -38,8 +40,10 @@ export default {
|
|||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
async deleteClientField({ dispatch }, fieldId) {
|
async deleteClientField({ dispatch }, fieldId) {
|
||||||
await ClientField.delete(fieldId);
|
const field = await ClientField.delete(fieldId);
|
||||||
return dispatch('clients/updateClient', null, { root: true }); // TODO: pass clientId to make generic
|
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 });
|
await Client.insert({ data: res });
|
||||||
return getClientById(res.id);
|
return getClientById(res.id);
|
||||||
},
|
},
|
||||||
clientProps({ state }, props) {
|
clientProps(store, payload) {
|
||||||
return Client.update({
|
return Client.update({
|
||||||
where: state.clientId,
|
where: payload.clientId,
|
||||||
data: props,
|
data: payload.props,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async updateClient({ getters, dispatch }, props) {
|
async updateClient({ dispatch }, payload) {
|
||||||
if (props) {
|
if (payload.props) {
|
||||||
await dispatch('clientProps', props);
|
await dispatch('clientProps', payload.props);
|
||||||
}
|
}
|
||||||
return ClientService.updateClient(getters.client);
|
return ClientService.updateClient(getClientById(payload.clientId));
|
||||||
},
|
|
||||||
async updateClientById(store, payload) {
|
|
||||||
const client = getClientById(payload.clientId);
|
|
||||||
client.$update(payload.props);
|
|
||||||
return ClientService.updateClient(client);
|
|
||||||
},
|
},
|
||||||
async openNewClientModal({ commit }) {
|
async openNewClientModal({ commit }) {
|
||||||
const client = await Client.createNew();
|
const client = await Client.createNew();
|
||||||
|
|||||||
@ -82,7 +82,7 @@ export default {
|
|||||||
const invoice = getInvoice(payload.invoiceId);
|
const invoice = getInvoice(payload.invoiceId);
|
||||||
|
|
||||||
if (Object.keys(clientProps).length > 0 && invoice.client_id) {
|
if (Object.keys(clientProps).length > 0 && invoice.client_id) {
|
||||||
dispatch('clients/updateClientById', {
|
dispatch('clients/updateClient', {
|
||||||
props: clientProps,
|
props: clientProps,
|
||||||
clientId: invoice.client_id,
|
clientId: invoice.client_id,
|
||||||
}, { root: true });
|
}, { root: true });
|
||||||
@ -189,6 +189,7 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
label: field.label,
|
label: field.label,
|
||||||
value: field.value,
|
value: field.value,
|
||||||
|
team_field_id: field.id,
|
||||||
},
|
},
|
||||||
}, { root: true });
|
}, { root: true });
|
||||||
});
|
});
|
||||||
|
|||||||
@ -9,6 +9,7 @@ export default class InvoiceTeamField extends Model {
|
|||||||
return {
|
return {
|
||||||
id: this.attr(() => uuidv4()),
|
id: this.attr(() => uuidv4()),
|
||||||
invoice_id: this.attr(null),
|
invoice_id: this.attr(null),
|
||||||
|
team_field_id: this.attr(null),
|
||||||
label: this.attr(''),
|
label: this.attr(''),
|
||||||
value: this.attr(''),
|
value: this.attr(''),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user