| @@ -1,14 +1,97 @@ | ||
| 1 | -import useSWRImmutable from 'swr/immutable' | |
| 2 | -import { getTasks } from '@assist/api/Data' | |
| 1 | +import { | |
| 2 | + domainSearchUrl, | |
| 3 | + showDomainTask, | |
| 4 | + showSecondaryDomainTask, | |
| 5 | +} from '@assist/lib/domains'; | |
| 6 | +import addPage from '@assist/tasks/add-page'; | |
| 7 | +import openAIImageEditor from '@assist/tasks/ai-image-editor'; | |
| 8 | +import openAITextEditor from '@assist/tasks/ai-text-editor'; | |
| 9 | +import demoCard from '@assist/tasks/demo-card'; | |
| 10 | +import domainRecommendation from '@assist/tasks/domain-recommendation'; | |
| 11 | +import editHomepage from '@assist/tasks/edit-homepage'; | |
| 12 | +import helpCenter from '@assist/tasks/help-center'; | |
| 13 | +import helpCenterAi from '@assist/tasks/help-center-ai'; | |
| 14 | +import ionosConnectDomain from '@assist/tasks/ionos-connect-domain'; | |
| 15 | +import openDesignLibrary from '@assist/tasks/open-design-library'; | |
| 16 | +import secondaryDomainRecommendation from '@assist/tasks/secondary-domain-recommendation'; | |
| 17 | +import setupAioseo from '@assist/tasks/setup-aioseo'; | |
| 18 | +import setupGivewp from '@assist/tasks/setup-givewp'; | |
| 19 | +import setupHubspot from '@assist/tasks/setup-hubspot'; | |
| 20 | +import setupMonsterInsights from '@assist/tasks/setup-monsterinsights'; | |
| 21 | +import setupSimplyAppointments from '@assist/tasks/setup-simply-appointments'; | |
| 22 | +import setupSimplyBook from '@assist/tasks/setup-simplybook'; | |
| 23 | +import setupTec from '@assist/tasks/setup-tec'; | |
| 24 | +import setupWoocommerceGermanizedStore from '@assist/tasks/setup-woocommerce-germanized-store'; | |
| 25 | +import setupWoocommerceStore from '@assist/tasks/setup-woocommerce-store'; | |
| 26 | +import setupWpforms from '@assist/tasks/setup-wpforms'; | |
| 27 | +import setupYourwebshop from '@assist/tasks/setup-yourwebshop'; | |
| 28 | +import siteBuilderLauncher from '@assist/tasks/site-builder-launcher'; | |
| 29 | +import updateSiteDescription from '@assist/tasks/update-site-description'; | |
| 30 | +import uploadLogo from '@assist/tasks/upload-logo'; | |
| 31 | +import uploadSiteIcon from '@assist/tasks/upload-site-icon'; | |
| 32 | +import { safeParseJson } from '@shared/lib/parsing'; | |
| 3 | 33 | |
| 34 | +const activePlugins = window.extSharedData?.activePlugins || []; | |
| 35 | +const sitePlugins = | |
| 36 | + safeParseJson(window.extSharedData.launchDataLegacy)?.state?.sitePlugins || | |
| 37 | + []; | |
| 38 | + | |
| 4 | 39 | export const useTasks = () => { |
| 5 | - const { data: tasks, error } = useSWRImmutable('tasks', async () => { | |
| 6 | - const response = await getTasks() | |
| 7 | - if (!response?.data || !Array.isArray(response.data)) { | |
| 8 | - console.error(response) | |
| 9 | - throw new Error('Bad data') | |
| 10 | - } | |
| 11 | - return response.data | |
| 12 | - }) | |
| 13 | - return { tasks, error, loading: !tasks && !error } | |
| 14 | -} | |
| 40 | + const tasks = Object.values({ | |
| 41 | + 'site-builder-launcher': { ...siteBuilderLauncher }, | |
| 42 | + 'ai-text-editor': { ...openAITextEditor }, | |
| 43 | + 'help-center-ai': { ...helpCenterAi }, | |
| 44 | + 'help-center': { ...helpCenter }, | |
| 45 | + 'ai-image-editor': { ...openAIImageEditor }, | |
| 46 | + 'design-library': { ...openDesignLibrary }, | |
| 47 | + 'domain-recommendation': { ...domainRecommendation }, | |
| 48 | + 'secondary-domain-recommendation': { ...secondaryDomainRecommendation }, | |
| 49 | + 'ionos-connect-domain': { ...ionosConnectDomain }, | |
| 50 | + 'edit-homepage': { ...editHomepage }, | |
| 51 | + 'upload-logo': { ...uploadLogo }, | |
| 52 | + 'upload-site-icon': { ...uploadSiteIcon }, | |
| 53 | + 'update-site-description': { ...updateSiteDescription }, | |
| 54 | + 'add-page': { ...addPage }, | |
| 55 | + 'demo-card': { ...demoCard }, | |
| 56 | + 'setup-woocommerce-store': { ...setupWoocommerceStore }, | |
| 57 | + 'setup-woocommerce-germanized-store': { | |
| 58 | + ...setupWoocommerceGermanizedStore, | |
| 59 | + }, | |
| 60 | + 'setup-hubspot': { ...setupHubspot }, | |
| 61 | + 'setup-givewp': { ...setupGivewp }, | |
| 62 | + 'setup-tec': { ...setupTec }, | |
| 63 | + 'setup-simply-appointments': { ...setupSimplyAppointments }, | |
| 64 | + 'setup-simplybook': { ...setupSimplyBook }, | |
| 65 | + 'setup-aioses': { ...setupAioseo }, | |
| 66 | + 'setup-wpforms': { ...setupWpforms }, | |
| 67 | + 'setup-yourwebshop': { ...setupYourwebshop }, | |
| 68 | + 'setup-monsterinsights': { ...setupMonsterInsights }, | |
| 69 | + }); | |
| 70 | + | |
| 71 | + const activePluginSlugs = activePlugins?.map((plugin) => { | |
| 72 | + try { | |
| 73 | + return plugin.split('/')[0]; | |
| 74 | + } catch (_e) { | |
| 75 | + return plugin; | |
| 76 | + } | |
| 77 | + }); | |
| 78 | + const sitePluginSlugs = sitePlugins?.map((p) => p.slug) || []; | |
| 79 | + const pluginsToCheck = [ | |
| 80 | + ...new Set([...activePluginSlugs, ...sitePluginSlugs]), | |
| 81 | + ]; | |
| 82 | + | |
| 83 | + return { | |
| 84 | + tasks: tasks.filter((task) => { | |
| 85 | + const { | |
| 86 | + dependencies: { plugins }, | |
| 87 | + } = task; | |
| 88 | + | |
| 89 | + return task.show({ | |
| 90 | + plugins, | |
| 91 | + activePlugins: pluginsToCheck, | |
| 92 | + showDomainTask: showDomainTask && domainSearchUrl, | |
| 93 | + showSecondaryDomainTask: showSecondaryDomainTask && domainSearchUrl, | |
| 94 | + }); | |
| 95 | + }), | |
| 96 | + }; | |
| 97 | +}; | |