diff --git a/frontend/src/app/distribution/_components/DeliveryEditPage.tsx b/frontend/src/app/distribution/_components/DeliveryEditPage.tsx index a4637bb..5740a59 100644 --- a/frontend/src/app/distribution/_components/DeliveryEditPage.tsx +++ b/frontend/src/app/distribution/_components/DeliveryEditPage.tsx @@ -433,6 +433,32 @@ export default function DeliveryEditPage({ planId }: Props) { ]); }; + // グループの全圃場をtripに一括割り当て + const assignGroupToTrip = (groupTempId: string, tripTempId: string) => { + const group = groups.find(g => g.tempId === groupTempId); + if (!group) return; + setTrips(prev => prev.map(t => { + if (t.tempId !== tripTempId) return t; + const newItems = [...t.items]; + for (const fieldId of group.fieldIds) { + for (const fert of selectedFertilizers) { + const remaining = getUnassignedBags(fieldId, fert.id); + if (remaining > 0) { + const existing = newItems.find( + item => item.fieldId === fieldId && item.fertilizerId === fert.id + ); + if (existing) { + existing.bags += remaining; + } else { + newItems.push({ fieldId, fertilizerId: fert.id, bags: remaining }); + } + } + } + } + return { ...t, items: newItems }; + })); + }; + // tripの中の圃場IDを取得(表示用・重複なし) const getTripFieldIds = useCallback((trip: LocalTrip): number[] => { const seen = new Set(); @@ -989,9 +1015,31 @@ export default function DeliveryEditPage({ planId }: Props) { )} - {/* このtripに圃場を追加 */} + {/* このtripに追加 */} {hasUnassignedBags && ( -
+
+ {/* グループ一括追加 */} + + {/* 圃場単体追加 */}