修复计划接受流程的前后端状态不一致
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user