|
| 1 | +import { useQuery } from '@tanstack/react-query'; |
| 2 | + |
| 3 | +import { getMonthlyCarbonAmount } from '@/api/home/CarbonController'; |
1 | 4 | import TreeIcon from '@/assets/icons/tree.svg'; |
2 | 5 |
|
3 | | -export default function MainDecreaseAmount({ amount }) { |
| 6 | +export default function MainDecreaseAmount({ month }) { |
| 7 | + const { data, isLoading, error } = useQuery({ |
| 8 | + queryKey: ['monthlyReducedAmount', month], |
| 9 | + queryFn: () => getMonthlyCarbonAmount(month), |
| 10 | + enabled: !!month, |
| 11 | + staleTime: 1000 * 60, |
| 12 | + }); |
| 13 | + |
| 14 | + if (isLoading) { |
| 15 | + return ( |
| 16 | + <div className="flex h-45 w-full p-4"> |
| 17 | + <div className="border-main-green flex h-full w-full animate-pulse flex-col items-center justify-center gap-2 rounded-3xl border-2 bg-gray-100 p-7"> |
| 18 | + <div className="flex items-center gap-3"> |
| 19 | + <div className="bg-gray-3 h-6 w-40 rounded-md"></div> |
| 20 | + <div className="bg-gray-3 h-6 w-6 rounded-full"></div> |
| 21 | + </div> |
| 22 | + <div className="flex items-end gap-1"> |
| 23 | + <div className="bg-gray-3 h-10 w-24 rounded-md"></div> |
| 24 | + <div className="bg-gray-3 h-8 w-12 rounded-md"></div> |
| 25 | + </div> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + if (error) return <div>error</div>; |
| 32 | + |
4 | 33 | return ( |
5 | 34 | <div className="flex h-45 w-full p-4"> |
6 | 35 | <div className="border-main-green flex h-full w-full flex-col items-center justify-center gap-2 rounded-3xl border-2 p-7"> |
7 | 36 | <div className="flex items-center gap-3"> |
8 | | - <span className="text-heading-1 font-bold">이번주 탄소 절감량</span> |
| 37 | + <span className="text-heading-1 font-bold">이번달 탄소 절감량</span> |
9 | 38 | <TreeIcon /> |
10 | 39 | </div> |
11 | 40 | <div className="flex items-end gap-1"> |
12 | | - <span className="text-title-0 text- text-main-green font-extrabold">{amount}kg</span> |
| 41 | + <span className="text-title-0 text- text-main-green font-extrabold">{data.totalSavedKg}kg</span> |
13 | 42 | <span className="text-heading-1 font-bold">CO2</span> |
14 | 43 | </div> |
15 | 44 | </div> |
|
0 commit comments