-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory-refresh-button.tsx
More file actions
36 lines (28 loc) · 1.03 KB
/
Copy pathhistory-refresh-button.tsx
File metadata and controls
36 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use client"
import { useState } from "react"
import { useRouter } from "next/navigation"
import { Database, Loader2 } from "lucide-react"
import { toast } from "sonner"
import { Button } from "@/components/ui/button"
import { refreshProgressionHistory } from "./actions"
export function HistoryRefreshButton() {
const router = useRouter()
const [loading, setLoading] = useState(false)
const handleRefresh = async () => {
setLoading(true)
const result = await refreshProgressionHistory()
setLoading(false)
if (result.error) {
toast.error(result.error)
return
}
toast.success(`Historique Strava importé (${result.synced ?? 0} activité${result.synced === 1 ? "" : "s"})`)
router.refresh()
}
return (
<Button variant="outline" size="sm" onClick={handleRefresh} disabled={loading} className="gap-1.5">
{loading ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Database className="h-3.5 w-3.5" />}
{loading ? "Import en cours..." : "Recalculer l'historique"}
</Button>
)
}