Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/components/GoalTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function GoalTracker() {
const [recurrence, setRecurrence] = useState<Recurrence>("none");
const [creating, setCreating] = useState(false);
const [createError, setCreateError] = useState<string | null>(null);
const [deleteError, setDeleteError] = useState<string | null>(null);
const [confirmingId, setConfirmingId] = useState<string | null>(null);
const [deletingId, setDeletingId] = useState<string | null>(null);

Expand Down Expand Up @@ -88,14 +89,17 @@ export default function GoalTracker() {
setGoals((prev) => prev.filter((g) => g.id !== id));
setConfirmingId(null);
setDeletingId(id);
setDeleteError(null);

try {
const res = await fetch(`/api/goals/${id}`, { method: "DELETE" });
if (!res.ok) {
setGoals(previousGoals);
setDeleteError("Failed to delete goal. Please try again.");
}
} catch {
setGoals(previousGoals);
setDeleteError("Failed to delete goal. Please check your connection.");
} finally {
setDeletingId(null);
}
Expand Down Expand Up @@ -173,6 +177,13 @@ export default function GoalTracker() {
<div className="h-full rounded-xl border border-[var(--border)] bg-[var(--card)] p-6 shadow-sm">
<h2 className="mb-4 text-lg font-semibold text-[var(--card-foreground)]">Weekly Goals</h2>

{deleteError && (
<div className="mb-4 rounded-lg border border-[var(--destructive)]/20 bg-[var(--destructive)]/10 p-3 text-sm text-[var(--destructive)] flex justify-between items-center">
<p>{deleteError}</p>
<button onClick={() => setDeleteError(null)} className="text-[var(--destructive)] hover:opacity-80 ml-2" aria-label="Dismiss error">✕</button>
</div>
)}

{goals.length === 0 ? (
<p className="text-sm text-[var(--muted-foreground)]">
No goals yet. Create one below.
Expand Down Expand Up @@ -221,7 +232,7 @@ export default function GoalTracker() {
<button
onClick={() => handleDelete(goal.id)}
disabled={isDeleting}
className="text-red-400 hover:text-red-300 font-semibold transition-colors disabled:opacity-50"
className="text-[var(--destructive)] hover:opacity-80 font-semibold transition-colors disabled:opacity-50"
aria-label={`Confirm delete goal: ${goal.title}`}
>
Yes
Expand All @@ -239,7 +250,7 @@ export default function GoalTracker() {
<button
onClick={() => setConfirmingId(goal.id)}
disabled={isDeleting}
className="text-[var(--muted-foreground)] hover:text-red-400 transition-colors disabled:opacity-50"
className="text-[var(--muted-foreground)] hover:text-[var(--destructive)] transition-colors disabled:opacity-50"
aria-label={`Delete goal: ${goal.title}`}
title="Delete goal"
>
Expand Down Expand Up @@ -363,7 +374,7 @@ export default function GoalTracker() {
</button>

{createError && (
<p className="text-sm text-red-500">{createError}</p>
<p className="text-sm text-[var(--destructive)]">{createError}</p>
)}
</form>
</div>
Expand Down
Loading