diff --git a/src/modules/settings/AuthenticationTab.tsx b/src/modules/settings/AuthenticationTab.tsx index a924cef..a24b194 100644 --- a/src/modules/settings/AuthenticationTab.tsx +++ b/src/modules/settings/AuthenticationTab.tsx @@ -15,7 +15,7 @@ import { } from "@components/Select"; import * as Tabs from "@radix-ui/react-tabs"; import { useApiCall } from "@utils/api"; -import { cn } from "@utils/helpers"; +import { cn, isInt } from "@utils/helpers"; import { isLocalDev, isNetBirdHosted } from "@utils/netbird"; import { CalendarClock, ShieldIcon, TimerReset, VoteIcon } from "lucide-react"; import React, { useMemo, useState } from "react"; @@ -55,18 +55,21 @@ export default function AuthenticationTab({ account }: Props) { const [expiresInSeconds] = useState( account.settings.peer_login_expiration || 86400, ); + const [expiresIn, setExpiresIn] = useState(() => { - if (expiresInSeconds <= 86400) { - return Math.round(expiresInSeconds / 3600).toString(); + if (expiresInSeconds <= 172800) { + const hours = expiresInSeconds / 3600; + return isInt(hours) ? hours.toString() : hours.toFixed(2).toString(); } - return Math.round(expiresInSeconds / 86400).toString(); + const days = expiresInSeconds / 86400; + return isInt(days) ? days.toString() : days.toFixed(2).toString(); }); /** * Interval */ const initialInterval = useMemo(() => { - if (expiresInSeconds <= 86400) return "hours"; + if (expiresInSeconds <= 172800) return "hours"; return "days"; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index a42b9f5..45510bf 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -75,3 +75,7 @@ export const validator = { return semverRegex.test(version); }, }; + +export function isInt(n: number) { + return n % 1 === 0; +}