refactor: remove duplicate order status labels, use ORDER_STATUS_DATA as single source
This commit is contained in:
@@ -19,7 +19,7 @@ import { getAdminNextOrderStatuses } from '@/shared/constants/order'
|
|||||||
import { formatPriceRub } from '@/shared/lib/format-price'
|
import { formatPriceRub } from '@/shared/lib/format-price'
|
||||||
import { invalidateQueryKeys } from '@/shared/lib/invalidate-query-keys'
|
import { invalidateQueryKeys } from '@/shared/lib/invalidate-query-keys'
|
||||||
import { parseOrderAddressSnapshot } from '@/shared/lib/order-address-snapshot'
|
import { parseOrderAddressSnapshot } from '@/shared/lib/order-address-snapshot'
|
||||||
import { orderStatusLabelRu } from '@/shared/lib/order-status-labels'
|
import { ORDER_STATUS_MAP } from '@/shared/lib/order-status-data'
|
||||||
import { $user } from '@/shared/model/auth'
|
import { $user } from '@/shared/model/auth'
|
||||||
import { ChatMessageBubble } from '@/shared/ui/ChatMessageBubble'
|
import { ChatMessageBubble } from '@/shared/ui/ChatMessageBubble'
|
||||||
import { OrderMessageBody } from '@/shared/ui/OrderMessageBody'
|
import { OrderMessageBody } from '@/shared/ui/OrderMessageBody'
|
||||||
@@ -66,7 +66,7 @@ export function OrderDetailContent({ detail, orderId }: { detail: AdminOrderDeta
|
|||||||
return (
|
return (
|
||||||
<Stack spacing={2} sx={{ mt: 1 }}>
|
<Stack spacing={2} sx={{ mt: 1 }}>
|
||||||
<Typography sx={{ fontWeight: 700 }}>
|
<Typography sx={{ fontWeight: 700 }}>
|
||||||
#{detail.id.slice(-8)} · {detail.user.email} · {orderStatusLabelRu(detail.status)} ·{' '}
|
#{detail.id.slice(-8)} · {detail.user.email} · {ORDER_STATUS_MAP[detail.status] ?? detail.status} ·{' '}
|
||||||
{formatPriceRub(detail.totalCents)}
|
{formatPriceRub(detail.totalCents)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="body2" color="text.secondary">
|
<Typography variant="body2" color="text.secondary">
|
||||||
@@ -184,7 +184,7 @@ export function OrderDetailContent({ detail, orderId }: { detail: AdminOrderDeta
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
{nextStatuses.map((s) => (
|
{nextStatuses.map((s) => (
|
||||||
<MenuItem key={s} value={s}>
|
<MenuItem key={s} value={s}>
|
||||||
{orderStatusLabelRu(s)}
|
{ORDER_STATUS_MAP[s] ?? s}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import Button from '@mui/material/Button'
|
import Button from '@mui/material/Button'
|
||||||
import Typography from '@mui/material/Typography'
|
import Typography from '@mui/material/Typography'
|
||||||
import { orderStatusLabelRu } from '@/shared/lib/order-status-labels'
|
import { ORDER_STATUS_MAP } from '@/shared/lib/order-status-data'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
status: string
|
status: string
|
||||||
@@ -43,7 +43,7 @@ export function OrderPaymentSection({ status, deliveryFeeLocked, paymentMethod,
|
|||||||
<>
|
<>
|
||||||
<Typography color="text.secondary" variant="body2" sx={{ mb: 1 }}>
|
<Typography color="text.secondary" variant="body2" sx={{ mb: 1 }}>
|
||||||
Вы будете перенаправлены на защищённую платёжную страницу ЮKassa. После оплаты заказ получит статус «
|
Вы будете перенаправлены на защищённую платёжную страницу ЮKassa. После оплаты заказ получит статус «
|
||||||
{orderStatusLabelRu('PAID')}».
|
{ORDER_STATUS_MAP['PAID'] ?? 'PAID'}».
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button variant="contained" onClick={onPay} disabled={isPayPending}>
|
<Button variant="contained" onClick={onPay} disabled={isPayPending}>
|
||||||
{isPayPending ? 'Создание платежа…' : 'Оплатить'}
|
{isPayPending ? 'Создание платежа…' : 'Оплатить'}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { OrderDetailContent } from '@/features/order-detail/ui/OrderDetailConten
|
|||||||
import { ORDER_STATUSES } from '@/shared/constants/order'
|
import { ORDER_STATUSES } from '@/shared/constants/order'
|
||||||
import { formatPriceRub } from '@/shared/lib/format-price'
|
import { formatPriceRub } from '@/shared/lib/format-price'
|
||||||
import { groupOrdersByStatus } from '@/shared/lib/group-orders-by-status'
|
import { groupOrdersByStatus } from '@/shared/lib/group-orders-by-status'
|
||||||
import { orderStatusLabelRu } from '@/shared/lib/order-status-labels'
|
import { ORDER_STATUS_MAP } from '@/shared/lib/order-status-data'
|
||||||
import { AdminDialog } from '@/shared/ui/AdminDialog/AdminDialog'
|
import { AdminDialog } from '@/shared/ui/AdminDialog/AdminDialog'
|
||||||
|
|
||||||
export function AdminOrdersPage() {
|
export function AdminOrdersPage() {
|
||||||
@@ -87,7 +87,7 @@ export function AdminOrdersPage() {
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
{ORDER_STATUSES.map((s) => (
|
{ORDER_STATUSES.map((s) => (
|
||||||
<MenuItem key={s} value={s}>
|
<MenuItem key={s} value={s}>
|
||||||
{orderStatusLabelRu(s)}
|
{ORDER_STATUS_MAP[s] ?? s}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
@@ -130,7 +130,7 @@ export function AdminOrdersPage() {
|
|||||||
<Fragment key={`group:${group.statusCode}`}>
|
<Fragment key={`group:${group.statusCode}`}>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={6} sx={{ fontWeight: 700, bgcolor: 'action.hover' }}>
|
<TableCell colSpan={6} sx={{ fontWeight: 700, bgcolor: 'action.hover' }}>
|
||||||
{orderStatusLabelRu(group.statusCode)} ({group.items.length})
|
{ORDER_STATUS_MAP[group.statusCode] ?? group.statusCode} ({group.items.length})
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
{group.items.map((o) => (
|
{group.items.map((o) => (
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { Link as RouterLink } from 'react-router-dom'
|
|||||||
import { fetchMyOrder, postOrderMessage } from '@/entities/order/api/order-api'
|
import { fetchMyOrder, postOrderMessage } from '@/entities/order/api/order-api'
|
||||||
import { fetchMyConversations, markOrderMessagesRead } from '@/entities/user/api/messages-api'
|
import { fetchMyConversations, markOrderMessagesRead } from '@/entities/user/api/messages-api'
|
||||||
import { fetchAdminAvatar } from '@/entities/user/api/user-api'
|
import { fetchAdminAvatar } from '@/entities/user/api/user-api'
|
||||||
import { orderStatusLabelRu } from '@/shared/lib/order-status-labels'
|
import { ORDER_STATUS_MAP } from '@/shared/lib/order-status-data'
|
||||||
import { usePageTitle } from '@/shared/lib/use-page-title'
|
import { usePageTitle } from '@/shared/lib/use-page-title'
|
||||||
import { $user } from '@/shared/model/auth'
|
import { $user } from '@/shared/model/auth'
|
||||||
import { ChatMessageBubble } from '@/shared/ui/ChatMessageBubble'
|
import { ChatMessageBubble } from '@/shared/ui/ChatMessageBubble'
|
||||||
@@ -125,7 +125,7 @@ export function MessagesPage() {
|
|||||||
№{c.orderId.slice(-6)}
|
№{c.orderId.slice(-6)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography component="span" variant="caption" color="text.secondary">
|
<Typography component="span" variant="caption" color="text.secondary">
|
||||||
· {orderStatusLabelRu(c.status)}
|
· {ORDER_STATUS_MAP[c.status] ?? c.status}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ export function MessagesPage() {
|
|||||||
<Typography variant="h6">
|
<Typography variant="h6">
|
||||||
Чат заказа №{order.id.slice(-6)}{' '}
|
Чат заказа №{order.id.slice(-6)}{' '}
|
||||||
<Typography component="span" variant="body2" color="text.secondary">
|
<Typography component="span" variant="body2" color="text.secondary">
|
||||||
({orderStatusLabelRu(order.status)})
|
({ORDER_STATUS_MAP[order.status] ?? order.status})
|
||||||
</Typography>
|
</Typography>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button component={RouterLink} to={`/me/orders/${order.id}`} size="small" variant="outlined">
|
<Button component={RouterLink} to={`/me/orders/${order.id}`} size="small" variant="outlined">
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { fetchMyOrders } from '@/entities/order/api/order-api'
|
|||||||
import { ORDER_STATUSES } from '@/shared/constants/order'
|
import { ORDER_STATUSES } from '@/shared/constants/order'
|
||||||
import { formatPriceRub } from '@/shared/lib/format-price'
|
import { formatPriceRub } from '@/shared/lib/format-price'
|
||||||
import { groupOrdersByStatus } from '@/shared/lib/group-orders-by-status'
|
import { groupOrdersByStatus } from '@/shared/lib/group-orders-by-status'
|
||||||
import { orderStatusLabelRu } from '@/shared/lib/order-status-labels'
|
import { ORDER_STATUS_MAP } from '@/shared/lib/order-status-data'
|
||||||
import { usePageTitle } from '@/shared/lib/use-page-title'
|
import { usePageTitle } from '@/shared/lib/use-page-title'
|
||||||
|
|
||||||
export function OrdersPage() {
|
export function OrdersPage() {
|
||||||
@@ -40,7 +40,7 @@ export function OrdersPage() {
|
|||||||
{groups.map((group) => (
|
{groups.map((group) => (
|
||||||
<Box key={group.status}>
|
<Box key={group.status}>
|
||||||
<Typography variant="h6" sx={{ mb: 1 }}>
|
<Typography variant="h6" sx={{ mb: 1 }}>
|
||||||
{orderStatusLabelRu(group.status)} ({group.items.length})
|
{ORDER_STATUS_MAP[group.status] ?? group.status} ({group.items.length})
|
||||||
</Typography>
|
</Typography>
|
||||||
<Stack spacing={2}>
|
<Stack spacing={2}>
|
||||||
{group.items.map((o) => (
|
{group.items.map((o) => (
|
||||||
|
|||||||
@@ -73,3 +73,7 @@ export const ORDER_STATUS_DATA: ReadonlyArray<OrderStatusData> = [
|
|||||||
export function getOrderStatusData(code: string): OrderStatusData | undefined {
|
export function getOrderStatusData(code: string): OrderStatusData | undefined {
|
||||||
return ORDER_STATUS_DATA.find((s) => s.code === code)
|
return ORDER_STATUS_DATA.find((s) => s.code === code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ORDER_STATUS_MAP: Record<string, string> = Object.fromEntries(
|
||||||
|
ORDER_STATUS_DATA.map((s) => [s.code, s.label]),
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
/** Человекочитаемые подписи к кодам статуса заказа */
|
|
||||||
export function orderStatusLabelRu(code: string): string {
|
|
||||||
const map: Record<string, string> = {
|
|
||||||
DRAFT: 'Черновик',
|
|
||||||
PENDING_PAYMENT: 'Ожидает оплаты',
|
|
||||||
PAID: 'Оплачен',
|
|
||||||
IN_PROGRESS: 'Подготовка к отправке',
|
|
||||||
SHIPPED: 'Отправлен',
|
|
||||||
READY_FOR_PICKUP: 'Готово к получению',
|
|
||||||
DONE: 'Завершён',
|
|
||||||
CANCELLED: 'Отменён',
|
|
||||||
}
|
|
||||||
return map[code] ?? code
|
|
||||||
}
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user