Use yeild* to call controlled actions
[MAILPOET-2681]
This commit is contained in:
committed by
Veljko V
parent
0d0538705b
commit
2557586e86
@@ -118,43 +118,17 @@ export function* verifyPremiumKey(key: string) {
|
||||
let pluginActive = res.meta.premium_plugin_active;
|
||||
|
||||
if (!pluginInstalled) {
|
||||
yield updateKeyActivationState({
|
||||
premiumStatus: 'valid_premium_plugin_being_installed',
|
||||
premiumInstallationStatus: 'install_installing',
|
||||
});
|
||||
const call = yield {
|
||||
type: 'CALL_API',
|
||||
endpoint: 'premium',
|
||||
action: 'installPlugin',
|
||||
};
|
||||
if (call && !call.success) {
|
||||
yield updateKeyActivationState({ premiumInstallationStatus: 'install_installing_error' });
|
||||
pluginInstalled = false;
|
||||
} else {
|
||||
pluginInstalled = true;
|
||||
const actions = installPremiumPlugin();
|
||||
let action = actions.next();
|
||||
while (!action.done) {
|
||||
yield action.value;
|
||||
action = actions.next();
|
||||
}
|
||||
pluginInstalled = action.value;
|
||||
}
|
||||
|
||||
if (pluginInstalled && !pluginActive) {
|
||||
const isAfterInstall = !res.meta.premium_plugin_installed;
|
||||
const doneStatus = isAfterInstall ? 'install_done' : 'activate_done';
|
||||
const errorStatus = isAfterInstall ? 'install_activating_error' : 'activate_error';
|
||||
yield updateKeyActivationState({
|
||||
premiumStatus: 'valid_premium_plugin_being_activated',
|
||||
premiumInstallationStatus: isAfterInstall ? 'install_activating' : 'activate_activating',
|
||||
});
|
||||
const call = yield {
|
||||
type: 'CALL_API',
|
||||
endpoint: 'premium',
|
||||
action: 'activatePlugin',
|
||||
};
|
||||
if (call && !call.success) {
|
||||
yield updateKeyActivationState({ premiumInstallationStatus: errorStatus });
|
||||
pluginActive = false;
|
||||
} else {
|
||||
yield updateKeyActivationState({ premiumInstallationStatus: doneStatus });
|
||||
pluginActive = true;
|
||||
}
|
||||
pluginActive = yield* activatePremiumPlugin(!res.meta.premium_plugin_installed);
|
||||
}
|
||||
|
||||
if (pluginInstalled && pluginActive) {
|
||||
@@ -206,5 +180,5 @@ export function* installPremiumPlugin() {
|
||||
yield updateKeyActivationState({ premiumInstallationStatus: 'install_installing_error' });
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return yield* activatePremiumPlugin(true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user