This commit is contained in:
@kirill.komarov
2026-05-11 15:14:35 +05:00
parent 20096c1eec
commit 4eda6d0f81
20 changed files with 299 additions and 56 deletions
+23 -10
View File
@@ -19,6 +19,7 @@ import { Link as RouterLink, useNavigate } from 'react-router-dom'
import { fetchMyCart } from '@/entities/cart/api/cart-api'
import { createOrder } from '@/entities/order/api/order-api'
import { fetchMyAddresses } from '@/entities/user/api/address-api'
import { DELIVERY_CARRIER_OPTIONS, type DeliveryCarrierCode } from '@/shared/constants/delivery-carrier'
import { formatPriceRub } from '@/shared/lib/format-price'
import { $user } from '@/shared/model/auth'
@@ -28,6 +29,7 @@ export function CheckoutPage() {
const navigate = useNavigate()
const [deliveryType, setDeliveryType] = useState<'delivery' | 'pickup'>('delivery')
const [pickupPayment, setPickupPayment] = useState<'online' | 'on_pickup'>('online')
const [deliveryCarrier, setDeliveryCarrier] = useState<DeliveryCarrierCode>('RUSSIAN_POST')
const [addressId, setAddressId] = useState('')
const [comment, setComment] = useState('')
@@ -50,6 +52,7 @@ export function CheckoutPage() {
mutationFn: () =>
createOrder({
deliveryType,
deliveryCarrier: deliveryType === 'delivery' ? deliveryCarrier : null,
paymentMethod: deliveryType === 'delivery' ? 'online' : pickupPayment,
addressId: deliveryType === 'delivery' ? selectedAddressId : null,
comment: comment.trim() || null,
@@ -74,9 +77,7 @@ export function CheckoutPage() {
const items = cartQuery.data?.items ?? []
const itemsSubtotalCents = items.reduce((s, x) => s + x.product.priceCents * x.qty, 0)
const totalQty = items.reduce((s, x) => s + x.qty, 0)
const deliveryFeeCents =
deliveryType === 'delivery' && items.length > 0 ? 50000 * Math.max(1, Math.ceil(totalQty / 2)) : 0
const deliveryFeeCents = deliveryType === 'delivery' && items.length > 0 ? 50000 : 0
const total = itemsSubtotalCents + deliveryFeeCents
const addresses = addressesQuery.data?.items ?? []
const hasOverLimit = items.some((x) => x.qty > (x.product.inStock ? x.product.quantity : 1))
@@ -153,6 +154,23 @@ export function CheckoutPage() {
{deliveryType === 'delivery' && (
<>
<Box>
<Typography variant="subtitle2" gutterBottom sx={{ mt: 0.5 }}>
Служба доставки
</Typography>
<RadioGroup
value={deliveryCarrier}
onChange={(e) => {
const v = String(e.target.value) as DeliveryCarrierCode
setDeliveryCarrier(v)
}}
>
{DELIVERY_CARRIER_OPTIONS.map((o) => (
<FormControlLabel key={o.code} value={o.code} control={<Radio size="small" />} label={o.label} />
))}
</RadioGroup>
</Box>
<FormControl size="small" fullWidth>
<InputLabel id="addr-label">Адрес доставки</InputLabel>
<Select
@@ -180,13 +198,8 @@ export function CheckoutPage() {
)}
<Alert severity="info">
Стоимость доставки: 500 за каждые 2 единицы (минимум 500 ).
{items.length > 0 && (
<>
{' '}
В этом заказе: {totalQty} шт. доставка {formatPriceRub(deliveryFeeCents)}.
</>
)}
Стоимость доставки ориентировочно 300 . Точная цена будет скорректирована после расчёта. В сумме заказа
сейчас заложено {items.length > 0 ? formatPriceRub(deliveryFeeCents) : '500 ₽'} до уточнения.
</Alert>
</>
)}