index.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React, { useContext, useState, useEffect, ChangeEvent, FC } from "react";
  2. import Select from "../../forms/select";
  3. import CalendarInput from "../../forms/calendarInput";
  4. import {
  5. DispatchContext,
  6. StateContext,
  7. } from "../../../../context/dashboard/Provider";
  8. import * as actions from "../../../../context/dashboard/actions";
  9. import { sectors } from "../../../../api";
  10. import { UserStateContext } from "../../../../context/auth/AuthProvider";
  11. const fincaList: string[] | number[] = ["a", "b", "c", "d"];
  12. const campaignList: any[] = ["2018", "2019", "2020", "2021"].map((c) => ({
  13. value: c,
  14. title: c,
  15. }));
  16. const Cockpit: FC = () => {
  17. const dashboardState = useContext(StateContext);
  18. const dashboardDispatch = useContext(DispatchContext);
  19. const userState = useContext(UserStateContext);
  20. const [sectorList, setSectorList] = useState<any[]>([]);
  21. // Inicializacion del selector de fincas
  22. // useEffect(() => {
  23. // const token = userState.userToken;
  24. // if (!token) return;
  25. // sectors(token)
  26. // .then((res: Response) => res.json())
  27. // .then((body: any[]) => {
  28. // debugger;
  29. // const options = body.map((s: any) => ({
  30. // title: s.title,
  31. // value: s.station_code,
  32. // }));
  33. // if (options.length) {
  34. // dashboardDispatch(actions.setSector(options[0].value));
  35. // }
  36. // setSectorList(options);
  37. // });
  38. // }, []);
  39. return (
  40. <section className="row p-lg-4 p-md-3 p-2">
  41. <div className="col-12 col-lg-4 mb-2 col-xl-3 mb-xl-0">
  42. <Select
  43. list={sectorList}
  44. onChange={(e: ChangeEvent<HTMLInputElement>) =>
  45. dashboardDispatch(actions.setSector(e.target.value))
  46. }
  47. name="Comparación"
  48. placeholder="Fincas"
  49. />
  50. </div>
  51. <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
  52. <CalendarInput
  53. onChange={(e: ChangeEvent<HTMLInputElement>) =>
  54. dashboardDispatch(actions.setFromControl(e.target.value))
  55. }
  56. value={dashboardState.from}
  57. name="Comparación"
  58. />
  59. </div>
  60. <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
  61. <CalendarInput
  62. onChange={(e: ChangeEvent<HTMLInputElement>) =>
  63. dashboardDispatch(actions.setToControl(e.target.value))
  64. }
  65. value={dashboardState.to}
  66. name="Comparación"
  67. />
  68. </div>
  69. <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
  70. <Select
  71. list={campaignList}
  72. onChange={(e: ChangeEvent<HTMLInputElement>) =>
  73. dashboardDispatch(actions.setYearControl(e.target.value))
  74. }
  75. value={dashboardState.year}
  76. name="Comparación"
  77. placeholder="Año historicos"
  78. />
  79. </div>
  80. {/* <div className="col-auto"> */}
  81. {/* <button type="button" className="btn btn-primary"> */}
  82. {/* Aplicar */}
  83. {/* </button> */}
  84. {/* </div> */}
  85. </section>
  86. );
  87. };
  88. export default Cockpit;