Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Mini Cart block - added notice support #7234

Merged
merged 25 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e1b9c32
Mini Cart block - added notice support #6941
gigitux Sep 27, 2022
df7547d
set isDismissible to true
gigitux Sep 28, 2022
178f3b4
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Oct 10, 2022
bec915e
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Oct 26, 2022
2d4a9a3
address feedback
gigitux Oct 26, 2022
0d7bbca
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Oct 27, 2022
49c8b61
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Oct 28, 2022
22935fe
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Oct 28, 2022
09389dd
improve layout
gigitux Oct 28, 2022
24a67f9
Merge branch 'fix/6941-add-validation-mini-cart' of https://github.co…
gigitux Oct 28, 2022
503d996
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Nov 14, 2022
9f3381f
fix style and update close button label
gigitux Nov 14, 2022
6153e35
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Nov 23, 2022
457e6f7
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Dec 9, 2022
3d05273
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Dec 9, 2022
c240714
fix UI when the admin bar is visible
gigitux Dec 9, 2022
63892ba
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Dec 12, 2022
74354fd
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Dec 13, 2022
538bbf7
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Dec 15, 2022
20c5292
Merge branch 'trunk' into fix/6941-add-validation-mini-cart
gigitux Dec 20, 2022
3b78ef2
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Dec 22, 2022
4ecb18f
Split out dismissible notices
mikejolley Dec 22, 2022
9de77aa
Merge branch 'fix/dismissible-notices' of https://github.com/woocomme…
gigitux Dec 22, 2022
4416792
fix css
gigitux Dec 22, 2022
103608f
Merge branch 'fix/6941-add-validation-mini-cart' of https://github.co…
gigitux Dec 22, 2022
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
5 changes: 1 addition & 4 deletions assets/js/base/components/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ const Drawer = ( {
slideOut,
}
) }
closeButtonLabel={ __(
'Close mini cart',
'woo-gutenberg-products-block'
) }
closeButtonLabel={ __( 'Close', 'woo-gutenberg-products-block' ) }
>
{ children }
</Modal>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/**
* External dependencies
*/
import { StoreNoticesContainer } from '@woocommerce/blocks-checkout';
import { useStoreCart } from '@woocommerce/base-context/hooks';

import { useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';

type FilledMiniCartContentsBlockProps = {
children: JSX.Element;
className: string;
Expand All @@ -12,13 +17,31 @@ const FilledMiniCartContentsBlock = ( {
children,
className,
}: FilledMiniCartContentsBlockProps ): JSX.Element | null => {
const { cartItems } = useStoreCart();
const { cartItems, cartItemErrors } = useStoreCart();

const { createErrorNotice } = useDispatch( 'core/notices' );

// Ensures any cart errors listed in the API response get shown.
useEffect( () => {
cartItemErrors.forEach( ( error ) => {
createErrorNotice( decodeEntities( error.message ), {
isDismissible: false,
danielwrobert marked this conversation as resolved.
Show resolved Hide resolved
id: error.code,
context: 'wc/cart',
} );
} );
}, [ createErrorNotice, cartItemErrors ] );

if ( cartItems.length === 0 ) {
return null;
}

return <div className={ className }>{ children }</div>;
return (
<div className={ className }>
<StoreNoticesContainer context="wc/cart" />
{ children }
</div>
);
};

export default FilledMiniCartContentsBlock;
41 changes: 37 additions & 4 deletions assets/js/blocks/mini-cart/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,42 @@
.wc-block-mini-cart__drawer {
font-size: 1rem;

.components-modal__content .components-modal__header .components-button {
padding: unset;
margin: unset;
}

.wc-block-components-notices {
margin: #{$gap} #{$gap-largest} -#{$gap} #{$gap};
margin-bottom: unset;

.wc-block-components-notices__notice {
margin-bottom: unset;
}
}

.components-modal__content {
padding: 0;
position: relative;
}

.components-modal__header {
position: relative;
height: calc($gap-largest + $gap);
position: absolute;
top: $gap-largest;
right: $gap;
right: $gap-smallest;


button {
color: inherit;
z-index: 9999;
margin: 0;
right: 0;
transform: translateY(-50%);
}

svg {
fill: currentColor;
display: block;
}
}
}
Expand All @@ -76,7 +95,7 @@

.wp-block-woocommerce-empty-mini-cart-contents-block,
.wp-block-woocommerce-filled-mini-cart-contents-block {
height: 100%;
height: 100vh;
display: flex;
flex-direction: column;
}
Expand Down Expand Up @@ -193,3 +212,17 @@ h2.wc-block-mini-cart__title {
}
}
}

.admin-bar .wp-block-woocommerce-mini-cart-contents {
margin-top: 32px;
}

.admin-bar .wp-block-woocommerce-mini-cart-contents,
.admin-bar .wp-block-woocommerce-empty-mini-cart-contents-block,
.admin-bar .wp-block-woocommerce-filled-mini-cart-contents-block {
height: calc(100vh - 32px);
}

.admin-bar .wc-block-components-drawer .components-modal__header .components-button {
top: 32px;
}