Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store: Product Trash Pickup #21810

Merged
merged 5 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Show a proper error message when a duplicate SKU is found. (16218)
  • Loading branch information
justinshreve committed Jan 24, 2018
commit aa2d729bc3750cffb44ed3215120dc907890459c
13 changes: 8 additions & 5 deletions client/extensions/woocommerce/app/products/product-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import ProductForm from './product-form';
import ProductHeader from './product-header';
import { getLink } from 'woocommerce/lib/nav-utils';
import { withAnalytics, recordTracksEvent } from 'state/analytics/actions';
import { getSaveErrorMessage } from './save-error-message';

class ProductCreate extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -156,11 +157,13 @@ class ProductCreate extends React.Component {
return getSuccessNotice( newProduct );
};

const failureAction = errorNotice(
translate( 'There was a problem saving %(product)s. Please try again.', {
args: { product: product.name },
} )
);
const failureAction = error => {
const errorSlug = ( error && error.error ) || undefined;

return errorNotice( getSaveErrorMessage( errorSlug, product.name, translate ), {
duration: 8000,
} );
};

if ( ! product.type ) {
// Product type was never switched, so set it before we save.
Expand Down
13 changes: 8 additions & 5 deletions client/extensions/woocommerce/app/products/product-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
clearProductCategoryEdits,
} from 'woocommerce/state/ui/product-categories/actions';
import { getProductCategoriesWithLocalEdits } from 'woocommerce/state/ui/product-categories/selectors';
import { getSaveErrorMessage } from './save-error-message';
import page from 'page';
import ProductForm from './product-form';
import ProductHeader from './product-header';
Expand Down Expand Up @@ -174,11 +175,13 @@ class ProductUpdate extends React.Component {
);
};

const failureAction = errorNotice(
translate( 'There was a problem saving %(product)s. Please try again.', {
args: { product: product.name },
} )
);
const failureAction = error => {
const errorSlug = ( error && error.error ) || undefined;

return errorNotice( getSaveErrorMessage( errorSlug, product.name, translate ), {
duration: 8000,
} );
};

this.props.createProductActionList( successAction, failureAction );
};
Expand Down
12 changes: 12 additions & 0 deletions client/extensions/woocommerce/app/products/save-error-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function getSaveErrorMessage( slug, productName, translate ) {
switch ( slug ) {
case 'product_invalid_sku':
return translate( 'There was a problem saving %(product)s. A product already exists with this SKU.', {
args: { product: productName },
} );
default:
return translate( 'There was a problem saving %(product)s. Please try again.', {
args: { product: productName },
} );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ export function handleProductActionListCreate( store, action ) {
}
return dispatch( successAction );
};
const onFailure = dispatch => {
dispatch( failureAction );
const onFailure = ( dispatch, { productError } ) => {
if ( isFunction( failureAction ) ) {
dispatch( failureAction( productError ) );
} else {
dispatch( failureAction );
}
dispatch( actionListClear() );
};
const actionList = makeProductActionList(
Expand Down Expand Up @@ -240,6 +244,15 @@ const productSuccess = ( actionList, type ) => (
dispatch( actionListStepSuccess( newActionList ) );
};

const productFailure = actionList => ( dispatch, getState, { error } ) => {
const newActionList = {
...actionList,
productError: error,
};

dispatch( actionListStepFailure( newActionList ) );
};

export function makeProductSteps( rootState, siteId, productEdits ) {
if ( ! productEdits ) {
return [];
Expand All @@ -261,7 +274,7 @@ export function makeProductSteps( rootState, siteId, productEdits ) {
siteId,
getCorrectedProduct( product, categoryIdMapping ),
productSuccess( actionList, 'create' ),
actionListStepFailure( actionList )
productFailure( actionList )
)
);
},
Expand All @@ -288,7 +301,7 @@ export function makeProductSteps( rootState, siteId, productEdits ) {
siteId,
getCorrectedProduct( product, categoryIdMapping ),
productSuccess( actionList, 'update' ),
actionListStepFailure( actionList )
productFailure( actionList )
)
);
},
Expand Down