diff --git a/src/admin/pages/InvoiceCreate.jsx b/src/admin/pages/InvoiceCreate.jsx index db6f82f..21397d9 100644 --- a/src/admin/pages/InvoiceCreate.jsx +++ b/src/admin/pages/InvoiceCreate.jsx @@ -6,6 +6,11 @@ import Forbidden from '../components/Forbidden' import FormField from '../components/FormField' import AdminDatePicker from '../components/AdminDatePicker' import { motion } from 'framer-motion' +import { DndContext, closestCenter, KeyboardSensor, PointerSensor, TouchSensor, useSensor, useSensors } from '@dnd-kit/core' +import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable' +import { restrictToVerticalAxis } from '@dnd-kit/modifiers' +import SortableRow, { DragHandle } from '../components/SortableRow' +import useSortableList from '../hooks/useSortableList' import apiFetch from '../utils/api' import { formatCurrency } from '../utils/formatters' @@ -315,15 +320,12 @@ export default function InvoiceCreate() { setItems(prev => prev.filter((_, i) => i !== index)) } - const moveItem = (index, direction) => { - setItems(prev => { - const newItems = [...prev] - const target = index + direction - if (target < 0 || target >= newItems.length) return prev - ;[newItems[index], newItems[target]] = [newItems[target], newItems[index]] - return newItems - }) - } + const sensors = useSensors( + useSensor(PointerSensor, { activationConstraint: { distance: 5 } }), + useSensor(TouchSensor, { activationConstraint: { delay: 200, tolerance: 5 } }), + useSensor(KeyboardSensor) + ) + const { handleDragEnd } = useSortableList(setItems, '_key') // Totals const totals = useMemo(() => { @@ -651,105 +653,114 @@ export default function InvoiceCreate() {
| # | -Popis | -Množství | -Jednotka | -Jedn. cena | - {form.apply_vat ?DPH | : null} -Celkem | -- | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {index + 1} | -- updateItem(index, 'description', e.target.value)} - className="admin-form-input" - placeholder="Popis položky..." - style={{ fontWeight: 500 }} - /> - | -- updateItem(index, 'quantity', e.target.value)} - className="admin-form-input" - min="0" - step="any" - style={{ textAlign: 'center', height: '2.25rem', padding: '0.375rem 0.5rem' }} - /> - | -- updateItem(index, 'unit', e.target.value)} - className="admin-form-input" - placeholder="ks" - style={{ textAlign: 'center', height: '2.25rem', padding: '0.375rem 0.5rem' }} - /> - | -- updateItem(index, 'unit_price', e.target.value)} - className="admin-form-input" - step="any" - style={{ textAlign: 'right', height: '2.25rem', padding: '0.375rem 0.5rem' }} - /> - | - {form.apply_vat ? ( -- - | - ) : null} -- {formatCurrency(lineTotal, form.currency)} - | -
-
-
-
- {items.length > 1 && (
-
+
|