From d9a17582d5b1064da6370ba813e1188d41876bf5 Mon Sep 17 00:00:00 2001 From: jordyBSK <125542402+jordyBSK@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:47:15 +0200 Subject: [PATCH] feat: remove the choice of precision according to the days chosen (#95) --- .../src/app/dashboard/esp/[espId]/page.tsx | 18 +++++++----------- nextjs-interface/src/lib/data.ts | 7 ------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/nextjs-interface/src/app/dashboard/esp/[espId]/page.tsx b/nextjs-interface/src/app/dashboard/esp/[espId]/page.tsx index 65c52e2..c98cfa5 100644 --- a/nextjs-interface/src/app/dashboard/esp/[espId]/page.tsx +++ b/nextjs-interface/src/app/dashboard/esp/[espId]/page.tsx @@ -19,7 +19,7 @@ import { } from "@/lib/data"; // import libraries -import { endOfMonth, format, startOfMonth } from "date-fns"; +import { differenceInDays, endOfWeek, format, startOfWeek } from "date-fns"; import { DateRange } from "react-day-picker"; import React, { useState } from "react"; @@ -39,8 +39,8 @@ export default function Page({ params }: { params: any }) { const [date, setDate] = React.useState(() => { const now = new Date(); return { - from: startOfMonth(now), - to: endOfMonth(now), + from: startOfWeek(now), + to: endOfWeek(now), }; }); @@ -69,8 +69,9 @@ export default function Page({ params }: { params: any }) { const handleSelect = (value: any) => { setPrecision(value); - console.log(value); }; + const dateRangeInDays = + date?.from && date?.to ? differenceInDays(date.to, date.from) : 0; return (
@@ -104,16 +105,11 @@ export default function Page({ params }: { params: any }) { 7 ? "cursor-not-allowed opacity-50" : ""}`} + disabled={dateRangeInDays > 7} > Hour - - Minute -
diff --git a/nextjs-interface/src/lib/data.ts b/nextjs-interface/src/lib/data.ts index 7aacd21..6c59631 100644 --- a/nextjs-interface/src/lib/data.ts +++ b/nextjs-interface/src/lib/data.ts @@ -34,7 +34,6 @@ export const useFetchData = ( .then((response) => response.json()) .then((apiData: avgData[]) => { setData(apiData); - console.log("useFetchData", apiData); }) .catch((e) => { console.error("Une erreur s'est produite :", e); @@ -52,7 +51,6 @@ export function useLastData(type: string, ip: string) { fetch(url, { headers: { Authorization: `Bearer ${getToken()}` } }) .then((response) => response.json()) .then((apiData: data[]) => { - console.log("useLastData", apiData); if (apiData && apiData.length > 0) { if (type == "humidity") { setValue(apiData[0].humidity); @@ -76,7 +74,6 @@ export const useAllEsp = () => { .then((response) => response.json()) .then((apiEsp: esp[]) => { setEsp(apiEsp); - console.log("useAllEsp", apiEsp); }) .catch((e) => { console.error("Une erreur s'est produite :", e); @@ -94,7 +91,6 @@ export default function useFindIpById(id: string) { fetch(url, { headers: { Authorization: `Bearer ${getToken()}` } }) .then((response) => response.json()) .then((apiIp: esp[]) => { - console.log("useFindIpByName", apiIp); setIp(apiIp[0].ip); }) .catch((e) => { @@ -113,7 +109,6 @@ export function useFindNameById(id: string) { fetch(url, { headers: { Authorization: `Bearer ${getToken()}` } }) .then((response) => response.json()) .then((apiIp: esp[]) => { - console.log("useFindIpByName", apiIp); setName(apiIp[0].name); }) .catch((e) => { @@ -133,7 +128,6 @@ export function useAllUsers() { .then((response) => response.json()) .then((apiUsers: user[]) => { setUsers(apiUsers); - console.log("useAllusers", apiUsers); }) .catch((e) => { console.error("Une erreur s'est produite :", e); @@ -152,7 +146,6 @@ export function GetEspPosition(id: string) { .then((response) => response.json()) .then((apiPosition: esp[]) => { setPosition(apiPosition); - console.log("GetEspPosition", apiPosition); }) .catch((e) => { console.error("Une erreur s'est produite :", e);