Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request scandipwa#4867 from AzizKHAN030/4827_fileResetIssue
Browse files Browse the repository at this point in the history
Updating the state of productActions component on fieldReset
  • Loading branch information
carinadues authored Jun 20, 2022
2 parents d565967 + b2e8473 commit 8f61245
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class AddToCartContainer extends PureComponent {
addToCart: PropTypes.func,
fallbackAddToCart: PropTypes.func.isRequired,
isDisabled: PropTypes.bool,
updateSelectedValues: PropTypes.func,

isIconEnabled: PropTypes.bool,
mix: MixType,
Expand All @@ -69,6 +70,7 @@ export class AddToCartContainer extends PureComponent {
isIconEnabled: true,
isDisabled: false,
addToCart: null,
updateSelectedValues: null,
product: {}
};

Expand All @@ -95,7 +97,8 @@ export class AddToCartContainer extends PureComponent {
};

async addProductToCart(e) {
const { product, addToCart } = this.props;
const { product, addToCart, updateSelectedValues } = this.props;
await updateSelectedValues();

if ((!product || Object.keys(product).length === 0) && !addToCart) {
return;
Expand Down
11 changes: 9 additions & 2 deletions packages/scandipwa/src/component/Field/Field.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class FieldContainer extends PureComponent {
value: PropTypes.number.isRequired,
changeValueOnDoubleClick: PropTypes.bool,
isSortSelect: PropTypes.bool,
resetFieldValue: PropTypes.func.isRequired,
updateSelectedValues: PropTypes.func,
resetFieldValue: PropTypes.func,
// Validation
validationRule: ValidationRuleType,
validateOn: PropTypes.arrayOf(PropTypes.string),
Expand All @@ -67,7 +68,9 @@ export class FieldContainer extends PureComponent {
subLabel: '',
elemRef: null,
changeValueOnDoubleClick: false,
isSortSelect: false
isSortSelect: false,
updateSelectedValues: null,
resetFieldValue: null
};

state = {
Expand Down Expand Up @@ -121,6 +124,8 @@ export class FieldContainer extends PureComponent {
}

resetFieldValue(fieldHandler, event) {
const { updateSelectedValues } = this.props;

event.preventDefault();
event.stopPropagation();

Expand All @@ -130,8 +135,10 @@ export class FieldContainer extends PureComponent {
isLoading: false
});

this.fieldRef.fileData = '';
this.fieldRef.value = '';
this.validate();
updateSelectedValues();
}

handleShowLengthError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ export class Product extends PureComponent {
addToCart,
inStock,
quantity,
getActiveProduct
getActiveProduct,
updateSelectedValues
} = this.props;

return (
Expand All @@ -276,6 +277,7 @@ export class Product extends PureComponent {
isDisabled={ !inStock }
isIconEnabled={ false }
layout={ layout }
updateSelectedValues={ updateSelectedValues }
quantity={ quantity }
product={ getActiveProduct() }
/>
Expand Down
11 changes: 9 additions & 2 deletions packages/scandipwa/src/component/Product/Product.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,21 @@ export class ProductContainer extends PureComponent {

const values = getFieldsData(current, true, [FIELD_TYPE.numberWithControls]);

values.forEach(({ name, value, type }) => {
values.forEach(({
field, name, value, type
}) => {
if (type === FIELD_TYPE.select) {
selectedOptions.push(value);
} else if (type === FIELD_TYPE.checkbox || type === FIELD_TYPE.radio) {
if (value !== FIELD_RADIO_NONE) {
selectedOptions.push(value);
}
} else if (type !== FIELD_TYPE.numberWithControls) {
} else if (type !== FIELD_TYPE.numberWithControls && type !== FIELD_TYPE.file) {
enteredOptions.push({
uid: name,
value
});
} else if (type === FIELD_TYPE.file && field.value) {
enteredOptions.push({
uid: name,
value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class ProductCustomizableOption extends PureComponent {
name: uid,
accept: fileExtensions
} }
updateSelectedValues={ updateSelectedValues }
events={ {
onChange: updateSelectedValues
} }
Expand Down

0 comments on commit 8f61245

Please sign in to comment.