mirror of
https://github.com/netbirdio/dashboard.git
synced 2026-01-26 01:21:04 +00:00
Add support for decimal expiration time and switch to days if interval exceeds 48h (#357)
* Add helper function to check for integer * Add support for decimal expiration time and switch to days if interval exceeds 48h
This commit is contained in:
@@ -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
|
||||
}, []);
|
||||
|
||||
@@ -75,3 +75,7 @@ export const validator = {
|
||||
return semverRegex.test(version);
|
||||
},
|
||||
};
|
||||
|
||||
export function isInt(n: number) {
|
||||
return n % 1 === 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user