handle plan base and permium
This commit is contained in:
@@ -12,7 +12,11 @@ import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileD
|
|||||||
import { useGetCartItems } from '../hooks/useCartData';
|
import { useGetCartItems } from '../hooks/useCartData';
|
||||||
import { useCartStore } from '../store/Store';
|
import { useCartStore } from '../store/Store';
|
||||||
|
|
||||||
const CartSummary = () => {
|
interface CartSummaryProps {
|
||||||
|
isPremium: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CartSummary = ({ isPremium }: CartSummaryProps) => {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
@@ -62,20 +66,22 @@ const CartSummary = () => {
|
|||||||
<>
|
<>
|
||||||
{!isCartEmpty && (
|
{!isCartEmpty && (
|
||||||
<>
|
<>
|
||||||
<div className='mt-2'>
|
{isPremium && (
|
||||||
<div className='relative'>
|
<div className='mt-2 mb-4'>
|
||||||
<h3 className='text-sm'>{t('InputDescription.Label')}</h3>
|
<div className='relative'>
|
||||||
<textarea
|
<h3 className='text-sm'>{t('InputDescription.Label')}</h3>
|
||||||
className='w-full px-4 py-2.5 mt-4 text-sm2 leading-6 outline-0 border border-border rounded-normal resize-none focus:ring-0'
|
<textarea
|
||||||
placeholder={t('InputDescription.Placeholder')}
|
className='w-full px-4 py-2.5 mt-4 text-sm2 leading-6 outline-0 border border-border rounded-normal resize-none focus:ring-0'
|
||||||
id='description'
|
placeholder={t('InputDescription.Placeholder')}
|
||||||
name='description'
|
id='description'
|
||||||
value={description}
|
name='description'
|
||||||
onChange={(e) => setDescription(e.target.value)}
|
value={description}
|
||||||
></textarea>
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
<span className='absolute top-4 right-2 px-2 bg-background text-foreground text-xs'></span>
|
></textarea>
|
||||||
|
<span className='absolute top-4 right-2 px-2 bg-background text-foreground text-xs'></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
|
||||||
<div className='fixed bottom-0 left-0 right-0 z-50 bg-white border-t border-border p-4 w-full'>
|
<div className='fixed bottom-0 left-0 right-0 z-50 bg-white border-t border-border p-4 w-full'>
|
||||||
<div className='flex justify-between items-center gap-4'>
|
<div className='flex justify-between items-center gap-4'>
|
||||||
@@ -84,19 +90,21 @@ const CartSummary = () => {
|
|||||||
<div className='text-sm mt-2 font-semibold'>{formatPrice(totalPrice)} تومان</div>
|
<div className='text-sm mt-2 font-semibold'>{formatPrice(totalPrice)} تومان</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Link
|
{isPremium && (
|
||||||
href={'order/checkout/0'}
|
<Link
|
||||||
onClick={(event) => {
|
href={'order/checkout/0'}
|
||||||
if (!isSuccess) {
|
onClick={(event) => {
|
||||||
event.preventDefault();
|
if (!isSuccess) {
|
||||||
const redirectUrl = encodeURIComponent(pathname);
|
event.preventDefault();
|
||||||
router.replace(`/${name}/auth?redirect=${redirectUrl}`);
|
const redirectUrl = encodeURIComponent(pathname);
|
||||||
return;
|
router.replace(`/${name}/auth?redirect=${redirectUrl}`);
|
||||||
}
|
return;
|
||||||
}}
|
}
|
||||||
>
|
}}
|
||||||
<Button className='w-fit! px-10'>{t('ButtonCheckout')}</Button>
|
>
|
||||||
</Link>
|
<Button className='w-fit! px-10'>{t('ButtonCheckout')}</Button>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -13,13 +13,20 @@ import VerticalScrollView from '@/components/listview/VerticalScrollView';
|
|||||||
import MenuItem from '@/components/listview/MenuItem';
|
import MenuItem from '@/components/listview/MenuItem';
|
||||||
import MenuItemRenderer from '@/components/listview/MenuItemRenderer';
|
import MenuItemRenderer from '@/components/listview/MenuItemRenderer';
|
||||||
import type { Food } from '@/app/[name]/(Main)/types/Types';
|
import type { Food } from '@/app/[name]/(Main)/types/Types';
|
||||||
|
import { useGetAbout } from '../../(Main)/about/hooks/useAboutData';
|
||||||
|
import PagerModal from '@/components/pager/PagerModal';
|
||||||
|
import Button from '@/components/button/PrimaryButton';
|
||||||
|
import NotificationBellIcon from '@/components/icons/NotificationBellIcon';
|
||||||
|
|
||||||
const CartIndex = () => {
|
const CartIndex = () => {
|
||||||
const { t } = useTranslation('parallels', { keyPrefix: 'Cart' });
|
const { t } = useTranslation('parallels', { keyPrefix: 'Cart' });
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { clearCart, items } = useCart();
|
const { clearCart, items } = useCart();
|
||||||
const [showClearConfirm, setShowClearConfirm] = React.useState(false);
|
const [showClearConfirm, setShowClearConfirm] = React.useState(false);
|
||||||
|
const [showPagerModal, setShowPagerModal] = React.useState(false);
|
||||||
const { data: foodsResponse, isFetching } = useGetFoods();
|
const { data: foodsResponse, isFetching } = useGetFoods();
|
||||||
|
const { data: aboutData } = useGetAbout();
|
||||||
|
const isPremium = aboutData?.data?.plan === 'premium';
|
||||||
const foods = React.useMemo(() => foodsResponse?.data ?? [], [foodsResponse?.data]);
|
const foods = React.useMemo(() => foodsResponse?.data ?? [], [foodsResponse?.data]);
|
||||||
const isLoading = isFetching && !foods.length;
|
const isLoading = isFetching && !foods.length;
|
||||||
|
|
||||||
@@ -96,12 +103,36 @@ const CartIndex = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<VerticalScrollView className="overflow-y-auto h-full pb-24">
|
<VerticalScrollView className="overflow-y-auto h-full pb-24">
|
||||||
|
{!isPremium && (
|
||||||
|
<div className='mb-4 bg-container rounded-container p-4 border border-border shadow-sm'>
|
||||||
|
<div className='flex items-start gap-3 mb-4'>
|
||||||
|
<div className='shrink-0 mt-0.5'>
|
||||||
|
<NotificationBellIcon width={24} height={24} className="text-primary" />
|
||||||
|
</div>
|
||||||
|
<div className='flex-1'>
|
||||||
|
<p className='text-sm font-medium text-foreground mb-1'>
|
||||||
|
ثبت سفارش
|
||||||
|
</p>
|
||||||
|
<p className='text-xs text-muted-foreground leading-5'>
|
||||||
|
برای ثبت سفارش، لطفاً گارسون را صدا کنید
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={() => setShowPagerModal(true)}
|
||||||
|
className='w-full flex items-center justify-center gap-2'
|
||||||
|
>
|
||||||
|
<NotificationBellIcon width={18} height={18} className="text-white dark:text-foreground" />
|
||||||
|
<span>صدا کردن گارسون</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{cartFoods.map((food) => (
|
{cartFoods.map((food) => (
|
||||||
<MenuItemRenderer key={food.id}>
|
<MenuItemRenderer key={food.id}>
|
||||||
<MenuItem food={food} />
|
<MenuItem food={food} />
|
||||||
</MenuItemRenderer>
|
</MenuItemRenderer>
|
||||||
))}
|
))}
|
||||||
<CartSummary />
|
<CartSummary isPremium={isPremium} />
|
||||||
</VerticalScrollView>
|
</VerticalScrollView>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -118,6 +149,8 @@ const CartIndex = () => {
|
|||||||
onClick={toggleClearConfirm}
|
onClick={toggleClearConfirm}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<PagerModal visible={showPagerModal} onClose={() => setShowPagerModal(false)} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user