actions.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import * as types from '../../types';
  2. export default {
  3. [types.FETCH_DISTRIBUTORS]: ({commit}) => {
  4. // TODO: Remove this mocked data
  5. const distributors = [
  6. {
  7. "id": 1,
  8. "title": "Charton Hobbes",
  9. "notes": "",
  10. "contacts": [
  11. {
  12. "uuid": "44490103-92B7-4712-B494-E65878E6B0DC",
  13. "email": "abc@wisksolutions.com",
  14. "date": "2018-02-28T05:01:26Z",
  15. "name": "ABC",
  16. "phone": "",
  17. },
  18. {
  19. "uuid": "E7AD1046-3293-4F41-910C-63A198C9D3B6",
  20. "email": "efg@wisksolutions.com",
  21. "date": "2018-02-28T05:01:26Z",
  22. "name": "EFG",
  23. "phone": "",
  24. }
  25. ]
  26. },
  27. {
  28. "id": 2,
  29. "title": "Bob Marley",
  30. "notes": "Something",
  31. "contacts": [
  32. {
  33. "uuid": "44490103-92B7-4712-B494-E65878E6B0DC",
  34. "email": "abc@wisksolutions.com",
  35. "date": "2018-02-28T05:01:26Z",
  36. "name": "ABC",
  37. "phone": "",
  38. }
  39. ]
  40. },
  41. ]
  42. commit(types.UPDATE_DISTRIBUTORS, distributors)
  43. },
  44. [types.CLEAR_DISTRIBUTORS]: ({commit}) => {
  45. commit(types.UPDATE_DISTRIBUTORS, []);
  46. },
  47. /**
  48. * Expected payload: {id, distributor}
  49. */
  50. [types.SET_DISTRIBUTOR]: ({commit, getters}, payload) => {
  51. if (payload.id) {
  52. // api call
  53. // Update server with what changed
  54. } else {
  55. // api call
  56. // Add new distributor
  57. }
  58. commit(types.UPDATE_DISTRIBUTOR, payload.distributor);
  59. },
  60. };