From 16ab237551747a098e5b5289bcfd0eff4b497fdd Mon Sep 17 00:00:00 2001 From: rassadin11 Date: Wed, 10 Jun 2026 19:06:29 +0300 Subject: [PATCH] fix legal convert --- src/pages/converter/ui/LegalConverterPage.tsx | 32 +++++++++++++++++-- src/widgets/wallet-header/ui/WalletHeader.tsx | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/pages/converter/ui/LegalConverterPage.tsx b/src/pages/converter/ui/LegalConverterPage.tsx index ee70fd9..8cd6da9 100644 --- a/src/pages/converter/ui/LegalConverterPage.tsx +++ b/src/pages/converter/ui/LegalConverterPage.tsx @@ -1,5 +1,6 @@ -import { useState } from 'react' -import { useCreatePurchaseRequest } from '@features/b2b' +import { useEffect, useState } from 'react' +import { useCreatePurchaseRequest, useMyPurchaseRequests } from '@features/b2b' +import type { B2bPurchaseRequest } from '@features/b2b' import { FormField, Notification, Select } from '@shared/ui' import styles from './LegalConverterPage.module.css' @@ -23,6 +24,20 @@ const TERM_OPTIONS = [ const ru = (n: number) => n.toLocaleString('ru-RU', { maximumFractionDigits: 0 }) +// Имя и контакт у заявки отдельных полей не имеют — они упакованы в comment +// (см. handleSubmit). Достаём их обратно для автозаполнения формы. +const parseContactFromComment = (comment: string | null) => ({ + name: comment?.match(/Имя:\s*([^;]+)/)?.[1]?.trim() ?? '', + contact: comment?.match(/Контакт:\s*([^;]+)/)?.[1]?.trim() ?? '', +}) + +// Последняя по времени создания заявка на аккаунте, либо null. +const latestRequest = (items: B2bPurchaseRequest[]): B2bPurchaseRequest | null => + items.reduce( + (latest, r) => (!latest || (r.created_at ?? '') > (latest.created_at ?? '') ? r : latest), + null, + ) + const dayLabel = (days: number) => { const mod10 = days % 10 const mod100 = days % 100 @@ -39,6 +54,19 @@ export function LegalConverterPage() { const [notice, setNotice] = useState<'success' | 'error' | null>(null) const { mutate: submitRequest, isPending } = useCreatePurchaseRequest() + const { data: requests } = useMyPurchaseRequests() + + // Автозаполнение имени и контакта из последней заявки аккаунта (один раз). + const [prefilled, setPrefilled] = useState(false) + useEffect(() => { + if (prefilled || !requests) return + const last = latestRequest(requests.items) + if (!last) return + const parsed = parseContactFromComment(last.comment) + if (parsed.name) setName(parsed.name) + if (parsed.contact) setContact(parsed.contact) + setPrefilled(true) + }, [prefilled, requests]) const numAmount = Number(amount.replace(/\D/g, '')) || 0 const belowMin = numAmount > 0 && numAmount < MIN_ORDER diff --git a/src/widgets/wallet-header/ui/WalletHeader.tsx b/src/widgets/wallet-header/ui/WalletHeader.tsx index 9cb5012..0b88101 100644 --- a/src/widgets/wallet-header/ui/WalletHeader.tsx +++ b/src/widgets/wallet-header/ui/WalletHeader.tsx @@ -82,7 +82,7 @@ export function WalletHeader() { ) : (
)} - {fullName || 'Test account'} + {fullName || me?.legal_entity?.name || 'Test account'} {open && (