|
1 | | -import SubmissionError from '../../../error/SubmissionError'; |
2 | | -import fetch from '../../../utils/fetch'; |
| 1 | +import SubmissionError from '../../../error/SubmissionError' |
| 2 | +import fetch from '../../../utils/fetch' |
3 | 3 | import { |
4 | 4 | {{{ uc }}}_CREATE_ERROR, |
5 | 5 | {{{ uc }}}_CREATE_LOADING, |
6 | 6 | {{{ uc }}}_CREATE_SUCCESS, |
7 | 7 | {{{ uc }}}_CREATE_VIOLATIONS, |
8 | 8 | {{{ uc }}}_CREATE_RESET |
9 | | -} from './mutation-types'; |
| 9 | +} from './mutation-types' |
10 | 10 |
|
11 | 11 | const state = { |
12 | 12 | loading: false, |
13 | 13 | error: '', |
14 | 14 | created: null, |
15 | 15 | violations: null |
16 | | -}; |
| 16 | +} |
17 | 17 |
|
18 | | -function error(error) { |
19 | | - return {type: {{{ uc }}}_CREATE_ERROR, error}; |
| 18 | +function error (error) { |
| 19 | + return {type: {{{ uc }}}_CREATE_ERROR, error} |
20 | 20 | } |
21 | 21 |
|
22 | | -function loading(loading) { |
23 | | - return {type: {{{ uc }}}_CREATE_LOADING, loading}; |
| 22 | +function loading (loading) { |
| 23 | + return {type: {{{ uc }}}_CREATE_LOADING, loading} |
24 | 24 | } |
25 | 25 |
|
26 | | -function success(created) { |
| 26 | +function success (created) { |
27 | 27 | return {type: {{{ uc }}}_CREATE_SUCCESS, created}; |
28 | 28 | } |
29 | 29 |
|
30 | | -function violations(violations) { |
31 | | - return {type: {{{ uc }}}_CREATE_VIOLATIONS, violations}; |
| 30 | +function violations (violations) { |
| 31 | + return {type: {{{ uc }}}_CREATE_VIOLATIONS, violations} |
32 | 32 | } |
33 | 33 |
|
34 | | -function reset() { |
35 | | - return {type: {{{ uc }}}_CREATE_RESET}; |
| 34 | +function reset () { |
| 35 | + return {type: {{{ uc }}}_CREATE_RESET} |
36 | 36 | } |
37 | 37 |
|
38 | 38 | const getters = { |
39 | 39 | created: state => state.created, |
40 | 40 | error: state => state.error, |
41 | 41 | loading: state => state.loading, |
42 | | - violations: state => state.violations, |
43 | | -}; |
| 42 | + violations: state => state.violations |
| 43 | +} |
44 | 44 |
|
45 | 45 | const actions = { |
46 | | - create({ commit }, values) { |
47 | | - commit(loading(true)); |
| 46 | + create ({ commit }, values) { |
| 47 | + commit(loading(true)) |
48 | 48 |
|
49 | 49 | return fetch('/{{{ name }}}', {method: 'POST', body: JSON.stringify(values)}) |
50 | 50 | .then(response => { |
51 | | - commit(loading(false)); |
52 | | - |
53 | | - return response.json(); |
| 51 | + commit(loading(false)) |
| 52 | + return response.json() |
54 | 53 | }) |
55 | 54 | .then(data => { |
56 | | - commit(success(data)); |
| 55 | + commit(success(data)) |
57 | 56 | }) |
58 | 57 | .catch(e => { |
59 | | - commit(loading(false)); |
| 58 | + commit(loading(false)) |
60 | 59 |
|
61 | 60 | if (e instanceof SubmissionError) { |
62 | | - commit(violations(e.errors)); |
63 | | - commit(error(e.errors._error)); |
64 | | - return; |
| 61 | + commit(violations(e.errors)) |
| 62 | + commit(error(e.errors._error)) |
| 63 | + return |
65 | 64 | } |
66 | 65 |
|
67 | | - commit(error(e.message)); |
| 66 | + commit(error(e.message)) |
68 | 67 | }); |
69 | 68 | }, |
70 | | - reset({ commit }) { |
71 | | - commit(reset()); |
| 69 | + reset ({ commit }) { |
| 70 | + commit(reset()) |
72 | 71 | } |
73 | 72 | }; |
74 | 73 |
|
75 | 74 | const mutations = { |
76 | | - [{{{ uc }}}_CREATE_ERROR] (state, payload) { |
77 | | - state.error = payload.error; |
78 | | - }, |
79 | | - [{{{ uc }}}_CREATE_LOADING] (state, payload) { |
80 | | - state.loading = payload.loading; |
81 | | - }, |
82 | | - [{{{ uc }}}_CREATE_SUCCESS] (state, payload) { |
83 | | - state.created = payload.created; |
84 | | - }, |
85 | | - [{{{ uc }}}_CREATE_VIOLATIONS] (state, payload) { |
86 | | - state.violations = payload.violations; |
87 | | - }, |
88 | | - [{{{ uc }}}_CREATE_RESET] (state) { |
89 | | - state.loading = false; |
90 | | - state.error = ''; |
91 | | - state.created = null; |
92 | | - state.violations = null; |
93 | | - } |
94 | | -}; |
| 75 | + [{{{ uc }}}_CREATE_ERROR] (state, payload) { |
| 76 | + state.error = payload.error |
| 77 | + }, |
| 78 | + [{{{ uc }}}_CREATE_LOADING] (state, payload) { |
| 79 | + state.loading = payload.loading |
| 80 | + }, |
| 81 | + [{{{ uc }}}_CREATE_SUCCESS] (state, payload) { |
| 82 | + state.created = payload.created |
| 83 | + }, |
| 84 | + [{{{ uc }}}_CREATE_VIOLATIONS] (state, payload) { |
| 85 | + state.violations = payload.violations |
| 86 | + }, |
| 87 | + [{{{ uc }}}_CREATE_RESET] (state) { |
| 88 | + state.loading = false |
| 89 | + state.error = '' |
| 90 | + state.created = null |
| 91 | + state.violations = null |
| 92 | + } |
| 93 | +} |
95 | 94 |
|
96 | 95 | export default { |
97 | 96 | namespaced: true, |
98 | 97 | state, |
99 | 98 | getters, |
100 | 99 | actions, |
101 | 100 | mutations |
102 | | -}; |
| 101 | +} |
0 commit comments