add customer name, service info, second pickup location, and structured address fields to deliveries

This commit is contained in:
Egor Pozharov
2026-04-16 20:16:21 +06:00
parent 7f775abf6a
commit ce6ea377ce
16 changed files with 852 additions and 77 deletions

View File

@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
import { Button, Input, Select, Modal } from '../ui';
import { pickupOptions } from '../../constants/pickup';
import { formatDateForInput, parseDateFromInput, getTodayFrontend } from '../../utils/date';
import { parseAddress } from '../../utils/addressParser';
import type { Delivery, PickupLocation, DeliveryStatus } from '../../types';
interface DeliveryFormProps {
@@ -20,28 +21,49 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
const [formData, setFormData] = useState({
date: defaultDate || getTodayFrontend(),
pickupLocation: 'warehouse' as PickupLocation,
pickupLocation2: null as PickupLocation | null,
productName: '',
productName2: '',
customerName: '',
address: '',
street: '',
house: '',
apartment: '',
entrance: '',
floor: '',
phone: '',
additionalPhone: '',
hasElevator: false,
serviceInfo: '',
comment: '',
status: 'new' as DeliveryStatus,
});
const [showSecondPickup, setShowSecondPickup] = useState(false);
const [showAddressDetails, setShowAddressDetails] = useState(false);
useEffect(() => {
if (initialData) {
setFormData({
date: initialData.date,
pickupLocation: initialData.pickupLocation,
pickupLocation2: initialData.pickupLocation2 || null,
productName: initialData.productName,
productName2: initialData.productName2 || '',
customerName: initialData.customerName,
address: initialData.address,
street: initialData.street,
house: initialData.house,
apartment: initialData.apartment || '',
entrance: initialData.entrance || '',
floor: initialData.floor || '',
phone: initialData.phone,
additionalPhone: initialData.additionalPhone || '',
hasElevator: initialData.hasElevator,
serviceInfo: initialData.serviceInfo || '',
comment: initialData.comment,
status: initialData.status,
});
setShowSecondPickup(!!initialData.pickupLocation2);
} else if (defaultDate) {
setFormData(prev => ({ ...prev, date: defaultDate }));
}
@@ -54,7 +76,7 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
const isPhoneValid = !formData.phone || validatePhone(formData.phone);
const isAdditionalPhoneValid = !formData.additionalPhone || validatePhone(formData.additionalPhone);
const isFormValid = formData.productName && formData.address && formData.phone && isPhoneValid;
const isFormValid = formData.productName && formData.address && formData.phone && isPhoneValid && formData.customerName && formData.street && formData.house;
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
@@ -65,14 +87,25 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
setFormData({
date: defaultDate || getTodayFrontend(),
pickupLocation: 'warehouse',
pickupLocation2: null,
productName: '',
productName2: '',
customerName: '',
address: '',
street: '',
house: '',
apartment: '',
entrance: '',
floor: '',
phone: '',
additionalPhone: '',
hasElevator: false,
serviceInfo: '',
comment: '',
status: 'new',
});
setShowSecondPickup(false);
setShowAddressDetails(false);
}
onClose();
} catch {
@@ -126,16 +159,106 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
required
/>
{/* Address with auto-parse */}
<div>
<label className="block text-sm font-medium text-[#1b1b1d] mb-1">
Адрес доставки
</label>
<input
type="text"
value={formData.address}
onChange={(e) => {
const newAddress = e.target.value;
const parsed = parseAddress(newAddress);
setFormData({
...formData,
address: newAddress,
street: parsed.street || formData.street,
house: parsed.house || formData.house,
apartment: parsed.apartment || formData.apartment,
entrance: parsed.entrance || formData.entrance,
floor: parsed.floor || formData.floor,
});
if (parsed.street || parsed.house) {
setShowAddressDetails(true);
}
}}
onBlur={() => setShowAddressDetails(true)}
placeholder="ул. Абая, д. 15, кв. 45, подъезд 3, этаж 5"
className="w-full px-3 py-2 bg-[#f5f3f5] border border-[#c5c6cd] rounded-md text-[#1b1b1d] focus:outline-none focus:ring-2 focus:ring-[#1B263B] focus:border-transparent transition-colors"
required
/>
<p className="text-xs text-[#75777d] mt-1">
Улица, дом, квартира, подъезд, этаж
</p>
</div>
{/* Parsed address details */}
{showAddressDetails && (
<div className="bg-[#f5f3f5] rounded-lg p-4 space-y-3">
<p className="text-sm font-medium text-[#1b1b1d]">Проверьте распознанные данные:</p>
<div className="grid grid-cols-2 gap-3">
<div>
<label className="block text-xs text-[#75777d] mb-1">Улица *</label>
<input
type="text"
value={formData.street}
onChange={(e) => setFormData({ ...formData, street: e.target.value })}
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
required
/>
</div>
<div>
<label className="block text-xs text-[#75777d] mb-1">Дом *</label>
<input
type="text"
value={formData.house}
onChange={(e) => setFormData({ ...formData, house: e.target.value })}
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
required
/>
</div>
<div>
<label className="block text-xs text-[#75777d] mb-1">Квартира</label>
<input
type="text"
value={formData.apartment}
onChange={(e) => setFormData({ ...formData, apartment: e.target.value })}
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
/>
</div>
<div>
<label className="block text-xs text-[#75777d] mb-1">Подъезд</label>
<input
type="text"
value={formData.entrance}
onChange={(e) => setFormData({ ...formData, entrance: e.target.value })}
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
/>
</div>
<div>
<label className="block text-xs text-[#75777d] mb-1">Этаж</label>
<input
type="text"
value={formData.floor}
onChange={(e) => setFormData({ ...formData, floor: e.target.value })}
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
/>
</div>
</div>
</div>
)}
<Input
label="Адрес разгрузки"
value={formData.address}
onChange={(e) => setFormData({ ...formData, address: e.target.value })}
placeholder="ул. Примерная, д. 1"
label="ФИО клиента *"
value={formData.customerName}
onChange={(e) => setFormData({ ...formData, customerName: e.target.value })}
placeholder="Иванов Иван Иванович"
required
/>
<Input
label="Телефон покупателя"
label="Телефон покупателя *"
type="tel"
value={formData.phone}
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
@@ -175,6 +298,43 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
</p>
)}
{/* Second pickup location */}
<div className="flex items-center gap-2">
<input
type="checkbox"
id="hasSecondPickup"
checked={showSecondPickup}
onChange={(e) => {
setShowSecondPickup(e.target.checked);
if (!e.target.checked) {
setFormData({ ...formData, pickupLocation2: null, productName2: '' });
}
}}
className="w-4 h-4 text-[#1B263B] border-[#c5c6cd] rounded focus:ring-[#1B263B]"
/>
<label htmlFor="hasSecondPickup" className="text-sm text-[#1b1b1d]">
Добавить вторую точку загрузки
</label>
</div>
{showSecondPickup && (
<div className="bg-[#f5f3f5] rounded-lg p-4 space-y-3">
<p className="text-sm font-medium text-[#1b1b1d]">Вторая точка загрузки</p>
<Select
label="Место загрузки 2"
value={formData.pickupLocation2 || ''}
onChange={(e) => setFormData({ ...formData, pickupLocation2: e.target.value as PickupLocation })}
options={pickupOptions}
/>
<Input
label="Что забрать со второй точки"
value={formData.productName2}
onChange={(e) => setFormData({ ...formData, productName2: e.target.value })}
placeholder="Название товара со второй точки"
/>
</div>
)}
<div className="flex items-center gap-2">
<input
type="checkbox"
@@ -188,6 +348,13 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
</label>
</div>
<Input
label="Услуги (сборка, подъём)"
value={formData.serviceInfo}
onChange={(e) => setFormData({ ...formData, serviceInfo: e.target.value })}
placeholder="Сборка 5000 тг, подъём на этаж 3000 тг"
/>
<Input
label="Комментарий"
value={formData.comment}