Remove task status endpoint (https://github.com/woocommerce/woocommerce-admin/pull/7841)
* Add extra status properties to tasks * Convert extra properties to camelcase * Replace task status usage in client * Remove task status data store * Remove task status endpoint * Remove remaining task status references * Add has products to appearance task data * Handle PR feedback * Fix up additional data for Avalara task * Add changelog entry
This commit is contained in:
parent
abc47adc95
commit
7d464a514c
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: Dev
|
||||
|
||||
Remove task status endpoint #7841
|
|
@ -63,13 +63,22 @@ export const ActivityPanel = ( { isEmbedded, query, userPreferencesData } ) => {
|
|||
const getPreviewSiteBtnTrackData = ( select, getOption ) => {
|
||||
let trackData = {};
|
||||
if ( query.page === 'wc-admin' && query.task === 'appearance' ) {
|
||||
const { getTasksStatus } = select( ONBOARDING_STORE_NAME );
|
||||
const tasksStatus = getTasksStatus();
|
||||
const { getTaskLists } = select( ONBOARDING_STORE_NAME );
|
||||
const taskLists = getTaskLists();
|
||||
const tasks = taskLists.reduce(
|
||||
( acc, taskList ) => [ ...acc, ...taskList.tasks ],
|
||||
[]
|
||||
);
|
||||
const task = tasks.find( ( t ) => t.id === 'appearance' );
|
||||
|
||||
const demoNotice = getOption( 'woocommerce_demo_store_notice' );
|
||||
trackData = {
|
||||
set_notice: demoNotice ? 'Y' : 'N',
|
||||
create_homepage: tasksStatus.hasHomepage === true ? 'Y' : 'N',
|
||||
upload_logo: tasksStatus.themeMods?.custom_logo ? 'Y' : 'N',
|
||||
create_homepage:
|
||||
task?.additionalData?.hasHomepage === true ? 'Y' : 'N',
|
||||
upload_logo: task?.additionalData?.themeMods?.custom_logo
|
||||
? 'Y'
|
||||
: 'N',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import { Fragment, useEffect } from '@wordpress/element';
|
|||
import { applyFilters } from '@wordpress/hooks';
|
||||
import { Icon, chevronRight, page } from '@wordpress/icons';
|
||||
import { partial } from 'lodash';
|
||||
import { getSetting } from '@woocommerce/wc-admin-settings';
|
||||
import { List, Section } from '@woocommerce/components';
|
||||
import {
|
||||
ONBOARDING_STORE_NAME,
|
||||
|
@ -272,15 +271,24 @@ function getShippingItems( { activePlugins, countryCode } ) {
|
|||
}
|
||||
|
||||
function getTaxItems( props ) {
|
||||
const { countryCode } = props;
|
||||
const {
|
||||
automatedTaxSupportedCountries = [],
|
||||
taxJarActivated,
|
||||
} = props.getSetting( 'onboarding', {} );
|
||||
const { countryCode, taskLists } = props;
|
||||
const tasks = taskLists.reduce(
|
||||
( acc, taskList ) => [ ...acc, ...taskList.tasks ],
|
||||
[]
|
||||
);
|
||||
|
||||
const task = tasks.find( ( t ) => t.id === 'tax' );
|
||||
|
||||
if ( ! task ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { additionalData } = task;
|
||||
const { woocommerceTaxCountries = [], taxJarActivated } = additionalData;
|
||||
|
||||
const showWCS =
|
||||
! taxJarActivated && // WCS integration doesn't work with the official TaxJar plugin.
|
||||
automatedTaxSupportedCountries.includes( countryCode );
|
||||
woocommerceTaxCountries.includes( countryCode );
|
||||
|
||||
return [
|
||||
{
|
||||
|
@ -411,7 +419,6 @@ export const HelpPanel = ( props ) => {
|
|||
};
|
||||
|
||||
HelpPanel.defaultProps = {
|
||||
getSetting,
|
||||
recordEvent,
|
||||
};
|
||||
|
||||
|
@ -428,6 +435,7 @@ export default compose(
|
|||
suggestions[ id ] = true;
|
||||
return suggestions;
|
||||
}, {} );
|
||||
const taskLists = select( ONBOARDING_STORE_NAME ).getTaskLists();
|
||||
|
||||
const countryCode = getCountryCode(
|
||||
generalSettings.woocommerce_default_country
|
||||
|
@ -437,6 +445,7 @@ export default compose(
|
|||
activePlugins,
|
||||
countryCode,
|
||||
paymentGatewaySuggestions,
|
||||
taskLists,
|
||||
};
|
||||
} )
|
||||
)( HelpPanel );
|
||||
|
|
|
@ -81,10 +81,20 @@ describe( 'Activity Panels', () => {
|
|||
const taxjarPluginEnabled = render(
|
||||
<HelpPanel
|
||||
countryCode="US"
|
||||
getSetting={ () => ( {
|
||||
automatedTaxSupportedCountries: [ 'US' ],
|
||||
taxJarActivated: true,
|
||||
} ) }
|
||||
taskLists={ [
|
||||
{
|
||||
id: 'setup',
|
||||
tasks: [
|
||||
{
|
||||
id: 'tax',
|
||||
additionalData: {
|
||||
woocommerceTaxCountries: [ 'US' ],
|
||||
taxJarActivated: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] }
|
||||
taskName="tax"
|
||||
/>
|
||||
);
|
||||
|
@ -96,10 +106,20 @@ describe( 'Activity Panels', () => {
|
|||
const unSupportedCountry = render(
|
||||
<HelpPanel
|
||||
countryCode="NZ"
|
||||
getSetting={ () => ( {
|
||||
automatedTaxSupportedCountries: [ 'US' ],
|
||||
taxJarActivated: false,
|
||||
} ) }
|
||||
taskLists={ [
|
||||
{
|
||||
id: 'setup',
|
||||
tasks: [
|
||||
{
|
||||
id: 'tax',
|
||||
additionalData: {
|
||||
woocommerceTaxCountries: [ 'US' ],
|
||||
taxJarActivated: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] }
|
||||
taskName="tax"
|
||||
/>
|
||||
);
|
||||
|
@ -111,10 +131,20 @@ describe( 'Activity Panels', () => {
|
|||
const supportedCountry = render(
|
||||
<HelpPanel
|
||||
countryCode="US"
|
||||
getSetting={ () => ( {
|
||||
automatedTaxSupportedCountries: [ 'US' ],
|
||||
taxJarActivated: false,
|
||||
} ) }
|
||||
taskLists={ [
|
||||
{
|
||||
id: 'setup',
|
||||
tasks: [
|
||||
{
|
||||
id: 'tax',
|
||||
additionalData: {
|
||||
woocommerceTaxCountries: [ 'US' ],
|
||||
taxJarActivated: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] }
|
||||
taskName="tax"
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -43,10 +43,9 @@ const withSelectHandler = ( select: WCDataSelector ) => {
|
|||
};
|
||||
|
||||
export default compose(
|
||||
onboardingData.profile || onboardingData.tasksStatus
|
||||
onboardingData.profile
|
||||
? withOnboardingHydration( {
|
||||
profileItems: onboardingData.profile,
|
||||
tasksStatus: onboardingData.tasksStatus,
|
||||
} )
|
||||
: identity,
|
||||
withSelect( withSelectHandler )
|
||||
|
|
|
@ -25,7 +25,7 @@ import { WooOnboardingTask } from '@woocommerce/onboarding';
|
|||
class Appearance extends Component {
|
||||
constructor( props ) {
|
||||
super( props );
|
||||
const { hasHomepage, hasProducts } = props.tasksStatus;
|
||||
const { hasHomepage, hasProducts } = props.task.additionalData;
|
||||
|
||||
this.stepVisibility = {
|
||||
homepage: ! hasHomepage,
|
||||
|
@ -50,7 +50,7 @@ class Appearance extends Component {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { themeMods } = this.props.tasksStatus;
|
||||
const { themeMods } = this.props.task.additionalData;
|
||||
|
||||
if ( themeMods && themeMods.custom_logo ) {
|
||||
/* eslint-disable react/no-did-mount-set-state */
|
||||
|
@ -106,7 +106,7 @@ class Appearance extends Component {
|
|||
}
|
||||
|
||||
importProducts() {
|
||||
const { clearTaskStatusCache, createNotice } = this.props;
|
||||
const { createNotice } = this.props;
|
||||
this.setState( { isPending: true } );
|
||||
|
||||
recordEvent( 'tasklist_appearance_import_demo', {} );
|
||||
|
@ -132,7 +132,6 @@ class Appearance extends Component {
|
|||
'woocommerce-admin'
|
||||
)
|
||||
);
|
||||
clearTaskStatusCache();
|
||||
}
|
||||
|
||||
this.setState( { isPending: false } );
|
||||
|
@ -145,7 +144,7 @@ class Appearance extends Component {
|
|||
}
|
||||
|
||||
createHomepage() {
|
||||
const { clearTaskStatusCache, createNotice } = this.props;
|
||||
const { createNotice } = this.props;
|
||||
this.setState( { isPending: true } );
|
||||
|
||||
recordEvent( 'tasklist_appearance_create_homepage', {
|
||||
|
@ -157,7 +156,6 @@ class Appearance extends Component {
|
|||
method: 'POST',
|
||||
} )
|
||||
.then( ( response ) => {
|
||||
clearTaskStatusCache();
|
||||
createNotice( response.status, response.message, {
|
||||
actions: response.edit_post_link
|
||||
? [
|
||||
|
@ -188,13 +186,8 @@ class Appearance extends Component {
|
|||
}
|
||||
|
||||
async updateLogo() {
|
||||
const {
|
||||
clearTaskStatusCache,
|
||||
createNotice,
|
||||
stylesheet,
|
||||
themeMods,
|
||||
updateOptions,
|
||||
} = this.props;
|
||||
const { createNotice, task, updateOptions } = this.props;
|
||||
const { stylesheet, themeMods } = task.additionalData;
|
||||
const { logo } = this.state;
|
||||
const updatedThemeMods = {
|
||||
...themeMods,
|
||||
|
@ -208,8 +201,6 @@ class Appearance extends Component {
|
|||
[ `theme_mods_${ stylesheet }` ]: updatedThemeMods,
|
||||
} );
|
||||
|
||||
clearTaskStatusCache();
|
||||
|
||||
if ( update.success ) {
|
||||
this.setState( { isUpdatingLogo: false } );
|
||||
createNotice(
|
||||
|
@ -223,11 +214,7 @@ class Appearance extends Component {
|
|||
}
|
||||
|
||||
async updateNotice() {
|
||||
const {
|
||||
clearTaskStatusCache,
|
||||
createNotice,
|
||||
updateOptions,
|
||||
} = this.props;
|
||||
const { createNotice, updateOptions } = this.props;
|
||||
const { storeNoticeText } = this.state;
|
||||
|
||||
recordEvent( 'tasklist_appearance_set_store_notice', {
|
||||
|
@ -240,8 +227,6 @@ class Appearance extends Component {
|
|||
woocommerce_demo_store_notice: storeNoticeText,
|
||||
} );
|
||||
|
||||
clearTaskStatusCache();
|
||||
|
||||
if ( update.success ) {
|
||||
this.setState( { isUpdatingNotice: false } );
|
||||
createNotice(
|
||||
|
@ -421,26 +406,18 @@ class Appearance extends Component {
|
|||
const AppearanceWrapper = compose(
|
||||
withSelect( ( select ) => {
|
||||
const { getOption } = select( OPTIONS_STORE_NAME );
|
||||
const { getTasksStatus } = select( ONBOARDING_STORE_NAME );
|
||||
const tasksStatus = getTasksStatus();
|
||||
|
||||
return {
|
||||
demoStoreNotice: getOption( 'woocommerce_demo_store_notice' ),
|
||||
stylesheet: getOption( 'stylesheet' ),
|
||||
tasksStatus,
|
||||
};
|
||||
} ),
|
||||
withDispatch( ( dispatch ) => {
|
||||
const { createNotice } = dispatch( 'core/notices' );
|
||||
const { updateOptions } = dispatch( OPTIONS_STORE_NAME );
|
||||
const { actionTask, invalidateResolutionForStoreSelector } = dispatch(
|
||||
ONBOARDING_STORE_NAME
|
||||
);
|
||||
const { actionTask } = dispatch( ONBOARDING_STORE_NAME );
|
||||
|
||||
return {
|
||||
actionTask,
|
||||
clearTaskStatusCache: () =>
|
||||
invalidateResolutionForStoreSelector( 'getTasksStatus' ),
|
||||
createNotice,
|
||||
updateOptions,
|
||||
};
|
||||
|
@ -451,8 +428,8 @@ registerPlugin( 'wc-admin-onboarding-task-appearance', {
|
|||
scope: 'woocommerce-tasks',
|
||||
render: () => (
|
||||
<WooOnboardingTask id="appearance">
|
||||
{ ( { onComplete } ) => (
|
||||
<AppearanceWrapper onComplete={ onComplete } />
|
||||
{ ( { onComplete, task } ) => (
|
||||
<AppearanceWrapper onComplete={ onComplete } task={ task } />
|
||||
) }
|
||||
</WooOnboardingTask>
|
||||
),
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
*/
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import apiFetch from '@wordpress/api-fetch';
|
||||
import { compose } from '@wordpress/compose';
|
||||
import { withDispatch } from '@wordpress/data';
|
||||
import { Component, Fragment } from '@wordpress/element';
|
||||
import { Button, FormToggle } from '@wordpress/components';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Flag, Form, TextControlWithAffixes } from '@woocommerce/components';
|
||||
import { ONBOARDING_STORE_NAME } from '@woocommerce/data';
|
||||
import { recordEvent } from '@woocommerce/tracks';
|
||||
import { Icon, globe } from '@wordpress/icons';
|
||||
|
||||
|
@ -57,11 +54,7 @@ class ShippingRates extends Component {
|
|||
}
|
||||
|
||||
async updateShippingZones( values ) {
|
||||
const {
|
||||
clearTaskStatusCache,
|
||||
createNotice,
|
||||
shippingZones,
|
||||
} = this.props;
|
||||
const { createNotice, shippingZones } = this.props;
|
||||
|
||||
let restOfTheWorld = false;
|
||||
let shippingCost = false;
|
||||
|
@ -118,8 +111,6 @@ class ShippingRates extends Component {
|
|||
rest_world: restOfTheWorld,
|
||||
} );
|
||||
|
||||
clearTaskStatusCache();
|
||||
|
||||
createNotice(
|
||||
'success',
|
||||
__( 'Your shipping rates have been updated', 'woocommerce-admin' )
|
||||
|
@ -355,15 +346,4 @@ ShippingRates.defaultProps = {
|
|||
|
||||
ShippingRates.contextType = CurrencyContext;
|
||||
|
||||
export default compose(
|
||||
withDispatch( ( dispatch ) => {
|
||||
const { invalidateResolutionForStoreSelector } = dispatch(
|
||||
ONBOARDING_STORE_NAME
|
||||
);
|
||||
|
||||
return {
|
||||
clearTaskStatusCache: () =>
|
||||
invalidateResolutionForStoreSelector( 'getTasksStatus' ),
|
||||
};
|
||||
} )
|
||||
)( ShippingRates );
|
||||
export default ShippingRates;
|
||||
|
|
|
@ -12,8 +12,8 @@ import { recordEvent } from '@woocommerce/tracks';
|
|||
import { PartnerCard } from '../components/partner-card';
|
||||
import logo from './logo.png';
|
||||
|
||||
export const Card = ( { isPending, tasksStatus } ) => {
|
||||
const { avalaraActivated } = tasksStatus;
|
||||
export const Card = ( { isPending, task } ) => {
|
||||
const { avalaraActivated } = task.additionalData;
|
||||
|
||||
return (
|
||||
<PartnerCard
|
||||
|
|
|
@ -45,35 +45,28 @@ const TaskCard = ( { children } ) => {
|
|||
);
|
||||
};
|
||||
|
||||
const Tax = ( { onComplete, query } ) => {
|
||||
const Tax = ( { onComplete, query, task } ) => {
|
||||
const [ isPending, setIsPending ] = useState( false );
|
||||
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
||||
const { createNotice } = useDispatch( 'core/notices' );
|
||||
const { updateAndPersistSettingsForGroup } = useDispatch(
|
||||
SETTINGS_STORE_NAME
|
||||
);
|
||||
const {
|
||||
generalSettings,
|
||||
isResolving,
|
||||
tasksStatus,
|
||||
taxSettings,
|
||||
} = useSelect( ( select ) => {
|
||||
const { getSettings, hasFinishedResolution } = select(
|
||||
SETTINGS_STORE_NAME
|
||||
) as SettingsSelector;
|
||||
const { generalSettings, isResolving, taxSettings } = useSelect(
|
||||
( select ) => {
|
||||
const { getSettings, hasFinishedResolution } = select(
|
||||
SETTINGS_STORE_NAME
|
||||
) as SettingsSelector;
|
||||
|
||||
return {
|
||||
generalSettings: getSettings( 'general' ).general,
|
||||
isResolving:
|
||||
! hasFinishedResolution( 'getSettings', [ 'general' ] ) ||
|
||||
! select( ONBOARDING_STORE_NAME ).hasFinishedResolution(
|
||||
'getTasksStatus'
|
||||
),
|
||||
// @Todo this should be removed as soon as https://github.com/woocommerce/woocommerce-admin/pull/7841 is merged.
|
||||
tasksStatus: select( ONBOARDING_STORE_NAME ).getTasksStatus(),
|
||||
taxSettings: getSettings( 'tax' ).tax || {},
|
||||
};
|
||||
} );
|
||||
return {
|
||||
generalSettings: getSettings( 'general' ).general,
|
||||
isResolving: ! hasFinishedResolution( 'getSettings', [
|
||||
'general',
|
||||
] ),
|
||||
taxSettings: getSettings( 'tax' ).tax || {},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const onManual = useCallback( async () => {
|
||||
setIsPending( true );
|
||||
|
@ -145,9 +138,9 @@ const Tax = ( { onComplete, query } ) => {
|
|||
generalSettings?.woocommerce_default_country
|
||||
);
|
||||
const {
|
||||
automatedTaxSupportedCountries = [],
|
||||
woocommerceTaxCountries = [],
|
||||
taxJarActivated,
|
||||
} = tasksStatus;
|
||||
} = task.additionalData;
|
||||
|
||||
const partners = [
|
||||
{
|
||||
|
@ -156,7 +149,7 @@ const Tax = ( { onComplete, query } ) => {
|
|||
component: WooCommerceTax,
|
||||
isVisible:
|
||||
! taxJarActivated && // WCS integration doesn't work with the official TaxJar plugin.
|
||||
automatedTaxSupportedCountries.includes(
|
||||
woocommerceTaxCountries.includes(
|
||||
getCountryCode(
|
||||
generalSettings?.woocommerce_default_country
|
||||
)
|
||||
|
@ -219,7 +212,7 @@ const Tax = ( { onComplete, query } ) => {
|
|||
onAutomate,
|
||||
onManual,
|
||||
onDisable,
|
||||
tasksStatus,
|
||||
task,
|
||||
};
|
||||
|
||||
if ( isResolving ) {
|
||||
|
@ -260,8 +253,8 @@ registerPlugin( 'wc-admin-onboarding-task-tax', {
|
|||
scope: 'woocommerce-tasks',
|
||||
render: () => (
|
||||
<WooOnboardingTask id="tax">
|
||||
{ ( { onComplete, query } ) => (
|
||||
<Tax onComplete={ onComplete } query={ query } />
|
||||
{ ( { onComplete, query, task } ) => (
|
||||
<Tax onComplete={ onComplete } query={ query } task={ task } />
|
||||
) }
|
||||
</WooOnboardingTask>
|
||||
),
|
||||
|
|
|
@ -3,7 +3,6 @@ const TYPES = {
|
|||
SET_IS_REQUESTING: 'SET_IS_REQUESTING',
|
||||
SET_PROFILE_ITEMS: 'SET_PROFILE_ITEMS',
|
||||
SET_EMAIL_PREFILL: 'SET_EMAIL_PREFILL',
|
||||
SET_TASKS_STATUS: 'SET_TASKS_STATUS',
|
||||
GET_PAYMENT_METHODS_SUCCESS: 'GET_PAYMENT_METHODS_SUCCESS',
|
||||
GET_PRODUCT_TYPES_SUCCESS: 'GET_PRODUCT_TYPES_SUCCESS',
|
||||
GET_PRODUCT_TYPES_ERROR: 'GET_PRODUCT_TYPES_ERROR',
|
||||
|
|
|
@ -179,13 +179,6 @@ export function optimisticallyCompleteTaskRequest( taskId ) {
|
|||
};
|
||||
}
|
||||
|
||||
export function setTasksStatus( tasksStatus ) {
|
||||
return {
|
||||
type: TYPES.SET_TASKS_STATUS,
|
||||
tasksStatus,
|
||||
};
|
||||
}
|
||||
|
||||
export function setPaymentMethods( paymentMethods ) {
|
||||
return {
|
||||
type: TYPES.GET_PAYMENT_METHODS_SUCCESS,
|
||||
|
|
|
@ -28,7 +28,6 @@ export const defaultState = {
|
|||
productTypes: [],
|
||||
requesting: {},
|
||||
taskLists: [],
|
||||
tasksStatus: {},
|
||||
};
|
||||
|
||||
const getUpdatedTaskLists = ( taskLists, args ) => {
|
||||
|
@ -66,7 +65,6 @@ const onboarding = (
|
|||
taskListId,
|
||||
taskList,
|
||||
taskLists,
|
||||
tasksStatus,
|
||||
}
|
||||
) => {
|
||||
switch ( type ) {
|
||||
|
@ -82,11 +80,6 @@ const onboarding = (
|
|||
...state,
|
||||
emailPrefill,
|
||||
};
|
||||
case TYPES.SET_TASKS_STATUS:
|
||||
return {
|
||||
...state,
|
||||
tasksStatus: { ...state.tasksStatus, ...tasksStatus },
|
||||
};
|
||||
case TYPES.SET_ERROR:
|
||||
return {
|
||||
...state,
|
||||
|
|
|
@ -14,7 +14,6 @@ import {
|
|||
getTaskListsSuccess,
|
||||
setProfileItems,
|
||||
setError,
|
||||
setTasksStatus,
|
||||
setPaymentMethods,
|
||||
setEmailPrefill,
|
||||
getProductTypesSuccess,
|
||||
|
@ -50,19 +49,6 @@ export function* getEmailPrefill() {
|
|||
}
|
||||
}
|
||||
|
||||
export function* getTasksStatus() {
|
||||
try {
|
||||
const results = yield apiFetch( {
|
||||
path: WC_ADMIN_NAMESPACE + '/onboarding/tasks/status',
|
||||
method: 'GET',
|
||||
} );
|
||||
|
||||
yield setTasksStatus( results, true );
|
||||
} catch ( error ) {
|
||||
yield setError( 'getTasksStatus', error );
|
||||
}
|
||||
}
|
||||
|
||||
export function* getTaskLists() {
|
||||
const deprecatedTasks = new DeprecatedTasks();
|
||||
try {
|
||||
|
|
|
@ -16,12 +16,6 @@ export const getProfileItems = (
|
|||
return state.profileItems || {};
|
||||
};
|
||||
|
||||
export const getTasksStatus = (
|
||||
state: OnboardingState
|
||||
): TasksStatusState | Record< string, never > => {
|
||||
return state.tasksStatus || {};
|
||||
};
|
||||
|
||||
const initialTaskLists: TaskListType[] = [];
|
||||
|
||||
const EMPTY_ARRAY: Product[] = [];
|
||||
|
@ -60,7 +54,6 @@ export const getProductTypes = ( state: OnboardingState ): Product[] => {
|
|||
// Types
|
||||
export type OnboardingSelectors = {
|
||||
getProfileItems: () => ReturnType< typeof getProfileItems >;
|
||||
getTasksStatus: () => ReturnType< typeof getTasksStatus >;
|
||||
getPaymentGatewaySuggestions: () => ReturnType<
|
||||
typeof getPaymentGatewaySuggestions
|
||||
>;
|
||||
|
@ -72,7 +65,6 @@ export type OnboardingState = {
|
|||
freeExtensions: ExtensionList[];
|
||||
profileItems: ProfileItemsState;
|
||||
taskLists: TaskListType[];
|
||||
tasksStatus: TasksStatusState;
|
||||
paymentMethods: PaymentMethodsState[];
|
||||
productTypes: Product[];
|
||||
emailPrefill: string;
|
||||
|
@ -81,16 +73,6 @@ export type OnboardingState = {
|
|||
requesting: Record< string, boolean >;
|
||||
};
|
||||
|
||||
export type TasksStatusState = {
|
||||
automatedTaxSupportedCountries: string[];
|
||||
hasHomepage: boolean;
|
||||
hasProducts: boolean;
|
||||
stylesheet: string;
|
||||
taxJarActivated: boolean;
|
||||
// TODO - fill out this type
|
||||
themeMods: unknown;
|
||||
};
|
||||
|
||||
export type Industry = {
|
||||
slug: string;
|
||||
};
|
||||
|
|
|
@ -88,21 +88,4 @@ describe( 'plugins reducer', () => {
|
|||
expect( state.requesting[ 'updateProfileItems' ] ).toBeTruthy();
|
||||
/* eslint-enable dot-notation */
|
||||
} );
|
||||
|
||||
it( 'should handle SET_TASKS_STATUS', () => {
|
||||
const state = reducer(
|
||||
{
|
||||
tasksStatus: { hasProducts: true },
|
||||
},
|
||||
{
|
||||
type: TYPES.SET_TASKS_STATUS,
|
||||
tasksStatus: { hasHomepage: false },
|
||||
}
|
||||
);
|
||||
|
||||
expect( state.tasksStatus ).toHaveProperty( 'hasProducts' );
|
||||
expect( state.tasksStatus ).toHaveProperty( 'hasHomepage' );
|
||||
expect( state.tasksStatus.hasProducts ).toBe( true );
|
||||
expect( state.tasksStatus.hasHomepage ).toBe( false );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -12,7 +12,6 @@ import { STORE_NAME } from './constants';
|
|||
|
||||
export const withOnboardingHydration = ( data ) => {
|
||||
let hydratedProfileItems = false;
|
||||
let hydratedTasksStatus = false;
|
||||
|
||||
return createHigherOrderComponent(
|
||||
( OriginalComponent ) => ( props ) => {
|
||||
|
@ -30,10 +29,9 @@ export const withOnboardingHydration = ( data ) => {
|
|||
startResolution,
|
||||
finishResolution,
|
||||
setProfileItems,
|
||||
setTasksStatus,
|
||||
} = registry.dispatch( STORE_NAME );
|
||||
|
||||
const { profileItems, tasksStatus } = onboardingRef.current;
|
||||
const { profileItems } = onboardingRef.current;
|
||||
|
||||
if (
|
||||
profileItems &&
|
||||
|
@ -47,19 +45,6 @@ export const withOnboardingHydration = ( data ) => {
|
|||
|
||||
hydratedProfileItems = true;
|
||||
}
|
||||
|
||||
if (
|
||||
tasksStatus &&
|
||||
! hydratedTasksStatus &&
|
||||
! isResolving( 'getTasksStatus', [] ) &&
|
||||
! hasFinishedResolution( 'getTasksStatus', [] )
|
||||
) {
|
||||
startResolution( 'getTasksStatus', [] );
|
||||
setTasksStatus( tasksStatus, true );
|
||||
finishResolution( 'getTasksStatus', [] );
|
||||
|
||||
hydratedTasksStatus = true;
|
||||
}
|
||||
}, [] );
|
||||
|
||||
return <OriginalComponent { ...props } />;
|
||||
|
|
|
@ -75,19 +75,6 @@ class OnboardingTasks extends \WC_REST_Data_Controller {
|
|||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/status',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_status' ),
|
||||
'permission_callback' => array( $this, 'get_status_permission_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_status_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/create_product_from_template',
|
||||
|
@ -250,20 +237,6 @@ class OnboardingTasks extends \WC_REST_Data_Controller {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to get onboarding tasks status.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
public function get_status_permission_check( $request ) {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to retrieve onboarding status.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to manage woocommerce.
|
||||
*
|
||||
|
@ -676,56 +649,6 @@ class OnboardingTasks extends \WC_REST_Data_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status endpoint schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_status_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'Onboarding Task Status',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'automatedTaxSupportedCountries' => array(
|
||||
'type' => 'array',
|
||||
'description' => __( 'Country codes that support Automated Taxes.', 'woocommerce-admin' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'hasHomepage' => array(
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'If the store has a homepage created.', 'woocommerce-admin' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'hasProducts' => array(
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'If the store has any products.', 'woocommerce-admin' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'taxJarActivated' => array(
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'If the store has the TaxJar extension active.', 'woocommerce-admin' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'themeMods' => array(
|
||||
'type' => 'object',
|
||||
'description' => __( 'Active theme modifications.', 'woocommerce-admin' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query params for task lists.
|
||||
*
|
||||
|
@ -749,17 +672,6 @@ class OnboardingTasks extends \WC_REST_Data_Controller {
|
|||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get various onboarding task statuses.
|
||||
*
|
||||
* @return WP_Error|array
|
||||
*/
|
||||
public function get_status() {
|
||||
$status = OnboardingTasksFeature::get_settings();
|
||||
|
||||
return rest_ensure_response( $status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the onboarding tasks.
|
||||
*
|
||||
|
|
|
@ -41,16 +41,6 @@ class Init {
|
|||
public function __construct() {
|
||||
DeprecatedOptions::init();
|
||||
TaskLists::init();
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Old settings injection.
|
||||
// Run after Onboarding.
|
||||
add_filter( 'woocommerce_components_settings', array( __CLASS__, 'component_settings' ), 30 );
|
||||
// New settings injection.
|
||||
add_filter( 'woocommerce_admin_shared_settings', array( $this, 'component_settings' ), 30 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,44 +58,6 @@ class Init {
|
|||
: false;
|
||||
}
|
||||
|
||||
$settings['automatedTaxSupportedCountries'] = Tax::get_automated_tax_supported_countries();
|
||||
$settings['hasHomepage'] = Appearance::has_homepage();
|
||||
$settings['hasProducts'] = Products::has_products();
|
||||
$settings['stylesheet'] = get_option( 'stylesheet' );
|
||||
$settings['taxJarActivated'] = class_exists( 'WC_Taxjar' );
|
||||
$settings['avalaraActivated'] = PluginsHelper::is_plugin_active( 'woocommerce-avatax' );
|
||||
$settings['themeMods'] = get_theme_mods();
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add task items to component settings.
|
||||
*
|
||||
* @param array $settings Component settings.
|
||||
* @return array
|
||||
*/
|
||||
public function component_settings( $settings ) {
|
||||
// Bail early if not on a wc-admin powered page, or task list shouldn't be shown.
|
||||
if (
|
||||
! \Automattic\WooCommerce\Admin\Loader::is_admin_page() ||
|
||||
! count( TaskLists::get_visible() )
|
||||
) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// If onboarding isn't enabled this will throw warnings.
|
||||
if ( ! isset( $settings['onboarding'] ) ) {
|
||||
$settings['onboarding'] = array();
|
||||
}
|
||||
|
||||
$settings['onboarding'] = array_merge(
|
||||
$settings['onboarding'],
|
||||
array(
|
||||
'tasksStatus' => self::get_settings(),
|
||||
)
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,6 +179,7 @@ class Task {
|
|||
'is_snoozeable' => false,
|
||||
'snoozed_until' => null,
|
||||
'additional_info' => '',
|
||||
'additional_data' => (object) array(),
|
||||
);
|
||||
|
||||
$data = wp_parse_args( $data, $defaults );
|
||||
|
@ -196,6 +197,7 @@ class Task {
|
|||
$this->time = (string) $data['time'];
|
||||
$this->is_dismissable = (bool) $data['is_dismissable'];
|
||||
$this->is_snoozeable = (bool) $data['is_snoozeable'];
|
||||
$this->additional_data = (object) $data['additional_data'];
|
||||
|
||||
$snoozed_tasks = get_option( self::SNOOZED_OPTION, array() );
|
||||
if ( isset( $snoozed_tasks[ $this->id ] ) ) {
|
||||
|
@ -395,9 +397,27 @@ class Task {
|
|||
'isSnoozed' => $this->is_snoozed(),
|
||||
'isSnoozeable' => $this->is_snoozeable,
|
||||
'snoozedUntil' => $this->snoozed_until,
|
||||
'additionalData' => self::convert_object_to_camelcase( $this->additional_data ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert object keys to camelcase.
|
||||
*
|
||||
* @param object $object Object to convert.
|
||||
* @return object
|
||||
*/
|
||||
public static function convert_object_to_camelcase( $object ) {
|
||||
$new_object = (object) array();
|
||||
|
||||
foreach ( $object as $key => $value ) {
|
||||
$new_key = lcfirst( implode( '', array_map( 'ucfirst', explode( '_', $key ) ) ) );
|
||||
$new_object->$new_key = $value;
|
||||
}
|
||||
|
||||
return $new_object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a task as actioned. Used to verify an action has taken place in some tasks.
|
||||
*
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
|
|||
|
||||
use Automattic\WooCommerce\Admin\Loader;
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Products;
|
||||
|
||||
/**
|
||||
* Appearance Task
|
||||
|
@ -24,16 +25,22 @@ class Appearance {
|
|||
*/
|
||||
public static function get_task() {
|
||||
return array(
|
||||
'id' => 'appearance',
|
||||
'title' => __( 'Personalize my store', 'woocommerce-admin' ),
|
||||
'content' => __(
|
||||
'id' => 'appearance',
|
||||
'title' => __( 'Personalize my store', 'woocommerce-admin' ),
|
||||
'content' => __(
|
||||
'Add your logo, create a homepage, and start designing your store.',
|
||||
'woocommerce-admin'
|
||||
),
|
||||
'action_label' => __( "Let's go", 'woocommerce-admin' ),
|
||||
'is_complete' => Task::is_task_actioned( 'appearance' ),
|
||||
'can_view' => true,
|
||||
'time' => __( '2 minutes', 'woocommerce-admin' ),
|
||||
'action_label' => __( "Let's go", 'woocommerce-admin' ),
|
||||
'is_complete' => Task::is_task_actioned( 'appearance' ),
|
||||
'can_view' => true,
|
||||
'time' => __( '2 minutes', 'woocommerce-admin' ),
|
||||
'additional_data' => array(
|
||||
'has_homepage' => self::has_homepage(),
|
||||
'has_products' => Products::has_products(),
|
||||
'stylesheet' => get_option( 'stylesheet' ),
|
||||
'theme_mods' => get_theme_mods(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,15 +82,18 @@ class Products {
|
|||
*/
|
||||
public static function get_task() {
|
||||
return array(
|
||||
'id' => 'products',
|
||||
'title' => __( 'Add my products', 'woocommerce-admin' ),
|
||||
'content' => __(
|
||||
'id' => 'products',
|
||||
'title' => __( 'Add my products', 'woocommerce-admin' ),
|
||||
'content' => __(
|
||||
'Start by adding the first product to your store. You can add your products manually, via CSV, or import them from another service.',
|
||||
'woocommerce-admin'
|
||||
),
|
||||
'is_complete' => self::has_products(),
|
||||
'can_view' => true,
|
||||
'time' => __( '1 minute per product', 'woocommerce-admin' ),
|
||||
'is_complete' => self::has_products(),
|
||||
'can_view' => true,
|
||||
'time' => __( '1 minute per product', 'woocommerce-admin' ),
|
||||
'additional_data' => array(
|
||||
'has_products' => self::has_products(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,9 +54,9 @@ class Tax {
|
|||
*/
|
||||
public static function get_task() {
|
||||
return array(
|
||||
'id' => 'tax',
|
||||
'title' => __( 'Set up tax', 'woocommerce-admin' ),
|
||||
'content' => self::can_use_automated_taxes()
|
||||
'id' => 'tax',
|
||||
'title' => __( 'Set up tax', 'woocommerce-admin' ),
|
||||
'content' => self::can_use_automated_taxes()
|
||||
? __(
|
||||
'Good news! WooCommerce Services and Jetpack can automate your sales tax calculations for you.',
|
||||
'woocommerce-admin'
|
||||
|
@ -65,15 +65,20 @@ class Tax {
|
|||
'Set your store location and configure tax rate settings.',
|
||||
'woocommerce-admin'
|
||||
),
|
||||
'action_label' => self::can_use_automated_taxes()
|
||||
'action_label' => self::can_use_automated_taxes()
|
||||
? __( 'Yes please', 'woocommerce-admin' )
|
||||
: __( "Let's go", 'woocommerce-admin' ),
|
||||
'is_complete' => get_option( 'wc_connect_taxes_enabled' ) ||
|
||||
'is_complete' => get_option( 'wc_connect_taxes_enabled' ) ||
|
||||
count( TaxDataStore::get_taxes( array() ) ) > 0 ||
|
||||
false !== get_option( 'woocommerce_no_sales_tax' ) ||
|
||||
PluginsHelper::is_plugin_active( 'woocommerce-avatax' ),
|
||||
'is_visible' => true,
|
||||
'time' => __( '1 minute', 'woocommerce-admin' ),
|
||||
'is_visible' => true,
|
||||
'time' => __( '1 minute', 'woocommerce-admin' ),
|
||||
'additional_data' => array(
|
||||
'avalara_activated' => PluginsHelper::is_plugin_active( 'woocommerce-avatax' ),
|
||||
'tax_jar_activated' => class_exists( 'WC_Taxjar' ),
|
||||
'woocommerce_tax_countries' => self::get_automated_support_countries(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -87,7 +92,7 @@ class Tax {
|
|||
return false;
|
||||
}
|
||||
|
||||
return in_array( WC()->countries->get_base_country(), self::get_automated_tax_supported_countries(), true );
|
||||
return in_array( WC()->countries->get_base_country(), self::get_automated_support_countries(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,7 +100,7 @@ class Tax {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_automated_tax_supported_countries() {
|
||||
public static function get_automated_support_countries() {
|
||||
// https://developers.taxjar.com/api/reference/#countries .
|
||||
$tax_supported_countries = array_merge(
|
||||
array( 'US', 'CA', 'AU' ),
|
||||
|
|
Loading…
Reference in New Issue