summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/checkout/components/Checkout.jsx3
-rw-r--r--src/lib/product/components/Product/ProductDesktopVariant.jsx34
2 files changed, 31 insertions, 6 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index a1b0116a..0e180d9c 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -67,7 +67,6 @@ const Checkout = () => {
const getAddresses = async () => {
const dataAddresses = await addressesApi();
- console.log('ini adalah adress',dataAddresses);
setAddresses(dataAddresses);
};
@@ -1665,7 +1664,7 @@ const SectionAddress = ({ address, label, url }) => (
);
const SectionValidation = ({ address }) =>
- address?.stateId == null && (
+ address?.stateId == 0 && (
<BottomPopup active={true} title='Update Alamat'>
<div className='leading-7 text-gray_r-12/80'>
Mohon untuk memperbarui alamat Anda dengan mengklik tombol di bawah ini.{' '}
diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx
index 09b30a44..4dd2ce3e 100644
--- a/src/lib/product/components/Product/ProductDesktopVariant.jsx
+++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx
@@ -1,4 +1,3 @@
-
import { Box, Skeleton, Tooltip } from '@chakra-ui/react';
import { HeartIcon } from '@heroicons/react/24/outline';
import { Info } from 'lucide-react';
@@ -18,6 +17,7 @@ import { updateItemCart } from '@/core/utils/cart';
import currencyFormat from '@/core/utils/currencyFormat';
import { createSlug } from '@/core/utils/slug';
import whatsappUrl from '@/core/utils/whatsappUrl';
+import { getAuth } from '~/libs/auth';
import productSimilarApi from '../../api/productSimilarApi';
import ProductCard from '../ProductCard';
@@ -30,7 +30,7 @@ const ProductDesktopVariant = ({
isVariant,
}) => {
const router = useRouter();
- const auth = useAuth();
+ let auth = useAuth();
const { slug } = router.query;
const [lowestPrice, setLowestPrice] = useState(null);
@@ -91,8 +91,34 @@ const ProductDesktopVariant = ({
setAddCartAlert(true);
};
- const handleBuy = (variant) => {
- const quantity = variantQuantityRefs.current[product.id].value;
+ const handleBuy = async (variant) => {
+ const quantity = variantQuantityRefs?.current[product.id]?.value;
+ let isLoggedIn = typeof auth === 'object';
+
+ if (!isLoggedIn) {
+ const currentUrl = encodeURIComponent(router.asPath);
+ await router.push(`/login?next=${currentUrl}`);
+
+ // Tunggu login berhasil, misalnya dengan memantau perubahan status auth.
+ const authCheckInterval = setInterval(() => {
+ const newAuth = getAuth();
+ if (typeof newAuth === 'object') {
+ isLoggedIn = true;
+ auth = newAuth; // Update nilai auth setelah login
+ clearInterval(authCheckInterval);
+ }
+ }, 500); // Periksa status login setiap 500ms
+
+ await new Promise((resolve) => {
+ const checkLogin = setInterval(() => {
+ if (isLoggedIn) {
+ clearInterval(checkLogin);
+ resolve(null);
+ }
+ }, 500);
+ });
+ }
+
if (!validQuantity(quantity)) return;
updateItemCart({