From b8d6dac70a2a004bbbc2cb804049804f92aa1a4a Mon Sep 17 00:00:00 2001 From: gahusb Date: Mon, 16 Mar 2026 08:32:42 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B6=80=EB=8F=99=EC=82=B0=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20api=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/subscription/Subscription.jsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pages/subscription/Subscription.jsx b/src/pages/subscription/Subscription.jsx index 4eed0d5..f04ded3 100644 --- a/src/pages/subscription/Subscription.jsx +++ b/src/pages/subscription/Subscription.jsx @@ -1055,11 +1055,21 @@ const Subscription = () => { }; const handleAdd = async (data) => { - const n = { ...data, id: Date.now() }; - const next = [...items, n]; - persist(next); + const tempId = Date.now(); + const n = { ...data, id: tempId }; + persist([...items, n]); setShowSubModal(false); - try { await apiPost('/api/subscription/items', data); } catch {} + try { + const res = await apiPost('/api/subscription/items', data); + if (res?.id) { + // 서버가 부여한 실제 DB ID로 교체 + setItems((prev) => { + const updated = prev.map((i) => (i.id === tempId ? { ...i, id: res.id } : i)); + localStorage.setItem('sub_items', JSON.stringify(updated)); + return updated; + }); + } + } catch {} }; const handleUpdate = async (data) => {