index.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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(
  55. actions.setFromControl(e.target.valueAsDate?.toISOString() ?? "")
  56. )
  57. }
  58. value={dashboardState.from.slice(0, 10)}
  59. name="Comparación"
  60. />
  61. </div>
  62. <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
  63. <CalendarInput
  64. onChange={(e: ChangeEvent<HTMLInputElement>) =>
  65. dashboardDispatch(
  66. actions.setToControl(e.target.valueAsDate?.toISOString() ?? "")
  67. )
  68. }
  69. value={dashboardState.to.slice(0, 10)}
  70. name="Comparación"
  71. />
  72. </div>
  73. <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
  74. <Select
  75. list={campaignList}
  76. onChange={(e: ChangeEvent<HTMLInputElement>) =>
  77. dashboardDispatch(actions.setYearControl(e.target.value))
  78. }
  79. value={dashboardState.year}
  80. name="Comparación"
  81. placeholder="Año historicos"
  82. />
  83. </div>
  84. {/* <div className="col-auto"> */}
  85. {/* <button type="button" className="btn btn-primary"> */}
  86. {/* Aplicar */}
  87. {/* </button> */}
  88. {/* </div> */}
  89. </section>
  90. );
  91. };
  92. export default Cockpit;