|
2 | 2 |
|
3 | 3 | import { useState, useEffect } from "react"; |
4 | 4 | import { useParams, useSearchParams, useRouter } from "next/navigation"; |
| 5 | +import { toast } from "sonner"; |
5 | 6 | import GreenCanvas from "@/components/greens/GreenCanvas"; |
6 | 7 | import { ChevronLeft, ChevronRight } from "lucide-react"; |
7 | 8 | import api from "@/lib/axios"; |
@@ -122,16 +123,22 @@ export default function StaffHoleEditPage() { |
122 | 123 | async function handleSave() { |
123 | 124 | if (!pin || !sessionId) return; |
124 | 125 |
|
125 | | - if (pinDbId) { |
126 | | - await api.delete(`/api/pins/${pinDbId}`); |
| 126 | + try { |
| 127 | + if (pinDbId) { |
| 128 | + await api.delete(`/api/pins/${pinDbId}`); |
| 129 | + } |
| 130 | + const response = await api.post("/api/pins", { |
| 131 | + hole_number: holeNumber, |
| 132 | + x: pin.x, |
| 133 | + y: pin.y, |
| 134 | + session_id: sessionId, |
| 135 | + }); |
| 136 | + setPinDbId(response.data.id); |
| 137 | + toast.success("ピンを保存しました"); |
| 138 | + } catch (err) { |
| 139 | + console.error("ピン保存エラー:", err); |
| 140 | + toast.error("保存に失敗しました"); |
127 | 141 | } |
128 | | - const response = await api.post("/api/pins", { |
129 | | - hole_number: holeNumber, |
130 | | - x: pin.x, |
131 | | - y: pin.y, |
132 | | - session_id: sessionId, |
133 | | - }); |
134 | | - setPinDbId(response.data.id); |
135 | 142 | } |
136 | 143 |
|
137 | 144 | function navigateHole(hole: number) { |
|
0 commit comments