| 1 |
import { buildExtendifyCodeLink } from '@auto-launch/functions/extendify-code'; |
| 2 |
import { checkIn } from '@auto-launch/functions/insights'; |
| 3 |
import { useLaunchDataStore } from '@auto-launch/state/launch-data'; |
| 4 |
import { launchStrings } from '@auto-launch/strings'; |
| 5 |
import { useEffect } from '@wordpress/element'; |
| 6 |
import { arrowRight, code, external, layout } from '@wordpress/icons'; |
| 7 |
|
| 8 |
export const useExtendifyCodeConnector = ({ onProceed }) => { |
| 9 |
const { descriptionRaw, title } = useLaunchDataStore(); |
| 10 |
const strings = launchStrings(); |
| 11 |
const { extendifyCodeData = {} } = window.extSharedData; |
| 12 |
const { link, title: codeTitle, message, ctaPrimary } = extendifyCodeData; |
| 13 |
const ready = Boolean(link && codeTitle && message && ctaPrimary); |
| 14 |
|
| 15 |
useEffect(() => { |
| 16 |
if (!ready) { |
| 17 |
onProceed(); |
| 18 |
return; |
| 19 |
} |
| 20 |
checkIn({ |
| 21 |
stage: 'extendify_code_screen_seen', |
| 22 |
description: descriptionRaw || title, |
| 23 |
}); |
| 24 |
}, [ready, onProceed, descriptionRaw, title]); |
| 25 |
|
| 26 |
// A partial partner payload must not trap the flow on a blank screen. |
| 27 |
if (!ready) return { options: [] }; |
| 28 |
|
| 29 |
return { |
| 30 |
title: strings.connectorTitle, |
| 31 |
subtitle: strings.connectorBody, |
| 32 |
options: [ |
| 33 |
{ |
| 34 |
key: 'wordpress', |
| 35 |
icon: layout, |
| 36 |
heading: strings.wordpressHeading, |
| 37 |
description: strings.wordpressBody, |
| 38 |
buttonLabel: strings.wordpressAction, |
| 39 |
buttonIcon: arrowRight, |
| 40 |
onClick: () => { |
| 41 |
checkIn({ stage: 'extendify_code_choose_wordpress' }); |
| 42 |
onProceed(); |
| 43 |
}, |
| 44 |
}, |
| 45 |
{ |
| 46 |
key: 'builder', |
| 47 |
icon: code, |
| 48 |
highlight: true, |
| 49 |
badgeLabel: strings.connectorBadge, |
| 50 |
heading: codeTitle, |
| 51 |
description: message, |
| 52 |
buttonLabel: ctaPrimary, |
| 53 |
buttonIcon: external, |
| 54 |
onClick: () => { |
| 55 |
const url = buildExtendifyCodeLink(link, { |
| 56 |
description: descriptionRaw, |
| 57 |
title, |
| 58 |
}); |
| 59 |
checkIn({ stage: 'extendify_code_choose_builder' }); |
| 60 |
if (url) window.location.assign(url); |
| 61 |
}, |
| 62 |
}, |
| 63 |
], |
| 64 |
}; |
| 65 |
}; |
| 66 |
|