fix(offers,invoices): per-button save loading state (only the clicked button spins)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -558,6 +558,10 @@ export default function InvoiceDetail() {
|
||||
]);
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [saving, setSaving] = useState(false);
|
||||
// Which save action is in flight ("draft" | LIVE_STATUS | "save"), so only the
|
||||
// clicked button shows its spinner — `saving` still disables all of them to
|
||||
// prevent a concurrent double-submit.
|
||||
const [savingAction, setSavingAction] = useState<string | null>(null);
|
||||
const [dataReady, setDataReady] = useState(false);
|
||||
const [invoiceNumber, setInvoiceNumber] = useState("");
|
||||
const initialSnapshotRef = useRef<string | null>(null);
|
||||
@@ -976,6 +980,7 @@ export default function InvoiceDetail() {
|
||||
if (Object.keys(newErrors).length > 0) return;
|
||||
|
||||
setSaving(true);
|
||||
setSavingAction(targetStatus ?? "save");
|
||||
try {
|
||||
const payload: Record<string, unknown> = {
|
||||
...form,
|
||||
@@ -1016,6 +1021,7 @@ export default function InvoiceDetail() {
|
||||
);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
setSavingAction(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1710,7 +1716,7 @@ export default function InvoiceDetail() {
|
||||
onClick={() => handleCreateSubmit("draft")}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? (
|
||||
{savingAction === "draft" ? (
|
||||
<CircularProgress size={16} color="inherit" />
|
||||
) : (
|
||||
"Uložit koncept"
|
||||
@@ -1720,7 +1726,7 @@ export default function InvoiceDetail() {
|
||||
onClick={() => handleCreateSubmit(LIVE_STATUS)}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? (
|
||||
{savingAction === LIVE_STATUS ? (
|
||||
<>
|
||||
<CircularProgress
|
||||
size={16}
|
||||
@@ -1745,7 +1751,7 @@ export default function InvoiceDetail() {
|
||||
onClick={() => handleCreateSubmit("draft")}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? (
|
||||
{savingAction === "draft" ? (
|
||||
<CircularProgress size={16} color="inherit" />
|
||||
) : (
|
||||
"Uložit koncept"
|
||||
@@ -1756,7 +1762,7 @@ export default function InvoiceDetail() {
|
||||
onClick={() => handleCreateSubmit(LIVE_STATUS)}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? (
|
||||
{savingAction === LIVE_STATUS ? (
|
||||
<>
|
||||
<CircularProgress
|
||||
size={16}
|
||||
@@ -1787,7 +1793,7 @@ export default function InvoiceDetail() {
|
||||
{isEdit && invoice && invoice.status !== "draft" && (
|
||||
<>
|
||||
<Button onClick={() => handleCreateSubmit()} disabled={saving}>
|
||||
{saving ? (
|
||||
{savingAction === "save" ? (
|
||||
<>
|
||||
<CircularProgress
|
||||
size={16}
|
||||
|
||||
Reference in New Issue
Block a user