Skip to content

Commit 6b98a01

Browse files
committed
feat: スタッフのピン保存時にトースト通知を追加
1 parent dbb6392 commit 6b98a01

2 files changed

Lines changed: 21 additions & 34 deletions

File tree

app/staff/hole/[id]/page.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useState, useEffect } from "react";
44
import { useParams, useSearchParams, useRouter } from "next/navigation";
5+
import { toast } from "sonner";
56
import GreenCanvas from "@/components/greens/GreenCanvas";
67
import { ChevronLeft, ChevronRight } from "lucide-react";
78
import api from "@/lib/axios";
@@ -26,15 +27,15 @@ export default function StaffHoleEditPage() {
2627
const hasPrev = holeNumber > minHole;
2728
const hasNext = holeNumber < maxHole;
2829

29-
const [pin, setPin] = useState<
30+
const [pin, setPin] = useState
3031
{ id: string; x: number; y: number } | undefined
3132
>(undefined);
3233
const [pinDbId, setPinDbId] = useState<string | null>(null);
3334
const [isRainyDay, setIsRainyDay] = useState(false);
3435
const [banCells, setBanCells] = useState<string[]>([]);
3536
const [damageCells, setDamageCells] = useState<string[]>([]);
3637
const [rainCells, setRainCells] = useState<string[]>([]);
37-
const [pastPins, setPastPins] = useState<
38+
const [pastPins, setPastPins] = useState
3839
{ id: string; x: number; y: number; date?: string }[]
3940
>([]);
4041
const [containerRef, containerSize] = useContainerSize();
@@ -122,16 +123,22 @@ export default function StaffHoleEditPage() {
122123
async function handleSave() {
123124
if (!pin || !sessionId) return;
124125

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("保存に失敗しました");
127141
}
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);
135142
}
136143

137144
function navigateHole(hole: number) {
@@ -203,4 +210,4 @@ export default function StaffHoleEditPage() {
203210
</main>
204211
</div>
205212
);
206-
}
213+
}

package-lock.json

Lines changed: 2 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)