|
@@ -17,8 +17,11 @@ import { sectors } from "../../../../api";
|
|
|
import { UserStateContext } from "../../../../context/auth/AuthProvider";
|
|
import { UserStateContext } from "../../../../context/auth/AuthProvider";
|
|
|
import { Station } from "../../../../types";
|
|
import { Station } from "../../../../types";
|
|
|
import { mustCheckDateOrder } from "../../../../utils";
|
|
import { mustCheckDateOrder } from "../../../../utils";
|
|
|
|
|
+import Modal from "../../../portals/modal";
|
|
|
|
|
|
|
|
const Cockpit: FC = () => {
|
|
const Cockpit: FC = () => {
|
|
|
|
|
+ const [error, setError] = useState<string | null>(null);
|
|
|
|
|
+
|
|
|
const dashboardState = useContext(StateContext);
|
|
const dashboardState = useContext(StateContext);
|
|
|
const dashboardDispatch = useContext(DispatchContext);
|
|
const dashboardDispatch = useContext(DispatchContext);
|
|
|
const userState = useContext(UserStateContext);
|
|
const userState = useContext(UserStateContext);
|
|
@@ -63,62 +66,85 @@ const Cockpit: FC = () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleFromChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
const handleFromChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
|
- mustCheckDateOrder(e.target.value, dashboardState.to);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ mustCheckDateOrder(e.target.value, dashboardState.to);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ setError(e as any);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
return dashboardDispatch(actions.setFromControl(e.target.value));
|
|
return dashboardDispatch(actions.setFromControl(e.target.value));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleToChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
const handleToChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ mustCheckDateOrder(e.target.value, dashboardState.to);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ setError(e as any);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
mustCheckDateOrder(e.target.value, dashboardState.to);
|
|
mustCheckDateOrder(e.target.value, dashboardState.to);
|
|
|
return dashboardDispatch(actions.setToControl(e.target.value));
|
|
return dashboardDispatch(actions.setToControl(e.target.value));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <section className="row p-lg-4 p-md-3 p-2">
|
|
|
|
|
- {/* Finca */}
|
|
|
|
|
- <div className="col-12 col-lg-4 mb-2 col-xl-3 mb-xl-0">
|
|
|
|
|
- <Select
|
|
|
|
|
- list={sectorChoices}
|
|
|
|
|
- onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
|
|
|
|
- dashboardDispatch(actions.setSector(e.target.value))
|
|
|
|
|
- }
|
|
|
|
|
- name="Comparación"
|
|
|
|
|
- placeholder="Fincas"
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
-
|
|
|
|
|
- {/* Campania */}
|
|
|
|
|
- <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
|
|
|
|
|
- <Select
|
|
|
|
|
- list={campaignList}
|
|
|
|
|
- onChange={handleCampChange}
|
|
|
|
|
- value={selectedCampaignYear}
|
|
|
|
|
- name="Comparación"
|
|
|
|
|
- placeholder="Camapaña"
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
-
|
|
|
|
|
- {/* Desde */}
|
|
|
|
|
- <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
|
|
|
|
|
- <CalendarInput
|
|
|
|
|
- onChange={handleFromChange}
|
|
|
|
|
- value={dashboardState.from}
|
|
|
|
|
- name="Comparación"
|
|
|
|
|
- min={dashboardState.minDate}
|
|
|
|
|
- max={dashboardState.maxDate}
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
-
|
|
|
|
|
- {/* Hasta */}
|
|
|
|
|
- <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
|
|
|
|
|
- <CalendarInput
|
|
|
|
|
- onChange={handleToChange}
|
|
|
|
|
- value={dashboardState.to}
|
|
|
|
|
- name="Comparación"
|
|
|
|
|
- min={dashboardState.minDate}
|
|
|
|
|
- max={dashboardState.maxDate}
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
- </section>
|
|
|
|
|
|
|
+ <>
|
|
|
|
|
+ {error && (
|
|
|
|
|
+ <Modal
|
|
|
|
|
+ key="Error"
|
|
|
|
|
+ title={"Error"}
|
|
|
|
|
+ staticBackdrop
|
|
|
|
|
+ accept={() => setError(null)}
|
|
|
|
|
+ >
|
|
|
|
|
+ <p style={{ color: "red" }}>{error.toString()}</p>
|
|
|
|
|
+ </Modal>
|
|
|
|
|
+ )}
|
|
|
|
|
+ <section className="row p-lg-4 p-md-3 p-2">
|
|
|
|
|
+ {/* Finca */}
|
|
|
|
|
+ <div className="col-12 col-lg-4 mb-2 col-xl-3 mb-xl-0">
|
|
|
|
|
+ <Select
|
|
|
|
|
+ list={sectorChoices}
|
|
|
|
|
+ onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
|
|
|
|
+ dashboardDispatch(actions.setSector(e.target.value))
|
|
|
|
|
+ }
|
|
|
|
|
+ name="Comparación"
|
|
|
|
|
+ placeholder="Fincas"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* Campania */}
|
|
|
|
|
+ <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
|
|
|
|
|
+ <Select
|
|
|
|
|
+ list={campaignList}
|
|
|
|
|
+ onChange={handleCampChange}
|
|
|
|
|
+ value={selectedCampaignYear}
|
|
|
|
|
+ name="Comparación"
|
|
|
|
|
+ placeholder="Camapaña"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* Desde */}
|
|
|
|
|
+ <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
|
|
|
|
|
+ <CalendarInput
|
|
|
|
|
+ onChange={handleFromChange}
|
|
|
|
|
+ value={dashboardState.from}
|
|
|
|
|
+ name="Comparación"
|
|
|
|
|
+ min={dashboardState.minDate}
|
|
|
|
|
+ max={dashboardState.maxDate}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* Hasta */}
|
|
|
|
|
+ <div className="col-6 col-lg-4 mb-2 col-xl-auto mb-xl-0">
|
|
|
|
|
+ <CalendarInput
|
|
|
|
|
+ onChange={handleToChange}
|
|
|
|
|
+ value={dashboardState.to}
|
|
|
|
|
+ name="Comparación"
|
|
|
|
|
+ min={dashboardState.minDate}
|
|
|
|
|
+ max={dashboardState.maxDate}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </section>
|
|
|
|
|
+ </>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|