|
|
@@ -1,30 +1,35 @@
|
|
|
-import React, { useState, useEffect, FC } from "react";
|
|
|
+import React, { useState, useEffect, FC, useContext } from "react";
|
|
|
import { generalTable } from "../../../api/tables";
|
|
|
+import { UserStateContext } from "../../../context/auth/AuthProvider";
|
|
|
+import { StateContext } from "../../../context/dashboard/Provider";
|
|
|
import { Summary } from "../../../types/summary";
|
|
|
import { TableHeader as Header, TdGroup } from "../shared";
|
|
|
import * as classes from "../tables.module.css";
|
|
|
|
|
|
-const TemperaturePerSector: FC = () => {
|
|
|
+const GeneralPerSector: FC = () => {
|
|
|
const [data, setData] = useState<Summary[] | null>(null);
|
|
|
+ const { userToken } = useContext(UserStateContext);
|
|
|
+ const { from, to } = useContext(StateContext);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- generalTable("", "", "").then((res) => {
|
|
|
- setData(JSON.parse(res));
|
|
|
+ if (!userToken) return;
|
|
|
+ generalTable(from, to, userToken).then((res) => {
|
|
|
+ setData(res);
|
|
|
});
|
|
|
- }, []);
|
|
|
+ }, [from, to, userToken]);
|
|
|
|
|
|
// Formato de los summaries(filas)
|
|
|
const rows = data?.map((x) => (
|
|
|
- <tr key={x.station.code}>
|
|
|
- <th className={classes.cell}>{x.station.name}</th>
|
|
|
+ <tr key={x.station.station_code}>
|
|
|
+ <th className={classes.cell}>{x.station.title}</th>
|
|
|
<TdGroup>
|
|
|
- <td>{x.lt10}%</td>
|
|
|
- <td>{x.gt30}%</td>
|
|
|
- <td>{x.gt33}%</td>
|
|
|
+ <td>{x.lt10 ?? "-"}%</td>
|
|
|
+ <td>{x.gt30 ?? "-"}%</td>
|
|
|
+ <td>{x.gt33 ?? "-"}%</td>
|
|
|
</TdGroup>
|
|
|
- <td className={classes.cell}>{x.grados_acumulados}</td>
|
|
|
- <td className={classes.cell}>{x.amplitud_termica}</td>
|
|
|
- <td className={classes.cell}>{x.precip_acumulada}</td>
|
|
|
+ <td className={classes.cell}>{x.grados_acumulados ?? "-"}</td>
|
|
|
+ <td className={classes.cell}>{x.amplitud_termica ?? "-"}</td>
|
|
|
+ <td className={classes.cell}>{x.precip_acumulada ?? "-"}</td>
|
|
|
</tr>
|
|
|
));
|
|
|
|
|
|
@@ -47,4 +52,4 @@ const TemperaturePerSector: FC = () => {
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
|
-export default TemperaturePerSector;
|
|
|
+export default GeneralPerSector;
|