|
@@ -14,7 +14,7 @@ import { useMergeCart } from "@utils/hooks/useMergeCart";
|
|
|
|
|
|
|
|
import { getCookie, setCookie } from "@/utils/cookie-tools";
|
|
import { getCookie, setCookie } from "@/utils/cookie-tools";
|
|
|
import { setLocalStorage } from "@/store/local-storage";
|
|
import { setLocalStorage } from "@/store/local-storage";
|
|
|
-import { useAppDispatch } from "@/store/hooks";
|
|
|
|
|
|
|
+import { useAppDispatch, useAppSelector } from "@/store/hooks";
|
|
|
import { setUser } from "@/store/slices/user-slice";
|
|
import { setUser } from "@/store/slices/user-slice";
|
|
|
import { useCartDetail } from "@utils/hooks/useCartDetail";
|
|
import { useCartDetail } from "@utils/hooks/useCartDetail";
|
|
|
import { GUEST_CART_ID, GUEST_CART_TOKEN, IS_GUEST } from "@/utils/constants";
|
|
import { GUEST_CART_ID, GUEST_CART_TOKEN, IS_GUEST } from "@/utils/constants";
|
|
@@ -30,7 +30,7 @@ export default function LoginForm() {
|
|
|
const { showToast } = useCustomToast();
|
|
const { showToast } = useCustomToast();
|
|
|
const { getCartDetail } = useCartDetail()
|
|
const { getCartDetail } = useCartDetail()
|
|
|
const { mergeCart } = useMergeCart();
|
|
const { mergeCart } = useMergeCart();
|
|
|
-
|
|
|
|
|
|
|
+ const cart = useAppSelector((state) => state.cartDetail.cart);
|
|
|
const {
|
|
const {
|
|
|
register,
|
|
register,
|
|
|
handleSubmit,
|
|
handleSubmit,
|
|
@@ -78,7 +78,9 @@ export default function LoginForm() {
|
|
|
// Only merge cart if user had a guest cart before login
|
|
// Only merge cart if user had a guest cart before login
|
|
|
if (userToken && guestCartId && guestCartToken) {
|
|
if (userToken && guestCartId && guestCartToken) {
|
|
|
try {
|
|
try {
|
|
|
- await mergeCart({ variables: { token: userToken, cartId: parseInt(guestCartId, 10) } });
|
|
|
|
|
|
|
+ if(cart) {
|
|
|
|
|
+ await mergeCart({ variables: { token: userToken, cartId: parseInt(guestCartId, 10) } });
|
|
|
|
|
+ }
|
|
|
setCookie(GUEST_CART_TOKEN, userToken);
|
|
setCookie(GUEST_CART_TOKEN, userToken);
|
|
|
setCookie(IS_GUEST, "false");
|
|
setCookie(IS_GUEST, "false");
|
|
|
await getCartDetail();
|
|
await getCartDetail();
|