feat: remove estimated_cost, auto-calculate final_cost in OrderModal
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { X, Save } from 'lucide-react';
|
||||
import { supabase } from '../../lib/supabase';
|
||||
import { useAuth } from '../auth/useAuth';
|
||||
import { usePricing } from '../../hooks/usePricing';
|
||||
|
||||
const STATUSES = ['новая', 'замер', 'согласование', 'монтаж', 'закрыт'];
|
||||
const OBJECT_TYPES = [
|
||||
@@ -30,13 +31,13 @@ const labelStyle = {
|
||||
|
||||
const OrderModal = ({ order, onClose, onSaved, mode = 'edit' }) => {
|
||||
const { session } = useAuth();
|
||||
const { prices } = usePricing();
|
||||
const [form, setForm] = useState({
|
||||
name: order?.name || '',
|
||||
phone: order?.phone || '',
|
||||
object_type: order?.object_type || '',
|
||||
area_sqm: order?.area_sqm ?? '',
|
||||
film_thickness: order?.film_thickness ?? 200,
|
||||
estimated_cost: order?.estimated_cost ?? '',
|
||||
final_cost: order?.final_cost ?? '',
|
||||
notes: order?.notes || '',
|
||||
assigned_to: order?.assigned_to || '',
|
||||
@@ -60,6 +61,13 @@ const OrderModal = ({ order, onClose, onSaved, mode = 'edit' }) => {
|
||||
}
|
||||
}, [order?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
const area = Number(form.area_sqm);
|
||||
if (!area || isNaN(area)) return;
|
||||
const price = prices[form.film_thickness] ?? prices[200];
|
||||
setForm((prev) => ({ ...prev, final_cost: Math.round(area * price) }));
|
||||
}, [form.area_sqm, form.film_thickness, prices]);
|
||||
|
||||
const modalRef = React.useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -76,7 +84,6 @@ const OrderModal = ({ order, onClose, onSaved, mode = 'edit' }) => {
|
||||
const toPayload = (f) => ({
|
||||
...f,
|
||||
area_sqm: f.area_sqm === '' ? null : Number(f.area_sqm),
|
||||
estimated_cost: f.estimated_cost === '' ? null : Number(f.estimated_cost),
|
||||
final_cost: f.final_cost === '' ? null : Number(f.final_cost),
|
||||
});
|
||||
|
||||
@@ -191,13 +198,10 @@ const OrderModal = ({ order, onClose, onSaved, mode = 'edit' }) => {
|
||||
<option value={300}>300 микрон</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="modal-estimated" style={labelStyle}>Ориентировочная стоимость (₽)</label>
|
||||
<input id="modal-estimated" type="number" name="estimated_cost" value={form.estimated_cost} onChange={set} style={inputStyle} />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="modal-final" style={labelStyle}>Итоговая стоимость (₽)</label>
|
||||
<input id="modal-final" type="number" name="final_cost" value={form.final_cost} onChange={set} style={inputStyle} />
|
||||
<p style={{ fontSize: '0.72rem', color: 'var(--text-muted)', marginTop: '3px' }}>Рассчитывается автоматически</p>
|
||||
</div>
|
||||
<div style={{ gridColumn: '1 / -1' }}>
|
||||
<label htmlFor="modal-assigned" style={labelStyle}>Ответственный (email)</label>
|
||||
|
||||
Reference in New Issue
Block a user