| 1 |
const { pluginRecommendations = [] } = window?.extAgentData?.agentContext || {}; |
| 2 |
const { adminUrl, homeUrl } = window?.extSharedData || {}; |
| 3 |
|
| 4 |
export const getRedirectUrl = (redirectTo, options = {}) => { |
| 5 |
if (redirectTo?.type === 'plugin-setup') { |
| 6 |
const plugin = pluginRecommendations.find( |
| 7 |
({ slug }) => slug === options.pluginSlug, |
| 8 |
); |
| 9 |
if (!plugin) return ''; |
| 10 |
return makeRedirectUrl(plugin.redirectTo); |
| 11 |
} |
| 12 |
|
| 13 |
return ''; |
| 14 |
}; |
| 15 |
|
| 16 |
const makeRedirectUrl = (url) => { |
| 17 |
try { |
| 18 |
return new URL( |
| 19 |
url.replace('{{ADMIN_URL}}', adminUrl).replace('{{HOME_URL}}', homeUrl), |
| 20 |
).toString(); |
| 21 |
} catch (e) { |
| 22 |
console.error(e); |
| 23 |
return ''; |
| 24 |
} |
| 25 |
}; |
| 26 |
|