diff --git a/client/src/entities/order/api/order-api.ts b/client/src/entities/order/api/order-api.ts index 6217aea..3b5f2fb 100644 --- a/client/src/entities/order/api/order-api.ts +++ b/client/src/entities/order/api/order-api.ts @@ -73,20 +73,6 @@ export async function postOrderMessage(id: string, text: string): Promise await apiClient.post(`me/orders/${id}/messages`, { text }) } -/** Подтверждение оплаты переводом: multipart detail + необязательный файл receipt (хотя бы одно нужно на сервере). */ -export async function submitOrderPayment( - orderId: string, - payload: { detail: string; receiptFile: File | null }, -): Promise<{ ok: boolean; status: string }> { - const formData = new FormData() - formData.append('detail', payload.detail) - if (payload.receiptFile) { - formData.append('receipt', payload.receiptFile) - } - const { data } = await apiClient.post<{ ok: boolean; status: string }>(`me/orders/${orderId}/pay`, formData) - return data -} - export async function confirmOrderReceived(id: string): Promise<{ ok: boolean; status: string }> { const { data } = await apiClient.post<{ ok: boolean; status: string }>(`me/orders/${id}/confirm-received`) return data diff --git a/client/src/features/order-payment/index.ts b/client/src/features/order-payment/index.ts index a7a90a5..e9b76a3 100644 --- a/client/src/features/order-payment/index.ts +++ b/client/src/features/order-payment/index.ts @@ -1,2 +1 @@ export { OrderPaymentSection } from './ui/OrderPaymentSection' -export { PaymentDialog } from './ui/PaymentDialog' diff --git a/client/src/features/order-payment/ui/PaymentDialog.tsx b/client/src/features/order-payment/ui/PaymentDialog.tsx deleted file mode 100644 index 767b62a..0000000 --- a/client/src/features/order-payment/ui/PaymentDialog.tsx +++ /dev/null @@ -1,146 +0,0 @@ -import { useEffect, useMemo, useState } from 'react' -import Alert from '@mui/material/Alert' -import Box from '@mui/material/Box' -import Button from '@mui/material/Button' -import Dialog from '@mui/material/Dialog' -import DialogActions from '@mui/material/DialogActions' -import DialogContent from '@mui/material/DialogContent' -import DialogTitle from '@mui/material/DialogTitle' -import Stack from '@mui/material/Stack' -import TextField from '@mui/material/TextField' -import Typography from '@mui/material/Typography' -import axios from 'axios' -import { PAYMENT_TRANSFER_INSTRUCTIONS_PLAIN } from '@/shared/constants/payment-instructions' - -type Props = { - open: boolean - isPending: boolean - error: unknown - onClose: () => void - onSubmit: (params: { detail: string; receiptFile: File | null }) => void -} - -function paySubmitErrorMessage(err: unknown): string { - if (axios.isAxiosError(err)) { - const raw = err.response?.data - const apiMsg = - raw && typeof raw === 'object' && 'error' in raw && typeof (raw as { error: unknown }).error === 'string' - ? (raw as { error: string }).error - : null - return apiMsg || err.message || 'Не удалось отправить данные оплаты' - } - if (err instanceof Error) return err.message - return 'Не удалось отправить данные оплаты' -} - -export function PaymentDialog({ open, isPending, error, onClose, onSubmit }: Props) { - const [detail, setDetail] = useState('') - const [receiptFile, setReceiptFile] = useState(null) - const [clientError, setClientError] = useState(null) - - const receiptPreviewUrl = useMemo(() => { - if (!receiptFile) return null - return URL.createObjectURL(receiptFile) - }, [receiptFile]) - - useEffect(() => { - if (!receiptPreviewUrl) return - return () => URL.revokeObjectURL(receiptPreviewUrl) - }, [receiptPreviewUrl]) - - const reset = () => { - setDetail('') - setReceiptFile(null) - setClientError(null) - } - - const handleClose = () => { - if (isPending) return - reset() - onClose() - } - - const handleSubmit = () => { - const hasText = detail.trim().length > 0 - const hasFile = Boolean(receiptFile) - if (!hasText && !hasFile) { - setClientError('Укажите комментарий и/или прикрепите чек.') - return - } - setClientError(null) - onSubmit({ detail: detail.trim(), receiptFile }) - } - - return ( - - Подтверждение оплаты - - - {PAYMENT_TRANSFER_INSTRUCTIONS_PLAIN} - - { - setDetail(e.target.value) - setClientError(null) - }} - fullWidth - multiline - minRows={3} - sx={{ mb: 2 }} - /> - - - {receiptFile && ( - - )} - - - Нужен текст комментария и/или изображение чека. - - {receiptPreviewUrl && ( - - )} - {clientError && ( - - {clientError} - - )} - {error ? ( - - {paySubmitErrorMessage(error)} - - ) : null} - - - - - - - ) -} diff --git a/client/src/shared/constants/payment-instructions.ts b/client/src/shared/constants/payment-instructions.ts deleted file mode 100644 index d1694e5..0000000 --- a/client/src/shared/constants/payment-instructions.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** Текст модалки оплаты (можно переопределить через VITE_PAYMENT_INSTRUCTIONS — многострочная строка \n). */ -const fromEnv = - typeof import.meta.env.VITE_PAYMENT_INSTRUCTIONS === 'string' ? import.meta.env.VITE_PAYMENT_INSTRUCTIONS.trim() : '' - -export const PAYMENT_TRANSFER_INSTRUCTIONS_PLAIN = - fromEnv || - [ - 'Временно оплата доступна только переводом на ВТБ / Сбербанк.', - '', - 'По номеру +79524181624', - 'Получатель: Лариса К', - ].join('\n')