UI changes

This commit is contained in:
2026-10-02 13:17:32 +05:30
parent bfd3e5cded
commit 9707ef596c
3 changed files with 99 additions and 8 deletions
@@ -71,7 +71,7 @@ const STEPS = [
n: 3,
label: 'Items',
title: 'What should be loaded from Shop POs?',
help: "Expand a shop to tick items and set quantities. If the main warehouse doesn't have enough stock, use \"Take remaining from another warehouse\" to top up the rest.",
help: "Expand a shop to tick items and set quantities. If the main warehouse can't cover an item, a top-up row is added automatically — just pick which other warehouse to take the rest from.",
},
{
n: 4,
@@ -321,10 +321,16 @@ function LoadingSheetForm() {
let changed = false
const next: Record<string, PickedLine> = {}
for (const [key, l] of Object.entries(prev)) {
const extras = l.extras.filter((e) => e.warehouseId !== warehouseId)
let extras = l.extras.filter((e) => e.warehouseId !== warehouseId)
const avail = stockByWh[warehouseId]?.[l.itemId] ?? 0
const quantity = Math.min(l.quantity, avail)
const checked = l.checked && (quantity > 0 || extras.length > 0)
// Pre-add an empty top-up row if the new main warehouse leaves this line short
// and one isn't already pending, mirroring toggleLine's auto-suggestion.
const shortBy = l.remainingQty - quantity - extras.reduce((sum, e) => sum + (Number(e.quantity) || 0), 0)
if (checked && shortBy > 0 && !extras.some((e) => !e.warehouseId)) {
extras = [...extras, { warehouseId: '', quantity: 0 }]
}
if (extras.length !== l.extras.length || quantity !== l.quantity || checked !== l.checked) changed = true
next[key] = { ...l, extras, quantity, checked }
}
@@ -452,7 +458,12 @@ function LoadingSheetForm() {
const avail = availIn(warehouseId, line.itemId)
if (!stockLoaded || avail <= 0) return
const quantity = Math.max(0, Math.min(line.remainingQty - extrasTotal(line), avail))
setLines((prev) => ({ ...prev, [line.shopPOItemId]: { ...line, checked, quantity } }))
// The main warehouse can't cover the full remaining quantity, so a top-up row is
// pre-added (still editable/removable) instead of making the user click "Take
// remaining from another warehouse" themselves.
const shortBy = line.remainingQty - quantity - extrasTotal(line)
const extras = shortBy > 0 ? [...line.extras, { warehouseId: '', quantity: 0 }] : line.extras
setLines((prev) => ({ ...prev, [line.shopPOItemId]: { ...line, checked, quantity, extras } }))
return
}
setLines((prev) => ({ ...prev, [line.shopPOItemId]: { ...line, checked } }))
@@ -912,10 +923,18 @@ function LoadingSheetForm() {
<tr>
<td className="px-3 pb-2"></td>
<td className="px-3 pb-2" colSpan={7}>
<span className="mr-3 text-xs text-muted-foreground">{shortBy} will stay open on the PO for another sheet</span>
<Button type="button" variant="outline" size="sm" onClick={() => addExtra(line)}>
Take remaining from another warehouse
</Button>
{line.extras.some((e) => !e.warehouseId) ? (
<span className="text-xs text-amber-600">
{shortBy} short — pick a warehouse above to top it up, or it stays open on the PO for another sheet.
</span>
) : (
<>
<span className="mr-3 text-xs text-muted-foreground">{shortBy} will stay open on the PO for another sheet</span>
<Button type="button" variant="outline" size="sm" onClick={() => addExtra(line)}>
Take remaining from another warehouse
</Button>
</>
)}
</td>
</tr>
)}