@automattic/data-stores 3.1.2 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -1
- package/dist/cjs/agents-manager/actions.js +116 -0
- package/dist/cjs/agents-manager/actions.js.map +1 -0
- package/dist/cjs/agents-manager/constants.js +5 -0
- package/dist/cjs/agents-manager/constants.js.map +1 -0
- package/dist/cjs/agents-manager/index.js +37 -0
- package/dist/cjs/agents-manager/index.js.map +1 -0
- package/dist/cjs/agents-manager/persist-state.js +58 -0
- package/dist/cjs/agents-manager/persist-state.js.map +1 -0
- package/dist/cjs/agents-manager/reducer.js +87 -0
- package/dist/cjs/agents-manager/reducer.js.map +1 -0
- package/dist/cjs/agents-manager/resolvers.js +60 -0
- package/dist/cjs/agents-manager/resolvers.js.map +1 -0
- package/dist/cjs/agents-manager/selectors.js +44 -0
- package/dist/cjs/agents-manager/selectors.js.map +1 -0
- package/dist/cjs/{domain-suggestions → agents-manager}/types.js.map +1 -1
- package/dist/cjs/contextual-help/admin-sections.js +2 -2
- package/dist/cjs/contextual-help/admin-sections.js.map +1 -1
- package/dist/cjs/help-center/actions.js +103 -69
- package/dist/cjs/help-center/actions.js.map +1 -1
- package/dist/cjs/help-center/constants.js +2 -1
- package/dist/cjs/help-center/constants.js.map +1 -1
- package/dist/cjs/help-center/index.js +14 -27
- package/dist/cjs/help-center/index.js.map +1 -1
- package/dist/cjs/help-center/reducer.js +36 -12
- package/dist/cjs/help-center/reducer.js.map +1 -1
- package/dist/cjs/help-center/resolvers.js +45 -24
- package/dist/cjs/help-center/resolvers.js.map +1 -1
- package/dist/cjs/help-center/selectors.js +13 -5
- package/dist/cjs/help-center/selectors.js.map +1 -1
- package/dist/cjs/help-center/utils.js +136 -0
- package/dist/cjs/help-center/utils.js.map +1 -0
- package/dist/cjs/index.js +8 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mutations/use-domains-bulk-actions-mutation.js +3 -3
- package/dist/cjs/mutations/use-domains-bulk-actions-mutation.js.map +1 -1
- package/dist/cjs/newsletter-categories/index.js +2 -2
- package/dist/cjs/newsletter-categories/index.js.map +1 -1
- package/dist/cjs/onboard/actions.js +16 -1
- package/dist/cjs/onboard/actions.js.map +1 -1
- package/dist/cjs/onboard/reducer.js +34 -1
- package/dist/cjs/onboard/reducer.js.map +1 -1
- package/dist/cjs/onboard/selectors.js +7 -1
- package/dist/cjs/onboard/selectors.js.map +1 -1
- package/dist/cjs/plans/constants.js +3 -1
- package/dist/cjs/plans/constants.js.map +1 -1
- package/dist/cjs/plans/hooks/use-pricing-meta-for-grid-plans.js +35 -18
- package/dist/cjs/plans/hooks/use-pricing-meta-for-grid-plans.js.map +1 -1
- package/dist/cjs/plans/index.js +2 -1
- package/dist/cjs/plans/index.js.map +1 -1
- package/dist/cjs/plans/queries/use-plans.js +21 -2
- package/dist/cjs/plans/queries/use-plans.js.map +1 -1
- package/dist/cjs/plans/queries/use-site-plans.js +2 -2
- package/dist/cjs/plans/queries/use-site-plans.js.map +1 -1
- package/dist/cjs/plans/resolvers.js +0 -1
- package/dist/cjs/plans/resolvers.js.map +1 -1
- package/dist/cjs/plans/selectors.js.map +1 -1
- package/dist/cjs/products-list/queries/use-products.js +2 -2
- package/dist/cjs/products-list/queries/use-products.js.map +1 -1
- package/dist/cjs/products-list/resolvers.js +2 -2
- package/dist/cjs/products-list/resolvers.js.map +1 -1
- package/dist/cjs/purchases/lib/assembler.js +15 -20
- package/dist/cjs/purchases/lib/assembler.js.map +1 -1
- package/dist/cjs/purchases/queries/use-get-jetpack-transferred-license-purchases.js +2 -2
- package/dist/cjs/purchases/queries/use-get-jetpack-transferred-license-purchases.js.map +1 -1
- package/dist/cjs/purchases/queries/use-site-purchases.js +3 -3
- package/dist/cjs/purchases/queries/use-site-purchases.js.map +1 -1
- package/dist/cjs/queries/use-all-domains-query.js +2 -2
- package/dist/cjs/queries/use-all-domains-query.js.map +1 -1
- package/dist/cjs/queries/use-bulk-domain-update-status-query.js +3 -57
- package/dist/cjs/queries/use-bulk-domain-update-status-query.js.map +1 -1
- package/dist/cjs/queries/use-happiness-engineers-query.js +2 -2
- package/dist/cjs/queries/use-happiness-engineers-query.js.map +1 -1
- package/dist/cjs/queries/use-launchpad.js +5 -5
- package/dist/cjs/queries/use-launchpad.js.map +1 -1
- package/dist/cjs/queries/use-site-domains-query.js +2 -2
- package/dist/cjs/queries/use-site-domains-query.js.map +1 -1
- package/dist/cjs/queries/use-site-intent.js +2 -2
- package/dist/cjs/queries/use-site-intent.js.map +1 -1
- package/dist/cjs/queries/use-site-query.js +2 -2
- package/dist/cjs/queries/use-site-query.js.map +1 -1
- package/dist/cjs/reader/contexts/index.js +1 -4
- package/dist/cjs/reader/contexts/index.js.map +1 -1
- package/dist/cjs/reader/helpers/index.js +4 -3
- package/dist/cjs/reader/helpers/index.js.map +1 -1
- package/dist/cjs/reader/helpers/optimistic-update.js +2 -1
- package/dist/cjs/reader/helpers/optimistic-update.js.map +1 -1
- package/dist/cjs/reader/index.js +2 -8
- package/dist/cjs/reader/index.js.map +1 -1
- package/dist/cjs/reader/mutations/use-pending-site-confirm-mutation.js +2 -2
- package/dist/cjs/reader/mutations/use-pending-site-confirm-mutation.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-delivery-frequency-mutation.js +26 -20
- package/dist/cjs/reader/mutations/use-site-delivery-frequency-mutation.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-email-me-new-comments-mutation.js +4 -3
- package/dist/cjs/reader/mutations/use-site-email-me-new-comments-mutation.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-email-me-new-posts-mutation.js +4 -3
- package/dist/cjs/reader/mutations/use-site-email-me-new-posts-mutation.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-notify-me-of-new-posts-mutation.js +4 -3
- package/dist/cjs/reader/mutations/use-site-notify-me-of-new-posts-mutation.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-subscribe-mutation.js +10 -4
- package/dist/cjs/reader/mutations/use-site-subscribe-mutation.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-unsubscribe-mutation.js +11 -4
- package/dist/cjs/reader/mutations/use-site-unsubscribe-mutation.js.map +1 -1
- package/dist/cjs/reader/queries/index.js +2 -8
- package/dist/cjs/reader/queries/index.js.map +1 -1
- package/dist/cjs/reader/queries/use-site-subscriptions-query.js +27 -26
- package/dist/cjs/reader/queries/use-site-subscriptions-query.js.map +1 -1
- package/dist/cjs/site/queries/use-site-features.js +2 -2
- package/dist/cjs/site/queries/use-site-features.js.map +1 -1
- package/dist/cjs/site/queries/use-site-media-storage.js +2 -2
- package/dist/cjs/site/queries/use-site-media-storage.js.map +1 -1
- package/dist/cjs/site/queries/use-site-user-query.js +2 -2
- package/dist/cjs/site/queries/use-site-user-query.js.map +1 -1
- package/dist/cjs/site/queries/use-site.js +2 -2
- package/dist/cjs/site/queries/use-site.js.map +1 -1
- package/dist/cjs/site/resolvers.js +5 -5
- package/dist/cjs/site/resolvers.js.map +1 -1
- package/dist/cjs/site/selectors.js +5 -3
- package/dist/cjs/site/selectors.js.map +1 -1
- package/dist/cjs/site/types.js.map +1 -1
- package/dist/cjs/site-reset/use-site-reset-content-summary-query.js +2 -2
- package/dist/cjs/site-reset/use-site-reset-content-summary-query.js.map +1 -1
- package/dist/cjs/site-reset/use-site-reset-mutation.js +2 -2
- package/dist/cjs/site-reset/use-site-reset-mutation.js.map +1 -1
- package/dist/cjs/site-reset/use-site-reset-status-query.js +2 -2
- package/dist/cjs/site-reset/use-site-reset-status-query.js.map +1 -1
- package/dist/cjs/starter-designs-queries/use-starter-design-by-slug.js +2 -2
- package/dist/cjs/starter-designs-queries/use-starter-design-by-slug.js.map +1 -1
- package/dist/cjs/starter-designs-queries/use-starter-designs-query.js +2 -2
- package/dist/cjs/starter-designs-queries/use-starter-designs-query.js.map +1 -1
- package/dist/cjs/subscriber/actions.js +5 -5
- package/dist/cjs/subscriber/actions.js.map +1 -1
- package/dist/cjs/templates/use-template.js +2 -2
- package/dist/cjs/templates/use-template.js.map +1 -1
- package/dist/cjs/users/use-send-invites.js +2 -2
- package/dist/cjs/users/use-send-invites.js.map +1 -1
- package/dist/cjs/utils.js +26 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/cjs/wpcom-request-controls/index.js +3 -2
- package/dist/cjs/wpcom-request-controls/index.js.map +1 -1
- package/dist/cjs/wpcom-request.js +24 -0
- package/dist/cjs/wpcom-request.js.map +1 -0
- package/dist/esm/agents-manager/actions.js +104 -0
- package/dist/esm/agents-manager/actions.js.map +1 -0
- package/dist/esm/agents-manager/constants.js +2 -0
- package/dist/esm/agents-manager/constants.js.map +1 -0
- package/dist/esm/agents-manager/index.js +31 -0
- package/dist/esm/agents-manager/index.js.map +1 -0
- package/dist/esm/agents-manager/persist-state.js +54 -0
- package/dist/esm/agents-manager/persist-state.js.map +1 -0
- package/dist/esm/agents-manager/reducer.js +82 -0
- package/dist/esm/agents-manager/reducer.js.map +1 -0
- package/dist/esm/agents-manager/resolvers.js +57 -0
- package/dist/esm/agents-manager/resolvers.js.map +1 -0
- package/dist/esm/agents-manager/selectors.js +31 -0
- package/dist/esm/agents-manager/selectors.js.map +1 -0
- package/dist/esm/{domain-suggestions → agents-manager}/types.js.map +1 -1
- package/dist/esm/contextual-help/admin-sections.js +2 -2
- package/dist/esm/contextual-help/admin-sections.js.map +1 -1
- package/dist/esm/help-center/actions.js +95 -65
- package/dist/esm/help-center/actions.js.map +1 -1
- package/dist/esm/help-center/constants.js +1 -0
- package/dist/esm/help-center/constants.js.map +1 -1
- package/dist/esm/help-center/index.js +11 -23
- package/dist/esm/help-center/index.js.map +1 -1
- package/dist/esm/help-center/reducer.js +36 -12
- package/dist/esm/help-center/reducer.js.map +1 -1
- package/dist/esm/help-center/resolvers.js +43 -24
- package/dist/esm/help-center/resolvers.js.map +1 -1
- package/dist/esm/help-center/selectors.js +6 -2
- package/dist/esm/help-center/selectors.js.map +1 -1
- package/dist/esm/help-center/utils.js +127 -0
- package/dist/esm/help-center/utils.js.map +1 -0
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mutations/use-domains-bulk-actions-mutation.js +1 -1
- package/dist/esm/mutations/use-domains-bulk-actions-mutation.js.map +1 -1
- package/dist/esm/newsletter-categories/index.js +1 -1
- package/dist/esm/newsletter-categories/index.js.map +1 -1
- package/dist/esm/onboard/actions.js +12 -0
- package/dist/esm/onboard/actions.js.map +1 -1
- package/dist/esm/onboard/reducer.js +30 -0
- package/dist/esm/onboard/reducer.js.map +1 -1
- package/dist/esm/onboard/selectors.js +3 -0
- package/dist/esm/onboard/selectors.js.map +1 -1
- package/dist/esm/plans/constants.js +2 -0
- package/dist/esm/plans/constants.js.map +1 -1
- package/dist/esm/plans/hooks/use-pricing-meta-for-grid-plans.js +35 -18
- package/dist/esm/plans/hooks/use-pricing-meta-for-grid-plans.js.map +1 -1
- package/dist/esm/plans/index.js +1 -1
- package/dist/esm/plans/index.js.map +1 -1
- package/dist/esm/plans/queries/use-plans.js +21 -2
- package/dist/esm/plans/queries/use-plans.js.map +1 -1
- package/dist/esm/plans/queries/use-site-plans.js +1 -1
- package/dist/esm/plans/resolvers.js +0 -1
- package/dist/esm/plans/resolvers.js.map +1 -1
- package/dist/esm/plans/selectors.js.map +1 -1
- package/dist/esm/products-list/queries/use-products.js +1 -1
- package/dist/esm/products-list/queries/use-products.js.map +1 -1
- package/dist/esm/products-list/resolvers.js +1 -1
- package/dist/esm/products-list/resolvers.js.map +1 -1
- package/dist/esm/purchases/lib/assembler.js +15 -20
- package/dist/esm/purchases/lib/assembler.js.map +1 -1
- package/dist/esm/purchases/queries/use-get-jetpack-transferred-license-purchases.js +1 -1
- package/dist/esm/purchases/queries/use-site-purchases.js +2 -2
- package/dist/esm/queries/use-all-domains-query.js +1 -1
- package/dist/esm/queries/use-all-domains-query.js.map +1 -1
- package/dist/esm/queries/use-bulk-domain-update-status-query.js +3 -56
- package/dist/esm/queries/use-bulk-domain-update-status-query.js.map +1 -1
- package/dist/esm/queries/use-happiness-engineers-query.js +1 -1
- package/dist/esm/queries/use-happiness-engineers-query.js.map +1 -1
- package/dist/esm/queries/use-launchpad.js +1 -1
- package/dist/esm/queries/use-launchpad.js.map +1 -1
- package/dist/esm/queries/use-site-domains-query.js +1 -1
- package/dist/esm/queries/use-site-domains-query.js.map +1 -1
- package/dist/esm/queries/use-site-intent.js +1 -1
- package/dist/esm/queries/use-site-intent.js.map +1 -1
- package/dist/esm/queries/use-site-query.js +1 -1
- package/dist/esm/queries/use-site-query.js.map +1 -1
- package/dist/esm/reader/contexts/index.js +0 -1
- package/dist/esm/reader/contexts/index.js.map +1 -1
- package/dist/esm/reader/helpers/index.js +3 -2
- package/dist/esm/reader/helpers/index.js.map +1 -1
- package/dist/esm/reader/helpers/optimistic-update.js +2 -1
- package/dist/esm/reader/helpers/optimistic-update.js.map +1 -1
- package/dist/esm/reader/index.js +2 -3
- package/dist/esm/reader/index.js.map +1 -1
- package/dist/esm/reader/mutations/use-pending-site-confirm-mutation.js +2 -2
- package/dist/esm/reader/mutations/use-pending-site-confirm-mutation.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-delivery-frequency-mutation.js +27 -21
- package/dist/esm/reader/mutations/use-site-delivery-frequency-mutation.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-email-me-new-comments-mutation.js +5 -4
- package/dist/esm/reader/mutations/use-site-email-me-new-comments-mutation.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-email-me-new-posts-mutation.js +5 -4
- package/dist/esm/reader/mutations/use-site-email-me-new-posts-mutation.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-notify-me-of-new-posts-mutation.js +5 -4
- package/dist/esm/reader/mutations/use-site-notify-me-of-new-posts-mutation.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-subscribe-mutation.js +10 -4
- package/dist/esm/reader/mutations/use-site-subscribe-mutation.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-unsubscribe-mutation.js +11 -4
- package/dist/esm/reader/mutations/use-site-unsubscribe-mutation.js.map +1 -1
- package/dist/esm/reader/queries/index.js +1 -4
- package/dist/esm/reader/queries/index.js.map +1 -1
- package/dist/esm/reader/queries/use-site-subscriptions-query.js +28 -27
- package/dist/esm/reader/queries/use-site-subscriptions-query.js.map +1 -1
- package/dist/esm/site/queries/use-site-features.js +1 -1
- package/dist/esm/site/queries/use-site-media-storage.js +1 -1
- package/dist/esm/site/queries/use-site-user-query.js +1 -1
- package/dist/esm/site/queries/use-site-user-query.js.map +1 -1
- package/dist/esm/site/queries/use-site.js +1 -1
- package/dist/esm/site/resolvers.js +1 -1
- package/dist/esm/site/resolvers.js.map +1 -1
- package/dist/esm/site/selectors.js +5 -3
- package/dist/esm/site/selectors.js.map +1 -1
- package/dist/esm/site/types.js.map +1 -1
- package/dist/esm/site-reset/use-site-reset-content-summary-query.js +1 -1
- package/dist/esm/site-reset/use-site-reset-content-summary-query.js.map +1 -1
- package/dist/esm/site-reset/use-site-reset-mutation.js +1 -1
- package/dist/esm/site-reset/use-site-reset-mutation.js.map +1 -1
- package/dist/esm/site-reset/use-site-reset-status-query.js +1 -1
- package/dist/esm/site-reset/use-site-reset-status-query.js.map +1 -1
- package/dist/esm/starter-designs-queries/use-starter-design-by-slug.js +1 -1
- package/dist/esm/starter-designs-queries/use-starter-design-by-slug.js.map +1 -1
- package/dist/esm/starter-designs-queries/use-starter-designs-query.js +1 -1
- package/dist/esm/starter-designs-queries/use-starter-designs-query.js.map +1 -1
- package/dist/esm/subscriber/actions.js +1 -1
- package/dist/esm/subscriber/actions.js.map +1 -1
- package/dist/esm/templates/use-template.js +1 -1
- package/dist/esm/templates/use-template.js.map +1 -1
- package/dist/esm/users/use-send-invites.js +1 -1
- package/dist/esm/users/use-send-invites.js.map +1 -1
- package/dist/esm/utils.js +21 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/wpcom-request-controls/index.js +2 -1
- package/dist/esm/wpcom-request-controls/index.js.map +1 -1
- package/dist/esm/wpcom-request.js +18 -0
- package/dist/esm/wpcom-request.js.map +1 -0
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/add-ons/types.d.ts +1 -0
- package/dist/types/add-ons/types.d.ts.map +1 -1
- package/dist/types/agents-manager/actions.d.ts +77 -0
- package/dist/types/agents-manager/actions.d.ts.map +1 -0
- package/dist/types/agents-manager/constants.d.ts +2 -0
- package/dist/types/agents-manager/constants.d.ts.map +1 -0
- package/dist/types/agents-manager/index.d.ts +6 -0
- package/dist/types/agents-manager/index.d.ts.map +1 -0
- package/dist/types/agents-manager/persist-state.d.ts +6 -0
- package/dist/types/agents-manager/persist-state.d.ts.map +1 -0
- package/dist/types/agents-manager/reducer.d.ts +29 -0
- package/dist/types/agents-manager/reducer.d.ts.map +1 -0
- package/dist/types/agents-manager/resolvers.d.ts +54 -0
- package/dist/types/agents-manager/resolvers.d.ts.map +1 -0
- package/dist/types/agents-manager/selectors.d.ts +22 -0
- package/dist/types/agents-manager/selectors.d.ts.map +1 -0
- package/dist/types/agents-manager/types.d.ts +20 -0
- package/dist/types/agents-manager/types.d.ts.map +1 -0
- package/dist/types/contextual-help/admin-sections.d.ts +330 -6
- package/dist/types/contextual-help/admin-sections.d.ts.map +1 -1
- package/dist/types/contextual-help/contextual-help.d.ts +410 -30
- package/dist/types/contextual-help/contextual-help.d.ts.map +1 -1
- package/dist/types/help-center/actions.d.ts +249 -28
- package/dist/types/help-center/actions.d.ts.map +1 -1
- package/dist/types/help-center/constants.d.ts +1 -0
- package/dist/types/help-center/constants.d.ts.map +1 -1
- package/dist/types/help-center/index.d.ts +1 -2
- package/dist/types/help-center/index.d.ts.map +1 -1
- package/dist/types/help-center/reducer.d.ts +19 -7
- package/dist/types/help-center/reducer.d.ts.map +1 -1
- package/dist/types/help-center/resolvers.d.ts +4 -23
- package/dist/types/help-center/resolvers.d.ts.map +1 -1
- package/dist/types/help-center/selectors.d.ts +14 -3
- package/dist/types/help-center/selectors.d.ts.map +1 -1
- package/dist/types/help-center/types.d.ts +21 -12
- package/dist/types/help-center/types.d.ts.map +1 -1
- package/dist/types/help-center/utils.d.ts +13 -0
- package/dist/types/help-center/utils.d.ts.map +1 -0
- package/dist/types/index.d.ts +347 -197
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/onboard/actions.d.ts +32 -4
- package/dist/types/onboard/actions.d.ts.map +1 -1
- package/dist/types/onboard/reducer.d.ts +11 -2
- package/dist/types/onboard/reducer.d.ts.map +1 -1
- package/dist/types/onboard/selectors.d.ts +14 -8
- package/dist/types/onboard/selectors.d.ts.map +1 -1
- package/dist/types/onboard/types.d.ts +1 -1
- package/dist/types/onboard/types.d.ts.map +1 -1
- package/dist/types/plans/constants.d.ts +3 -2
- package/dist/types/plans/constants.d.ts.map +1 -1
- package/dist/types/plans/hooks/use-pricing-meta-for-grid-plans.d.ts +6 -1
- package/dist/types/plans/hooks/use-pricing-meta-for-grid-plans.d.ts.map +1 -1
- package/dist/types/plans/index.d.ts +1 -1
- package/dist/types/plans/index.d.ts.map +1 -1
- package/dist/types/plans/queries/use-plans.d.ts.map +1 -1
- package/dist/types/plans/resolvers.d.ts.map +1 -1
- package/dist/types/plans/types.d.ts +6 -0
- package/dist/types/plans/types.d.ts.map +1 -1
- package/dist/types/products-list/index.d.ts +1 -1
- package/dist/types/products-list/index.d.ts.map +1 -1
- package/dist/types/products-list/queries/use-products.d.ts.map +1 -1
- package/dist/types/purchases/lib/assembler.d.ts +3 -3
- package/dist/types/purchases/lib/assembler.d.ts.map +1 -1
- package/dist/types/purchases/types.d.ts +40 -109
- package/dist/types/purchases/types.d.ts.map +1 -1
- package/dist/types/queries/use-all-domains-query.d.ts +3 -3
- package/dist/types/queries/use-all-domains-query.d.ts.map +1 -1
- package/dist/types/queries/use-bulk-domain-update-status-query.d.ts +5 -48
- package/dist/types/queries/use-bulk-domain-update-status-query.d.ts.map +1 -1
- package/dist/types/queries/use-site-domains-query.d.ts +1 -1
- package/dist/types/queries/use-site-domains-query.d.ts.map +1 -1
- package/dist/types/queries/use-site-intent.d.ts.map +1 -1
- package/dist/types/queries/use-site-query.d.ts +1 -1
- package/dist/types/queries/use-site-query.d.ts.map +1 -1
- package/dist/types/reader/contexts/index.d.ts +0 -1
- package/dist/types/reader/contexts/index.d.ts.map +1 -1
- package/dist/types/reader/helpers/index.d.ts.map +1 -1
- package/dist/types/reader/helpers/optimistic-update.d.ts.map +1 -1
- package/dist/types/reader/index.d.ts +342 -196
- package/dist/types/reader/index.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-delivery-frequency-mutation.d.ts +3 -2
- package/dist/types/reader/mutations/use-site-delivery-frequency-mutation.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-email-me-new-comments-mutation.d.ts +3 -2
- package/dist/types/reader/mutations/use-site-email-me-new-comments-mutation.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-email-me-new-posts-mutation.d.ts +3 -2
- package/dist/types/reader/mutations/use-site-email-me-new-posts-mutation.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-notify-me-of-new-posts-mutation.d.ts +3 -2
- package/dist/types/reader/mutations/use-site-notify-me-of-new-posts-mutation.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-subscribe-mutation.d.ts +3 -2
- package/dist/types/reader/mutations/use-site-subscribe-mutation.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-unsubscribe-mutation.d.ts +3 -2
- package/dist/types/reader/mutations/use-site-unsubscribe-mutation.d.ts.map +1 -1
- package/dist/types/reader/queries/index.d.ts +1 -5
- package/dist/types/reader/queries/index.d.ts.map +1 -1
- package/dist/types/reader/queries/use-pending-post-subscriptions-query.d.ts +75 -7
- package/dist/types/reader/queries/use-pending-post-subscriptions-query.d.ts.map +1 -1
- package/dist/types/reader/queries/use-pending-site-subscriptions-query.d.ts +75 -7
- package/dist/types/reader/queries/use-pending-site-subscriptions-query.d.ts.map +1 -1
- package/dist/types/reader/queries/use-post-subscriptions-query.d.ts +143 -13
- package/dist/types/reader/queries/use-post-subscriptions-query.d.ts.map +1 -1
- package/dist/types/reader/queries/use-site-subscriptions-query.d.ts +6 -135
- package/dist/types/reader/queries/use-site-subscriptions-query.d.ts.map +1 -1
- package/dist/types/reader/types/index.d.ts +32 -44
- package/dist/types/reader/types/index.d.ts.map +1 -1
- package/dist/types/shared-types.d.ts +11 -0
- package/dist/types/shared-types.d.ts.map +1 -1
- package/dist/types/site/actions.d.ts +1 -1
- package/dist/types/site/actions.d.ts.map +1 -1
- package/dist/types/site/queries/use-site-user-query.d.ts.map +1 -1
- package/dist/types/site/selectors.d.ts.map +1 -1
- package/dist/types/site/types.d.ts +5 -0
- package/dist/types/site/types.d.ts.map +1 -1
- package/dist/types/starter-designs-queries/types.d.ts +1 -1
- package/dist/types/starter-designs-queries/types.d.ts.map +1 -1
- package/dist/types/starter-designs-queries/use-starter-design-by-slug.d.ts +1 -1
- package/dist/types/starter-designs-queries/use-starter-design-by-slug.d.ts.map +1 -1
- package/dist/types/starter-designs-queries/use-starter-designs-query.d.ts +1 -1
- package/dist/types/starter-designs-queries/use-starter-designs-query.d.ts.map +1 -1
- package/dist/types/subscriber/index.d.ts +1 -1
- package/dist/types/subscriber/index.d.ts.map +1 -1
- package/dist/types/user/actions.d.ts +1 -1
- package/dist/types/user/reducer.d.ts +1 -1
- package/dist/types/user/resolvers.d.ts +2 -2
- package/dist/types/user/selectors.d.ts +2 -2
- package/dist/types/user/selectors.d.ts.map +1 -1
- package/dist/types/user/types.d.ts +2 -33
- package/dist/types/user/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/wpcom-plans-ui/actions.d.ts +1 -1
- package/dist/types/wpcom-plans-ui/index.d.ts +1 -1
- package/dist/types/wpcom-plans-ui/index.d.ts.map +1 -1
- package/dist/types/wpcom-request-controls/index.d.ts +1 -1
- package/dist/types/wpcom-request-controls/index.d.ts.map +1 -1
- package/dist/types/wpcom-request.d.ts +7 -0
- package/dist/types/wpcom-request.d.ts.map +1 -0
- package/package.json +26 -29
- package/src/add-ons/types.ts +1 -0
- package/src/agents-manager/actions.ts +151 -0
- package/src/agents-manager/constants.ts +1 -0
- package/src/agents-manager/index.ts +38 -0
- package/src/agents-manager/persist-state.ts +60 -0
- package/src/agents-manager/reducer.ts +106 -0
- package/src/agents-manager/resolvers.ts +87 -0
- package/src/agents-manager/selectors.ts +32 -0
- package/src/agents-manager/test/persist-state.test.ts +81 -0
- package/src/agents-manager/test/reducer.test.ts +69 -0
- package/src/agents-manager/types.ts +24 -0
- package/src/contextual-help/admin-sections.ts +2 -2
- package/src/help-center/actions.ts +139 -79
- package/src/help-center/constants.ts +1 -0
- package/src/help-center/index.ts +11 -32
- package/src/help-center/reducer.ts +55 -19
- package/src/help-center/resolvers.ts +47 -32
- package/src/help-center/selectors.ts +7 -2
- package/src/help-center/test/utils.ts +99 -0
- package/src/help-center/types.ts +23 -13
- package/src/help-center/utils.ts +156 -0
- package/src/index.ts +11 -4
- package/src/mutations/use-domains-bulk-actions-mutation.ts +1 -1
- package/src/newsletter-categories/index.ts +1 -1
- package/src/newsletter-categories/test/index.tsx +5 -2
- package/src/onboard/actions.ts +20 -3
- package/src/onboard/reducer.ts +38 -3
- package/src/onboard/selectors.ts +3 -0
- package/src/onboard/types.ts +1 -1
- package/src/plans/constants.ts +2 -0
- package/src/plans/hooks/test/use-pricing-meta-for-grid-plans.ts +120 -0
- package/src/plans/hooks/use-pricing-meta-for-grid-plans.ts +48 -18
- package/src/plans/index.ts +1 -0
- package/src/plans/queries/use-plans.ts +30 -2
- package/src/plans/queries/use-site-plans.ts +1 -1
- package/src/plans/resolvers.ts +0 -1
- package/src/plans/selectors.ts +9 -9
- package/src/plans/types.ts +6 -0
- package/src/products-list/queries/use-products.ts +1 -1
- package/src/products-list/resolvers.ts +1 -1
- package/src/products-list/selectors.ts +1 -1
- package/src/products-list/test/selectors.ts +2 -2
- package/src/purchases/lib/assembler.ts +20 -29
- package/src/purchases/queries/use-get-jetpack-transferred-license-purchases.tsx +1 -1
- package/src/purchases/queries/use-site-purchases.ts +2 -2
- package/src/purchases/types.ts +47 -116
- package/src/queries/use-all-domains-query.ts +3 -3
- package/src/queries/use-bulk-domain-update-status-query.ts +14 -115
- package/src/queries/use-happiness-engineers-query.ts +1 -1
- package/src/queries/use-launchpad.ts +1 -1
- package/src/queries/use-site-domains-query.ts +1 -1
- package/src/queries/use-site-intent.ts +1 -1
- package/src/queries/use-site-query.ts +1 -1
- package/src/reader/contexts/index.ts +0 -4
- package/src/reader/helpers/index.ts +3 -2
- package/src/reader/helpers/optimistic-update.ts +2 -1
- package/src/reader/index.ts +2 -4
- package/src/reader/mutations/test/use-site-subscription-mutations.test.tsx +208 -0
- package/src/reader/mutations/use-pending-site-confirm-mutation.ts +2 -2
- package/src/reader/mutations/use-site-delivery-frequency-mutation.ts +32 -36
- package/src/reader/mutations/use-site-email-me-new-comments-mutation.ts +10 -10
- package/src/reader/mutations/use-site-email-me-new-posts-mutation.ts +10 -10
- package/src/reader/mutations/use-site-notify-me-of-new-posts-mutation.ts +10 -10
- package/src/reader/mutations/use-site-subscribe-mutation.ts +21 -10
- package/src/reader/mutations/use-site-unsubscribe-mutation.ts +20 -10
- package/src/reader/queries/index.ts +4 -6
- package/src/reader/queries/test/use-site-subscriptions-query.tsx +158 -52
- package/src/reader/queries/use-site-subscriptions-query.ts +53 -55
- package/src/reader/types/index.ts +34 -48
- package/src/shared-types.ts +13 -0
- package/src/site/actions.ts +1 -1
- package/src/site/queries/use-site-features.ts +1 -1
- package/src/site/queries/use-site-media-storage.ts +1 -1
- package/src/site/queries/use-site-user-query.ts +1 -1
- package/src/site/queries/use-site.ts +1 -1
- package/src/site/resolvers.ts +1 -1
- package/src/site/selectors.ts +18 -10
- package/src/site/test/selectors.ts +3 -3
- package/src/site/types.ts +5 -0
- package/src/site-reset/test/use-site-reset-mutation.tsx +3 -4
- package/src/site-reset/use-site-reset-content-summary-query.ts +1 -1
- package/src/site-reset/use-site-reset-mutation.ts +1 -1
- package/src/site-reset/use-site-reset-status-query.ts +1 -1
- package/src/starter-designs-queries/types.ts +1 -1
- package/src/starter-designs-queries/use-starter-design-by-slug.ts +2 -2
- package/src/starter-designs-queries/use-starter-designs-query.ts +2 -2
- package/src/subscriber/actions.ts +1 -1
- package/src/templates/use-template.ts +1 -1
- package/src/user/types.ts +2 -38
- package/src/users/use-send-invites.ts +1 -1
- package/src/utils.ts +33 -0
- package/src/wpcom-request-controls/index.ts +2 -1
- package/src/wpcom-request.ts +26 -0
- package/dist/cjs/domain-suggestions/actions.js +0 -33
- package/dist/cjs/domain-suggestions/actions.js.map +0 -1
- package/dist/cjs/domain-suggestions/constants.js +0 -12
- package/dist/cjs/domain-suggestions/constants.js.map +0 -1
- package/dist/cjs/domain-suggestions/index.js +0 -25
- package/dist/cjs/domain-suggestions/index.js.map +0 -1
- package/dist/cjs/domain-suggestions/queries.js +0 -78
- package/dist/cjs/domain-suggestions/queries.js.map +0 -1
- package/dist/cjs/domain-suggestions/reducer.js +0 -65
- package/dist/cjs/domain-suggestions/reducer.js.map +0 -1
- package/dist/cjs/domain-suggestions/resolvers.js +0 -91
- package/dist/cjs/domain-suggestions/resolvers.js.map +0 -1
- package/dist/cjs/domain-suggestions/selectors.js +0 -58
- package/dist/cjs/domain-suggestions/selectors.js.map +0 -1
- package/dist/cjs/domain-suggestions/utils.js +0 -47
- package/dist/cjs/domain-suggestions/utils.js.map +0 -1
- package/dist/cjs/reader/contexts/unsubscribed-feeds-search.js +0 -26
- package/dist/cjs/reader/contexts/unsubscribed-feeds-search.js.map +0 -1
- package/dist/cjs/reader/queries/use-read-feed-query.js +0 -21
- package/dist/cjs/reader/queries/use-read-feed-query.js.map +0 -1
- package/dist/cjs/reader/queries/use-read-feed-search-query.js +0 -39
- package/dist/cjs/reader/queries/use-read-feed-search-query.js.map +0 -1
- package/dist/cjs/reader/queries/use-read-feed-site-query.js +0 -26
- package/dist/cjs/reader/queries/use-read-feed-site-query.js.map +0 -1
- package/dist/esm/domain-suggestions/actions.js +0 -25
- package/dist/esm/domain-suggestions/actions.js.map +0 -1
- package/dist/esm/domain-suggestions/constants.js +0 -9
- package/dist/esm/domain-suggestions/constants.js.map +0 -1
- package/dist/esm/domain-suggestions/index.js +0 -20
- package/dist/esm/domain-suggestions/index.js.map +0 -1
- package/dist/esm/domain-suggestions/queries.js +0 -72
- package/dist/esm/domain-suggestions/queries.js.map +0 -1
- package/dist/esm/domain-suggestions/reducer.js +0 -61
- package/dist/esm/domain-suggestions/reducer.js.map +0 -1
- package/dist/esm/domain-suggestions/resolvers.js +0 -84
- package/dist/esm/domain-suggestions/resolvers.js.map +0 -1
- package/dist/esm/domain-suggestions/selectors.js +0 -47
- package/dist/esm/domain-suggestions/selectors.js.map +0 -1
- package/dist/esm/domain-suggestions/utils.js +0 -41
- package/dist/esm/domain-suggestions/utils.js.map +0 -1
- package/dist/esm/reader/contexts/unsubscribed-feeds-search.js +0 -20
- package/dist/esm/reader/contexts/unsubscribed-feeds-search.js.map +0 -1
- package/dist/esm/reader/queries/use-read-feed-query.js +0 -18
- package/dist/esm/reader/queries/use-read-feed-query.js.map +0 -1
- package/dist/esm/reader/queries/use-read-feed-search-query.js +0 -35
- package/dist/esm/reader/queries/use-read-feed-search-query.js.map +0 -1
- package/dist/esm/reader/queries/use-read-feed-site-query.js +0 -23
- package/dist/esm/reader/queries/use-read-feed-site-query.js.map +0 -1
- package/dist/types/domain-suggestions/actions.d.ts +0 -27
- package/dist/types/domain-suggestions/actions.d.ts.map +0 -1
- package/dist/types/domain-suggestions/constants.d.ts +0 -8
- package/dist/types/domain-suggestions/constants.d.ts.map +0 -1
- package/dist/types/domain-suggestions/index.d.ts +0 -10
- package/dist/types/domain-suggestions/index.d.ts.map +0 -1
- package/dist/types/domain-suggestions/queries.d.ts +0 -323
- package/dist/types/domain-suggestions/queries.d.ts.map +0 -1
- package/dist/types/domain-suggestions/reducer.d.ts +0 -16
- package/dist/types/domain-suggestions/reducer.d.ts.map +0 -1
- package/dist/types/domain-suggestions/resolvers.d.ts +0 -39
- package/dist/types/domain-suggestions/resolvers.d.ts.map +0 -1
- package/dist/types/domain-suggestions/selectors.d.ts +0 -18
- package/dist/types/domain-suggestions/selectors.d.ts.map +0 -1
- package/dist/types/domain-suggestions/types.d.ts +0 -206
- package/dist/types/domain-suggestions/types.d.ts.map +0 -1
- package/dist/types/domain-suggestions/utils.d.ts +0 -23
- package/dist/types/domain-suggestions/utils.d.ts.map +0 -1
- package/dist/types/reader/contexts/unsubscribed-feeds-search.d.ts +0 -12
- package/dist/types/reader/contexts/unsubscribed-feeds-search.d.ts.map +0 -1
- package/dist/types/reader/queries/use-read-feed-query.d.ts +0 -28
- package/dist/types/reader/queries/use-read-feed-query.d.ts.map +0 -1
- package/dist/types/reader/queries/use-read-feed-search-query.d.ts +0 -34
- package/dist/types/reader/queries/use-read-feed-search-query.d.ts.map +0 -1
- package/dist/types/reader/queries/use-read-feed-site-query.d.ts +0 -15
- package/dist/types/reader/queries/use-read-feed-site-query.d.ts.map +0 -1
- package/src/domain-suggestions/actions.ts +0 -51
- package/src/domain-suggestions/constants.ts +0 -8
- package/src/domain-suggestions/index.ts +0 -22
- package/src/domain-suggestions/queries.ts +0 -85
- package/src/domain-suggestions/reducer.ts +0 -77
- package/src/domain-suggestions/resolvers.ts +0 -110
- package/src/domain-suggestions/selectors.ts +0 -86
- package/src/domain-suggestions/test/reducer.ts +0 -105
- package/src/domain-suggestions/test/selectors.ts +0 -127
- package/src/domain-suggestions/types.ts +0 -254
- package/src/domain-suggestions/utils.ts +0 -50
- package/src/reader/contexts/unsubscribed-feeds-search.tsx +0 -35
- package/src/reader/queries/test/use-read-feed-search-query.tsx +0 -55
- package/src/reader/queries/use-read-feed-query.ts +0 -45
- package/src/reader/queries/use-read-feed-search-query.ts +0 -72
- package/src/reader/queries/use-read-feed-site-query.ts +0 -35
- /package/dist/cjs/{domain-suggestions → agents-manager}/types.js +0 -0
- /package/dist/esm/{domain-suggestions → agents-manager}/types.js +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
getSiteSubscriptionsQueryKey,
|
|
6
|
+
type SiteSubscriptionsInfiniteData,
|
|
7
|
+
} from '@automattic/api-queries';
|
|
8
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
9
|
+
import { act, renderHook, waitFor } from '@testing-library/react';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { callApi } from '../../helpers';
|
|
12
|
+
import useSiteSubscribeMutation from '../../mutations/use-site-subscribe-mutation';
|
|
13
|
+
import useSiteUnsubscribeMutation from '../../mutations/use-site-unsubscribe-mutation';
|
|
14
|
+
import type { SiteSubscriptionItem } from '../../types';
|
|
15
|
+
import type { ReactNode } from 'react';
|
|
16
|
+
|
|
17
|
+
jest.mock( '../../hooks', () => ( {
|
|
18
|
+
useIsLoggedIn: jest.fn().mockReturnValue( { isLoggedIn: true, id: 1 } ),
|
|
19
|
+
useCacheKey: jest.fn( ( key ) => [ ...key, true, 1 ] ),
|
|
20
|
+
} ) );
|
|
21
|
+
|
|
22
|
+
jest.mock( '../../helpers', () => ( {
|
|
23
|
+
...jest.requireActual( '../../helpers' ),
|
|
24
|
+
callApi: jest.fn(),
|
|
25
|
+
} ) );
|
|
26
|
+
|
|
27
|
+
const makeQueryClient = () => new QueryClient( { defaultOptions: { queries: { retry: false } } } );
|
|
28
|
+
|
|
29
|
+
const makeWrapper = ( queryClient: QueryClient ) =>
|
|
30
|
+
function Wrapper( { children }: { children: ReactNode } ) {
|
|
31
|
+
return <QueryClientProvider client={ queryClient }>{ children }</QueryClientProvider>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const makeSubscription = (
|
|
35
|
+
overrides: Partial< SiteSubscriptionItem > = {}
|
|
36
|
+
): SiteSubscriptionItem => ( {
|
|
37
|
+
ID: 123,
|
|
38
|
+
URL: 'https://example.com',
|
|
39
|
+
feed_URL: 'https://example.com/feed',
|
|
40
|
+
blog_ID: 123,
|
|
41
|
+
feed_ID: 456,
|
|
42
|
+
is_following: true,
|
|
43
|
+
isDeleted: false,
|
|
44
|
+
...overrides,
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
const makeSiteSubscriptionsData = (
|
|
48
|
+
subscriptions: SiteSubscriptionItem[],
|
|
49
|
+
totalCount = subscriptions.length
|
|
50
|
+
): SiteSubscriptionsInfiniteData => ( {
|
|
51
|
+
pages: [
|
|
52
|
+
{
|
|
53
|
+
subscriptions,
|
|
54
|
+
totalCount,
|
|
55
|
+
page: 1,
|
|
56
|
+
number: 200,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
pageParams: [ 1 ],
|
|
60
|
+
} );
|
|
61
|
+
|
|
62
|
+
const getCachedSubscriptions = ( queryClient: QueryClient ) =>
|
|
63
|
+
queryClient.getQueryData< SiteSubscriptionsInfiniteData >( getSiteSubscriptionsQueryKey() )
|
|
64
|
+
?.pages[ 0 ];
|
|
65
|
+
|
|
66
|
+
describe( 'site subscription mutations', () => {
|
|
67
|
+
beforeEach( () => {
|
|
68
|
+
jest.clearAllMocks();
|
|
69
|
+
} );
|
|
70
|
+
|
|
71
|
+
it( 'optimistically restores a deleted site subscription and increments total count', async () => {
|
|
72
|
+
const queryClient = makeQueryClient();
|
|
73
|
+
queryClient.setQueryData(
|
|
74
|
+
getSiteSubscriptionsQueryKey(),
|
|
75
|
+
makeSiteSubscriptionsData(
|
|
76
|
+
[ makeSubscription( { is_following: false, isDeleted: true } ) ],
|
|
77
|
+
0
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
( callApi as jest.Mock ).mockResolvedValue( { subscribed: true } );
|
|
81
|
+
|
|
82
|
+
const { result } = renderHook( () => useSiteSubscribeMutation(), {
|
|
83
|
+
wrapper: makeWrapper( queryClient ),
|
|
84
|
+
} );
|
|
85
|
+
|
|
86
|
+
act( () => {
|
|
87
|
+
result.current.mutate( {
|
|
88
|
+
blog_id: 123,
|
|
89
|
+
url: 'https://example.com/feed',
|
|
90
|
+
doNotInvalidateSiteSubscriptions: true,
|
|
91
|
+
} );
|
|
92
|
+
} );
|
|
93
|
+
|
|
94
|
+
await waitFor( () => expect( callApi ).toHaveBeenCalled() );
|
|
95
|
+
const page = getCachedSubscriptions( queryClient );
|
|
96
|
+
expect( page?.totalCount ).toBe( 1 );
|
|
97
|
+
expect( page?.subscriptions[ 0 ] ).toMatchObject( {
|
|
98
|
+
is_following: true,
|
|
99
|
+
isDeleted: false,
|
|
100
|
+
} );
|
|
101
|
+
} );
|
|
102
|
+
|
|
103
|
+
it( 'rolls back site subscription restore when subscribe fails', async () => {
|
|
104
|
+
const queryClient = makeQueryClient();
|
|
105
|
+
const previousData = makeSiteSubscriptionsData(
|
|
106
|
+
[ makeSubscription( { is_following: false, isDeleted: true } ) ],
|
|
107
|
+
0
|
|
108
|
+
);
|
|
109
|
+
queryClient.setQueryData( getSiteSubscriptionsQueryKey(), previousData );
|
|
110
|
+
( callApi as jest.Mock ).mockRejectedValue( new Error( 'subscribe failed' ) );
|
|
111
|
+
|
|
112
|
+
const { result } = renderHook( () => useSiteSubscribeMutation(), {
|
|
113
|
+
wrapper: makeWrapper( queryClient ),
|
|
114
|
+
} );
|
|
115
|
+
|
|
116
|
+
act( () => {
|
|
117
|
+
result.current.mutate( {
|
|
118
|
+
blog_id: 123,
|
|
119
|
+
url: 'https://example.com/feed',
|
|
120
|
+
doNotInvalidateSiteSubscriptions: true,
|
|
121
|
+
} );
|
|
122
|
+
} );
|
|
123
|
+
|
|
124
|
+
await waitFor( () => expect( result.current.isError ).toBe( true ) );
|
|
125
|
+
expect( queryClient.getQueryData( getSiteSubscriptionsQueryKey() ) ).toEqual( previousData );
|
|
126
|
+
} );
|
|
127
|
+
|
|
128
|
+
it( 'optimistically marks a site subscription deleted and decrements total count', async () => {
|
|
129
|
+
const queryClient = makeQueryClient();
|
|
130
|
+
queryClient.setQueryData(
|
|
131
|
+
getSiteSubscriptionsQueryKey(),
|
|
132
|
+
makeSiteSubscriptionsData( [ makeSubscription() ], 1 )
|
|
133
|
+
);
|
|
134
|
+
( callApi as jest.Mock ).mockResolvedValue( { subscribed: false } );
|
|
135
|
+
|
|
136
|
+
const { result } = renderHook( () => useSiteUnsubscribeMutation(), {
|
|
137
|
+
wrapper: makeWrapper( queryClient ),
|
|
138
|
+
} );
|
|
139
|
+
|
|
140
|
+
act( () => {
|
|
141
|
+
result.current.mutate( {
|
|
142
|
+
subscriptionId: 123,
|
|
143
|
+
blog_id: 123,
|
|
144
|
+
doNotInvalidateSiteSubscriptions: true,
|
|
145
|
+
} );
|
|
146
|
+
} );
|
|
147
|
+
|
|
148
|
+
await waitFor( () => expect( callApi ).toHaveBeenCalled() );
|
|
149
|
+
const page = getCachedSubscriptions( queryClient );
|
|
150
|
+
expect( page?.totalCount ).toBe( 0 );
|
|
151
|
+
expect( page?.subscriptions[ 0 ] ).toMatchObject( {
|
|
152
|
+
is_following: false,
|
|
153
|
+
isDeleted: true,
|
|
154
|
+
resubscribed: false,
|
|
155
|
+
} );
|
|
156
|
+
} );
|
|
157
|
+
|
|
158
|
+
it( 'does not decrement total count when unsubscribe cannot match a cached subscription', async () => {
|
|
159
|
+
const queryClient = makeQueryClient();
|
|
160
|
+
queryClient.setQueryData(
|
|
161
|
+
getSiteSubscriptionsQueryKey(),
|
|
162
|
+
makeSiteSubscriptionsData( [ makeSubscription( { ID: 456, blog_ID: 456 } ) ], 1 )
|
|
163
|
+
);
|
|
164
|
+
( callApi as jest.Mock ).mockResolvedValue( { subscribed: false } );
|
|
165
|
+
|
|
166
|
+
const { result } = renderHook( () => useSiteUnsubscribeMutation(), {
|
|
167
|
+
wrapper: makeWrapper( queryClient ),
|
|
168
|
+
} );
|
|
169
|
+
|
|
170
|
+
act( () => {
|
|
171
|
+
result.current.mutate( {
|
|
172
|
+
subscriptionId: 123,
|
|
173
|
+
blog_id: 123,
|
|
174
|
+
doNotInvalidateSiteSubscriptions: true,
|
|
175
|
+
} );
|
|
176
|
+
} );
|
|
177
|
+
|
|
178
|
+
await waitFor( () => expect( callApi ).toHaveBeenCalled() );
|
|
179
|
+
const page = getCachedSubscriptions( queryClient );
|
|
180
|
+
expect( page?.totalCount ).toBe( 1 );
|
|
181
|
+
expect( page?.subscriptions[ 0 ] ).toMatchObject( {
|
|
182
|
+
is_following: true,
|
|
183
|
+
isDeleted: false,
|
|
184
|
+
} );
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
it( 'rolls back site subscription delete when unsubscribe fails', async () => {
|
|
188
|
+
const queryClient = makeQueryClient();
|
|
189
|
+
const previousData = makeSiteSubscriptionsData( [ makeSubscription() ], 1 );
|
|
190
|
+
queryClient.setQueryData( getSiteSubscriptionsQueryKey(), previousData );
|
|
191
|
+
( callApi as jest.Mock ).mockRejectedValue( new Error( 'unsubscribe failed' ) );
|
|
192
|
+
|
|
193
|
+
const { result } = renderHook( () => useSiteUnsubscribeMutation(), {
|
|
194
|
+
wrapper: makeWrapper( queryClient ),
|
|
195
|
+
} );
|
|
196
|
+
|
|
197
|
+
act( () => {
|
|
198
|
+
result.current.mutate( {
|
|
199
|
+
subscriptionId: 123,
|
|
200
|
+
blog_id: 123,
|
|
201
|
+
doNotInvalidateSiteSubscriptions: true,
|
|
202
|
+
} );
|
|
203
|
+
} );
|
|
204
|
+
|
|
205
|
+
await waitFor( () => expect( result.current.isError ).toBe( true ) );
|
|
206
|
+
expect( queryClient.getQueryData( getSiteSubscriptionsQueryKey() ) ).toEqual( previousData );
|
|
207
|
+
} );
|
|
208
|
+
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { getSiteSubscriptionsQueryKey } from '@automattic/api-queries';
|
|
1
2
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
3
|
import { callApi } from '../helpers';
|
|
3
4
|
import { useCacheKey, useIsLoggedIn } from '../hooks';
|
|
4
|
-
import { siteSubscriptionsQueryKeyPrefix } from '../queries';
|
|
5
5
|
import { subscriptionsCountQueryKeyPrefix } from '../queries/use-subscriptions-count-query';
|
|
6
6
|
import { PendingSiteSubscriptionsResult, SubscriptionManagerSubscriptionsCount } from '../types';
|
|
7
7
|
|
|
@@ -17,7 +17,7 @@ type PendingSiteConfirmResponse = {
|
|
|
17
17
|
const usePendingSiteConfirmMutation = () => {
|
|
18
18
|
const { isLoggedIn } = useIsLoggedIn();
|
|
19
19
|
const queryClient = useQueryClient();
|
|
20
|
-
const subscriptionsCacheKey =
|
|
20
|
+
const subscriptionsCacheKey = getSiteSubscriptionsQueryKey();
|
|
21
21
|
const countCacheKey = useCacheKey( subscriptionsCountQueryKeyPrefix );
|
|
22
22
|
|
|
23
23
|
return useMutation( {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSiteSubscriptionsQueryKey,
|
|
3
|
+
type SiteSubscriptionsInfiniteData,
|
|
4
|
+
} from '@automattic/api-queries';
|
|
1
5
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
6
|
import { EmailDeliveryFrequency } from '../constants';
|
|
3
|
-
import { callApi
|
|
7
|
+
import { callApi } from '../helpers';
|
|
4
8
|
import {
|
|
5
9
|
alterSiteSubscriptionDetails,
|
|
6
10
|
invalidateSiteSubscriptionDetails,
|
|
7
11
|
} from '../helpers/optimistic-update';
|
|
8
12
|
import { useIsLoggedIn } from '../hooks';
|
|
9
|
-
import type {
|
|
10
|
-
PagedQueryResult,
|
|
11
|
-
SiteSubscriptionsResponseItem,
|
|
12
|
-
SiteSubscriptionDetails,
|
|
13
|
-
} from '../types';
|
|
13
|
+
import type { SiteSubscriptionDetails } from '../types';
|
|
14
14
|
|
|
15
15
|
type SiteSubscriptionDeliveryFrequencyParams = {
|
|
16
16
|
delivery_frequency: EmailDeliveryFrequency;
|
|
@@ -63,39 +63,35 @@ const useSiteDeliveryFrequencyMutation = () => {
|
|
|
63
63
|
return response;
|
|
64
64
|
},
|
|
65
65
|
onMutate: async ( { blog_id, delivery_frequency, subscriptionId } ) => {
|
|
66
|
-
const siteSubscriptionsCacheKey =
|
|
67
|
-
[ 'read', 'site-subscriptions' ],
|
|
68
|
-
isLoggedIn,
|
|
69
|
-
id
|
|
70
|
-
);
|
|
66
|
+
const siteSubscriptionsCacheKey = getSiteSubscriptionsQueryKey();
|
|
71
67
|
|
|
72
68
|
await queryClient.cancelQueries( { queryKey: siteSubscriptionsCacheKey } );
|
|
73
69
|
|
|
74
70
|
const previousSiteSubscriptions =
|
|
75
|
-
queryClient.getQueryData<
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
71
|
+
queryClient.getQueryData< SiteSubscriptionsInfiniteData >( siteSubscriptionsCacheKey );
|
|
72
|
+
const mutatedSiteSubscriptions = previousSiteSubscriptions
|
|
73
|
+
? {
|
|
74
|
+
...previousSiteSubscriptions,
|
|
75
|
+
pages: previousSiteSubscriptions.pages.map( ( page ) => ( {
|
|
76
|
+
...page,
|
|
77
|
+
subscriptions: page.subscriptions.map( ( siteSubscription ) => {
|
|
78
|
+
if ( Number( siteSubscription.blog_ID ) === Number( blog_id ) ) {
|
|
79
|
+
return {
|
|
80
|
+
...siteSubscription,
|
|
81
|
+
delivery_methods: {
|
|
82
|
+
...siteSubscription.delivery_methods,
|
|
83
|
+
email: {
|
|
84
|
+
...( siteSubscription.delivery_methods?.email ?? { send_posts: false } ),
|
|
85
|
+
post_delivery_frequency: delivery_frequency,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return siteSubscription;
|
|
91
|
+
} ),
|
|
92
|
+
} ) ),
|
|
93
|
+
}
|
|
94
|
+
: previousSiteSubscriptions;
|
|
99
95
|
queryClient.setQueryData( siteSubscriptionsCacheKey, mutatedSiteSubscriptions );
|
|
100
96
|
|
|
101
97
|
const previousSiteSubscriptionDetails = await alterSiteSubscriptionDetails(
|
|
@@ -122,7 +118,7 @@ const useSiteDeliveryFrequencyMutation = () => {
|
|
|
122
118
|
},
|
|
123
119
|
onError: ( err, _, context ) => {
|
|
124
120
|
queryClient.setQueryData(
|
|
125
|
-
|
|
121
|
+
getSiteSubscriptionsQueryKey(),
|
|
126
122
|
context?.previousSiteSubscriptions
|
|
127
123
|
);
|
|
128
124
|
if ( context?.previousSiteSubscriptionDetails ) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSiteSubscriptionsQueryKey,
|
|
3
|
+
type SiteSubscriptionsInfiniteData,
|
|
4
|
+
} from '@automattic/api-queries';
|
|
1
5
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
6
|
+
import { callApi } from '../helpers';
|
|
3
7
|
import {
|
|
4
8
|
alterSiteSubscriptionDetails,
|
|
5
9
|
invalidateSiteSubscriptionDetails,
|
|
6
10
|
} from '../helpers/optimistic-update';
|
|
7
11
|
import { useIsLoggedIn } from '../hooks';
|
|
8
|
-
import type {
|
|
12
|
+
import type { SiteSubscriptionDetails } from '../types';
|
|
9
13
|
|
|
10
14
|
type SiteSubscriptionEmailMeNewCommentsParams = {
|
|
11
15
|
send_comments: boolean;
|
|
@@ -50,16 +54,12 @@ const useSiteEmailMeNewCommentsMutation = () => {
|
|
|
50
54
|
return response;
|
|
51
55
|
},
|
|
52
56
|
onMutate: async ( { blog_id, send_comments, subscriptionId } ) => {
|
|
53
|
-
const siteSubscriptionsQueryKey =
|
|
54
|
-
[ 'read', 'site-subscriptions' ],
|
|
55
|
-
isLoggedIn,
|
|
56
|
-
id
|
|
57
|
-
);
|
|
57
|
+
const siteSubscriptionsQueryKey = getSiteSubscriptionsQueryKey();
|
|
58
58
|
|
|
59
59
|
await queryClient.cancelQueries( { queryKey: siteSubscriptionsQueryKey } );
|
|
60
60
|
|
|
61
61
|
const previousSiteSubscriptions =
|
|
62
|
-
queryClient.getQueryData<
|
|
62
|
+
queryClient.getQueryData< SiteSubscriptionsInfiniteData >( siteSubscriptionsQueryKey );
|
|
63
63
|
|
|
64
64
|
if ( previousSiteSubscriptions ) {
|
|
65
65
|
queryClient.setQueryData( siteSubscriptionsQueryKey, {
|
|
@@ -68,7 +68,7 @@ const useSiteEmailMeNewCommentsMutation = () => {
|
|
|
68
68
|
return {
|
|
69
69
|
...page,
|
|
70
70
|
subscriptions: page.subscriptions.map( ( siteSubscription ) => {
|
|
71
|
-
if ( siteSubscription.blog_ID === blog_id ) {
|
|
71
|
+
if ( Number( siteSubscription.blog_ID ) === Number( blog_id ) ) {
|
|
72
72
|
return {
|
|
73
73
|
...siteSubscription,
|
|
74
74
|
delivery_methods: {
|
|
@@ -112,7 +112,7 @@ const useSiteEmailMeNewCommentsMutation = () => {
|
|
|
112
112
|
onError: ( _err, _, context ) => {
|
|
113
113
|
if ( context?.previousSiteSubscriptions ) {
|
|
114
114
|
queryClient.setQueryData(
|
|
115
|
-
|
|
115
|
+
getSiteSubscriptionsQueryKey(),
|
|
116
116
|
context.previousSiteSubscriptions
|
|
117
117
|
);
|
|
118
118
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSiteSubscriptionsQueryKey,
|
|
3
|
+
type SiteSubscriptionsInfiniteData,
|
|
4
|
+
} from '@automattic/api-queries';
|
|
1
5
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
6
|
+
import { callApi } from '../helpers';
|
|
3
7
|
import {
|
|
4
8
|
alterSiteSubscriptionDetails,
|
|
5
9
|
invalidateSiteSubscriptionDetails,
|
|
6
10
|
} from '../helpers/optimistic-update';
|
|
7
11
|
import { useIsLoggedIn } from '../hooks';
|
|
8
|
-
import type {
|
|
12
|
+
import type { SiteSubscriptionDetails } from '../types';
|
|
9
13
|
|
|
10
14
|
type SiteSubscriptionEmailMeNewPostsParams = {
|
|
11
15
|
send_posts: boolean;
|
|
@@ -50,16 +54,12 @@ const useSiteEmailMeNewPostsMutation = () => {
|
|
|
50
54
|
return response;
|
|
51
55
|
},
|
|
52
56
|
onMutate: async ( { blog_id, send_posts, subscriptionId } ) => {
|
|
53
|
-
const siteSubscriptionsQueryKey =
|
|
54
|
-
[ 'read', 'site-subscriptions' ],
|
|
55
|
-
isLoggedIn,
|
|
56
|
-
id
|
|
57
|
-
);
|
|
57
|
+
const siteSubscriptionsQueryKey = getSiteSubscriptionsQueryKey();
|
|
58
58
|
|
|
59
59
|
await queryClient.cancelQueries( { queryKey: siteSubscriptionsQueryKey } );
|
|
60
60
|
|
|
61
61
|
const previousSiteSubscriptions =
|
|
62
|
-
queryClient.getQueryData<
|
|
62
|
+
queryClient.getQueryData< SiteSubscriptionsInfiniteData >( siteSubscriptionsQueryKey );
|
|
63
63
|
if ( previousSiteSubscriptions ) {
|
|
64
64
|
queryClient.setQueryData( siteSubscriptionsQueryKey, {
|
|
65
65
|
...previousSiteSubscriptions,
|
|
@@ -67,7 +67,7 @@ const useSiteEmailMeNewPostsMutation = () => {
|
|
|
67
67
|
return {
|
|
68
68
|
...page,
|
|
69
69
|
subscriptions: page.subscriptions.map( ( siteSubscription ) => {
|
|
70
|
-
if ( siteSubscription.blog_ID === blog_id ) {
|
|
70
|
+
if ( Number( siteSubscription.blog_ID ) === Number( blog_id ) ) {
|
|
71
71
|
return {
|
|
72
72
|
...siteSubscription,
|
|
73
73
|
delivery_methods: {
|
|
@@ -116,7 +116,7 @@ const useSiteEmailMeNewPostsMutation = () => {
|
|
|
116
116
|
onError: ( _err, _, context ) => {
|
|
117
117
|
if ( context?.previousSiteSubscriptions ) {
|
|
118
118
|
queryClient.setQueryData(
|
|
119
|
-
|
|
119
|
+
getSiteSubscriptionsQueryKey(),
|
|
120
120
|
context.previousSiteSubscriptions
|
|
121
121
|
);
|
|
122
122
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSiteSubscriptionsQueryKey,
|
|
3
|
+
type SiteSubscriptionsInfiniteData,
|
|
4
|
+
} from '@automattic/api-queries';
|
|
1
5
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
6
|
+
import { callApi } from '../helpers';
|
|
3
7
|
import {
|
|
4
8
|
alterSiteSubscriptionDetails,
|
|
5
9
|
invalidateSiteSubscriptionDetails,
|
|
6
10
|
} from '../helpers/optimistic-update';
|
|
7
11
|
import { useIsLoggedIn } from '../hooks';
|
|
8
|
-
import type {
|
|
12
|
+
import type { SiteSubscriptionDetails } from '../types';
|
|
9
13
|
|
|
10
14
|
type SiteSubscriptionNotifyMeOfNewPostsParams = {
|
|
11
15
|
send_posts: boolean;
|
|
@@ -51,16 +55,12 @@ const useSiteNotifyMeOfNewPostsMutation = () => {
|
|
|
51
55
|
return response;
|
|
52
56
|
},
|
|
53
57
|
onMutate: async ( { blog_id, send_posts, subscriptionId } ) => {
|
|
54
|
-
const siteSubscriptionsQueryKey =
|
|
55
|
-
[ 'read', 'site-subscriptions' ],
|
|
56
|
-
isLoggedIn,
|
|
57
|
-
id
|
|
58
|
-
);
|
|
58
|
+
const siteSubscriptionsQueryKey = getSiteSubscriptionsQueryKey();
|
|
59
59
|
|
|
60
60
|
await queryClient.cancelQueries( { queryKey: siteSubscriptionsQueryKey } );
|
|
61
61
|
|
|
62
62
|
const previousSiteSubscriptions =
|
|
63
|
-
queryClient.getQueryData<
|
|
63
|
+
queryClient.getQueryData< SiteSubscriptionsInfiniteData >( siteSubscriptionsQueryKey );
|
|
64
64
|
|
|
65
65
|
if ( previousSiteSubscriptions ) {
|
|
66
66
|
queryClient.setQueryData( siteSubscriptionsQueryKey, {
|
|
@@ -69,7 +69,7 @@ const useSiteNotifyMeOfNewPostsMutation = () => {
|
|
|
69
69
|
return {
|
|
70
70
|
...page,
|
|
71
71
|
subscriptions: page.subscriptions.map( ( siteSubscription ) => {
|
|
72
|
-
if ( siteSubscription.blog_ID === blog_id ) {
|
|
72
|
+
if ( Number( siteSubscription.blog_ID ) === Number( blog_id ) ) {
|
|
73
73
|
return {
|
|
74
74
|
...siteSubscription,
|
|
75
75
|
delivery_methods: {
|
|
@@ -118,7 +118,7 @@ const useSiteNotifyMeOfNewPostsMutation = () => {
|
|
|
118
118
|
onError: ( err, _, context ) => {
|
|
119
119
|
if ( context?.previousSiteSubscriptions ) {
|
|
120
120
|
queryClient.setQueryData(
|
|
121
|
-
|
|
121
|
+
getSiteSubscriptionsQueryKey(),
|
|
122
122
|
context.previousSiteSubscriptions
|
|
123
123
|
);
|
|
124
124
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSiteSubscriptionsQueryKey,
|
|
3
|
+
type SiteSubscriptionsInfiniteData,
|
|
4
|
+
} from '@automattic/api-queries';
|
|
1
5
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
6
|
import { buildQueryKey, callApi, getSubscriptionMutationParams, isValidId } from '../helpers';
|
|
3
7
|
import { useIsLoggedIn } from '../hooks';
|
|
4
|
-
import { SiteSubscriptionsPages } from '../types';
|
|
5
8
|
import type { SiteSubscriptionDetails } from '../types';
|
|
6
9
|
|
|
7
10
|
type SubscribeParams = {
|
|
@@ -20,6 +23,7 @@ type SubscribeResponse = {
|
|
|
20
23
|
success?: boolean;
|
|
21
24
|
subscribed?: boolean;
|
|
22
25
|
subscription?: {
|
|
26
|
+
ID: string;
|
|
23
27
|
blog_ID: string;
|
|
24
28
|
delivery_frequency: string;
|
|
25
29
|
status: string;
|
|
@@ -38,11 +42,7 @@ const buildSubscriptionDetailsByBlogIdQueryKey = (
|
|
|
38
42
|
const useSiteSubscribeMutation = () => {
|
|
39
43
|
const { isLoggedIn, id: userId } = useIsLoggedIn();
|
|
40
44
|
const queryClient = useQueryClient();
|
|
41
|
-
const siteSubscriptionsCacheKey =
|
|
42
|
-
[ 'read', 'site-subscriptions' ],
|
|
43
|
-
isLoggedIn,
|
|
44
|
-
userId
|
|
45
|
-
);
|
|
45
|
+
const siteSubscriptionsCacheKey = getSiteSubscriptionsQueryKey();
|
|
46
46
|
const subscriptionsCountCacheKey = buildQueryKey(
|
|
47
47
|
[ 'read', 'subscriptions-count' ],
|
|
48
48
|
isLoggedIn,
|
|
@@ -68,7 +68,8 @@ const useSiteSubscribeMutation = () => {
|
|
|
68
68
|
if ( ! response.subscribed ) {
|
|
69
69
|
throw new Error(
|
|
70
70
|
// reminder: translate this string when we add it to the UI
|
|
71
|
-
'Something went wrong while subscribing.'
|
|
71
|
+
'Something went wrong while subscribing.',
|
|
72
|
+
{ cause: response.info }
|
|
72
73
|
);
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -98,20 +99,30 @@ const useSiteSubscribeMutation = () => {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
const previousSiteSubscriptions =
|
|
101
|
-
queryClient.getQueryData<
|
|
102
|
+
queryClient.getQueryData< SiteSubscriptionsInfiniteData >( siteSubscriptionsCacheKey );
|
|
102
103
|
|
|
103
104
|
if ( previousSiteSubscriptions ) {
|
|
104
105
|
queryClient.setQueryData( siteSubscriptionsCacheKey, {
|
|
105
106
|
...previousSiteSubscriptions,
|
|
106
107
|
pages: previousSiteSubscriptions.pages.map( ( page ) => {
|
|
108
|
+
const shouldIncreaseTotalCount = page.subscriptions.some(
|
|
109
|
+
( siteSubscription ) =>
|
|
110
|
+
Number( siteSubscription.blog_ID ) === Number( params.blog_id ) &&
|
|
111
|
+
( siteSubscription.isDeleted || ! siteSubscription.is_following )
|
|
112
|
+
);
|
|
113
|
+
|
|
107
114
|
return {
|
|
108
115
|
...page,
|
|
109
|
-
|
|
116
|
+
totalCount:
|
|
117
|
+
typeof page.totalCount === 'number' && shouldIncreaseTotalCount
|
|
118
|
+
? page.totalCount + 1
|
|
119
|
+
: page.totalCount,
|
|
110
120
|
subscriptions: page.subscriptions.map( ( siteSubscription ) =>
|
|
111
|
-
siteSubscription.blog_ID === params.blog_id
|
|
121
|
+
Number( siteSubscription.blog_ID ) === Number( params.blog_id )
|
|
112
122
|
? {
|
|
113
123
|
...siteSubscription,
|
|
114
124
|
date_subscribed: new Date(),
|
|
125
|
+
is_following: true,
|
|
115
126
|
isDeleted: false,
|
|
116
127
|
resubscribed: params.resubscribed ?? false,
|
|
117
128
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSiteSubscriptionsQueryKey,
|
|
3
|
+
type SiteSubscriptionsInfiniteData,
|
|
4
|
+
} from '@automattic/api-queries';
|
|
1
5
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
6
|
import { buildQueryKey, callApi, getSubscriptionMutationParams, isValidId } from '../helpers';
|
|
3
7
|
import { useCacheKey, useIsLoggedIn } from '../hooks';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
SubscriptionManagerSubscriptionsCount,
|
|
7
|
-
SiteSubscriptionDetails,
|
|
8
|
-
} from '../types';
|
|
8
|
+
import { SubscriptionManagerSubscriptionsCount, SiteSubscriptionDetails } from '../types';
|
|
9
|
+
import type { SiteSubscriptionItem } from '@automattic/api-core';
|
|
9
10
|
|
|
10
11
|
type UnsubscribeParams = {
|
|
11
12
|
subscriptionId: number;
|
|
@@ -46,7 +47,7 @@ const buildSiteSubscriptionDetailsQueryKey = (
|
|
|
46
47
|
const useSiteUnsubscribeMutation = () => {
|
|
47
48
|
const { isLoggedIn, id: userId } = useIsLoggedIn();
|
|
48
49
|
const queryClient = useQueryClient();
|
|
49
|
-
const siteSubscriptionsQueryKey =
|
|
50
|
+
const siteSubscriptionsQueryKey = getSiteSubscriptionsQueryKey();
|
|
50
51
|
const subscriptionsCountQueryKey = useCacheKey( [ 'read', 'subscriptions-count' ] );
|
|
51
52
|
|
|
52
53
|
return useMutation( {
|
|
@@ -93,21 +94,30 @@ const useSiteUnsubscribeMutation = () => {
|
|
|
93
94
|
await queryClient.cancelQueries( { queryKey: siteSubscriptionDetailsQueryKey } );
|
|
94
95
|
|
|
95
96
|
const previousSiteSubscriptions =
|
|
96
|
-
queryClient.getQueryData<
|
|
97
|
+
queryClient.getQueryData< SiteSubscriptionsInfiniteData >( siteSubscriptionsQueryKey );
|
|
97
98
|
|
|
98
99
|
// remove blog from site subscriptions
|
|
99
100
|
if ( previousSiteSubscriptions ) {
|
|
100
101
|
queryClient.setQueryData( siteSubscriptionsQueryKey, {
|
|
101
102
|
...previousSiteSubscriptions,
|
|
102
103
|
pages: previousSiteSubscriptions.pages.map( ( page ) => {
|
|
104
|
+
const isTargetSubscription = ( siteSubscription: SiteSubscriptionItem ) =>
|
|
105
|
+
Number( siteSubscription.ID ) === params.subscriptionId ||
|
|
106
|
+
( isValidId( params.blog_id ) &&
|
|
107
|
+
Number( siteSubscription.blog_ID ) === Number( params.blog_id ) );
|
|
108
|
+
const shouldDecrementTotalCount = page.subscriptions.some( isTargetSubscription );
|
|
109
|
+
|
|
103
110
|
return {
|
|
104
111
|
...page,
|
|
105
|
-
|
|
112
|
+
totalCount:
|
|
113
|
+
typeof page.totalCount === 'number' && shouldDecrementTotalCount
|
|
114
|
+
? page.totalCount - 1
|
|
115
|
+
: page.totalCount,
|
|
106
116
|
subscriptions: page.subscriptions.map( ( siteSubscription ) =>
|
|
107
|
-
|
|
108
|
-
( isValidId( params.blog_id ) && siteSubscription.blog_ID === params.blog_id ) //siteSubscription.blog_ID is not valid ID for non-wpcom subscriptions, so when unsubscribing from such site, the param.blog_id will also be not valid, this would create false positive
|
|
117
|
+
isTargetSubscription( siteSubscription )
|
|
109
118
|
? {
|
|
110
119
|
...siteSubscription,
|
|
120
|
+
is_following: false,
|
|
111
121
|
isDeleted: true,
|
|
112
122
|
resubscribed: false,
|
|
113
123
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
export { default as usePendingPostSubscriptionsQuery } from './use-pending-post-subscriptions-query';
|
|
2
2
|
export { default as usePendingSiteSubscriptionsQuery } from './use-pending-site-subscriptions-query';
|
|
3
3
|
export { default as usePostSubscriptionsQuery } from './use-post-subscriptions-query';
|
|
4
|
-
export { default as useReadFeedSearchQuery, FeedSort } from './use-read-feed-search-query';
|
|
5
|
-
export { default as useReadFeedSiteQuery } from './use-read-feed-site-query';
|
|
6
|
-
export { default as useReadFeedQuery } from './use-read-feed-query';
|
|
7
4
|
export { default as useSiteSubscriptionDetailsQuery } from './use-site-subscription-details-query';
|
|
8
5
|
export {
|
|
9
6
|
default as useSiteSubscriptionsQuery,
|
|
10
7
|
siteSubscriptionsQueryKeyPrefix,
|
|
11
8
|
} from './use-site-subscriptions-query';
|
|
12
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
default as useSubscriptionsCountQuery,
|
|
11
|
+
subscriptionsCountQueryKeyPrefix,
|
|
12
|
+
} from './use-subscriptions-count-query';
|
|
13
13
|
export { default as useUserSettingsQuery } from './use-user-settings-query';
|
|
14
|
-
|
|
15
|
-
export type { FeedItem } from './use-read-feed-search-query';
|