-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WooCommerce Labels - fix the build errors (#17755)
* Fixed the PropTypes imports * Conditionally rendering the labels UI in order details * Fixed some of the imports * Copied over ActionButtons component * Fixed ActionButtons imports * Fixed /lib imports * Fixed build errors for missing components * Fixed the rest of the imports and copied over missing components * Tweaked the main label view and purchase label to work * Merged the selectors files, removed reselect usages * Minor fix * Added siteId and orderId to all action definitions * Made the modal render * Address normalization fix * Made the packages step work * Tweaked the rates step * Made the label items not throw errors * Added CSS import for the label * Fixed print url and cross-browser warnings * Style fixes * Fixed the spinners * Replaced formatDate with moment's format method * Fixed a typo in CSS class selector * Made the refund and reprint dialogs render * Changed the order of orderId, siteId arguments in actions to match selectors
- Loading branch information
Showing
50 changed files
with
1,513 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
client/extensions/woocommerce/woocommerce-services/components/action-buttons/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FormButton from 'components/forms/form-button'; | ||
import FormButtonsBar from 'components/forms/form-buttons-bar'; | ||
|
||
const ActionButtons = ( { buttons, className } ) => { | ||
return ( | ||
<FormButtonsBar className={ className }> | ||
{ buttons.map( ( button, idx ) => ( | ||
<FormButton | ||
type="button" | ||
key={ idx } | ||
disabled={ button.isDisabled } | ||
onClick={ button.onClick } | ||
isPrimary={ Boolean( button.isPrimary ) }> | ||
{ button.label } | ||
</FormButton> | ||
) ) } | ||
</FormButtonsBar> | ||
); | ||
}; | ||
|
||
ActionButtons.propTypes = { | ||
buttons: PropTypes.arrayOf( | ||
PropTypes.shape( { | ||
label: PropTypes.node.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
isPrimary: PropTypes.bool, | ||
isDisabled: PropTypes.bool, | ||
} ) | ||
).isRequired, | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default ActionButtons; |
39 changes: 39 additions & 0 deletions
39
client/extensions/woocommerce/woocommerce-services/components/country-dropdown/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Dropdown from '../dropdown'; | ||
|
||
const CountryDropdown = ( props ) => { | ||
const valuesMap = {}; | ||
Object.keys( props.countriesData ).forEach( ( countryCode ) => { | ||
valuesMap[ countryCode ] = props.countriesData[ countryCode ].name; | ||
} ); | ||
return ( | ||
<Dropdown | ||
{ ...props } | ||
valuesMap={ valuesMap } | ||
/> | ||
); | ||
}; | ||
|
||
CountryDropdown.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
countriesData: PropTypes.object.isRequired, | ||
title: PropTypes.string, | ||
description: PropTypes.string, | ||
value: PropTypes.string.isRequired, | ||
updateValue: PropTypes.func.isRequired, | ||
error: PropTypes.oneOfType( [ | ||
PropTypes.string, | ||
PropTypes.bool, | ||
] ), | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default CountryDropdown; |
59 changes: 59 additions & 0 deletions
59
client/extensions/woocommerce/woocommerce-services/components/dropdown/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FormFieldset from 'components/forms/form-fieldset'; | ||
import FormSelect from 'components/forms/form-select'; | ||
import FormLegend from 'components/forms/form-legend'; | ||
import FieldError from '../field-error'; | ||
import FieldDescription from '../field-description'; | ||
|
||
const Dropdown = ( { id, valuesMap, title, description, value, updateValue, error, disabled, className } ) => { | ||
const onChange = ( event ) => updateValue( event.target.value ); | ||
|
||
return ( | ||
<FormFieldset className={ className }> | ||
<FormLegend>{ title }</FormLegend> | ||
<FormSelect | ||
id={ id } | ||
name={ id } | ||
value={ value } | ||
onChange={ onChange } | ||
disabled={ Boolean( disabled ) } | ||
isError={ Boolean( error ) } > | ||
{ Object.keys( valuesMap ).map( key => { | ||
return ( | ||
<option | ||
key={ key } | ||
value={ key }> | ||
{ valuesMap[ key ] } | ||
</option> | ||
); | ||
} ) } | ||
</FormSelect> | ||
{ error ? <FieldError text={ error } /> : <FieldDescription text={ description } /> } | ||
</FormFieldset> | ||
); | ||
}; | ||
|
||
Dropdown.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
valuesMap: PropTypes.object.isRequired, | ||
title: PropTypes.string, | ||
description: PropTypes.string, | ||
value: PropTypes.string.isRequired, | ||
updateValue: PropTypes.func.isRequired, | ||
error: PropTypes.oneOfType( [ | ||
PropTypes.string, | ||
PropTypes.bool, | ||
] ), | ||
disabled: PropTypes.bool, | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default Dropdown; |
22 changes: 22 additions & 0 deletions
22
client/extensions/woocommerce/woocommerce-services/components/field-description/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FormSettingExplanation from 'components/forms/form-setting-explanation'; | ||
|
||
const FieldDescription = ( { text } ) => { | ||
return ( | ||
text ? <FormSettingExplanation>{ text }</FormSettingExplanation> : null | ||
); | ||
}; | ||
|
||
FieldDescription.propTypes = { | ||
text: PropTypes.string, | ||
}; | ||
|
||
export default FieldDescription; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
client/extensions/woocommerce/woocommerce-services/components/number-field/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FormFieldset from 'components/forms/form-fieldset'; | ||
import FormLabel from 'components/forms/form-label'; | ||
import NumberInput from './number-input'; | ||
import FieldError from '../field-error'; | ||
import FieldDescription from '../field-description'; | ||
|
||
const parseNumber = ( value ) => { | ||
if ( '' === value ) { | ||
return 0; | ||
} | ||
const float = Number.parseFloat( value ); | ||
return isNaN( float ) ? value : float; | ||
}; | ||
|
||
const NumberField = ( { id, title, description, value, placeholder, updateValue, error, className } ) => { | ||
const onChange = ( event ) => updateValue( parseNumber( event.target.value ) ); | ||
|
||
return ( | ||
<FormFieldset className={ className }> | ||
<FormLabel htmlFor={ id }>{ title }</FormLabel> | ||
<NumberInput | ||
id={ id } | ||
name={ id } | ||
placeholder={ placeholder } | ||
value={ value } | ||
onChange={ onChange } | ||
isError={ Boolean( error ) } | ||
/> | ||
{ error ? <FieldError text={ error } /> : <FieldDescription text={ description } /> } | ||
</FormFieldset> | ||
); | ||
}; | ||
|
||
NumberField.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
title: PropTypes.string, | ||
description: PropTypes.string, | ||
value: PropTypes.oneOfType( [ | ||
PropTypes.string, | ||
PropTypes.number, | ||
] ).isRequired, | ||
updateValue: PropTypes.func, | ||
error: PropTypes.oneOfType( [ | ||
PropTypes.string, | ||
PropTypes.bool, | ||
] ), | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default NumberField; |
60 changes: 60 additions & 0 deletions
60
client/extensions/woocommerce/woocommerce-services/components/number-field/number-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FormTextInput from 'components/forms/form-text-input'; | ||
|
||
export default class NumberInput extends Component { | ||
static propTypes = { | ||
onChange: PropTypes.func, | ||
}; | ||
|
||
static defaultProps = { | ||
onChange: () => {}, | ||
}; | ||
|
||
state = { | ||
focused: false, | ||
text: this.props.value, | ||
}; | ||
|
||
componentWillReceiveProps( nextProps ) { | ||
if ( ! this.state.focused && nextProps.value !== this.props.value ) { | ||
this.setState( { text: nextProps.value } ); | ||
} | ||
} | ||
|
||
handleChange = ( event ) => { | ||
this.setState( { text: event.target.value } ); | ||
this.props.onChange( event ); | ||
} | ||
|
||
handleBlur = ( event ) => { | ||
this.setState( { | ||
focused: false, | ||
text: this.props.value, | ||
} ); | ||
this.props.onChange( event ); | ||
} | ||
|
||
handleFocus = () => { | ||
this.setState( { focused: true } ); | ||
} | ||
|
||
render() { | ||
return ( | ||
<FormTextInput | ||
{ ...this.props } | ||
value={ this.state.text } | ||
onChange={ this.handleChange } | ||
onBlur={ this.handleBlur } | ||
onFocus={ this.handleFocus } | ||
/> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.