Proposed Changes
For WoA sites, a background job copies data to the remote WoA site after purchase. Due to this, the correct DIFM data is not available immediately in the GET /rest/v1.2/sites/<siteid>
endpoint response.
This PR adds a hook to the website content step that polls the endpoint and checks for DIFM-related data. A valid DIFM purchase has .options.is_difm_lite_in_progress
set to true
and .options.difm_lite_site_options.pages
should be an array of strings.
If the above conditions are met, the hook returns { isLoading: false, hasValidPurchase: true }
.
If the above conditions are not met, it retries the request MAXTRIES
times, with a linear backoff. If the conditions are still not met, the hook returns { isLoading: false, hasValidPurchase: false }
.
The default return value is { isLoading: true, hasValidPurchase: false }
.
This logic assumes that most users on this page will have a valid purchase and will have the best-case scenario – the form is shown after 1 request for simple sites and n
requests for WoA sites (assuming data is synced within ~27 seconds).
Users without a valid purchase will have the worst-case scenario where the page would wait for ~27 seconds before redirecting to /home
. IMO, this tradeoff is acceptable since this scenario can happen only if users manually visit this URL.
Test Case |
Result |
Simple site with a valid purchase |
Form is shown after the first request |
Simple site without a valid purchase |
Redirected to /home after 10 requests |
Simple site with a valid purchase and content already submitted |
Redirected to /home after 1 request |
Atomic site with a valid purchase and data is in sync |
Form is shown after the first request |
Atomic site with a valid purchase and data is not in sync yet |
Form is shown after n requests (after data sync happens) |
Atomic site without a valid purchase |
Redirected to /home after 10 requests |
Testing Instructions
Testing WoA sites
- Go to
/start/do-it-for-me/?flags=difm/allow-woa-sites
. Choose Existing site and in the site picker, select a WoA site.
- Go through the flow steps and complete the purchase.
- After purchase, you should see a loading screen and then see the form.
Testing Simple sites
- Follow the above steps, but select a simple site in the site picker.
Testing Simple sites without a valid purchase
- Go to
start/site-content-collection/website-content?siteSlug=<site slug>
for a site that does not have a DIFM purchase.
- Confirm that you are redirected to /home.
Testing Simple sites with content already submitted
- Go to
start/site-content-collection/website-content?siteSlug=<site slug>
for a site for which you have already submitted the content form.
- Confirm that you are redirected to /home.
Screenshots
Loading Screen
Error Screen
Pre-merge Checklist
- Have you written new tests for your changes? – NA
- Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
- Have you checked for TypeScript, React or other console errors?
- Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
- Have we added the “[Status] String Freeze” label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
Fixes Automattic/martech#1199
Unfortunately, no screenshots were provided by the developer.