Skip to content

Commit

Permalink
refactor useAppInstallationHandler hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoevanp committed Oct 24, 2024
1 parent 96b37df commit 8782909
Showing 1 changed file with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ export function useAppInstallationHandler({
throw new Error('Apps orchestrator is not available');
}

const acquireApp = useCallback(async () => {
if (action === 'purchase' && !isAppPurchased) {
try {
const data = await appsOrchestrator.buildExternalUrl(app.id, app.purchaseType, false);
setModal(
<IframeModal
url={data.url}
cancel={onDismiss}
confirm={() => {
setIsPurchased(true);
openPermissionModal();
}}
/>,
);
} catch (error) {
handleAPIError(error);
return useCallback(async () => {
const acquireApp = async () => {
if (action === 'purchase' && !isAppPurchased) {
try {
const data = await appsOrchestrator.buildExternalUrl(app.id, app.purchaseType, false);
setModal(
<IframeModal
url={data.url}
cancel={onDismiss}
confirm={() => {
setIsPurchased(true);
openPermissionModal();
}}
/>,
);
} catch (error) {
handleAPIError(error);
}
return;
}
return;
}

openPermissionModal();
}, [action, isAppPurchased, openPermissionModal, appsOrchestrator, app.id, app.purchaseType, setModal, onDismiss, setIsPurchased]);
openPermissionModal();
};

return useCallback(async () => {
if (app?.versionIncompatible) {
openIncompatibleModal(app, action, closeModal);
return;
Expand Down Expand Up @@ -147,13 +147,15 @@ export function useAppInstallationHandler({
appCountQuery.data,
setModal,
closeModal,
acquireApp,
isAppPurchased,
openPermissionModal,
appsOrchestrator,
onDismiss,
setIsPurchased,
openIncompatibleModal,
dispatchToastMessage,
notifyAdmins,
success,
appsOrchestrator,
onDismiss,
openExternalLink,
manageSubscriptionUrl,
]);
Expand Down

0 comments on commit 8782909

Please sign in to comment.