-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AC-312]: Improve Add-to-Cart Interaction (#110)
* [AC-312]: Improve Add-to-Cart Interaction * fix: add zustand * feat: Open cart dropdown when product is added from product page * fix: modify duration for auto-closing cart dropdown * fix: adjust toast notification position
- Loading branch information
1 parent
2a6b864
commit 13b7e11
Showing
8 changed files
with
180 additions
and
131 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
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,21 @@ | ||
import { create } from 'zustand' | ||
|
||
interface CartStore { | ||
isOpenCartDropdown: boolean | ||
openCartDropdown: () => void | ||
closeCartDropdown: () => void | ||
} | ||
|
||
export const useCartStore = create<CartStore>((set) => { | ||
return { | ||
isOpenCartDropdown: false, | ||
openCartDropdown: () => | ||
set(() => ({ | ||
isOpenCartDropdown: true, | ||
})), | ||
closeCartDropdown: () => | ||
set(() => ({ | ||
isOpenCartDropdown: false, | ||
})), | ||
} | ||
}) |
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 |
---|---|---|
@@ -1,24 +1,9 @@ | ||
import { enrichLineItems, retrieveCart } from '@lib/data/cart' | ||
import { retrieveCart } from '@lib/data/cart' | ||
|
||
import CartDropdown from '../cart-dropdown' | ||
|
||
const fetchCart = async () => { | ||
const cart = await retrieveCart() | ||
|
||
if (!cart) { | ||
return null | ||
} | ||
|
||
if (cart?.items?.length) { | ||
const enrichedItems = await enrichLineItems(cart.items, cart.region_id!) | ||
cart.items = enrichedItems | ||
} | ||
|
||
return cart | ||
} | ||
|
||
export default async function CartButton() { | ||
const cart = await fetchCart() | ||
const cart = await retrieveCart() | ||
|
||
return <CartDropdown cart={cart} /> | ||
} |
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
Oops, something went wrong.