Explorar o código

Control de finca

wilitp %!s(int64=4) %!d(string=hai) anos
pai
achega
6938ad1acf

+ 1 - 1
app/src/components/UI/dashboard/cockpit/index.tsx

@@ -20,7 +20,7 @@ const Cockpit: FC = () => {
         <Select
           list={fincaList}
           onChange={(e: ChangeEvent<HTMLInputElement>) =>
-            console.log(e.target.value)
+            dashboardDispatch(actions.setSector(e.target.value))
           }
           name="Comparación"
           placeholder="Fincas"

+ 3 - 1
app/src/context/dashboard/actionTypes.ts

@@ -1,10 +1,12 @@
 export type ActionType =
   | "SET_FROM_CONTROL"
   | "SET_TO_CONTROL"
-  | "SET_YEAR_CONTROL";
+  | "SET_YEAR_CONTROL"
+  | "SET_SECTOR";
 
 export type Action = {
   type: ActionType;
+  sector?: string | null;
   to?: string | null;
   from?: string | null;
   year?: string | null;

+ 5 - 0
app/src/context/dashboard/actions.ts

@@ -15,4 +15,9 @@ export const setToControl = (to: string): Action => ({
   to,
 });
 
+export const setSector = (sector: string): Action => ({
+  type: "SET_SECTOR",
+  sector,
+});
+
 export default {};

+ 8 - 0
app/src/context/dashboard/reducer.ts

@@ -14,13 +14,16 @@ export const getInitialState = (): State => {
     dayNum < 10 ? `0${dayNum}` : dayNum
   }`;
   return {
+    sector: null,
     year: now.getFullYear().toString(),
     from: day,
     to: day,
   };
 };
 
+// Sector = Station
 export type State = {
+  sector: string | null;
   to: string;
   from: string;
   year: string;
@@ -31,6 +34,11 @@ const fixYear = (year: string, dateString: string) =>
 
 const reducer: Reducer<State, Action> = (state, action) => {
   switch (action.type) {
+    case "SET_SECTOR":
+      return {
+        ...state,
+        sector: action.sector!,
+      };
     case "SET_TO_CONTROL":
       return {
         ...state,