base commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { CartItem } from '@/entities/cart/model/types'
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
|
||||
export type CartResponse = { items: CartItem[] }
|
||||
|
||||
export async function fetchMyCart(): Promise<CartResponse> {
|
||||
const { data } = await apiClient.get<CartResponse>('me/cart')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function addToCart(body: { productId: string; qty?: number }): Promise<void> {
|
||||
await apiClient.post('me/cart/items', body)
|
||||
}
|
||||
|
||||
export async function setCartQty(id: string, qty: number): Promise<void> {
|
||||
await apiClient.patch(`me/cart/items/${id}`, { qty })
|
||||
}
|
||||
|
||||
export async function removeCartItem(id: string): Promise<void> {
|
||||
await apiClient.delete(`me/cart/items/${id}`)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { Product } from '@/entities/product/model/types'
|
||||
|
||||
export type CartItem = {
|
||||
id: string
|
||||
qty: number
|
||||
product: Product
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
|
||||
export type AdminOrderListItem = {
|
||||
id: string
|
||||
status: string
|
||||
totalCents: number
|
||||
currency: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
user: { id: string; email: string }
|
||||
itemsCount: number
|
||||
}
|
||||
|
||||
export type AdminOrdersListResponse = {
|
||||
items: AdminOrderListItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
export type AdminOrderDetailResponse = {
|
||||
item: {
|
||||
id: string
|
||||
status: string
|
||||
totalCents: number
|
||||
currency: string
|
||||
addressSnapshotJson: string
|
||||
comment: string | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
user: { id: string; email: string; name: string | null; phone: string | null }
|
||||
items: Array<{
|
||||
id: string
|
||||
productId: string
|
||||
qty: number
|
||||
titleSnapshot: string
|
||||
priceCentsSnapshot: number
|
||||
}>
|
||||
messages: Array<{
|
||||
id: string
|
||||
authorType: string
|
||||
text: string
|
||||
createdAt: string
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchAdminOrders(
|
||||
token: string,
|
||||
params?: { status?: string; q?: string; page?: number; pageSize?: number },
|
||||
): Promise<AdminOrdersListResponse> {
|
||||
const { data } = await apiClient.get<AdminOrdersListResponse>('admin/orders', {
|
||||
params,
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export async function fetchAdminOrder(token: string, id: string): Promise<AdminOrderDetailResponse> {
|
||||
const { data } = await apiClient.get<AdminOrderDetailResponse>(`admin/orders/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export async function setAdminOrderStatus(token: string, id: string, status: string): Promise<void> {
|
||||
await apiClient.patch(
|
||||
`admin/orders/${id}/status`,
|
||||
{ status },
|
||||
{
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export async function postAdminOrderMessage(token: string, id: string, text: string): Promise<void> {
|
||||
await apiClient.post(
|
||||
`admin/orders/${id}/messages`,
|
||||
{ text },
|
||||
{
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
|
||||
export type OrderListItem = {
|
||||
id: string
|
||||
status: string
|
||||
totalCents: number
|
||||
currency: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
itemsCount: number
|
||||
}
|
||||
|
||||
export type OrderListResponse = { items: OrderListItem[] }
|
||||
|
||||
export type OrderDetailResponse = {
|
||||
item: {
|
||||
id: string
|
||||
status: string
|
||||
totalCents: number
|
||||
currency: string
|
||||
addressSnapshotJson: string
|
||||
comment: string | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
items: Array<{
|
||||
id: string
|
||||
productId: string
|
||||
qty: number
|
||||
titleSnapshot: string
|
||||
priceCentsSnapshot: number
|
||||
}>
|
||||
messages: Array<{
|
||||
id: string
|
||||
authorType: string
|
||||
text: string
|
||||
createdAt: string
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
export async function createOrder(body: { addressId: string; comment?: string | null }): Promise<{ orderId: string }> {
|
||||
const { data } = await apiClient.post<{ orderId: string }>('me/orders', body)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function fetchMyOrders(): Promise<OrderListResponse> {
|
||||
const { data } = await apiClient.get<OrderListResponse>('me/orders')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function fetchMyOrder(id: string): Promise<OrderDetailResponse> {
|
||||
const { data } = await apiClient.get<OrderDetailResponse>(`me/orders/${id}`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function postOrderMessage(id: string, text: string): Promise<void> {
|
||||
await apiClient.post(`me/orders/${id}/messages`, { text })
|
||||
}
|
||||
|
||||
export async function payOrderStub(id: string): Promise<void> {
|
||||
await apiClient.post(`me/orders/${id}/pay`)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMemo, useRef } from 'react'
|
||||
import Button from '@mui/material/Button'
|
||||
import Card from '@mui/material/Card'
|
||||
import CardContent from '@mui/material/CardContent'
|
||||
import CardMedia from '@mui/material/CardMedia'
|
||||
@@ -7,16 +8,22 @@ import Box from '@mui/material/Box'
|
||||
import Link from '@mui/material/Link'
|
||||
import Stack from '@mui/material/Stack'
|
||||
import Typography from '@mui/material/Typography'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Swiper, SwiperSlide } from 'swiper/react'
|
||||
import type { Swiper as SwiperType } from 'swiper/types'
|
||||
import 'swiper/css'
|
||||
import { Link as RouterLink } from 'react-router-dom'
|
||||
import { useUnit } from 'effector-react'
|
||||
import { addToCart } from '@/entities/cart/api/cart-api'
|
||||
import type { Product } from '@/entities/product/model/types'
|
||||
import { formatPriceRub } from '@/shared/lib/format-price'
|
||||
import { $user } from '@/shared/model/auth'
|
||||
|
||||
type Props = { product: Product; mediaHeight?: number }
|
||||
|
||||
export function ProductCard({ product, mediaHeight = 200 }: Props) {
|
||||
const qc = useQueryClient()
|
||||
const user = useUnit($user)
|
||||
const swiperRef = useRef<SwiperType | null>(null)
|
||||
const imageUrls = useMemo(() => {
|
||||
const fromImages = (product.images ?? [])
|
||||
@@ -39,6 +46,11 @@ export function ProductCard({ product, mediaHeight = 200 }: Props) {
|
||||
swiperRef.current.slideTo(idx, 0)
|
||||
}
|
||||
|
||||
const addMut = useMutation({
|
||||
mutationFn: () => addToCart({ productId: product.id, qty: 1 }),
|
||||
onSuccess: () => void qc.invalidateQueries({ queryKey: ['me', 'cart'] }),
|
||||
})
|
||||
|
||||
return (
|
||||
<Card
|
||||
variant="outlined"
|
||||
@@ -148,6 +160,18 @@ export function ProductCard({ product, mediaHeight = 200 }: Props) {
|
||||
<Typography variant="h6" color="primary">
|
||||
{formatPriceRub(product.priceCents)}
|
||||
</Typography>
|
||||
<Button
|
||||
variant="contained"
|
||||
size="small"
|
||||
disabled={!user || addMut.isPending}
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
addMut.mutate()
|
||||
}}
|
||||
>
|
||||
{user ? 'В корзину' : 'Войдите, чтобы купить'}
|
||||
</Button>
|
||||
</Stack>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
|
||||
export type AdminReview = {
|
||||
id: string
|
||||
rating: number
|
||||
text: string | null
|
||||
status: string
|
||||
createdAt: string
|
||||
moderatedAt: string | null
|
||||
user: { id: string; email: string; name: string | null }
|
||||
product: { id: string; title: string }
|
||||
}
|
||||
|
||||
export type AdminReviewsListResponse = {
|
||||
items: AdminReview[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
export async function fetchAdminReviews(
|
||||
token: string,
|
||||
params?: { status?: string; page?: number; pageSize?: number },
|
||||
): Promise<AdminReviewsListResponse> {
|
||||
const { data } = await apiClient.get<AdminReviewsListResponse>('admin/reviews', {
|
||||
params,
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export async function moderateReview(token: string, id: string, action: 'approve' | 'reject'): Promise<void> {
|
||||
await apiClient.patch(
|
||||
`admin/reviews/${id}`,
|
||||
{ action },
|
||||
{
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user