[FIX] Unhandled action on UIKit (#1703)

This commit is contained in:
Djorkaeff Alexandre 2020-02-11 13:00:58 -03:00 committed by GitHub
parent 836683591c
commit ebe36cdc00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 47 deletions

View File

@ -29,13 +29,17 @@ export const useBlockContext = ({
loading, setLoading, error, value, language loading, setLoading, error, value, language
}, async({ value }) => { }, async({ value }) => {
setLoading(true); setLoading(true);
await action({ try {
blockId, await action({
appId: appId || appIdFromContext, blockId,
actionId, appId: appId || appIdFromContext,
value, actionId,
viewId value,
}); viewId
});
} catch (e) {
// do nothing
}
setLoading(false); setLoading(false);
}]; }];
} }
@ -44,12 +48,16 @@ export const useBlockContext = ({
loading, setLoading, value, error, language loading, setLoading, value, error, language
}, async({ value }) => { }, async({ value }) => {
setLoading(true); setLoading(true);
await state({ try {
blockId, await state({
appId, blockId,
actionId, appId,
value actionId,
}); value
});
} catch (e) {
// do nothing
}
setLoading(false); setLoading(false);
}]; }];
}; };

View File

@ -1,8 +1,6 @@
import random from '../../utils/random'; import random from '../../utils/random';
import EventEmitter from '../../utils/events'; import EventEmitter from '../../utils/events';
import Navigation from '../Navigation'; import Navigation from '../Navigation';
import { showErrorAlert } from '../../utils/info';
import I18n from '../../i18n';
const TRIGGER_TIMEOUT = 5000; const TRIGGER_TIMEOUT = 5000;
@ -112,43 +110,41 @@ export function triggerAction({
const { userId, authToken } = this.sdk.currentLogin; const { userId, authToken } = this.sdk.currentLogin;
const { host } = this.sdk.client; const { host } = this.sdk.client;
// we need to use fetch because this.sdk.post add /v1 to url
const result = await fetch(`${ host }/api/apps/ui.interaction/${ appId }/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Auth-Token': authToken,
'X-User-Id': userId
},
body: JSON.stringify({
type,
actionId,
payload,
container,
mid,
rid,
triggerId,
viewId
})
});
try { try {
const { type: interactionType, ...data } = await result.json(); // we need to use fetch because this.sdk.post add /v1 to url
handlePayloadUserInteraction(interactionType, data); const result = await fetch(`${ host }/api/apps/ui.interaction/${ appId }/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Auth-Token': authToken,
'X-User-Id': userId
},
body: JSON.stringify({
type,
actionId,
payload,
container,
mid,
rid,
triggerId,
viewId
})
});
if (data.success) { try {
return resolve(); const { type: interactionType, ...data } = await result.json();
return resolve(handlePayloadUserInteraction(interactionType, data));
} catch (e) {
// modal.close has no body, so result.json will fail
// but it returns ok status
if (result.ok) {
return resolve();
}
} }
return reject();
} catch (e) { } catch (e) {
if (result.status !== 200) { // do nothing
showErrorAlert(I18n.t('Oops'));
return reject();
}
} }
return reject();
return resolve();
}); });
} }