| 58 | }, |
| 59 | actions: { |
| 60 | async fetchCurrentTrialRequest ({ commit, state }) { |
| 61 | if (state.properties.email) return // already fetched |
| 62 | let trialRequests |
| 63 | try { |
| 64 | trialRequests = await api.getOwn() |
| 65 | } catch (err) { |
| 66 | console.error('fetchCurrentTrialRequest err', err) |
| 67 | } |
| 68 | if (!trialRequests || trialRequests.length === 0) { |
| 69 | console.error('trialRequests empty', trialRequests) |
| 70 | return {} |
| 71 | } |
| 72 | if (trialRequests.length > 1) { |
| 73 | console.error(`More than 1 TrialRequest, chose ${trialRequests[0]?.id}`, trialRequests) |
| 74 | } |
| 75 | trialRequests = _.sortBy(trialRequests, (t) => t.id) |
| 76 | // assuming that the last trial request should be updated |
| 77 | // right now only used for hoc signed up teachers who will have only one trial request |
| 78 | // can update later if the assumption is not true for any situation in the future |
| 79 | const trialRequest = _.last(trialRequests) |
| 80 | commit('setTrialData', trialRequest) |
| 81 | }, |
| 82 | async updateProperties ({ state, commit }, updates) { |
| 83 | const clonedState = _.clone(state) |
| 84 | clonedState.properties = Object.assign({}, clonedState.properties, updates) |