diff --git a/app/javascript/widget/store/modules/message.js b/app/javascript/widget/store/modules/message.js index 99c284e1f..04c2e7af0 100644 --- a/app/javascript/widget/store/modules/message.js +++ b/app/javascript/widget/store/modules/message.js @@ -12,9 +12,12 @@ export const getters = { export const actions = { update: async ( - { commit, dispatch }, + { commit, dispatch, getters: { getUIFlags: uiFlags } }, { email, messageId, submittedValues } ) => { + if (uiFlags.isUpdating) { + return; + } commit('toggleUpdateStatus', true); try { await MessageAPI.update({ diff --git a/app/javascript/widget/store/modules/specs/message/actions.spec.js b/app/javascript/widget/store/modules/specs/message/actions.spec.js index 36e4341ef..61c3f453a 100644 --- a/app/javascript/widget/store/modules/specs/message/actions.spec.js +++ b/app/javascript/widget/store/modules/specs/message/actions.spec.js @@ -17,7 +17,17 @@ describe('#actions', () => { API.patch.mockResolvedValue({ data: { contact: { pubsub_token: '8npuMUfDgizrwVoqcK1t7FMY' } }, }); - await actions.update({ commit }, user); + await actions.update( + { + commit, + getters: { + getUIFlags: { + isUpdating: false, + }, + }, + }, + user + ); expect(commit.mock.calls).toEqual([ ['toggleUpdateStatus', true], [ @@ -34,5 +44,21 @@ describe('#actions', () => { ['toggleUpdateStatus', false], ]); }); + + it('blocks all new action calls when isUpdating', async () => { + await actions.update( + { + commit, + getters: { + getUIFlags: { + isUpdating: true, + }, + }, + }, + {} + ); + + expect(commit.mock.calls).toEqual([]); + }); }); });