summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-migrate/modules/product-detail/components/PriceAction.tsx75
-rw-r--r--src-migrate/modules/product-detail/components/ProductDetail.tsx12
-rw-r--r--src-migrate/modules/product-detail/stores/useProductDetail.ts6
-rw-r--r--src-migrate/pages/shop/cart/cart.module.css4
-rw-r--r--src-migrate/pages/shop/cart/index.tsx2
-rw-r--r--src/lib/quotation/components/Quotation.jsx62
-rw-r--r--src/pages/index.jsx14
7 files changed, 124 insertions, 51 deletions
diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx
index f25847a5..d91ea49c 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -1,15 +1,16 @@
-import style from '../styles/price-action.module.css'
+import style from '../styles/price-action.module.css';
-import React, { useEffect } from 'react'
-import formatCurrency from '~/libs/formatCurrency'
-import { IProductDetail } from '~/types/product'
-import { useProductDetail } from '../stores/useProductDetail'
-import AddToCart from './AddToCart'
-import Link from 'next/link'
+import React, { useEffect } from 'react';
+import formatCurrency from '~/libs/formatCurrency';
+import { IProductDetail } from '~/types/product';
+import { useProductDetail } from '../stores/useProductDetail';
+import AddToCart from './AddToCart';
+import Link from 'next/link';
+import { getAuth } from '~/libs/auth';
type Props = {
- product: IProductDetail
-}
+ product: IProductDetail;
+};
const PriceAction = ({ product }: Props) => {
const {
@@ -18,15 +19,22 @@ const PriceAction = ({ product }: Props) => {
activeVariantId,
quantityInput,
setQuantityInput,
- askAdminUrl
- } = useProductDetail()
+ askAdminUrl,
+ isApproval,
+ setIsApproval,
+ } = useProductDetail();
useEffect(() => {
- setActive(product.variants[0])
+ setActive(product.variants[0]);
}, [product, setActive]);
+
+
return (
- <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10' id='price-section'>
+ <div
+ className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10'
+ id='price-section'
+ >
{!!activePrice && activePrice.price > 0 && (
<>
<div className='flex items-end gap-x-2'>
@@ -46,8 +54,8 @@ const PriceAction = ({ product }: Props) => {
</div>
<div className='h-1' />
<div className={style['secondary-text']}>
- Termasuk PPN: {' '}
- Rp {formatCurrency(Math.round(activePrice.price_discount * 1.11))}
+ Termasuk PPN: Rp{' '}
+ {formatCurrency(Math.round(activePrice.price_discount * 1.11))}
</div>
</>
)}
@@ -55,7 +63,11 @@ const PriceAction = ({ product }: Props) => {
{!!activePrice && activePrice.price === 0 && (
<span>
Hubungi kami untuk dapatkan harga terbaik,{' '}
- <Link href={askAdminUrl} target='_blank' className={style['contact-us']}>
+ <Link
+ href={askAdminUrl}
+ target='_blank'
+ className={style['contact-us']}
+ >
klik disini
</Link>
</span>
@@ -64,13 +76,30 @@ const PriceAction = ({ product }: Props) => {
<div className='h-4' />
<div className={style['action-wrapper']}>
- <label htmlFor="quantity" className='hidden'>Quantity</label>
- <input type='number' id='quantity' value={quantityInput} onChange={(e) => setQuantityInput(e.target.value)} className={style['quantity-input']} />
- <AddToCart variantId={activeVariantId} quantity={Number(quantityInput)} />
- <AddToCart source='buy' variantId={activeVariantId} quantity={Number(quantityInput)} />
+ <label htmlFor='quantity' className='hidden'>
+ Quantity
+ </label>
+ <input
+ type='number'
+ id='quantity'
+ value={quantityInput}
+ onChange={(e) => setQuantityInput(e.target.value)}
+ className={style['quantity-input']}
+ />
+ <AddToCart
+ variantId={activeVariantId}
+ quantity={Number(quantityInput)}
+ />
+ {!isApproval && (
+ <AddToCart
+ source='buy'
+ variantId={activeVariantId}
+ quantity={Number(quantityInput)}
+ />
+ )}
</div>
</div>
- )
-}
+ );
+};
-export default PriceAction \ No newline at end of file
+export default PriceAction;
diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx
index 3b1bdbea..6cd72353 100644
--- a/src-migrate/modules/product-detail/components/ProductDetail.tsx
+++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx
@@ -22,6 +22,7 @@ import PriceAction from './PriceAction'
import SimilarBottom from './SimilarBottom'
import SimilarSide from './SimilarSide'
import VariantList from './VariantList'
+import { getAuth } from '~/libs/auth'
type Props = {
product: IProductDetail
@@ -32,7 +33,8 @@ const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST
const ProductDetail = ({ product }: Props) => {
const { isDesktop, isMobile } = useDevice()
const router = useRouter()
- const { setAskAdminUrl, askAdminUrl, activeVariantId } = useProductDetail()
+ const auth = getAuth()
+ const { setAskAdminUrl, askAdminUrl, activeVariantId, setIsApproval, isApproval } = useProductDetail()
useEffect(() => {
const createdAskUrl = whatsappUrl({
@@ -48,6 +50,12 @@ const ProductDetail = ({ product }: Props) => {
setAskAdminUrl(createdAskUrl)
}, [router.asPath, product.manufacture.name, product.name, setAskAdminUrl])
+ useEffect(() => {
+ if (typeof auth === 'object') {
+ setIsApproval(auth?.feature?.soApproval);
+ }
+ }, []);
+
return (
<>
<div className='md:flex md:flex-wrap'>
@@ -115,7 +123,7 @@ const ProductDetail = ({ product }: Props) => {
)}
<div className='h-4 md:h-10' />
- {!!activeVariantId && <ProductPromoSection productId={activeVariantId} />}
+ {!!activeVariantId && !isApproval && <ProductPromoSection productId={activeVariantId} />}
<div className={style['section-card']}>
<h2 className={style['heading']}>
diff --git a/src-migrate/modules/product-detail/stores/useProductDetail.ts b/src-migrate/modules/product-detail/stores/useProductDetail.ts
index 794f0346..2da8835d 100644
--- a/src-migrate/modules/product-detail/stores/useProductDetail.ts
+++ b/src-migrate/modules/product-detail/stores/useProductDetail.ts
@@ -6,12 +6,14 @@ type State = {
activePrice: IProductVariantDetail['price'] | null;
quantityInput: string;
askAdminUrl: string;
+ isApproval : boolean;
};
type Action = {
setActive: (variant: IProductVariantDetail) => void;
setQuantityInput: (value: string) => void;
setAskAdminUrl: (url: string) => void;
+ setIsApproval : (value : boolean) => void;
};
export const useProductDetail = create<State & Action>((set, get) => ({
@@ -19,6 +21,7 @@ export const useProductDetail = create<State & Action>((set, get) => ({
activePrice: null,
quantityInput: '1',
askAdminUrl: '',
+ isApproval : false,
setActive: (variant) => {
set({ activeVariantId: variant.id, activePrice: variant.price });
},
@@ -28,4 +31,7 @@ export const useProductDetail = create<State & Action>((set, get) => ({
setAskAdminUrl: (url: string) => {
set({ askAdminUrl: url });
},
+ setIsApproval : (value : boolean) => {
+ set({ isApproval : value })
+ }
}));
diff --git a/src-migrate/pages/shop/cart/cart.module.css b/src-migrate/pages/shop/cart/cart.module.css
index 98a6ac86..806104be 100644
--- a/src-migrate/pages/shop/cart/cart.module.css
+++ b/src-migrate/pages/shop/cart/cart.module.css
@@ -29,3 +29,7 @@
.summary-buttons {
@apply grid grid-cols-2 gap-x-3 mt-6;
}
+
+.summary-buttons-step-approval {
+ @apply grid grid-cols-1 gap-y-3 mt-6;
+}
diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx
index e101b5ad..d89707d2 100644
--- a/src-migrate/pages/shop/cart/index.tsx
+++ b/src-migrate/pages/shop/cart/index.tsx
@@ -110,7 +110,7 @@ const CartPage = () => {
<CartSummary {...summary} isLoaded={!!cart} />
)}
- <div className={style['summary-buttons'] + isStepApproval ? '!grid-cols-1 mt-4' : ''}>
+ <div className={isStepApproval ? style['summary-buttons-step-approval'] : style['summary-buttons'] }>
<Tooltip
label={
hasSelectedPromo &&
diff --git a/src/lib/quotation/components/Quotation.jsx b/src/lib/quotation/components/Quotation.jsx
index 09d55e92..8855c6c4 100644
--- a/src/lib/quotation/components/Quotation.jsx
+++ b/src/lib/quotation/components/Quotation.jsx
@@ -68,6 +68,8 @@ const Quotation = () => {
const [etd, setEtd] = useState(null);
const [etdFix, setEtdFix] = useState(null);
+ const [isApproval, setIsApproval] = useState(false);
+
const expedisiValidation = useRef(null);
const [selectedAddress, setSelectedAddress] = useState({
@@ -86,6 +88,7 @@ const Quotation = () => {
};
getAddresses();
+ setIsApproval(auth?.feature?.soApproval);
}, [auth]);
useEffect(() => {
@@ -185,6 +188,13 @@ const Quotation = () => {
if (etd) setEtdFix(calculateEstimatedArrival(etd));
}, [etd]);
+ useEffect(() => {
+ if (isApproval) {
+ setselectedCarrierId(1);
+ setselectedExpedisiService('indoteknik');
+ }
+ }, [isApproval]);
+
// end set up address and carrier
useEffect(() => {
@@ -235,7 +245,7 @@ const Quotation = () => {
const checkout = async () => {
// validation checkout
- if (selectedExpedisi === 0) {
+ if (selectedExpedisi === 0 && !isApproval) {
setCheckoutValidation(true);
if (expedisiValidation.current) {
const position = expedisiValidation.current.getBoundingClientRect();
@@ -246,7 +256,7 @@ const Quotation = () => {
}
return;
}
- if (selectedCarrier != 1 && biayaKirim == 0) {
+ if (selectedCarrier != 1 && biayaKirim == 0 && !isApproval) {
toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
return;
}
@@ -267,7 +277,9 @@ const Quotation = () => {
estimated_arrival_days: splitDuration(etd),
delivery_service_type: selectedExpedisiService,
};
+ console.log('data checkout', data);
const isSuccess = await checkoutApi({ data });
+ console.log('isSuccess', isSuccess);
setIsLoading(false);
if (isSuccess?.id) {
for (const product of products) deleteItemCart({ productId: product.id });
@@ -343,16 +355,21 @@ const Quotation = () => {
)}
<Divider />
<SectionValidation address={selectedAddress.invoicing} />
- <SectionExpedisi
- address={selectedAddress.shipping}
- listExpedisi={listExpedisi}
- setSelectedExpedisi={setSelectedExpedisi}
- checkWeigth={checkWeigth}
- checkoutValidation={checkoutValidation}
- expedisiValidation={expedisiValidation}
- loadingRajaOngkir={loadingRajaOngkir}
- />
- <Divider />
+ {!isApproval && (
+ <>
+ <SectionExpedisi
+ address={selectedAddress.shipping}
+ listExpedisi={listExpedisi}
+ setSelectedExpedisi={setSelectedExpedisi}
+ checkWeigth={checkWeigth}
+ checkoutValidation={checkoutValidation}
+ expedisiValidation={expedisiValidation}
+ loadingRajaOngkir={loadingRajaOngkir}
+ />
+ <Divider />
+ </>
+ )}
+
<SectionListService
listserviceExpedisi={listserviceExpedisi}
setSelectedServiceType={setSelectedServiceType}
@@ -468,15 +485,18 @@ const Quotation = () => {
)}
<Divider />
<SectionValidation address={selectedAddress.invoicing} />
- <SectionExpedisi
- address={selectedAddress.shipping}
- listExpedisi={listExpedisi}
- setSelectedExpedisi={setSelectedExpedisi}
- checkWeigth={checkWeigth}
- checkoutValidation={checkoutValidation}
- expedisiValidation={expedisiValidation}
- loadingRajaOngkir={loadingRajaOngkir}
- />
+ {!isApproval && (
+ <SectionExpedisi
+ address={selectedAddress.shipping}
+ listExpedisi={listExpedisi}
+ setSelectedExpedisi={setSelectedExpedisi}
+ checkWeigth={checkWeigth}
+ checkoutValidation={checkoutValidation}
+ expedisiValidation={expedisiValidation}
+ loadingRajaOngkir={loadingRajaOngkir}
+ />
+ )}
+
<Divider />
<SectionListService
listserviceExpedisi={listserviceExpedisi}
diff --git a/src/pages/index.jsx b/src/pages/index.jsx
index c097530c..914fb266 100644
--- a/src/pages/index.jsx
+++ b/src/pages/index.jsx
@@ -11,6 +11,8 @@ import { FlashSaleSkeleton } from '@/lib/flashSale/skeleton/FlashSaleSkeleton';
import PreferredBrandSkeleton from '@/lib/home/components/Skeleton/PreferredBrandSkeleton';
import PromotinProgram from '@/lib/promotinProgram/components/HomePage';
import PagePopupIformation from '~/modules/popup-information';
+import useProductDetail from '~/modules/product-detail/stores/useProductDetail';
+import { getAuth } from '~/libs/auth';
const BasicLayout = dynamic(() =>
import('@/core/components/layouts/BasicLayout')
@@ -56,6 +58,8 @@ export default function Home() {
const bannerRef = useRef(null);
const wrapperRef = useRef(null);
+ const auth = getAuth();
+
const handleOnLoad = () => {
wrapperRef.current.style.height =
bannerRef.current?.querySelector(':first-child')?.clientHeight + 'px';
@@ -102,7 +106,7 @@ export default function Home() {
<div id='flashsale'>
<PreferredBrand />
</div>
- <FlashSale />
+ {!auth?.feature?.soApproval && <FlashSale />}
<PromotinProgram />
<CategoryHomeId />
<BannerSection />
@@ -124,9 +128,11 @@ export default function Home() {
<PreferredBrand />
</div>
</DelayRender>
- <DelayRender renderAfter={600}>
- <FlashSale />
- </DelayRender>
+ {!auth?.feature?.soApproval && (
+ <DelayRender renderAfter={600}>
+ <FlashSale />
+ </DelayRender>
+ )}
<DelayRender renderAfter={600}>
<PromotinProgram />
</DelayRender>