fix: Prevents duplicate action trigger on interactive messages (#6448)
Co-authored-by: raph941 <45232708+raph941@users.noreply.github.com> Co-authored-by: phunguyenmurcul <51897872+phunguyenmurcul@users.noreply.github.com>
This commit is contained in:
@@ -12,9 +12,12 @@ export const getters = {
|
|||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
update: async (
|
update: async (
|
||||||
{ commit, dispatch },
|
{ commit, dispatch, getters: { getUIFlags: uiFlags } },
|
||||||
{ email, messageId, submittedValues }
|
{ email, messageId, submittedValues }
|
||||||
) => {
|
) => {
|
||||||
|
if (uiFlags.isUpdating) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
commit('toggleUpdateStatus', true);
|
commit('toggleUpdateStatus', true);
|
||||||
try {
|
try {
|
||||||
await MessageAPI.update({
|
await MessageAPI.update({
|
||||||
|
|||||||
@@ -17,7 +17,17 @@ describe('#actions', () => {
|
|||||||
API.patch.mockResolvedValue({
|
API.patch.mockResolvedValue({
|
||||||
data: { contact: { pubsub_token: '8npuMUfDgizrwVoqcK1t7FMY' } },
|
data: { contact: { pubsub_token: '8npuMUfDgizrwVoqcK1t7FMY' } },
|
||||||
});
|
});
|
||||||
await actions.update({ commit }, user);
|
await actions.update(
|
||||||
|
{
|
||||||
|
commit,
|
||||||
|
getters: {
|
||||||
|
getUIFlags: {
|
||||||
|
isUpdating: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
user
|
||||||
|
);
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
['toggleUpdateStatus', true],
|
['toggleUpdateStatus', true],
|
||||||
[
|
[
|
||||||
@@ -34,5 +44,21 @@ describe('#actions', () => {
|
|||||||
['toggleUpdateStatus', false],
|
['toggleUpdateStatus', false],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('blocks all new action calls when isUpdating', async () => {
|
||||||
|
await actions.update(
|
||||||
|
{
|
||||||
|
commit,
|
||||||
|
getters: {
|
||||||
|
getUIFlags: {
|
||||||
|
isUpdating: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(commit.mock.calls).toEqual([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user