修复计划接受流程的前后端状态不一致

This commit is contained in:
2026-03-03 12:16:04 +08:00
parent 67fdf7427a
commit 673dc1177e
2 changed files with 29 additions and 14 deletions
+23 -13
View File
@@ -224,20 +224,30 @@ export function useBlindboxPlan(
}, [profile, planDays, handlePlanDaysChange, toast]);
const handleAcceptPlan = useCallback(async () => {
setPlanAccepted(true);
fireConfetti();
if (planId && profile) {
try {
const res = await fetch("/api/blindbox/plan", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ planId, userId: profile.id, action: "accept" }),
});
const data = await res.json();
setActiveContract({ id: planId, days: planDays, endTime: data.endTime ?? null });
} catch (e) { console.error("acceptPlan failed:", e); }
if (!planId || !profile) {
toast.show("计划信息不完整,请重新生成后再试");
return;
}
try {
const res = await fetch("/api/blindbox/plan", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ planId, userId: profile.id, action: "accept" }),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
throw new Error(data.error || "接受契约失败");
}
setPlanAccepted(true);
setActiveContract({ id: planId, days: planDays, endTime: data.endTime ?? null });
fireConfetti();
toast.show("契约已接受!");
} catch (e) {
console.error("acceptPlan failed:", e);
toast.show(e instanceof Error ? e.message : "接受契约失败");
}
toast.show("契约已接受!");
}, [planId, profile, planDays, fireConfetti, toast]);
const handleRegenerate = useCallback(() => {