/ src / components / Charts / ChartFooter.tsx
ChartFooter.tsx
 1  import { useEffect, useState } from "react";
 2  import { ExportButton } from "./ExportButton";
 3  import SupplyDataLastUpdated from "./LastUpdated";
 4  import { getCommitUrlForTab, getLastUpdatedDate } from "../lib/chart/helpers";
 5  
 6  type ChartFooterProps = {
 7    lastUpdatedDate: string;
 8    handleSaveToPng: any;
 9    imgLabel: string;
10  };
11  
12  const ChartFooter = (props: ChartFooterProps) => {
13    const [lastUpdated, setLastUpdated] = useState<Date | null>(null);
14    useEffect(() => {
15      console.log('props' , props.lastUpdatedDate)
16        const controller = new AbortController();
17    
18        const fetchAllData = async () => {
19          try {
20            const [lastUpdated] = await Promise.all([
21              getLastUpdatedDate(getCommitUrlForTab(props.lastUpdatedDate), controller.signal),
22            ]);
23    
24            if (lastUpdated) {
25              setLastUpdated(new Date(lastUpdated));
26            }
27          } catch (err) {
28            console.error("Error fetching dashboard data:", err);
29          }
30        };
31    
32        fetchAllData();
33    
34        return () => {
35          controller.abort();
36        };
37      }, [props.lastUpdatedDate]);
38    return (
39      <>
40        {lastUpdated && (
41          <div
42            className="flex items-baseline"
43            style={{
44              display: "flex",
45              justifyContent: "space-between",
46              marginTop: 48,
47            }}
48          >
49            <SupplyDataLastUpdated lastUpdated={lastUpdated} />
50  
51            <ExportButton
52              handleSaveToPng={props.handleSaveToPng}
53              imgLabel={props.imgLabel}
54            />
55          </div>
56        )}
57      </>
58    );
59  };
60  
61  export default ChartFooter;