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

Pwa 3137 #4128

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 2 additions & 15 deletions packages/pagebuilder/lib/ContentTypes/Row/__tests__/row.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ test('render row with parallax initializes Jarallax', () => {
}
});

expect(mockJarallax).toHaveBeenCalledWith(true, {
speed: 0.75,
imgPosition: 'center center',
imgRepeat: 'repeat',
imgSize: 'cover'
});
expect(mockJarallax).toHaveBeenCalledWith(true, 'destroy');
});

test('render row with parallax initializes JarallaxVideo', () => {
Expand Down Expand Up @@ -99,15 +94,7 @@ test('row unmount causes Jarallax to be destroyed', () => {
});

expect(mockJarallax.mock.calls).toEqual([
[
true,
{
speed: 0.75,
imgPosition: 'top left',
imgRepeat: 'no-repeat',
imgSize: 'contain'
}
],
[true, 'destroy'],
[true, 'destroy']
]);
});
Expand Down
7 changes: 1 addition & 6 deletions packages/pagebuilder/lib/ContentTypes/Row/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,7 @@ const Row = props => {
if (enableParallax && bgImageStyle && backgroundType !== 'video') {
({ jarallax } = require('jarallax'));
parallaxElement = backgroundElement.current;
jarallax(parallaxElement, {
speed: parallaxSpeed,
imgSize: backgroundSize,
imgPosition: backgroundPosition,
imgRepeat: backgroundRepeat
});
jarallax(parallaxElement, 'destroy');
}

if (backgroundType === 'video') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ Array [
fieldInput="region[region]"
fieldSelect="region[region_id]"
optionValueKey="id"
validate={[Function]}
/>

</div>
<div
className="postcode"
Expand Down Expand Up @@ -827,8 +827,8 @@ Array [
fieldInput="region[region]"
fieldSelect="region[region_id]"
optionValueKey="id"
validate={[Function]}
/>

</div>
<div
className="postcode"
Expand Down Expand Up @@ -1364,8 +1364,8 @@ Array [
fieldInput="region[region]"
fieldSelect="region[region_id]"
optionValueKey="id"
validate={[Function]}
/>

</div>
<div
className="postcode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ Array [
fieldInput="region[region]"
fieldSelect="region[region_id]"
optionValueKey="id"
validate={[Function]}
/>

</div>
<div
className="postcode"
Expand Down Expand Up @@ -800,8 +800,8 @@ Array [
fieldInput="region[region]"
fieldSelect="region[region_id]"
optionValueKey="id"
validate={[Function]}
/>

</div>
<div
className="postcode"
Expand Down Expand Up @@ -1255,8 +1255,8 @@ Array [
fieldInput="region[region]"
fieldSelect="region[region_id]"
optionValueKey="id"
validate={[Function]}
/>

</div>
<div
className="postcode"
Expand Down Expand Up @@ -1736,8 +1736,8 @@ Array [
fieldInput="region[region]"
fieldSelect="region[region_id]"
optionValueKey="id"
validate={[Function]}
/>

</div>
<div
className="postcode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ const CustomerForm = props => {
<Text type="hidden" field="default_shipping" initialValue={true} />
);

const createErrorMessage = JSON.stringify(
errors.get('createCustomerAddressMutation')
);
const updateErrorMessage = JSON.stringify(
errors.get('updateCustomerAddressMutation')
);
const errorMessage = 'region_id is required for the specified country code';
const regionError =
createErrorMessage?.includes(errorMessage) ||
updateErrorMessage?.includes(errorMessage);

// errors
return (
<Fragment>
<FormError errors={Array.from(errors.values())} />
Expand Down Expand Up @@ -257,9 +269,10 @@ const CustomerForm = props => {
/>
</Field>
</div>

<div className={classes.region}>
<Region
validate={isRequired}
regionError={regionError}
data-cy="CustomerForm-region"
fieldInput={'region[region]'}
fieldSelect={'region[region_id]'}
Expand All @@ -269,7 +282,20 @@ const CustomerForm = props => {
defaultMessage: 'State Required'
})}
/>
{regionError ? (
<Message>
<div className={classes.regionError}>
<FormattedMessage
id={'validation.isRequired'}
defaultMessage={'isRequired'}
/>
</div>
</Message>
) : (
''
)}
</div>

<div className={classes.postcode}>
<Postcode
validate={isRequired}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
composes: p-xs from global;
}

.regionError {
color: brown;
font-weight: 600;
}

@media (max-width: 959px) {
.firstname {
grid-column: 1 / span 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ const GuestForm = props => {
}
}, [addToast, formatMessage, showSignInToast, handleToastAction]);

const createErrorMessage = JSON.stringify(
errors.get('createCustomerAddressMutation')
);
const updateErrorMessage = JSON.stringify(
errors.get('updateCustomerAddressMutation')
);
const errorMessage = 'region_id is required for the specified country code';
const regionError =
createErrorMessage?.includes(errorMessage) ||
updateErrorMessage?.includes(errorMessage);

return (
<Fragment>
<FormError errors={Array.from(errors.values())} />
Expand Down Expand Up @@ -308,7 +319,6 @@ const GuestForm = props => {
id: 'region.label',
defaultMessage: 'State'
})}
validate={isRequired}
fieldInput={'region[region]'}
fieldSelect={'region[region_id]'}
optionValueKey={'id'}
Expand All @@ -318,6 +328,18 @@ const GuestForm = props => {
defaultMessage: 'State Required'
})}
/>
{regionError ? (
<Message>
<div className={classes.regionError}>
<FormattedMessage
id={'validation.isRequired'}
defaultMessage={'isRequired'}
/>
</div>
</Message>
) : (
''
)}
</div>
<div className={classes.postcode}>
<Postcode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
composes: p-xs from global;
}

.regionError {
color: brown;
font-weight: 600;
}

@media (max-width: 959px) {
.firstname {
grid-column: 1 / span 2;
Expand Down
9 changes: 8 additions & 1 deletion packages/venia-ui/lib/components/Region/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { GET_REGIONS_QUERY } from './region.gql';
const Region = props => {
const {
classes: propClasses,
regionError,
countryCodeField,
fieldInput,
fieldSelect,
Expand Down Expand Up @@ -47,13 +48,19 @@ const Region = props => {
const regionField =
regions.length || loading ? (
<Select
regionError={regionError}
{...regionProps}
field={fieldSelect}
id={classes.root}
items={regions}
/>
) : (
<TextInput {...regionProps} field={fieldInput} id={classes.root} />
<TextInput
{...regionProps}
field={fieldInput}
id={classes.root}
regionError={regionError}
/>
);

return (
Expand Down
4 changes: 3 additions & 1 deletion packages/venia-ui/lib/components/Select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ const Select = props => {
const {
before,
classes: propClasses,
regionError,
field,
items,
message,
...rest
} = props;
const fieldState = useFieldState(field);
const classes = useStyle(defaultClasses, propClasses);
const inputClass = fieldState.error ? classes.input_error : classes.input;
const inputClass =
fieldState.error || regionError ? classes.input_error : classes.input;

const options = items.map(
({ disabled = null, hidden = null, label, value, key = value }) => (
Expand Down
4 changes: 3 additions & 1 deletion packages/venia-ui/lib/components/TextInput/textInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const TextInput = props => {
after,
before,
classes: propClasses,
regionError,
field,
message,
...rest
} = props;
const fieldState = useFieldState(field);
const classes = useStyle(defaultClasses, propClasses);
const inputClass = fieldState.error ? classes.input_error : classes.input;
var inputClass =
fieldState.error || regionError ? classes.input_error : classes.input;

return (
<Fragment>
Expand Down