mirror of
				https://github.com/mokuappio/serverless-invoices.git
				synced 2025-10-31 18:01:07 -04:00 
			
		
		
		
	Update team and client when updating custom field on invoice.
This commit is contained in:
		| @ -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