Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8eebec78b4 | ||
|
|
3e01a6dafd | ||
|
|
1555b94043 | ||
|
|
6c62127d42 | ||
|
|
b71d0fde89 | ||
|
|
84c239ce30 | ||
|
|
ba66201c64 | ||
|
|
c6341e000f | ||
|
|
750f660bcc | ||
|
|
ea148545e8 | ||
|
|
d2febbf27b | ||
|
|
615b4487ad | ||
|
|
a7c7800916 | ||
|
|
3d51e0893e | ||
|
|
d7d44b5817 | ||
|
|
f67f39b68b | ||
|
|
d2bc7a1f57 | ||
|
|
818ba5daa4 | ||
|
|
3a30f76629 | ||
|
|
34dc21c89d | ||
|
|
2e37703622 | ||
|
|
8aec338c43 | ||
|
|
f4f0c240fd | ||
|
|
04e22a3c7e | ||
|
|
54ef076303 | ||
|
|
92676b6c38 | ||
|
|
3affa8908f | ||
|
|
52fd984912 | ||
|
|
83e3159ee4 |
13
.github/workflows/build_and_push.yml
vendored
13
.github/workflows/build_and_push.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
- name: setup-node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '18'
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
@@ -54,8 +54,19 @@ jobs:
|
||||
fileName: "ironrdp_web_bg.wasm"
|
||||
out-file-path: 'public/ironrdp-pkg'
|
||||
|
||||
- name: Get version from tag
|
||||
id: version
|
||||
run: |
|
||||
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
||||
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "version=development" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
env:
|
||||
NEXT_PUBLIC_DASHBOARD_VERSION: ${{ steps.version.outputs.version }}
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -37,6 +37,8 @@ next-env.d.ts
|
||||
|
||||
# config
|
||||
.local-config.json
|
||||
.test-config.json
|
||||
cypress.env.json
|
||||
.configs/.local-config.zitadel.json
|
||||
.configs/.staging-config.json
|
||||
.configs/.temp-config.json
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## Contributor License Agreement
|
||||
|
||||
This Contributor License Agreement (referred to as the "Agreement") is entered into by the individual
|
||||
submitting this Agreement and NetBird GmbH, c/o Max-Beer-Straße 2-4 Münzstraße 12 10178 Berlin, Germany,
|
||||
submitting this Agreement and NetBird GmbH, Brunnenstraße 196, 10119 Berlin, Germany,
|
||||
referred to as "NetBird" (collectively, the "Parties"). The Agreement outlines the terms and conditions
|
||||
under which NetBird may utilize software contributions provided by the Contributor for inclusion in
|
||||
its software development projects. By submitting this Agreement, the Contributor confirms their acceptance
|
||||
|
||||
19
README.md
19
README.md
@@ -10,6 +10,7 @@ See [NetBird repo](https://github.com/netbirdio/netbird)
|
||||
|
||||
The purpose of this project is simple - make it easy to manage VPN built with [NetBird](https://github.com/netbirdio/netbird).
|
||||
The dashboard makes it possible to:
|
||||
|
||||
- track the status of your peers
|
||||
- remove peers
|
||||
- manage Setup Keys (to authenticate new peers)
|
||||
@@ -17,10 +18,10 @@ The dashboard makes it possible to:
|
||||
- define access controls
|
||||
|
||||
## Some Screenshots
|
||||
|
||||
<img src="./src/assets/screenshots/peers.png" alt="peers"/>
|
||||
<img src="./src/assets/screenshots/add-peer.png" alt="add-peer"/>
|
||||
|
||||
|
||||
## Technologies Used
|
||||
|
||||
- NextJS
|
||||
@@ -33,8 +34,9 @@ The dashboard makes it possible to:
|
||||
- Let's Encrypt
|
||||
|
||||
## How to run
|
||||
|
||||
Disclaimer. We believe that proper user management system is not a trivial task and requires quite some effort to make it right. Therefore we decided to
|
||||
use Auth0 service that covers all our needs (user management, social login, JTW for the management API).
|
||||
use Auth0 service that covers all our needs (user management, social login, JWT for the management API).
|
||||
Auth0 so far is the only 3rd party dependency that can't be really self-hosted.
|
||||
|
||||
1. Install [Docker](https://docs.docker.com/get-docker/)
|
||||
@@ -43,9 +45,9 @@ Auth0 so far is the only 3rd party dependency that can't be really self-hosted.
|
||||
|
||||
`AUTH0_DOMAIN` `AUTH0_CLIENT_ID` `AUTH0_AUDIENCE`
|
||||
|
||||
To obtain these, please use [Auth0 React SDK Guide](https://auth0.com/docs/quickstart/spa/react/01-login#configure-auth0) up until "Configure Allowed Web Origins"
|
||||
To obtain these, please use [Auth0 React SDK Guide](https://auth0.com/docs/quickstart/spa/react) up until "Configure Allowed Web Origins"
|
||||
|
||||
4. NetBird UI Dashboard uses NetBirds Management Service HTTP API, so setting `NETBIRD_MGMT_API_ENDPOINT` is required. Most likely it will be `http://localhost:33071` if you are hosting Management API on the same server.
|
||||
4. NetBird UI Dashboard uses NetBird's Management Service HTTP API, so setting `NETBIRD_MGMT_API_ENDPOINT` is required. Most likely it will be `http://localhost:33071` if you are hosting Management API on the same server.
|
||||
5. Run docker container without SSL (Let's Encrypt):
|
||||
|
||||
```shell
|
||||
@@ -54,9 +56,10 @@ Auth0 so far is the only 3rd party dependency that can't be really self-hosted.
|
||||
-e AUTH0_DOMAIN=<SET YOUR AUTH DOMAIN> \
|
||||
-e AUTH0_CLIENT_ID=<SET YOUR CLIENT ID> \
|
||||
-e AUTH0_AUDIENCE=<SET YOUR AUDIENCE> \
|
||||
-e NETBIRD_MGMT_API_ENDPOINT=<SET YOUR MANAGEMETN API URL> \
|
||||
-e NETBIRD_MGMT_API_ENDPOINT=<SET YOUR MANAGEMENT API URL> \
|
||||
netbirdio/dashboard:main
|
||||
```
|
||||
|
||||
6. Run docker container with SSL (Let's Encrypt):
|
||||
|
||||
```shell
|
||||
@@ -68,7 +71,7 @@ Auth0 so far is the only 3rd party dependency that can't be really self-hosted.
|
||||
-e AUTH0_DOMAIN=<SET YOUR AUTH DOMAIN> \
|
||||
-e AUTH0_CLIENT_ID=<SET YOUR CLEITN ID> \
|
||||
-e AUTH0_AUDIENCE=<SET YOUR AUDIENCE> \
|
||||
-e NETBIRD_MGMT_API_ENDPOINT=<SET YOUR MANAGEMETN API URL> \
|
||||
-e NETBIRD_MGMT_API_ENDPOINT=<SET YOUR MANAGEMENT API URL> \
|
||||
netbirdio/dashboard:main
|
||||
```
|
||||
|
||||
@@ -84,11 +87,11 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the
|
||||
You can start editing by modifying the code inside `src/..`
|
||||
The page auto-updates as you edit the file.
|
||||
|
||||
## How to migrate from old dashboard (v1)
|
||||
## How to migrate from old dashboard (v1)
|
||||
|
||||
The new dashboard comes with a new docker image `netbirdio/dashboard:main`.
|
||||
To migrate from the old dashboard (v1) `wiretrustee/dashboard:main` to the new one, please follow the steps below.
|
||||
|
||||
1. Stop the dashboard container `docker compose down dashboard`
|
||||
2. Replace the docker image name in your `docker-compose.yml` with `netbirdio/dashboard:main`
|
||||
3. Recreate the dashboard container `docker compose up -d --force-recreate dashboard`
|
||||
3. Recreate the dashboard container `docker compose up -d --force-recreate dashboard`
|
||||
|
||||
12
announcements.json
Normal file
12
announcements.json
Normal file
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"tag": "New",
|
||||
"text": "NetBird Reverse Proxy - Expose internal services to the public with automatic TLS and optional authentication.",
|
||||
"link": "https://docs.netbird.io/manage/reverse-proxy",
|
||||
"linkText": "Learn more",
|
||||
"variant": "important",
|
||||
"isExternal": true,
|
||||
"closeable": true,
|
||||
"isCloudOnly": false
|
||||
}
|
||||
]
|
||||
@@ -15,4 +15,4 @@
|
||||
"googleAnalyticsID": "$NETBIRD_GOOGLE_ANALYTICS_ID",
|
||||
"googleTagManagerID": "$NETBIRD_GOOGLE_TAG_MANAGER_ID",
|
||||
"wasmPath": "$NETBIRD_WASM_PATH"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ const nextConfig = {
|
||||
reactStrictMode: false,
|
||||
env: {
|
||||
APP_ENV: process.env.APP_ENV || "production",
|
||||
NEXT_PUBLIC_DASHBOARD_VERSION:
|
||||
process.env.NEXT_PUBLIC_DASHBOARD_VERSION || "development",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
4487
package-lock.json
generated
4487
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
72
package.json
72
package.json
@@ -2,6 +2,9 @@
|
||||
"name": "netbird-dashboard",
|
||||
"version": "2.0.0",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": ">=20.9.0"
|
||||
},
|
||||
"scripts": {
|
||||
"copy": "copyfiles -f ./node_modules/@axa-fr/react-oidc/dist/OidcServiceWorker.js ./public",
|
||||
"copytrusted": "copyfiles -f ./public/local/OidcTrustedDomains.js ./public",
|
||||
@@ -13,34 +16,34 @@
|
||||
"cypress:open": "cypress open"
|
||||
},
|
||||
"dependencies": {
|
||||
"@axa-fr/react-oidc": "^7.22.18",
|
||||
"@axa-fr/react-oidc": "^7.26.3",
|
||||
"@dagrejs/dagre": "^1.1.5",
|
||||
"@radix-ui/react-accordion": "^1.1.2",
|
||||
"@radix-ui/react-checkbox": "^1.0.4",
|
||||
"@radix-ui/react-collapsible": "^1.0.3",
|
||||
"@radix-ui/react-dialog": "^1.0.5",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||
"@radix-ui/react-hover-card": "^1.1.4",
|
||||
"@radix-ui/react-label": "^2.0.2",
|
||||
"@radix-ui/react-popover": "^1.0.7",
|
||||
"@radix-ui/react-radio-group": "^1.1.3",
|
||||
"@radix-ui/react-scroll-area": "^1.1.0",
|
||||
"@radix-ui/react-select": "^2.0.0",
|
||||
"@radix-ui/react-slider": "^1.1.2",
|
||||
"@radix-ui/react-slot": "^1.0.2",
|
||||
"@radix-ui/react-switch": "^1.0.3",
|
||||
"@radix-ui/react-tabs": "^1.0.4",
|
||||
"@radix-ui/react-toast": "^1.1.5",
|
||||
"@radix-ui/react-tooltip": "^1.0.7",
|
||||
"@tabler/icons-react": "^2.39.0",
|
||||
"@radix-ui/react-accordion": "^1.2.12",
|
||||
"@radix-ui/react-checkbox": "^1.3.3",
|
||||
"@radix-ui/react-collapsible": "^1.1.12",
|
||||
"@radix-ui/react-dialog": "^1.1.15",
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||
"@radix-ui/react-hover-card": "^1.1.15",
|
||||
"@radix-ui/react-label": "^2.1.8",
|
||||
"@radix-ui/react-popover": "^1.1.15",
|
||||
"@radix-ui/react-radio-group": "^1.3.8",
|
||||
"@radix-ui/react-scroll-area": "^1.2.10",
|
||||
"@radix-ui/react-select": "^2.2.6",
|
||||
"@radix-ui/react-slider": "^1.3.6",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@radix-ui/react-switch": "^1.2.6",
|
||||
"@radix-ui/react-tabs": "^1.1.13",
|
||||
"@radix-ui/react-toast": "^1.2.15",
|
||||
"@radix-ui/react-tooltip": "^1.2.8",
|
||||
"@tabler/icons-react": "^3.36.1",
|
||||
"@tanstack/match-sorter-utils": "^8.8.4",
|
||||
"@tanstack/react-table": "^8.10.7",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/d3": "^7.4.3",
|
||||
"@types/lodash": "^4.14.200",
|
||||
"@types/node": "20.10.6",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"@types/react-window": "^1.8.8",
|
||||
"@xterm/addon-fit": "^0.10.0",
|
||||
"@xterm/xterm": "^5.5.0",
|
||||
@@ -49,8 +52,9 @@
|
||||
"chart.js": "^4.4.8",
|
||||
"chroma-js": "^3.1.2",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"classnames": "^2.5.1",
|
||||
"clsx": "^2.0.0",
|
||||
"cmdk": "^0.2.0",
|
||||
"cmdk": "^1.1.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"d3": "^7.9.0",
|
||||
"date-fns": "^2.30.0",
|
||||
@@ -58,27 +62,27 @@
|
||||
"elkjs": "^0.10.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"flowbite": "^1.8.1",
|
||||
"flowbite-react": "^0.6.4",
|
||||
"framer-motion": "^10.16.4",
|
||||
"framer-motion": "^12.29.2",
|
||||
"ip-address": "^10.1.0",
|
||||
"ip-cidr": "^3.1.0",
|
||||
"js-cookie": "^3.0.5",
|
||||
"lodash": "^4.17.21",
|
||||
"lucide-react": "^0.539.0",
|
||||
"next": "^14.2.35",
|
||||
"lodash": "^4.17.23",
|
||||
"lucide-react": "^0.562.0",
|
||||
"next": "^16.1.6",
|
||||
"next-themes": "^0.2.1",
|
||||
"punycode": "^2.3.1",
|
||||
"react": "^18.3.1",
|
||||
"react-day-picker": "^8.9.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react": "^19.2.4",
|
||||
"react-day-picker": "^9.13.0",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-ga4": "^2.1.0",
|
||||
"react-hot-toast": "^2.4.1",
|
||||
"react-hotjar": "^6.2.0",
|
||||
"react-hotjar": "^6.3.1",
|
||||
"react-hotkeys-hook": "^4.4.1",
|
||||
"react-icons": "^5.5.0",
|
||||
"react-jwt": "^1.2.0",
|
||||
"react-loading-skeleton": "^3.3.1",
|
||||
"react-responsive": "^9.0.2",
|
||||
"react-virtuoso": "^4.9.0",
|
||||
"sonner": "^2.0.7",
|
||||
"swr": "^2.2.4",
|
||||
"tailwind-merge": "^1.14.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
@@ -90,7 +94,7 @@
|
||||
"@types/chroma-js": "^3.1.1",
|
||||
"@types/js-cookie": "^3.0.6",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-config-next": "^16.0.5",
|
||||
"eslint-config-next": "^16.1.6",
|
||||
"postcss": "^8",
|
||||
"prettier": "3.0.3",
|
||||
"tailwindcss": "^3.4.17"
|
||||
|
||||
@@ -6,5 +6,5 @@ import React from "react";
|
||||
|
||||
export default function Redirect() {
|
||||
useRedirect("/events/audit");
|
||||
return <FullScreenLoading height={"auto"} />;
|
||||
return <FullScreenLoading fullScreen={false} />;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,15 @@
|
||||
|
||||
import "@xyflow/react/dist/style.css";
|
||||
import Button from "@components/Button";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import { NoPeersGettingStarted } from "@components/NoPeersGettingStarted";
|
||||
import {
|
||||
SelectDropdown,
|
||||
SelectOption,
|
||||
} from "@components/select/SelectDropdown";
|
||||
import SquareIcon from "@components/SquareIcon";
|
||||
import GetStartedTest from "@components/ui/GetStartedTest";
|
||||
import { SmallBadge } from "@components/ui/SmallBadge";
|
||||
import useFetchApi from "@utils/api";
|
||||
import {
|
||||
Background,
|
||||
@@ -15,6 +20,8 @@ import {
|
||||
NodeTypes,
|
||||
ReactFlow,
|
||||
ReactFlowProvider,
|
||||
useEdgesState,
|
||||
useNodesState,
|
||||
useReactFlow,
|
||||
} from "@xyflow/react";
|
||||
import { forEach, orderBy, sortBy } from "lodash";
|
||||
@@ -25,9 +32,23 @@ import {
|
||||
MessageSquareShareIcon,
|
||||
NetworkIcon,
|
||||
} from "lucide-react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import NetworkRoutesIcon from "@/assets/icons/NetworkRoutesIcon";
|
||||
import PeersProvider from "@/contexts/PeersProvider";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import PoliciesProvider from "@/contexts/PoliciesProvider";
|
||||
import { useLoggedInUser } from "@/contexts/UsersProvider";
|
||||
import { Group } from "@/interfaces/Group";
|
||||
import { Network, NetworkResource } from "@/interfaces/Network";
|
||||
import { Peer } from "@/interfaces/Peer";
|
||||
import { Policy } from "@/interfaces/Policy";
|
||||
import { User } from "@/interfaces/User";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import { AccessControlUpdateModal } from "@/modules/access-control/AccessControlModal";
|
||||
import { FlowSelector, FlowView } from "@/modules/control-center/FlowSelector";
|
||||
import { NetworkRoutingPeerCount } from "@/modules/control-center/NetworkRoutingPeerCount";
|
||||
import { ControlCenterCurrentUserBadge } from "@/modules/control-center/user/ControlCenterCurrentUserBadge";
|
||||
import { EDGE_TYPES } from "@/modules/control-center/utils/edges";
|
||||
import {
|
||||
getFirstGroup,
|
||||
@@ -41,24 +62,6 @@ import {
|
||||
DEFAULT_MIN_ZOOM,
|
||||
} from "@/modules/control-center/utils/layouts";
|
||||
import { NODE_TYPES } from "@/modules/control-center/utils/nodes";
|
||||
import PeersProvider from "@/contexts/PeersProvider";
|
||||
import PoliciesProvider from "@/contexts/PoliciesProvider";
|
||||
import { Group } from "@/interfaces/Group";
|
||||
import { Network, NetworkResource } from "@/interfaces/Network";
|
||||
import { OperatingSystem } from "@/interfaces/OperatingSystem";
|
||||
import { Peer } from "@/interfaces/Peer";
|
||||
import { Policy } from "@/interfaces/Policy";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import { useLoggedInUser } from "@/contexts/UsersProvider";
|
||||
import { AccessControlUpdateModal } from "@/modules/access-control/AccessControlModal";
|
||||
import { NoPeersGettingStarted } from "@components/NoPeersGettingStarted";
|
||||
import GetStartedTest from "@components/ui/GetStartedTest";
|
||||
import SquareIcon from "@components/SquareIcon";
|
||||
import NetworkRoutesIcon from "@/assets/icons/NetworkRoutesIcon";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { SmallBadge } from "@components/ui/SmallBadge";
|
||||
|
||||
export default function ControlCenter() {
|
||||
return (
|
||||
@@ -71,8 +74,8 @@ export default function ControlCenter() {
|
||||
}
|
||||
|
||||
function ControlCenterView() {
|
||||
const [nodes, setNodes] = useState<Node[]>([]);
|
||||
const [edges, setEdges] = useState<Edge[]>([]);
|
||||
const [nodes, setNodes, onNodesChange] = useNodesState<Node>([]);
|
||||
const [edges, setEdges, onEdgesChange] = useEdgesState<Edge>([]);
|
||||
const reactFlow = useReactFlow();
|
||||
const [layoutInitialized, setLayoutInitialized] = useState(false);
|
||||
const [forceLayoutChange, setForceLayoutChange] = useState(false);
|
||||
@@ -82,6 +85,7 @@ function ControlCenterView() {
|
||||
const queryTab = queryParams.get("tab");
|
||||
const initialTab = useMemo(() => {
|
||||
if (queryTab === "peers") return FlowView.PEERS;
|
||||
if (queryTab === "users") return FlowView.USERS;
|
||||
if (queryTab === "groups") return FlowView.GROUPS;
|
||||
if (queryTab === "networks") return FlowView.NETWORKS;
|
||||
return FlowView.PEERS;
|
||||
@@ -99,17 +103,24 @@ function ControlCenterView() {
|
||||
>("/networks/resources");
|
||||
const { data: groups, isLoading: isGroupsLoading } =
|
||||
useFetchApi<Group[]>("/groups");
|
||||
const { data: users, isLoading: isUsersLoading } = useFetchApi<User[]>(
|
||||
"/users?service_user=false",
|
||||
);
|
||||
|
||||
const isLoading =
|
||||
isPoliciesLoading ||
|
||||
isPeersLoading ||
|
||||
isNetworksLoading ||
|
||||
isResourcesLoading ||
|
||||
isGroupsLoading;
|
||||
isGroupsLoading ||
|
||||
isUsersLoading;
|
||||
|
||||
const [selectedNetwork, setSelectedNetwork] = useState("");
|
||||
const [selectedGroup, setSelectedGroup] = useState("");
|
||||
const [selectedPeer, setSelectedPeer] = useState("");
|
||||
const [selectedUser, setSelectedUser] = useState("");
|
||||
const [previousSelectedUser, setPreviousSelectedUser] = useState("");
|
||||
|
||||
const [selectedPolicy, setSelectedPolicy] = useState("");
|
||||
const [selectedDestinationGroup, setSelectedDestinationGroup] = useState("");
|
||||
|
||||
@@ -138,14 +149,149 @@ function ControlCenterView() {
|
||||
|
||||
const onDestinationGroupSelect = useCallback(
|
||||
(groupId: string) => {
|
||||
setLayoutInitialized(false);
|
||||
if (selectedDestinationGroup == groupId) {
|
||||
setSelectedDestinationGroup("");
|
||||
} else {
|
||||
setSelectedDestinationGroup(groupId);
|
||||
const isTogglingSameGroup = selectedDestinationGroup === groupId;
|
||||
const newSelectedGroup = isTogglingSameGroup ? "" : groupId;
|
||||
|
||||
setSelectedDestinationGroup(newSelectedGroup);
|
||||
|
||||
if (
|
||||
currentView !== FlowView.PEERS &&
|
||||
currentView !== FlowView.GROUPS &&
|
||||
currentView !== FlowView.USERS
|
||||
) {
|
||||
setLayoutInitialized(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const getPeersAndResources = (groupId: string) => {
|
||||
const resources =
|
||||
networkResources?.filter((n) => {
|
||||
const resourceGroupIds =
|
||||
n.groups?.map((g) => (g as Group)?.id) || [];
|
||||
return resourceGroupIds.includes(groupId);
|
||||
}) || [];
|
||||
|
||||
const groupPeers =
|
||||
peers?.filter((p) => {
|
||||
const peerGroupIds = p.groups?.map((g) => g.id) || [];
|
||||
return peerGroupIds.includes(groupId);
|
||||
}) || [];
|
||||
|
||||
return { resources, peers: groupPeers };
|
||||
};
|
||||
|
||||
const addExpandedNodes = (groupId: string, baseNodes: Node[]) => {
|
||||
const { resources, peers } = getPeersAndResources(groupId);
|
||||
const destinationGroupNode = baseNodes.find(
|
||||
(node) => node.id === `group-${groupId}`,
|
||||
);
|
||||
|
||||
if (!destinationGroupNode) return [];
|
||||
|
||||
const baseX = destinationGroupNode.position.x + 300;
|
||||
const groupCenterY = destinationGroupNode.position.y;
|
||||
const nodeSpacing = 80;
|
||||
const totalNodes = peers.length + resources.length;
|
||||
const totalHeight = (totalNodes - 1) * nodeSpacing;
|
||||
const startY = groupCenterY - totalHeight / 2;
|
||||
|
||||
const newNodes: Node[] = [];
|
||||
let currentY = startY;
|
||||
|
||||
// Add peer nodes
|
||||
peers.forEach((peer) => {
|
||||
newNodes.push({
|
||||
id: `peer-${peer.id}`,
|
||||
type:
|
||||
currentView === FlowView.PEERS ? "expandedGroupPeer" : "peerNode",
|
||||
data: { peer },
|
||||
position: { x: baseX, y: currentY },
|
||||
});
|
||||
currentY += nodeSpacing;
|
||||
});
|
||||
|
||||
// Add resource nodes
|
||||
resources.forEach((resource) => {
|
||||
newNodes.push({
|
||||
id: `resource-${resource.id}`,
|
||||
type: "resourceNode",
|
||||
data: { resource },
|
||||
position: { x: baseX, y: currentY },
|
||||
});
|
||||
currentY += nodeSpacing;
|
||||
});
|
||||
|
||||
return newNodes;
|
||||
};
|
||||
|
||||
const addExpandedEdges = (groupId: string) => {
|
||||
const { resources, peers } = getPeersAndResources(groupId);
|
||||
const newEdges: Edge[] = [];
|
||||
|
||||
// Add peer edges
|
||||
peers.forEach((peer) => {
|
||||
newEdges.push({
|
||||
id: `group-peer-${groupId}-${peer.id}`,
|
||||
source: `group-${groupId}`,
|
||||
target: `peer-${peer.id}`,
|
||||
type: "simple",
|
||||
data: { enabled: true },
|
||||
});
|
||||
});
|
||||
|
||||
// Add resource edges
|
||||
resources.forEach((resource) => {
|
||||
newEdges.push({
|
||||
id: `group-resource-${groupId}-${resource.id}`,
|
||||
source: `group-${groupId}`,
|
||||
target: `resource-${resource.id}`,
|
||||
type: "simple",
|
||||
data: { enabled: true },
|
||||
});
|
||||
});
|
||||
|
||||
return newEdges;
|
||||
};
|
||||
|
||||
// Update nodes
|
||||
setNodes((prevNodes) => {
|
||||
// Remove previous nodes
|
||||
const baseNodes = prevNodes.filter(
|
||||
(node) =>
|
||||
!node.id.startsWith(`peer-`) && !node.id.startsWith(`resource-`),
|
||||
);
|
||||
// If toggling a new group, add its nodes
|
||||
if (!isTogglingSameGroup) {
|
||||
const expandedNodes = addExpandedNodes(groupId, baseNodes);
|
||||
return [...baseNodes, ...expandedNodes];
|
||||
}
|
||||
return baseNodes;
|
||||
});
|
||||
|
||||
// Update edges
|
||||
setEdges((prevEdges) => {
|
||||
// Remove all previously expanded peer/resource edges
|
||||
const baseEdges = prevEdges.filter(
|
||||
(edge) =>
|
||||
!edge.id.includes(`group-peer-`) &&
|
||||
!edge.id.includes(`group-resource-`),
|
||||
);
|
||||
// If expanding a new group, add its edges
|
||||
if (!isTogglingSameGroup) {
|
||||
const expandedEdges = addExpandedEdges(groupId);
|
||||
return [...baseEdges, ...expandedEdges];
|
||||
}
|
||||
return baseEdges;
|
||||
});
|
||||
},
|
||||
[selectedDestinationGroup],
|
||||
[
|
||||
selectedDestinationGroup,
|
||||
currentView,
|
||||
setNodes,
|
||||
setEdges,
|
||||
networkResources,
|
||||
peers,
|
||||
],
|
||||
);
|
||||
|
||||
const applySingleGroupView = (groupId: string) => {
|
||||
@@ -211,7 +357,6 @@ function ControlCenterView() {
|
||||
type: "destinationGroupNode",
|
||||
data: {
|
||||
group: destination,
|
||||
enabled,
|
||||
},
|
||||
position: { x: 0, y: 0 },
|
||||
});
|
||||
@@ -235,7 +380,7 @@ function ControlCenterView() {
|
||||
allNodes.push({
|
||||
id: peerNodeId,
|
||||
type: "peerNode",
|
||||
data: { peer, enabled },
|
||||
data: { peer },
|
||||
position: { x: 0, y: 0 },
|
||||
});
|
||||
} else {
|
||||
@@ -281,7 +426,7 @@ function ControlCenterView() {
|
||||
allNodes.push({
|
||||
id: resourceNodeId,
|
||||
type: "resourceNode",
|
||||
data: { resource, enabled },
|
||||
data: { resource },
|
||||
position: { x: 0, y: 0 },
|
||||
});
|
||||
} else {
|
||||
@@ -356,6 +501,9 @@ function ControlCenterView() {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Add destination resource nodes
|
||||
addDestinationResourceNodes(policy, allNodes, allEdges);
|
||||
});
|
||||
|
||||
return applyD3HierarchicalLayout(allNodes, allEdges, 400, 120, "group", {
|
||||
@@ -645,7 +793,6 @@ function ControlCenterView() {
|
||||
if (!groups || isGroupsLoading) return;
|
||||
if (!networks || isNetworksLoading) return;
|
||||
if (!networkResources || isResourcesLoading) return;
|
||||
if (layoutInitialized) return;
|
||||
|
||||
const allNodes: Node[] = [];
|
||||
const allEdges: Edge[] = [];
|
||||
@@ -704,7 +851,6 @@ function ControlCenterView() {
|
||||
type: "destinationGroupNode",
|
||||
data: {
|
||||
group: destination,
|
||||
enabled,
|
||||
},
|
||||
position: { x: 0, y: 0 },
|
||||
});
|
||||
@@ -848,6 +994,9 @@ function ControlCenterView() {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Add destination resource nodes
|
||||
addDestinationResourceNodes(policy, allNodes, allEdges);
|
||||
});
|
||||
|
||||
return applyD3HierarchicalLayout(allNodes, allEdges, 400, 120, "peer", {
|
||||
@@ -857,13 +1006,290 @@ function ControlCenterView() {
|
||||
});
|
||||
};
|
||||
|
||||
const addDestinationResourceNodes = (
|
||||
policy: Policy,
|
||||
nodes: Node[],
|
||||
edges: Edge[],
|
||||
) => {
|
||||
const destinationPolicyResource = policy?.rules?.[0].destinationResource;
|
||||
const enabled = policy.enabled;
|
||||
|
||||
if (destinationPolicyResource) {
|
||||
const type = destinationPolicyResource.type;
|
||||
const peer = peers?.find((p) => p.id === destinationPolicyResource.id);
|
||||
const resource = networkResources?.find(
|
||||
(r) => r.id === destinationPolicyResource.id,
|
||||
);
|
||||
const nodeId = `destination-resource-${destinationPolicyResource.id}`;
|
||||
const nodeExists = nodes.some((n) => n.id === nodeId);
|
||||
if (!nodeExists) {
|
||||
if (type === "peer" && peer) {
|
||||
nodes.push({
|
||||
id: nodeId,
|
||||
type: "destinationResourceNode",
|
||||
data: {
|
||||
peer: peer,
|
||||
enabled,
|
||||
className: "pl-3",
|
||||
},
|
||||
position: { x: 0, y: 0 },
|
||||
});
|
||||
} else if (resource) {
|
||||
nodes.push({
|
||||
id: nodeId,
|
||||
type: "destinationResourceNode",
|
||||
data: {
|
||||
resource: resource,
|
||||
enabled,
|
||||
className: "pl-3",
|
||||
},
|
||||
position: { x: 0, y: 0 },
|
||||
});
|
||||
}
|
||||
} else {
|
||||
nodes.forEach((n) => {
|
||||
if (n.id === nodeId) {
|
||||
n.data = {
|
||||
...n.data,
|
||||
enabled,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const edgeExists = edges.some(
|
||||
(e) => e.id === `policy-dest-resource-${policy.id}-${nodeId}`,
|
||||
);
|
||||
if (!edgeExists) {
|
||||
edges.push({
|
||||
id: `policy-dest-resource-${policy.id}-${nodeId}`,
|
||||
source: `policy-${policy.id}`,
|
||||
target: nodeId,
|
||||
type: "in",
|
||||
data: { enabled, type: "bezier" },
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const applyUserView = (userId: string) => {
|
||||
if (!policies || isLoading) return;
|
||||
if (!groups || isGroupsLoading) return;
|
||||
if (!networks || isNetworksLoading) return;
|
||||
if (!networkResources || isResourcesLoading) return;
|
||||
|
||||
const allNodes: Node[] = [];
|
||||
const allEdges: Edge[] = [];
|
||||
|
||||
// Get all peers for this user
|
||||
const userPeers = peers?.filter((p) => p.user_id === userId) || [];
|
||||
if (userPeers.length === 0) {
|
||||
return applyD3HierarchicalLayout([], [], 400, 120, "user", {
|
||||
policy: { width: 500, spacing: 60 },
|
||||
destinationGroup: { width: 1000, spacing: 100 },
|
||||
peersAndResources: { width: 1400, spacing: 80 },
|
||||
});
|
||||
}
|
||||
|
||||
// Add peer nodes
|
||||
userPeers.forEach((peer, index) => {
|
||||
allNodes.push({
|
||||
id: `source-peer-${peer.id}`,
|
||||
type: "sourcePeerNode",
|
||||
data: {
|
||||
peer,
|
||||
enabled: true,
|
||||
onClick: () => {
|
||||
setPreviousSelectedUser(userId);
|
||||
forceSinglePeerView(peer.id || "", userId);
|
||||
},
|
||||
},
|
||||
position: { x: 0, y: 0 },
|
||||
});
|
||||
|
||||
allEdges.push({
|
||||
id: `user-peer-${userId}-${peer.id}`,
|
||||
source: `select-user-node`,
|
||||
target: `source-peer-${peer.id}`,
|
||||
type: "simple",
|
||||
data: { enabled: true },
|
||||
});
|
||||
});
|
||||
|
||||
const allUserGroups = [
|
||||
...new Set(userPeers.flatMap((p) => p.groups?.map((g) => g.id) || [])),
|
||||
];
|
||||
const userPolicies = sortBy(
|
||||
policies?.filter((p) => {
|
||||
const rule = p.rules?.[0];
|
||||
if (!rule) return false;
|
||||
const sources = rule.sources as Group[];
|
||||
return sources?.some((d) => allUserGroups.includes(d.id));
|
||||
}),
|
||||
"enabled",
|
||||
"desc",
|
||||
);
|
||||
|
||||
// Add policies and their connections
|
||||
userPolicies?.forEach((policy, policyIndex) => {
|
||||
const enabled = policy.enabled;
|
||||
const policyNodeId = `policy-${policy.id}`;
|
||||
|
||||
allNodes.push({
|
||||
id: policyNodeId,
|
||||
type: "policyNode",
|
||||
data: { policy },
|
||||
position: { x: 600, y: policyIndex * 120 },
|
||||
});
|
||||
|
||||
// Add peer to policy edges
|
||||
const rule = policy.rules?.[0];
|
||||
const sourcesIds = (rule?.sources as Group[])?.map((g) => g.id) || [];
|
||||
|
||||
userPeers.forEach((peer) => {
|
||||
const peerGroupIds = peer.groups?.map((g) => g.id) || [];
|
||||
const hasSharedGroup = sourcesIds.some((sourceId) =>
|
||||
peerGroupIds.includes(sourceId),
|
||||
);
|
||||
|
||||
if (hasSharedGroup) {
|
||||
allEdges.push({
|
||||
id: `peer-policy-${peer.id}-${policy.id}`,
|
||||
source: `source-peer-${peer.id}`,
|
||||
target: policyNodeId,
|
||||
type: "in",
|
||||
data: { enabled, type: "bezier" },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Add destination groups
|
||||
const destinations = (rule?.destinations as Group[]) || [];
|
||||
destinations.forEach((destination, destIndex) => {
|
||||
const destinationNodeId = `group-${destination.id}`;
|
||||
const destinationNodeExists = allNodes.some(
|
||||
(n) => n.id === destinationNodeId,
|
||||
);
|
||||
|
||||
if (!destinationNodeExists) {
|
||||
allNodes.push({
|
||||
id: destinationNodeId,
|
||||
type: "destinationGroupNode",
|
||||
data: {
|
||||
group: destination,
|
||||
},
|
||||
position: { x: 900, y: policyIndex * 120 + destIndex * 60 },
|
||||
});
|
||||
}
|
||||
|
||||
const destinationEdgeExists = allEdges.some(
|
||||
(e) => e.id === `policy-group-${policy.id}-${destination.id}`,
|
||||
);
|
||||
if (!destinationEdgeExists) {
|
||||
allEdges.push({
|
||||
id: `policy-group-${policy.id}-${destination.id}`,
|
||||
source: policyNodeId,
|
||||
target: destinationNodeId,
|
||||
type: "in",
|
||||
data: { enabled, type: "bezier" },
|
||||
});
|
||||
}
|
||||
|
||||
// Add expanded destination group content if selected
|
||||
if (selectedDestinationGroup === destination.id) {
|
||||
const resources = networkResources.filter((n) => {
|
||||
const resourceGroupIds =
|
||||
n.groups?.map((g) => (g as Group)?.id) || [];
|
||||
return resourceGroupIds.includes(destination.id);
|
||||
});
|
||||
|
||||
const destinationPeers = peers?.filter((p) => {
|
||||
const peerGroupIds = p.groups?.map((g) => g.id) || [];
|
||||
return peerGroupIds.includes(destination.id);
|
||||
});
|
||||
|
||||
// Add peer nodes
|
||||
destinationPeers?.forEach((peer, peerIndex) => {
|
||||
const peerNodeId = `dest-peer-${peer.id}`;
|
||||
const peerNodeExists = allNodes.some((n) => n.id === peerNodeId);
|
||||
if (!peerNodeExists) {
|
||||
allNodes.push({
|
||||
id: peerNodeId,
|
||||
type: "peerNode",
|
||||
data: { peer },
|
||||
position: { x: 1200, y: policyIndex * 120 + peerIndex * 80 },
|
||||
});
|
||||
}
|
||||
|
||||
const peerEdgeExists = allEdges.some(
|
||||
(e) => e.id === `group-peer-${destination.id}-${peer.id}`,
|
||||
);
|
||||
if (!peerEdgeExists) {
|
||||
allEdges.push({
|
||||
id: `group-peer-${destination.id}-${peer.id}`,
|
||||
source: destinationNodeId,
|
||||
target: peerNodeId,
|
||||
type: "simple",
|
||||
data: { enabled },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Add resource nodes
|
||||
resources.forEach((resource, resourceIndex) => {
|
||||
const resourceNodeId = `resource-${resource.id}`;
|
||||
const resourceNodeExists = allNodes.some(
|
||||
(n) => n.id === resourceNodeId,
|
||||
);
|
||||
if (!resourceNodeExists) {
|
||||
allNodes.push({
|
||||
id: resourceNodeId,
|
||||
type: "resourceNode",
|
||||
data: { resource },
|
||||
position: {
|
||||
x: 1200,
|
||||
y:
|
||||
policyIndex * 120 +
|
||||
(destinationPeers?.length || 0) * 80 +
|
||||
resourceIndex * 80,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const resourceEdgeExists = allEdges.some(
|
||||
(e) => e.id === `group-resource-${destination.id}-${resource.id}`,
|
||||
);
|
||||
if (!resourceEdgeExists) {
|
||||
allEdges.push({
|
||||
id: `group-resource-${destination.id}-${resource.id}`,
|
||||
source: destinationNodeId,
|
||||
target: resourceNodeId,
|
||||
type: "simple",
|
||||
data: { enabled },
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Add destination resource nodes
|
||||
addDestinationResourceNodes(policy, allNodes, allEdges);
|
||||
});
|
||||
|
||||
return applyD3HierarchicalLayout(allNodes, allEdges, 400, 120, "user", {
|
||||
policy: { width: 500, spacing: 60 },
|
||||
destinationGroup: { width: 1000, spacing: 100 },
|
||||
peersAndResources: { width: 1400, spacing: 80 },
|
||||
});
|
||||
};
|
||||
|
||||
const fitView = (newNodes?: Node[]) => {
|
||||
window.requestAnimationFrame(() =>
|
||||
reactFlow.fitView({
|
||||
nodes: newNodes ?? nodes,
|
||||
padding: 0.1,
|
||||
duration: 750,
|
||||
maxZoom: DEFAULT_MAX_ZOOM,
|
||||
maxZoom: 0.8,
|
||||
minZoom: DEFAULT_MIN_ZOOM,
|
||||
}),
|
||||
);
|
||||
@@ -903,6 +1329,76 @@ function ControlCenterView() {
|
||||
});
|
||||
};
|
||||
|
||||
const handlePeerChange = (newPeerId: string) => {
|
||||
setNodes((prev) => {
|
||||
const shouldRecalculate = selectedPeer !== newPeerId;
|
||||
shouldRecalculate && setSelectedPeer(newPeerId);
|
||||
|
||||
let selectPeerNode;
|
||||
const previousNodes = prev.map((node) => {
|
||||
if (node.id === `select-peer-node`) {
|
||||
selectPeerNode = shouldRecalculate
|
||||
? {
|
||||
...node,
|
||||
data: {
|
||||
...node.data,
|
||||
currentPeer: newPeerId,
|
||||
},
|
||||
}
|
||||
: node;
|
||||
return selectPeerNode;
|
||||
}
|
||||
return node;
|
||||
});
|
||||
const result = applyPeerView(newPeerId);
|
||||
if (result && selectPeerNode) {
|
||||
let nodesWithCurrentPeer = result.updatedNodes;
|
||||
nodesWithCurrentPeer.push(selectPeerNode);
|
||||
setEdges(result.updatedEdges);
|
||||
setLayoutInitialized(true);
|
||||
shouldRecalculate && fitView(nodesWithCurrentPeer);
|
||||
return nodesWithCurrentPeer;
|
||||
} else {
|
||||
return previousNodes;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const handleUserChange = (newUserId: string) => {
|
||||
setNodes((prev) => {
|
||||
const shouldRecalculate = selectedUser !== newUserId;
|
||||
shouldRecalculate && setSelectedUser(newUserId);
|
||||
|
||||
let selectUserNode;
|
||||
const previousNodes = prev.map((node) => {
|
||||
if (node.id === `select-user-node`) {
|
||||
selectUserNode = shouldRecalculate
|
||||
? {
|
||||
...node,
|
||||
data: {
|
||||
...node.data,
|
||||
currentUser: newUserId,
|
||||
},
|
||||
}
|
||||
: node;
|
||||
return selectUserNode;
|
||||
}
|
||||
return node;
|
||||
});
|
||||
const result = applyUserView(newUserId);
|
||||
if (result && selectUserNode) {
|
||||
let nodesWithCurrentUser = result.updatedNodes;
|
||||
nodesWithCurrentUser.push(selectUserNode);
|
||||
setEdges(result.updatedEdges);
|
||||
setLayoutInitialized(true);
|
||||
shouldRecalculate && fitView(nodesWithCurrentUser);
|
||||
return nodesWithCurrentUser;
|
||||
} else {
|
||||
return previousNodes;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const forceSingleGroupView = (groupId: string) => {
|
||||
setSelectedGroup(groupId);
|
||||
setSelectedNetwork("");
|
||||
@@ -928,13 +1424,70 @@ function ControlCenterView() {
|
||||
}
|
||||
};
|
||||
|
||||
const forceSingleUserView = (userId: string) => {
|
||||
setSelectedPeer("");
|
||||
setSelectedUser("");
|
||||
setPreviousSelectedUser("");
|
||||
setCurrentView(FlowView.USERS);
|
||||
|
||||
const selectUserNode = {
|
||||
id: `select-user-node`,
|
||||
type: "selectUserNode",
|
||||
position: { x: -550, y: 0 },
|
||||
data: {
|
||||
currentUser: userId,
|
||||
onUserChange: handleUserChange,
|
||||
},
|
||||
};
|
||||
|
||||
setNodes([selectUserNode]);
|
||||
|
||||
const result = applyUserView(userId);
|
||||
if (result) {
|
||||
let nodesWithUser = result.updatedNodes;
|
||||
nodesWithUser.push(selectUserNode);
|
||||
setEdges(result.updatedEdges);
|
||||
setNodes(nodesWithUser);
|
||||
setLayoutInitialized(true);
|
||||
fitView(nodesWithUser);
|
||||
}
|
||||
};
|
||||
|
||||
const forceSinglePeerView = (peerId: string, userId?: string) => {
|
||||
setSelectedPeer(peerId);
|
||||
setSelectedNetwork("");
|
||||
setSelectedUser("");
|
||||
setCurrentView(FlowView.PEERS);
|
||||
const selectPeerNode = {
|
||||
id: `select-peer-node`,
|
||||
type: "selectPeerNode",
|
||||
position: { x: 0, y: 0 },
|
||||
data: {
|
||||
currentPeer: peerId,
|
||||
onPeerChange: handlePeerChange,
|
||||
userId: userId,
|
||||
placeholder: "Search peers of user...",
|
||||
},
|
||||
};
|
||||
setNodes([selectPeerNode]);
|
||||
const result = applyPeerView(peerId);
|
||||
if (result) {
|
||||
let nodesWithCurrentPeer = result.updatedNodes;
|
||||
nodesWithCurrentPeer.push(selectPeerNode);
|
||||
setEdges(result.updatedEdges);
|
||||
setNodes(nodesWithCurrentPeer);
|
||||
setLayoutInitialized(true);
|
||||
fitView(nodesWithCurrentPeer);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) return;
|
||||
if (layoutInitialized) return;
|
||||
|
||||
switch (currentView) {
|
||||
case FlowView.PEERS:
|
||||
if (peers?.length === 0) {
|
||||
if (!peers || peers.length === 0) {
|
||||
setEdges([]);
|
||||
setNodes([]);
|
||||
setLayoutInitialized(true);
|
||||
@@ -942,41 +1495,6 @@ function ControlCenterView() {
|
||||
return;
|
||||
}
|
||||
|
||||
const handlePeerChange = (newPeerId: string) => {
|
||||
setNodes((prev) => {
|
||||
const shouldRecalculate = selectedPeer !== newPeerId;
|
||||
shouldRecalculate && setSelectedPeer(newPeerId);
|
||||
|
||||
let selectPeerNode;
|
||||
const previousNodes = prev.map((node) => {
|
||||
if (node.id === `select-peer-node`) {
|
||||
selectPeerNode = shouldRecalculate
|
||||
? {
|
||||
...node,
|
||||
data: {
|
||||
...node.data,
|
||||
currentPeer: newPeerId,
|
||||
},
|
||||
}
|
||||
: node;
|
||||
return selectPeerNode;
|
||||
}
|
||||
return node;
|
||||
});
|
||||
const result = applyPeerView(newPeerId);
|
||||
if (result && selectPeerNode) {
|
||||
let nodesWithCurrentPeer = result.updatedNodes;
|
||||
nodesWithCurrentPeer.push(selectPeerNode);
|
||||
setEdges(result.updatedEdges);
|
||||
setLayoutInitialized(true);
|
||||
shouldRecalculate && fitView(nodesWithCurrentPeer);
|
||||
return nodesWithCurrentPeer;
|
||||
} else {
|
||||
return previousNodes;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (selectedPeer === "") {
|
||||
const userPeer = peers?.find((p) => p.user_id === loggedInUser?.id);
|
||||
const firstPeer = userPeer ?? peers?.[0];
|
||||
@@ -998,6 +1516,50 @@ function ControlCenterView() {
|
||||
handlePeerChange(selectedPeer);
|
||||
}
|
||||
|
||||
break;
|
||||
case FlowView.USERS:
|
||||
if (!users || users.length === 0) {
|
||||
setEdges([]);
|
||||
setNodes([]);
|
||||
setLayoutInitialized(true);
|
||||
fitView([]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedUser === "") {
|
||||
let initialUser = users?.find((u) => u.id === loggedInUser?.id);
|
||||
|
||||
if (
|
||||
!initialUser ||
|
||||
!peers?.some((p) => p.user_id === initialUser?.id)
|
||||
) {
|
||||
initialUser = users?.find(
|
||||
(u) => peers?.some((p) => p.user_id === u.id),
|
||||
);
|
||||
}
|
||||
|
||||
if (!initialUser) {
|
||||
initialUser = users?.[0];
|
||||
}
|
||||
|
||||
const initialUserId = initialUser?.id ?? "";
|
||||
setNodes([
|
||||
{
|
||||
id: `select-user-node`,
|
||||
type: "selectUserNode",
|
||||
position: { x: -550, y: 0 },
|
||||
data: {
|
||||
currentUser: initialUserId,
|
||||
onUserChange: handleUserChange,
|
||||
},
|
||||
},
|
||||
]);
|
||||
if (initialUserId !== "") handleUserChange(initialUserId);
|
||||
} else {
|
||||
resetView();
|
||||
handleUserChange(selectedUser);
|
||||
}
|
||||
|
||||
break;
|
||||
case FlowView.GROUPS:
|
||||
if (selectedGroup === "") {
|
||||
@@ -1023,7 +1585,7 @@ function ControlCenterView() {
|
||||
}
|
||||
break;
|
||||
case FlowView.NETWORKS:
|
||||
if (networks?.length === 0) {
|
||||
if (!networks || networks.length === 0) {
|
||||
setEdges([]);
|
||||
setNodes([]);
|
||||
setLayoutInitialized(true);
|
||||
@@ -1051,6 +1613,7 @@ function ControlCenterView() {
|
||||
selectedNetwork,
|
||||
selectedPeer,
|
||||
selectedGroup,
|
||||
selectedUser,
|
||||
isLoading,
|
||||
layoutInitialized,
|
||||
]);
|
||||
@@ -1077,6 +1640,7 @@ function ControlCenterView() {
|
||||
setSelectedPeer("");
|
||||
setSelectedGroup("");
|
||||
setSelectedNetwork("");
|
||||
setSelectedUser("");
|
||||
setCurrentView(view);
|
||||
|
||||
try {
|
||||
@@ -1108,7 +1672,11 @@ function ControlCenterView() {
|
||||
if (networkId && currentView === FlowView.NETWORKS) {
|
||||
onNetworkSelect(networkId);
|
||||
}
|
||||
if (currentView === FlowView.PEERS || currentView === FlowView.GROUPS) {
|
||||
if (
|
||||
currentView === FlowView.PEERS ||
|
||||
currentView === FlowView.GROUPS ||
|
||||
currentView === FlowView.USERS
|
||||
) {
|
||||
groupId && onGroupSelect(groupId);
|
||||
destinationGroupId && onDestinationGroupSelect(destinationGroupId);
|
||||
}
|
||||
@@ -1206,10 +1774,6 @@ function ControlCenterView() {
|
||||
<div className={"absolute left-0 top-0 z-10"}>
|
||||
<div className={"flex justify-between px-6 py-4 text-sm w-full"}>
|
||||
<div className={"flex gap-4"}>
|
||||
{selectedNetwork === "" && (
|
||||
<FlowSelector value={currentView} onChange={onViewChange} />
|
||||
)}
|
||||
|
||||
{selectedNetwork !== "" && (
|
||||
<Button
|
||||
variant={"secondary"}
|
||||
@@ -1221,6 +1785,28 @@ function ControlCenterView() {
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{previousSelectedUser !== "" && (
|
||||
<>
|
||||
<Button
|
||||
variant={"secondary"}
|
||||
size={"xs"}
|
||||
className={"!bg-nb-gray-930"}
|
||||
onClick={() => {
|
||||
forceSingleUserView(previousSelectedUser);
|
||||
}}
|
||||
>
|
||||
<ArrowLeftIcon size={14} />
|
||||
</Button>
|
||||
<ControlCenterCurrentUserBadge
|
||||
userId={previousSelectedUser}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{selectedNetwork === "" && previousSelectedUser === "" && (
|
||||
<FlowSelector value={currentView} onChange={onViewChange} />
|
||||
)}
|
||||
|
||||
{currentView === "networks" && (
|
||||
<div className={"w-64"}>
|
||||
<SelectDropdown
|
||||
@@ -1270,6 +1856,8 @@ function ControlCenterView() {
|
||||
<ReactFlow
|
||||
edges={edges}
|
||||
nodes={nodes}
|
||||
onNodesChange={onNodesChange}
|
||||
onEdgesChange={onEdgesChange}
|
||||
proOptions={{
|
||||
hideAttribution: true,
|
||||
}}
|
||||
|
||||
@@ -7,7 +7,7 @@ import SkeletonTable from "@components/skeletons/SkeletonTable";
|
||||
import { RestrictedAccess } from "@components/ui/RestrictedAccess";
|
||||
import { usePortalElement } from "@hooks/usePortalElement";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { ExternalLinkIcon, ServerIcon } from "lucide-react";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import React, { lazy, Suspense } from "react";
|
||||
import DNSIcon from "@/assets/icons/DNSIcon";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
@@ -15,7 +15,7 @@ import { NameserverGroup } from "@/interfaces/Nameserver";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
|
||||
const NameserverGroupTable = lazy(
|
||||
() => import("@/modules/dns-nameservers/table/NameserverGroupTable"),
|
||||
() => import("@/modules/dns/nameservers/table/NameserverGroupTable"),
|
||||
);
|
||||
|
||||
export default function NameServers() {
|
||||
@@ -40,7 +40,7 @@ export default function NameServers() {
|
||||
href={"/dns/nameservers"}
|
||||
label={"Nameservers"}
|
||||
active
|
||||
icon={<ServerIcon size={13} />}
|
||||
icon={<DNSIcon size={13} />}
|
||||
/>
|
||||
</Breadcrumbs>
|
||||
<h1 ref={headingRef}>Nameservers</h1>
|
||||
|
||||
@@ -11,5 +11,5 @@ export default function DNS() {
|
||||
router.push("/dns/nameservers");
|
||||
}, [router]);
|
||||
|
||||
return <FullScreenLoading height={"auto"} />;
|
||||
return <FullScreenLoading fullScreen={false} />;
|
||||
}
|
||||
|
||||
8
src/app/(dashboard)/dns/zones/layout.tsx
Normal file
8
src/app/(dashboard)/dns/zones/layout.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { globalMetaTitle } from "@utils/meta";
|
||||
import type { Metadata } from "next";
|
||||
import BlankLayout from "@/layouts/BlankLayout";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `Zones - DNS - ${globalMetaTitle}`,
|
||||
};
|
||||
export default BlankLayout;
|
||||
70
src/app/(dashboard)/dns/zones/page.tsx
Normal file
70
src/app/(dashboard)/dns/zones/page.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
"use client";
|
||||
|
||||
import Breadcrumbs from "@components/Breadcrumbs";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import SkeletonTable from "@components/skeletons/SkeletonTable";
|
||||
import { RestrictedAccess } from "@components/ui/RestrictedAccess";
|
||||
import { usePortalElement } from "@hooks/usePortalElement";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import React, { lazy, Suspense } from "react";
|
||||
import DNSIcon from "@/assets/icons/DNSIcon";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { DNS_ZONE_DOCS_LINK, DNSZone } from "@/interfaces/DNS";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import { DNSZonesProvider } from "@/modules/dns/zones/DNSZonesProvider";
|
||||
import DNSZoneIcon from "@/assets/icons/DNSZoneIcon";
|
||||
|
||||
const DNSZonesTable = lazy(
|
||||
() => import("@/modules/dns/zones/table/DNSZonesTable"),
|
||||
);
|
||||
|
||||
export default function DNSZonePage() {
|
||||
const { permission } = usePermissions();
|
||||
|
||||
const { data: zones, isLoading } = useFetchApi<DNSZone[]>("/dns/zones");
|
||||
|
||||
const { ref: headingRef, portalTarget } =
|
||||
usePortalElement<HTMLHeadingElement>();
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<div className={"p-default py-6"}>
|
||||
<Breadcrumbs>
|
||||
<Breadcrumbs.Item label={"DNS"} icon={<DNSIcon size={13} />} />
|
||||
<Breadcrumbs.Item
|
||||
href={"/dns/zones"}
|
||||
label={"Zones"}
|
||||
active
|
||||
icon={<DNSZoneIcon size={16} />}
|
||||
/>
|
||||
</Breadcrumbs>
|
||||
<h1 ref={headingRef}>Zones</h1>
|
||||
<Paragraph>
|
||||
Manage DNS zones to control domain name resolution for your network.
|
||||
</Paragraph>
|
||||
<Paragraph>
|
||||
Learn more about
|
||||
<InlineLink href={DNS_ZONE_DOCS_LINK} target={"_blank"}>
|
||||
DNS Zones
|
||||
<ExternalLinkIcon size={12} />
|
||||
</InlineLink>
|
||||
in our documentation.
|
||||
</Paragraph>
|
||||
</div>
|
||||
|
||||
<RestrictedAccess page={"DNS Zones"} hasAccess={permission?.dns?.read}>
|
||||
<Suspense fallback={<SkeletonTable />}>
|
||||
<DNSZonesProvider>
|
||||
<DNSZonesTable
|
||||
isLoading={isLoading}
|
||||
headingTarget={portalTarget}
|
||||
data={zones}
|
||||
/>
|
||||
</DNSZonesProvider>
|
||||
</Suspense>
|
||||
</RestrictedAccess>
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
78
src/app/(dashboard)/events/proxy/page.tsx
Normal file
78
src/app/(dashboard)/events/proxy/page.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
"use client";
|
||||
|
||||
import Breadcrumbs from "@components/Breadcrumbs";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import { RestrictedAccess } from "@components/ui/RestrictedAccess";
|
||||
import dayjs from "dayjs";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import ReverseProxyIcon from "@/assets/icons/ReverseProxyIcon";
|
||||
import React, { useMemo } from "react";
|
||||
import ActivityIcon from "@/assets/icons/ActivityIcon";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import ServerPaginationProvider from "@/contexts/ServerPaginationProvider";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import ReverseProxyEventsTable from "@/modules/reverse-proxy/events/ReverseProxyEventsTable";
|
||||
import { usePortalElement } from "@hooks/usePortalElement";
|
||||
import { REVERSE_PROXY_EVENTS_DOCS_LINK } from "@/interfaces/ReverseProxy";
|
||||
|
||||
export default function ProxyEventsPage() {
|
||||
const { permission } = usePermissions();
|
||||
const { ref: headingRef, portalTarget } =
|
||||
usePortalElement<HTMLHeadingElement>();
|
||||
|
||||
const defaultFilters = useMemo(
|
||||
() => ({
|
||||
start_date: dayjs().subtract(7, "day").startOf("day").toISOString(),
|
||||
end_date: dayjs().endOf("day").toISOString(),
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<div className="p-default py-6">
|
||||
<Breadcrumbs>
|
||||
<Breadcrumbs.Item
|
||||
label="Activity"
|
||||
disabled
|
||||
icon={<ActivityIcon size={13} />}
|
||||
/>
|
||||
<Breadcrumbs.Item
|
||||
href="/events/proxy"
|
||||
label="Proxy Events"
|
||||
icon={<ReverseProxyIcon size={15} />}
|
||||
/>
|
||||
</Breadcrumbs>
|
||||
|
||||
<h1 ref={headingRef}>Proxy Events</h1>
|
||||
|
||||
<Paragraph>
|
||||
View access logs for your reverse proxy services, including allowed
|
||||
and denied requests.
|
||||
</Paragraph>
|
||||
|
||||
<Paragraph>
|
||||
Learn more about{" "}
|
||||
<InlineLink href={REVERSE_PROXY_EVENTS_DOCS_LINK} target="_blank">
|
||||
Proxy Events <ExternalLinkIcon size={12} />
|
||||
</InlineLink>{" "}
|
||||
in our documentation.
|
||||
</Paragraph>
|
||||
</div>
|
||||
|
||||
<RestrictedAccess
|
||||
page="Proxy Events"
|
||||
hasAccess={permission?.services?.read}
|
||||
>
|
||||
<ServerPaginationProvider
|
||||
url="/events/proxy"
|
||||
defaultPageSize={10}
|
||||
defaultFilters={defaultFilters}
|
||||
>
|
||||
<ReverseProxyEventsTable headingTarget={portalTarget} />
|
||||
</ServerPaginationProvider>
|
||||
</RestrictedAccess>
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { useSearchParams } from "next/navigation";
|
||||
import React, { useState } from "react";
|
||||
import AccessControlIcon from "@/assets/icons/AccessControlIcon";
|
||||
import DNSIcon from "@/assets/icons/DNSIcon";
|
||||
import DNSZoneIcon from "@/assets/icons/DNSZoneIcon";
|
||||
import NetworkRoutesIcon from "@/assets/icons/NetworkRoutesIcon";
|
||||
import PeerIcon from "@/assets/icons/PeerIcon";
|
||||
import SetupKeysIcon from "@/assets/icons/SetupKeysIcon";
|
||||
@@ -24,6 +25,7 @@ import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import RoutesProvider from "@/contexts/RoutesProvider";
|
||||
import { Group, GROUP_TOOLTIP_TEXT } from "@/interfaces/Group";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import { GroupDNSZonesSection } from "@/modules/groups/details/GroupDNSZonesSection";
|
||||
import { GroupNameserversSection } from "@/modules/groups/details/GroupNameserversSection";
|
||||
import { GroupNetworkRoutesSection } from "@/modules/groups/details/GroupNetworkRoutesSection";
|
||||
import { GroupPeersSection } from "@/modules/groups/details/GroupPeersSection";
|
||||
@@ -134,7 +136,9 @@ const validAllGroupTabs = [
|
||||
"resources",
|
||||
"network-routes",
|
||||
"nameservers",
|
||||
"zones",
|
||||
];
|
||||
|
||||
const validOtherGroupTabs = ["users", "peers", "setup-keys"];
|
||||
|
||||
const GroupOverviewTabs = ({ group }: { group: Group }) => {
|
||||
@@ -162,6 +166,7 @@ const GroupOverviewTabs = ({ group }: { group: Group }) => {
|
||||
const resourcesCount = groupDetails?.resources_count || 0;
|
||||
const routesCount = groupDetails?.routes?.length || 0;
|
||||
const nameserversCount = groupDetails?.nameservers?.length || 0;
|
||||
const zonesCount = groupDetails?.zones?.length || 0;
|
||||
const setupKeysCount = groupDetails?.setupKeys?.length || 0;
|
||||
|
||||
return (
|
||||
@@ -249,6 +254,19 @@ const GroupOverviewTabs = ({ group }: { group: Group }) => {
|
||||
{singularize("Nameservers", nameserversCount)}
|
||||
</TabsTrigger>
|
||||
|
||||
<TabsTrigger
|
||||
value={"zones"}
|
||||
className={groupDetails === null ? "animate-pulse" : ""}
|
||||
>
|
||||
<DNSZoneIcon
|
||||
size={16}
|
||||
className={
|
||||
"fill-nb-gray-500 group-data-[state=active]/trigger:fill-netbird transition-all"
|
||||
}
|
||||
/>
|
||||
{singularize("Zones", zonesCount)}
|
||||
</TabsTrigger>
|
||||
|
||||
{group.name !== "All" && (
|
||||
<TabsTrigger
|
||||
value={"setup-keys"}
|
||||
@@ -304,6 +322,13 @@ const GroupOverviewTabs = ({ group }: { group: Group }) => {
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value={"zones"} className={"pb-8"}>
|
||||
<GroupDNSZonesSection
|
||||
zones={groupDetails?.zones}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value={"setup-keys"} className={"pb-8"}>
|
||||
<GroupSetupKeysSection
|
||||
setupKeys={groupDetails?.setupKeys}
|
||||
|
||||
@@ -61,7 +61,7 @@ export default function NetworkRoutes() {
|
||||
in our documentation.
|
||||
</Paragraph>
|
||||
|
||||
<Callout className={"max-w-xl mt-3"} variant={"warning"}>
|
||||
<Callout className={"max-w-xl mt-5"} variant={"warning"}>
|
||||
<span>
|
||||
We recommend using the new Networks concept to easier visualise
|
||||
and manage access to your resources.{" "}
|
||||
|
||||
@@ -12,14 +12,14 @@ import {
|
||||
} from "@components/DropdownMenu";
|
||||
import FullTooltip from "@components/FullTooltip";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import Separator from "@components/Separator";
|
||||
import FullScreenLoading from "@components/ui/FullScreenLoading";
|
||||
import useRedirect from "@hooks/useRedirect";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { cn, singularize } from "@utils/helpers";
|
||||
import {
|
||||
ArrowUpRightIcon,
|
||||
HelpCircle,
|
||||
Layers3Icon,
|
||||
MoreVertical,
|
||||
PencilLineIcon,
|
||||
ServerIcon,
|
||||
@@ -28,19 +28,27 @@ import {
|
||||
Trash2,
|
||||
} from "lucide-react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import React, { useMemo } from "react";
|
||||
import useUrlTab from "@/hooks/useUrlTab";
|
||||
import NetworkRoutesIcon from "@/assets/icons/NetworkRoutesIcon";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { Network } from "@/interfaces/Network";
|
||||
import { Network, NetworkResource, NetworkRouter } from "@/interfaces/Network";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import { NetworkInformationSquare } from "@/modules/networks/misc/NetworkInformationSquare";
|
||||
import {
|
||||
NetworkProvider,
|
||||
useNetworksContext,
|
||||
} from "@/modules/networks/NetworkProvider";
|
||||
import { ResourcesSection } from "@/modules/networks/resources/ResourcesSection";
|
||||
import { NetworkRoutingPeersSection } from "@/modules/networks/routing-peers/NetworkRoutingPeersSection";
|
||||
import { ResourcesTabContent } from "@/modules/networks/resources/ResourcesTabContent";
|
||||
import { NetworkRoutingPeersTabContent } from "@/modules/networks/routing-peers/NetworkRoutingPeersTabContent";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@components/Tabs";
|
||||
import PeerIcon from "@/assets/icons/PeerIcon";
|
||||
import ReverseProxyIcon from "@/assets/icons/ReverseProxyIcon";
|
||||
import { ReverseProxyFlatTargetsTabContent } from "@/modules/reverse-proxy/targets/flat/ReverseProxyFlatTargetsTabContent";
|
||||
import ReverseProxiesProvider, {
|
||||
flattenReverseProxies,
|
||||
useReverseProxies,
|
||||
} from "@/contexts/ReverseProxiesProvider";
|
||||
|
||||
export default function NetworkDetailPage() {
|
||||
const queryParameter = useSearchParams();
|
||||
@@ -53,7 +61,9 @@ export default function NetworkDetailPage() {
|
||||
useRedirect("/networks", false, !networkId);
|
||||
|
||||
return network && !isLoading ? (
|
||||
<NetworkOverview network={network} />
|
||||
<ReverseProxiesProvider initialNetwork={network}>
|
||||
<NetworkOverview network={network} />
|
||||
</ReverseProxiesProvider>
|
||||
) : (
|
||||
<FullScreenLoading />
|
||||
);
|
||||
@@ -62,8 +72,23 @@ export default function NetworkDetailPage() {
|
||||
function NetworkOverview({ network }: Readonly<{ network: Network }>) {
|
||||
const { permission } = usePermissions();
|
||||
|
||||
const [networkModal, setNetworkModal] = useState(false);
|
||||
const { mutate } = useSWRConfig();
|
||||
const { data: resources, isLoading: isResourcesLoading } = useFetchApi<
|
||||
NetworkResource[]
|
||||
>(`/networks/${network.id}/resources`);
|
||||
const { data: routers, isLoading: isRoutersLoading } = useFetchApi<
|
||||
NetworkRouter[]
|
||||
>(`/networks/${network.id}/routers`);
|
||||
|
||||
const { reverseProxies, isLoading: isServicesLoading } = useReverseProxies();
|
||||
const services = useMemo(
|
||||
() => flattenReverseProxies({ reverseProxies, network }),
|
||||
[reverseProxies, network],
|
||||
);
|
||||
|
||||
const [tab, setTab] = useUrlTab(
|
||||
["resources", "routing-peers", "services"],
|
||||
"resources",
|
||||
);
|
||||
|
||||
const isActive = !!(
|
||||
network?.routing_peers_count && network.routing_peers_count > 0
|
||||
@@ -72,7 +97,7 @@ function NetworkOverview({ network }: Readonly<{ network: Network }>) {
|
||||
return (
|
||||
<PageContainer>
|
||||
<NetworkProvider network={network}>
|
||||
<div className={"p-default py-6 mb-4"}>
|
||||
<div className={"p-default py-6"}>
|
||||
<Breadcrumbs>
|
||||
<Breadcrumbs.Item
|
||||
href={"/networks"}
|
||||
@@ -115,11 +140,58 @@ function NetworkOverview({ network }: Readonly<{ network: Network }>) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
<ResourcesSection network={network} />
|
||||
<div className={"h-3"} />
|
||||
<Separator />
|
||||
<NetworkRoutingPeersSection network={network} />
|
||||
<Tabs
|
||||
defaultValue={tab}
|
||||
onValueChange={setTab}
|
||||
value={tab}
|
||||
className={"pb-0 mb-0"}
|
||||
>
|
||||
<TabsList justify={"start"} className={"px-8"}>
|
||||
<TabsTrigger value={"resources"}>
|
||||
<Layers3Icon size={14} />
|
||||
{singularize("Resources", network?.resources?.length)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value={"routing-peers"}>
|
||||
<PeerIcon
|
||||
size={12}
|
||||
className={
|
||||
"fill-nb-gray-500 group-data-[state=active]/trigger:fill-netbird transition-all"
|
||||
}
|
||||
/>
|
||||
{singularize("Routing Peers", network?.routing_peers_count)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value={"services"}>
|
||||
<ReverseProxyIcon
|
||||
size={16}
|
||||
className={
|
||||
"fill-nb-gray-500 group-data-[state=active]/trigger:fill-netbird transition-all"
|
||||
}
|
||||
/>
|
||||
{singularize("Services", services.length)}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value={"resources"} className={"pb-8"}>
|
||||
<ResourcesTabContent
|
||||
data={resources}
|
||||
isLoading={isResourcesLoading}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value={"routing-peers"} className={"pb-8"}>
|
||||
<NetworkRoutingPeersTabContent
|
||||
routers={routers}
|
||||
isLoading={isRoutersLoading}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value={"services"} className={"pb-8"}>
|
||||
<ReverseProxyFlatTargetsTabContent
|
||||
targets={services}
|
||||
isLoading={isServicesLoading}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</NetworkProvider>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
@@ -26,7 +26,7 @@ import { RestrictedAccess } from "@components/ui/RestrictedAccess";
|
||||
import TextWithTooltip from "@components/ui/TextWithTooltip";
|
||||
import useRedirect from "@hooks/useRedirect";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { singularize } from "@utils/helpers";
|
||||
import dayjs from "dayjs";
|
||||
import { isEmpty, trim } from "lodash";
|
||||
import {
|
||||
@@ -37,12 +37,14 @@ import {
|
||||
FlagIcon,
|
||||
Globe,
|
||||
History,
|
||||
ListIcon,
|
||||
MapPin,
|
||||
MonitorSmartphoneIcon,
|
||||
NetworkIcon,
|
||||
PencilIcon,
|
||||
TimerResetIcon,
|
||||
RadioTowerIcon,
|
||||
} from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { toASCII } from "punycode";
|
||||
import React, { useMemo, useState } from "react";
|
||||
@@ -52,21 +54,28 @@ import RoundedFlag from "@/assets/countries/RoundedFlag";
|
||||
import CircleIcon from "@/assets/icons/CircleIcon";
|
||||
import NetBirdIcon from "@/assets/icons/NetBirdIcon";
|
||||
import PeerIcon from "@/assets/icons/PeerIcon";
|
||||
import ReverseProxyIcon from "@/assets/icons/ReverseProxyIcon";
|
||||
import { useCountries } from "@/contexts/CountryProvider";
|
||||
import PeerProvider, { usePeer } from "@/contexts/PeerProvider";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import RoutesProvider from "@/contexts/RoutesProvider";
|
||||
import { useHasChanges } from "@/hooks/useHasChanges";
|
||||
import type { Group } from "@/interfaces/Group";
|
||||
import type { Peer } from "@/interfaces/Peer";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import useGroupHelper from "@/modules/groups/useGroupHelper";
|
||||
import { AccessiblePeersSection } from "@/modules/peer/AccessiblePeersSection";
|
||||
import { PeerExpirationToggle } from "@/modules/peer/PeerExpirationToggle";
|
||||
import { PeerNetworkRoutesSection } from "@/modules/peer/PeerNetworkRoutesSection";
|
||||
import { PeerRemoteJobsSection } from "@/modules/peer/PeerRemoteJobsSection";
|
||||
import ReverseProxiesProvider, {
|
||||
flattenReverseProxies,
|
||||
useReverseProxies,
|
||||
} from "@/contexts/ReverseProxiesProvider";
|
||||
import { ReverseProxyFlatTargetsTabContent } from "@/modules/reverse-proxy/targets/flat/ReverseProxyFlatTargetsTabContent";
|
||||
import { PeerSSHToggle } from "@/modules/peer/PeerSSHToggle";
|
||||
import { RDPButton } from "@/modules/remote-access/rdp/RDPButton";
|
||||
import { SSHButton } from "@/modules/remote-access/ssh/SSHButton";
|
||||
import Link from "next/link";
|
||||
import { PeerExpirationSettings } from "@/modules/peer/PeerExpirationSettings";
|
||||
|
||||
export default function PeerPage() {
|
||||
const queryParameter = useSearchParams();
|
||||
@@ -80,12 +89,6 @@ export default function PeerPage() {
|
||||
|
||||
useRedirect("/peers", false, !peerId || isRestricted);
|
||||
|
||||
const peerKey = useMemo(() => {
|
||||
let id = peer?.id ?? "";
|
||||
let expiration = peer?.login_expiration_enabled ? "1" : "0";
|
||||
return `${id}-${expiration}`;
|
||||
}, [peer]);
|
||||
|
||||
if (isRestricted) {
|
||||
return (
|
||||
<PageContainer>
|
||||
@@ -104,10 +107,12 @@ export default function PeerPage() {
|
||||
/>
|
||||
);
|
||||
|
||||
return peer && !isLoading ? (
|
||||
<PeerProvider peer={peer} key={peerId} isPeerDetailPage={true}>
|
||||
<PeerOverview key={peerKey} />
|
||||
</PeerProvider>
|
||||
return peer && peer.id && !isLoading ? (
|
||||
<ReverseProxiesProvider initialPeer={peer}>
|
||||
<PeerProvider peer={peer} key={peerId} isPeerDetailPage={true}>
|
||||
<PeerOverview key={peer?.id} />
|
||||
</PeerProvider>
|
||||
</ReverseProxiesProvider>
|
||||
) : (
|
||||
<FullScreenLoading />
|
||||
);
|
||||
@@ -119,48 +124,62 @@ function PeerOverview() {
|
||||
return (
|
||||
<PageContainer>
|
||||
<RoutesProvider>
|
||||
<div className={"p-default py-6 pb-0"}>
|
||||
<Breadcrumbs>
|
||||
<Breadcrumbs.Item
|
||||
href={"/peers"}
|
||||
label={"Peers"}
|
||||
icon={<PeerIcon size={13} />}
|
||||
/>
|
||||
<Breadcrumbs.Item label={peer.ip} active />
|
||||
</Breadcrumbs>
|
||||
<PeerGeneralInformation />
|
||||
</div>
|
||||
<PeerOverviewTabs />
|
||||
<PeerSettingsProvider>
|
||||
<div className={"p-default py-6 pb-0"}>
|
||||
<Breadcrumbs>
|
||||
<Breadcrumbs.Item
|
||||
href={"/peers"}
|
||||
label={"Peers"}
|
||||
icon={<PeerIcon size={13} />}
|
||||
/>
|
||||
<Breadcrumbs.Item label={peer.ip} active />
|
||||
</Breadcrumbs>
|
||||
<PeerHeader />
|
||||
</div>
|
||||
<PeerOverviewTabs />
|
||||
</PeerSettingsProvider>
|
||||
</RoutesProvider>
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
|
||||
const PeerGeneralInformation = () => {
|
||||
const router = useRouter();
|
||||
type PeerSettingsContextType = {
|
||||
selectedGroups: Group[];
|
||||
setSelectedGroups: React.Dispatch<React.SetStateAction<Group[]>>;
|
||||
hasChanges: boolean;
|
||||
updatePeer: (newName?: string) => Promise<void>;
|
||||
name: string;
|
||||
setName: (name: string) => void;
|
||||
tab: string;
|
||||
setTab: (tab: string) => void;
|
||||
};
|
||||
|
||||
const PeerSettingsContext = React.createContext<PeerSettingsContextType | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
const usePeerSettings = () => {
|
||||
const context = React.useContext(PeerSettingsContext);
|
||||
if (!context) {
|
||||
throw new Error("usePeerSettings must be used within PeerSettingsProvider");
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
const PeerSettingsProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const { mutate } = useSWRConfig();
|
||||
const { peer, user, peerGroups, update } = usePeer();
|
||||
const { peer, peerGroups, update } = usePeer();
|
||||
const { permission } = usePermissions();
|
||||
const [name, setName] = useState(peer.name);
|
||||
const [showEditNameModal, setShowEditNameModal] = useState(false);
|
||||
const [loginExpiration, setLoginExpiration] = useState(
|
||||
peer.login_expiration_enabled,
|
||||
);
|
||||
const [inactivityExpiration, setInactivityExpiration] = useState(
|
||||
peer.inactivity_expiration_enabled,
|
||||
);
|
||||
const [tab, setTab] = useState("overview");
|
||||
const [selectedGroups, setSelectedGroups, { getAllGroupCalls }] =
|
||||
useGroupHelper({
|
||||
initial: peerGroups?.filter((g) => g?.name !== "All"),
|
||||
peer,
|
||||
});
|
||||
|
||||
/**
|
||||
* Detect if there are changes in the peer information, if there are changes, then enable the save button.
|
||||
*/
|
||||
const { hasChanges, updateRef: updateHasChangedRef } = useHasChanges([
|
||||
selectedGroups,
|
||||
loginExpiration,
|
||||
inactivityExpiration,
|
||||
]);
|
||||
|
||||
const updatePeer = async (newName?: string) => {
|
||||
@@ -170,8 +189,6 @@ const PeerGeneralInformation = () => {
|
||||
if (permission.peers.update) {
|
||||
const updateRequest = update({
|
||||
name: newName ?? name,
|
||||
loginExpiration,
|
||||
inactivityExpiration,
|
||||
});
|
||||
batchCall = groupCalls ? [...groupCalls, updateRequest] : [updateRequest];
|
||||
} else {
|
||||
@@ -184,17 +201,37 @@ const PeerGeneralInformation = () => {
|
||||
promise: Promise.all(batchCall).then(() => {
|
||||
mutate("/peers/" + peer.id);
|
||||
mutate("/groups");
|
||||
updateHasChangedRef([
|
||||
selectedGroups,
|
||||
loginExpiration,
|
||||
inactivityExpiration,
|
||||
]);
|
||||
updateHasChangedRef([selectedGroups]);
|
||||
}),
|
||||
loadingMessage: "Saving the peer...",
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<PeerSettingsContext.Provider
|
||||
value={{
|
||||
selectedGroups,
|
||||
setSelectedGroups,
|
||||
hasChanges,
|
||||
updatePeer,
|
||||
name,
|
||||
setName,
|
||||
tab,
|
||||
setTab,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</PeerSettingsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const PeerHeader = () => {
|
||||
const router = useRouter();
|
||||
const { peer, user } = usePeer();
|
||||
const { permission } = usePermissions();
|
||||
const { name, setName, hasChanges, updatePeer, tab } = usePeerSettings();
|
||||
const [showEditNameModal, setShowEditNameModal] = useState(false);
|
||||
const isOverviewTab = tab === "overview";
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -255,83 +292,145 @@ const PeerGeneralInformation = () => {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className={"flex gap-4"}>
|
||||
<Button
|
||||
variant={"default"}
|
||||
className={"w-full"}
|
||||
onClick={() => router.push("/peers")}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant={"primary"}
|
||||
className={"w-full"}
|
||||
onClick={() => updatePeer()}
|
||||
disabled={
|
||||
!hasChanges || !permission.peers.read || !permission.groups.update
|
||||
}
|
||||
>
|
||||
Save Changes
|
||||
</Button>
|
||||
</div>
|
||||
{isOverviewTab && (
|
||||
<div className={"flex gap-4"}>
|
||||
<Button
|
||||
variant={"default"}
|
||||
className={"w-full"}
|
||||
onClick={() => router.push("/peers")}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant={"primary"}
|
||||
className={"w-full"}
|
||||
onClick={() => updatePeer()}
|
||||
disabled={
|
||||
!hasChanges ||
|
||||
!permission.peers.update ||
|
||||
!permission.groups.update
|
||||
}
|
||||
>
|
||||
Save Changes
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const PeerOverviewTabs = () => {
|
||||
const { peer } = usePeer();
|
||||
const { permission } = usePermissions();
|
||||
const { reverseProxies, isLoading: isServicesLoading } = useReverseProxies();
|
||||
const { tab, setTab } = usePeerSettings();
|
||||
|
||||
const flatTargets = useMemo(
|
||||
() => flattenReverseProxies({ reverseProxies, peer }),
|
||||
[reverseProxies, peer],
|
||||
);
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
defaultValue={tab}
|
||||
onValueChange={setTab}
|
||||
value={tab}
|
||||
className={"pt-4 pb-0 mb-0"}
|
||||
>
|
||||
<TabsList justify={"start"} className={"px-8"}>
|
||||
<TabsTrigger value={"overview"}>
|
||||
<ListIcon size={16} />
|
||||
Overview
|
||||
</TabsTrigger>
|
||||
|
||||
{permission.routes.read && (
|
||||
<TabsTrigger value={"network-routes"}>
|
||||
<NetworkIcon size={16} />
|
||||
Network Routes
|
||||
</TabsTrigger>
|
||||
)}
|
||||
|
||||
{peer?.id && permission.peers.read && (
|
||||
<TabsTrigger value={"accessible-peers"}>
|
||||
<MonitorSmartphoneIcon size={16} />
|
||||
Accessible Peers
|
||||
</TabsTrigger>
|
||||
)}
|
||||
|
||||
{peer?.id && permission.services?.read && (
|
||||
<TabsTrigger value={"reverse-proxies"}>
|
||||
<ReverseProxyIcon
|
||||
size={16}
|
||||
className="fill-nb-gray-400 group-data-[state=active]/trigger:fill-netbird"
|
||||
/>
|
||||
{singularize("Services", flatTargets.length)}
|
||||
</TabsTrigger>
|
||||
)}
|
||||
|
||||
{peer?.id && permission.peers.delete && (
|
||||
<TabsTrigger value={"peer-job"}>
|
||||
<RadioTowerIcon size={16} />
|
||||
Remote Jobs
|
||||
</TabsTrigger>
|
||||
)}
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value={"overview"} className={"pb-8"}>
|
||||
<PeerOverviewTabContent />
|
||||
</TabsContent>
|
||||
|
||||
{permission.routes.read && (
|
||||
<TabsContent value={"network-routes"} className={"pb-8"}>
|
||||
<PeerNetworkRoutesSection peer={peer} />
|
||||
</TabsContent>
|
||||
)}
|
||||
|
||||
{peer?.id && permission.peers.read && (
|
||||
<TabsContent value={"accessible-peers"} className={"pb-8"}>
|
||||
<AccessiblePeersSection peerID={peer.id} />
|
||||
</TabsContent>
|
||||
)}
|
||||
|
||||
{peer?.id && permission.services?.read && (
|
||||
<TabsContent value={"reverse-proxies"} className={"pb-8"}>
|
||||
<ReverseProxyFlatTargetsTabContent
|
||||
targets={flatTargets}
|
||||
isLoading={isServicesLoading}
|
||||
hideResourceColumn
|
||||
emptyTableTitle={"This peer has no services"}
|
||||
emptyTableDescription={
|
||||
"Add your services to this peer and securely expose them through NetBird's reverse proxy"
|
||||
}
|
||||
/>
|
||||
</TabsContent>
|
||||
)}
|
||||
|
||||
{peer.id && permission.peers.delete && (
|
||||
<TabsContent value={"peer-job"} className={"pb-8"}>
|
||||
<PeerRemoteJobsSection peerID={peer.id} />
|
||||
</TabsContent>
|
||||
)}
|
||||
</Tabs>
|
||||
);
|
||||
};
|
||||
|
||||
const PeerOverviewTabContent = () => {
|
||||
const { peer } = usePeer();
|
||||
const { permission } = usePermissions();
|
||||
const { selectedGroups, setSelectedGroups } = usePeerSettings();
|
||||
|
||||
return (
|
||||
<div className={"px-8"}>
|
||||
<div
|
||||
className={
|
||||
"flex-wrap xl:flex-nowrap flex gap-10 w-full mt-5 max-w-6xl items-start"
|
||||
"flex-wrap xl:flex-nowrap flex gap-10 w-full items-start pt-2 max-w-6xl"
|
||||
}
|
||||
>
|
||||
<PeerInformationCard peer={peer} />
|
||||
|
||||
<div className={"flex flex-col gap-6 lg:w-1/2 transition-all"}>
|
||||
<div>
|
||||
<PeerExpirationToggle
|
||||
peer={peer}
|
||||
value={loginExpiration}
|
||||
icon={<TimerResetIcon size={16} />}
|
||||
onChange={(state) => {
|
||||
setLoginExpiration(state);
|
||||
!state && setInactivityExpiration(false);
|
||||
}}
|
||||
/>
|
||||
{permission.peers.update && !!peer?.user_id && (
|
||||
<div
|
||||
className={cn(
|
||||
"border border-nb-gray-900 border-t-0 rounded-b-md bg-nb-gray-940 px-[1.28rem] pt-3 pb-5 flex flex-col gap-4 mx-[0.25rem]",
|
||||
!loginExpiration
|
||||
? "opacity-50 pointer-events-none"
|
||||
: "bg-nb-gray-930/80",
|
||||
)}
|
||||
>
|
||||
<PeerExpirationToggle
|
||||
peer={peer}
|
||||
variant={"blank"}
|
||||
value={inactivityExpiration}
|
||||
onChange={setInactivityExpiration}
|
||||
title={"Require login after disconnect"}
|
||||
description={
|
||||
"Enable to require authentication after users disconnect from management for 10 minutes."
|
||||
}
|
||||
className={
|
||||
!loginExpiration ? "opacity-40 pointer-events-none" : ""
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<PeerSSHToggle />
|
||||
|
||||
{/* Remote Access Buttons */}
|
||||
<div>
|
||||
<Label>Remote Access</Label>
|
||||
<HelpText>Connect directly to this peer via SSH or RDP.</HelpText>
|
||||
<div className="flex gap-3">
|
||||
<SSHButton peer={peer} />
|
||||
<RDPButton peer={peer} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={"flex flex-col gap-8 lg:w-1/2 transition-all"}>
|
||||
<PeerExpirationSettings />
|
||||
{permission.groups.read && (
|
||||
<div>
|
||||
<Label>Assigned Groups</Label>
|
||||
@@ -347,55 +446,21 @@ const PeerGeneralInformation = () => {
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<PeerSSHToggle />
|
||||
|
||||
{/* Remote Access Buttons */}
|
||||
<div>
|
||||
<Label>Remote Access</Label>
|
||||
<HelpText>Connect directly to this peer via SSH or RDP.</HelpText>
|
||||
<div className="flex gap-3">
|
||||
<SSHButton peer={peer} />
|
||||
<RDPButton peer={peer} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const PeerOverviewTabs = () => {
|
||||
const { peer } = usePeer();
|
||||
const { permission } = usePermissions();
|
||||
|
||||
const [tab, setTab] = useState(
|
||||
permission.routes.read ? "network-routes" : "accessible-peers",
|
||||
);
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
defaultValue={tab}
|
||||
onValueChange={(v) => setTab(v)}
|
||||
value={tab}
|
||||
className={"pt-10 pb-0 mb-0"}
|
||||
>
|
||||
<TabsList justify={"start"} className={"px-8"}>
|
||||
{permission.routes.read && (
|
||||
<TabsTrigger value={"network-routes"}>
|
||||
<NetworkIcon size={16} />
|
||||
Network Routes
|
||||
</TabsTrigger>
|
||||
)}
|
||||
|
||||
{peer?.id && permission.peers.read && (
|
||||
<TabsTrigger value={"accessible-peers"}>
|
||||
<MonitorSmartphoneIcon size={16} />
|
||||
Accessible Peers
|
||||
</TabsTrigger>
|
||||
)}
|
||||
</TabsList>
|
||||
|
||||
{permission.routes.read && (
|
||||
<TabsContent value={"network-routes"} className={"pb-8"}>
|
||||
<PeerNetworkRoutesSection peer={peer} />
|
||||
</TabsContent>
|
||||
)}
|
||||
|
||||
{peer?.id && permission.peers.read && (
|
||||
<TabsContent value={"accessible-peers"} className={"pb-8"}>
|
||||
<AccessiblePeersSection peerID={peer.id} />
|
||||
</TabsContent>
|
||||
)}
|
||||
</Tabs>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ function PeersBlockedView() {
|
||||
<div className={"px-3 pt-1 pb-8 max-w-3xl w-full"}>
|
||||
<div
|
||||
className={
|
||||
"rounded-md border border-nb-gray-900/70 grid w-full bg-nb-gray-930/40"
|
||||
"rounded-md border border-nb-gray-900/70 grid w-full bg-nb-gray-930/40 stepper-bg-variant"
|
||||
}
|
||||
>
|
||||
<SetupModalContent header={false} footer={false} />
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { globalMetaTitle } from "@utils/meta";
|
||||
import type { Metadata } from "next";
|
||||
import BlankLayout from "@/layouts/BlankLayout";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `Custom Domains - Reverse Proxy - ${globalMetaTitle}`,
|
||||
};
|
||||
export default BlankLayout;
|
||||
70
src/app/(dashboard)/reverse-proxy/custom-domains/page.tsx
Normal file
70
src/app/(dashboard)/reverse-proxy/custom-domains/page.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
"use client";
|
||||
|
||||
import Breadcrumbs from "@components/Breadcrumbs";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import SkeletonTable from "@components/skeletons/SkeletonTable";
|
||||
import { RestrictedAccess } from "@components/ui/RestrictedAccess";
|
||||
import { usePortalElement } from "@hooks/usePortalElement";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import React, { lazy, Suspense } from "react";
|
||||
import ReverseProxyIcon from "@/assets/icons/ReverseProxyIcon";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import ReverseProxiesProvider from "@/contexts/ReverseProxiesProvider";
|
||||
import { REVERSE_PROXY_CUSTOM_DOMAINS_DOCS_LINK } from "@/interfaces/ReverseProxy";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
|
||||
const CustomDomainsTable = lazy(
|
||||
() => import("@/modules/reverse-proxy/domain/CustomDomainsTable"),
|
||||
);
|
||||
|
||||
export default function ReverseProxyCustomDomainsPage() {
|
||||
const { permission } = usePermissions();
|
||||
|
||||
const { ref: headingRef, portalTarget } =
|
||||
usePortalElement<HTMLHeadingElement>();
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<div className={"p-default py-6"}>
|
||||
<Breadcrumbs>
|
||||
<Breadcrumbs.Item
|
||||
href={"/reverse-proxy/services"}
|
||||
label={"Reverse Proxy"}
|
||||
icon={<ReverseProxyIcon size={16} />}
|
||||
/>
|
||||
<Breadcrumbs.Item
|
||||
href={"/reverse-proxy/custom-domains"}
|
||||
label={"Custom Domains"}
|
||||
active={true}
|
||||
/>
|
||||
</Breadcrumbs>
|
||||
<h1 ref={headingRef}>Domains</h1>
|
||||
<Paragraph>
|
||||
Add and manage custom domains for your reverse proxy services.
|
||||
</Paragraph>
|
||||
<Paragraph>
|
||||
Learn more about
|
||||
<InlineLink
|
||||
href={REVERSE_PROXY_CUSTOM_DOMAINS_DOCS_LINK}
|
||||
target={"_blank"}
|
||||
>
|
||||
Custom Domains
|
||||
<ExternalLinkIcon size={12} />
|
||||
</InlineLink>
|
||||
in our documentation.
|
||||
</Paragraph>
|
||||
</div>
|
||||
<RestrictedAccess
|
||||
page={"Custom Domains"}
|
||||
hasAccess={permission?.services?.read}
|
||||
>
|
||||
<ReverseProxiesProvider>
|
||||
<Suspense fallback={<SkeletonTable />}>
|
||||
<CustomDomainsTable headingTarget={portalTarget} />
|
||||
</Suspense>
|
||||
</ReverseProxiesProvider>
|
||||
</RestrictedAccess>
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
15
src/app/(dashboard)/reverse-proxy/page.tsx
Normal file
15
src/app/(dashboard)/reverse-proxy/page.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import FullScreenLoading from "@components/ui/FullScreenLoading";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export default function ReverseProxyRedirectPage() {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
router.replace("/reverse-proxy/services");
|
||||
}, [router]);
|
||||
|
||||
return <FullScreenLoading fullScreen={false} />;
|
||||
}
|
||||
8
src/app/(dashboard)/reverse-proxy/services/layout.tsx
Normal file
8
src/app/(dashboard)/reverse-proxy/services/layout.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { globalMetaTitle } from "@utils/meta";
|
||||
import type { Metadata } from "next";
|
||||
import BlankLayout from "@/layouts/BlankLayout";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `Services - Reverse Proxy - ${globalMetaTitle}`,
|
||||
};
|
||||
export default BlankLayout;
|
||||
83
src/app/(dashboard)/reverse-proxy/services/page.tsx
Normal file
83
src/app/(dashboard)/reverse-proxy/services/page.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
"use client";
|
||||
|
||||
import Breadcrumbs from "@components/Breadcrumbs";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import SkeletonTable from "@components/skeletons/SkeletonTable";
|
||||
import { RestrictedAccess } from "@components/ui/RestrictedAccess";
|
||||
import { usePortalElement } from "@hooks/usePortalElement";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import React, { lazy, Suspense } from "react";
|
||||
import ReverseProxyIcon from "@/assets/icons/ReverseProxyIcon";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import ReverseProxiesProvider from "@/contexts/ReverseProxiesProvider";
|
||||
import { REVERSE_PROXY_DOCS_LINK } from "@/interfaces/ReverseProxy";
|
||||
import PageContainer from "@/layouts/PageContainer";
|
||||
import { Callout } from "@components/Callout";
|
||||
import { isNetBirdHosted } from "@utils/netbird";
|
||||
|
||||
const ReverseProxyTable = lazy(
|
||||
() => import("@/modules/reverse-proxy/table/ReverseProxyTable"),
|
||||
);
|
||||
|
||||
export default function ReverseProxyServicesPage() {
|
||||
const { permission } = usePermissions();
|
||||
|
||||
const { ref: headingRef, portalTarget } =
|
||||
usePortalElement<HTMLHeadingElement>();
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<div className={"p-default py-6"}>
|
||||
<Breadcrumbs>
|
||||
<Breadcrumbs.Item
|
||||
href={"/reverse-proxy/services"}
|
||||
label={"Reverse Proxy"}
|
||||
icon={<ReverseProxyIcon size={16} />}
|
||||
/>
|
||||
<Breadcrumbs.Item
|
||||
href={"/reverse-proxy/services"}
|
||||
label={"Services"}
|
||||
active={true}
|
||||
/>
|
||||
</Breadcrumbs>
|
||||
<h1 ref={headingRef}>Services</h1>
|
||||
<Paragraph>
|
||||
Expose services securely through NetBird's reverse proxy.
|
||||
</Paragraph>
|
||||
<Paragraph>
|
||||
Learn more about
|
||||
<InlineLink href={REVERSE_PROXY_DOCS_LINK} target={"_blank"}>
|
||||
Services
|
||||
<ExternalLinkIcon size={12} />
|
||||
</InlineLink>
|
||||
in our documentation.
|
||||
</Paragraph>
|
||||
|
||||
{isNetBirdHosted() ? (
|
||||
<Callout className={"max-w-xl mt-5"} variant={"info"}>
|
||||
NetBird's Reverse Proxy is currently in beta and available at
|
||||
no cost during this period. Features, functionality, and pricing are
|
||||
subject to change upon release.
|
||||
</Callout>
|
||||
) : (
|
||||
<Callout className={"max-w-xl mt-5"} variant={"info"}>
|
||||
NetBird's Reverse Proxy is currently in beta. <br /> Features
|
||||
and functionality are subject to change upon release.
|
||||
</Callout>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<RestrictedAccess
|
||||
page={"Services"}
|
||||
hasAccess={permission?.services?.read}
|
||||
>
|
||||
<ReverseProxiesProvider>
|
||||
<Suspense fallback={<SkeletonTable />}>
|
||||
<ReverseProxyTable headingTarget={portalTarget} />
|
||||
</Suspense>
|
||||
</ReverseProxiesProvider>
|
||||
</RestrictedAccess>
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { RestrictedAccess } from "@components/ui/RestrictedAccess";
|
||||
import { VerticalTabs } from "@components/VerticalTabs";
|
||||
import {
|
||||
AlertOctagonIcon,
|
||||
FingerprintIcon,
|
||||
FolderGit2Icon,
|
||||
LockIcon,
|
||||
MonitorSmartphoneIcon,
|
||||
@@ -19,6 +20,7 @@ import { useAccount } from "@/modules/account/useAccount";
|
||||
import AuthenticationTab from "@/modules/settings/AuthenticationTab";
|
||||
import ClientSettingsTab from "@/modules/settings/ClientSettingsTab";
|
||||
import DangerZoneTab from "@/modules/settings/DangerZoneTab";
|
||||
import IdentityProvidersTab from "@/modules/settings/IdentityProvidersTab";
|
||||
import NetworkSettingsTab from "@/modules/settings/NetworkSettingsTab";
|
||||
import PermissionsTab from "@/modules/settings/PermissionsTab";
|
||||
import GroupsSettings from "@/modules/settings/GroupsSettings";
|
||||
@@ -53,6 +55,13 @@ export default function NetBirdSettings() {
|
||||
<ShieldIcon size={14} />
|
||||
Authentication
|
||||
</VerticalTabs.Trigger>
|
||||
{account?.settings?.embedded_idp_enabled &&
|
||||
permission?.identity_providers?.read && (
|
||||
<VerticalTabs.Trigger value="identity-providers">
|
||||
<FingerprintIcon size={14} />
|
||||
Identity Providers
|
||||
</VerticalTabs.Trigger>
|
||||
)}
|
||||
<VerticalTabs.Trigger value="groups">
|
||||
<FolderGit2Icon size={14} />
|
||||
Groups
|
||||
@@ -80,6 +89,8 @@ export default function NetBirdSettings() {
|
||||
>
|
||||
<div className={"border-l border-nb-gray-930 w-full"}>
|
||||
{account && <AuthenticationTab account={account} />}
|
||||
{account?.settings?.embedded_idp_enabled &&
|
||||
permission.identity_providers.read && <IdentityProvidersTab />}
|
||||
{account && <PermissionsTab account={account} />}
|
||||
{account && <GroupsSettings account={account} />}
|
||||
{account && <NetworkSettingsTab account={account} />}
|
||||
|
||||
@@ -11,5 +11,5 @@ export default function Team() {
|
||||
router.push("/team/users");
|
||||
}, [router]);
|
||||
|
||||
return <FullScreenLoading height={"auto"} />;
|
||||
return <FullScreenLoading fullScreen={false} />;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
useNetBirdClient,
|
||||
} from "@/modules/remote-access/useNetBirdClient";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { isNetbirdSSHProtocolSupported } from "@utils/version";
|
||||
|
||||
export default function RDPPage() {
|
||||
const { peerId } = useRDPQueryParams();
|
||||
@@ -85,11 +84,8 @@ function RDPSession({ peer }: Props) {
|
||||
try {
|
||||
setCredentials(rdpCredentials);
|
||||
setIsNetBirdConnecting(true);
|
||||
const protocol = isNetbirdSSHProtocolSupported(peer.version)
|
||||
? "netbird-ssh"
|
||||
: "tcp";
|
||||
await client.connectTemporary(peer.id, [
|
||||
`${protocol}/${rdpCredentials.port}`,
|
||||
`tcp/${rdpCredentials.port}`,
|
||||
]);
|
||||
setIsNetBirdConnecting(false);
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--toasts-before: 0;
|
||||
--lift: 1;
|
||||
}
|
||||
|
||||
html{
|
||||
@apply bg-nb-gray;
|
||||
}
|
||||
|
||||
h1 {
|
||||
@apply text-2xl font-medium text-gray-700 dark:text-nb-gray-100 my-1;
|
||||
@@ -169,6 +176,25 @@ p {
|
||||
@apply m-0 p-0 box-border;
|
||||
}
|
||||
|
||||
/* Disable sonner's opacity fade-in for custom toasts, but respect visibility */
|
||||
[data-sonner-toast][data-visible="true"] {
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
|
||||
/* Adjust sonner stacking: less shrink and less lift per toast */
|
||||
[data-sonner-toast][data-expanded="false"][data-front="false"] {
|
||||
--scale: calc(var(--toasts-before) * 0.03 - 1) !important;
|
||||
--lift-amount: calc(var(--lift) * 10px) !important;
|
||||
}
|
||||
|
||||
/* Override stacked toast removal to move up instead of down */
|
||||
[data-sonner-toast][data-removed='true'][data-front='false'][data-swipe-out='false'][data-expanded='false'] {
|
||||
--y: translateY(calc(var(--lift) * -20%)) !important;
|
||||
|
||||
opacity: 0 !important;
|
||||
transition: transform 400ms ease, opacity 300ms ease !important;
|
||||
}
|
||||
|
||||
/* Control Center */
|
||||
.react-flow__node-groupNode .selected{
|
||||
|
||||
8
src/app/invite/layout.tsx
Normal file
8
src/app/invite/layout.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { globalMetaTitle } from "@utils/meta";
|
||||
import type { Metadata } from "next";
|
||||
import BlankLayout from "@/layouts/BlankLayout";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `Accept Invite - ${globalMetaTitle}`,
|
||||
};
|
||||
export default BlankLayout;
|
||||
321
src/app/invite/page.tsx
Normal file
321
src/app/invite/page.tsx
Normal file
@@ -0,0 +1,321 @@
|
||||
"use client";
|
||||
|
||||
import Button from "@components/Button";
|
||||
import { Input } from "@components/Input";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import FullScreenLoading from "@components/ui/FullScreenLoading";
|
||||
import { acceptInvite, fetchInviteInfo } from "@utils/unauthenticatedApi";
|
||||
import {
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
Clock,
|
||||
KeyRound,
|
||||
Mail,
|
||||
User2,
|
||||
} from "lucide-react";
|
||||
import dayjs from "dayjs";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { Suspense, useEffect, useMemo, useState } from "react";
|
||||
import NetBirdIcon from "@/assets/icons/NetBirdIcon";
|
||||
import { UserInviteInfo } from "@/interfaces/User";
|
||||
|
||||
export default function InviteAcceptPage() {
|
||||
return (
|
||||
<Suspense fallback={<FullScreenLoading />}>
|
||||
<InviteAcceptContent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
function InviteAcceptContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const token = searchParams?.get("token");
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [inviteInfo, setInviteInfo] = useState<UserInviteInfo | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isRateLimited, setIsRateLimited] = useState(false);
|
||||
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [success, setSuccess] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
setError("No invite token provided");
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
fetchInviteInfo(token)
|
||||
.then((info) => {
|
||||
setInviteInfo(info);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.code === 429) {
|
||||
setError("Too many attempts. Please wait a moment and try again.");
|
||||
setIsRateLimited(true);
|
||||
} else {
|
||||
setError(err.message || "Invalid or expired invite link");
|
||||
setIsRateLimited(false);
|
||||
}
|
||||
setLoading(false);
|
||||
});
|
||||
}, [token]);
|
||||
|
||||
const passwordsMatch = password === confirmPassword;
|
||||
const hasMinLength = password.length >= 8;
|
||||
const hasUppercase = /[A-Z]/.test(password);
|
||||
const hasLowercase = /[a-z]/.test(password);
|
||||
const hasNumber = /[0-9]/.test(password);
|
||||
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(password);
|
||||
const passwordValid = hasMinLength && hasUppercase && hasLowercase && hasNumber && hasSpecialChar;
|
||||
const canSubmit = passwordValid && passwordsMatch && !submitting;
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!canSubmit || !token) return;
|
||||
|
||||
setSubmitting(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await acceptInvite(token, password);
|
||||
setSuccess(true);
|
||||
} catch (err: any) {
|
||||
setError(err.message || "Failed to accept invite");
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const isExpired = useMemo(() => {
|
||||
if (!inviteInfo) return false;
|
||||
return new Date(inviteInfo.expires_at) < new Date();
|
||||
}, [inviteInfo]);
|
||||
|
||||
if (loading) {
|
||||
return <FullScreenLoading />;
|
||||
}
|
||||
|
||||
if (error && !inviteInfo) {
|
||||
if (isRateLimited) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-nb-gray-950 p-4">
|
||||
<div className="max-w-md w-full text-center">
|
||||
<div className="mb-6 flex justify-center">
|
||||
<div className="w-16 h-16 bg-yellow-500/10 rounded-full flex items-center justify-center">
|
||||
<Clock className="w-8 h-8 text-yellow-500" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold text-white mb-2">
|
||||
Too Many Requests
|
||||
</h1>
|
||||
<Paragraph className="text-nb-gray-400 text-base">
|
||||
You've made too many requests. Please wait a moment and try
|
||||
again.
|
||||
</Paragraph>
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="mt-6"
|
||||
onClick={() => window.location.reload()}
|
||||
>
|
||||
Try Again
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-nb-gray-950 p-4">
|
||||
<div className="max-w-md w-full text-center">
|
||||
<div className="mb-6 flex justify-center">
|
||||
<div className="w-16 h-16 bg-red-500/10 rounded-full flex items-center justify-center">
|
||||
<AlertCircle className="w-8 h-8 text-red-500" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold text-white mb-2">
|
||||
Invalid Invite
|
||||
</h1>
|
||||
<Paragraph className="text-nb-gray-400 text-base">
|
||||
This invite link is invalid or has expired. Please contact your
|
||||
administrator to receive a new invitation.
|
||||
</Paragraph>
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="mt-6"
|
||||
onClick={() => router.push("/")}
|
||||
>
|
||||
Go to Login
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-nb-gray-950 p-4">
|
||||
<div className="max-w-md w-full text-center">
|
||||
<div className="mb-6 flex justify-center">
|
||||
<div className="w-16 h-16 bg-green-500/10 rounded-full flex items-center justify-center">
|
||||
<CheckCircle2 className="w-8 h-8 text-green-500" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold text-white mb-2">
|
||||
Account Created!
|
||||
</h1>
|
||||
<Paragraph className="text-nb-gray-400">
|
||||
Your account has been created successfully. You can now log in with
|
||||
your email and password.
|
||||
</Paragraph>
|
||||
<Button
|
||||
variant="primary"
|
||||
className="mt-6"
|
||||
onClick={() => router.push("/")}
|
||||
>
|
||||
Go to Login
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isExpired || !inviteInfo?.valid) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-nb-gray-950 p-4">
|
||||
<div className="max-w-md w-full text-center">
|
||||
<div className="mb-6 flex justify-center">
|
||||
<div className="w-16 h-16 bg-yellow-500/10 rounded-full flex items-center justify-center">
|
||||
<AlertCircle className="w-8 h-8 text-yellow-500" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold text-white mb-2">
|
||||
Invite Expired
|
||||
</h1>
|
||||
<Paragraph className="text-nb-gray-400">
|
||||
This invite link has expired. Please contact your administrator to
|
||||
receive a new invitation.
|
||||
</Paragraph>
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="mt-6"
|
||||
onClick={() => router.push("/")}
|
||||
>
|
||||
Go to Login
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-nb-gray-950 p-4">
|
||||
<div className="max-w-md w-full">
|
||||
<div className="mb-8 flex justify-center">
|
||||
<NetBirdIcon size={48} />
|
||||
</div>
|
||||
|
||||
<div className="text-center mb-8">
|
||||
<h1 className="text-2xl font-semibold text-white mb-2">
|
||||
Welcome to NetBird
|
||||
</h1>
|
||||
<p className="dark:text-nb-gray-400 text-nb-gray-500 text-base">
|
||||
You've been invited by <span className="dark:text-white text-nb-gray-900 font-medium">{inviteInfo.invited_by}</span> to join the network. Set your password to complete your account setup.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-nb-gray-930 border border-nb-gray-900 rounded-lg p-6 mb-6">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="w-10 h-10 bg-nb-gray-900 rounded-full flex items-center justify-center">
|
||||
<User2 className="w-5 h-5 text-nb-gray-400" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-white font-medium">{inviteInfo.name}</div>
|
||||
<div className="text-nb-gray-400 text-sm flex items-center gap-1">
|
||||
<Mail className="w-3 h-3" />
|
||||
{inviteInfo.email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
customPrefix={
|
||||
<KeyRound size={16} className="text-nb-gray-400" />
|
||||
}
|
||||
/>
|
||||
{password && (
|
||||
<div className="mt-2 space-y-1">
|
||||
<PasswordRule met={hasMinLength} text="At least 8 characters" />
|
||||
<PasswordRule met={hasUppercase} text="One uppercase letter" />
|
||||
<PasswordRule met={hasLowercase} text="One lowercase letter" />
|
||||
<PasswordRule met={hasNumber} text="One number" />
|
||||
<PasswordRule met={hasSpecialChar} text="One special character (!@#$%^&*)" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Confirm Password"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
customPrefix={
|
||||
<KeyRound size={16} className="text-nb-gray-400" />
|
||||
}
|
||||
/>
|
||||
{confirmPassword && !passwordsMatch && (
|
||||
<p className="text-xs text-red-500 mt-1">
|
||||
Passwords do not match
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-500/10 border border-red-500/20 rounded-md p-3">
|
||||
<p className="text-sm text-red-500">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
className="w-full"
|
||||
disabled={!canSubmit}
|
||||
>
|
||||
{submitting ? "Creating Account..." : "Create Account"}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<p className="text-center text-xs text-nb-gray-500">
|
||||
Invite expires on {dayjs(inviteInfo.expires_at).format("D MMMM, YYYY [at] h:mm A")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PasswordRule({ met, text }: { met: boolean; text: string }) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 text-xs">
|
||||
{met ? (
|
||||
<CheckCircle2 className="w-3 h-3 text-green-500" />
|
||||
) : (
|
||||
<AlertCircle className="w-3 h-3 text-nb-gray-500" />
|
||||
)}
|
||||
<span className={met ? "text-green-500" : "text-nb-gray-500"}>{text}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -36,6 +36,6 @@ export default function NotFound() {
|
||||
|
||||
const Redirect = ({ url, queryParams }: Props) => {
|
||||
const params = queryParams && `?${queryParams}`;
|
||||
useRedirect(url == "/" ? `/peers${params}` : `${url}${params}`);
|
||||
useRedirect(url == "/" ? `/peers${params}` : `${url}${params}`, true);
|
||||
return <FullScreenLoading />;
|
||||
};
|
||||
|
||||
@@ -37,6 +37,6 @@ export default function Home() {
|
||||
|
||||
const Redirect = ({ url, queryParams }: Props) => {
|
||||
const params = queryParams && `?${queryParams}`;
|
||||
useRedirect(url == "/" ? `/peers${params}` : `${url}${params}`);
|
||||
useRedirect(url == "/" ? `/peers${params}` : `${url}${params}`, true);
|
||||
return <FullScreenLoading />;
|
||||
};
|
||||
|
||||
8
src/app/setup/layout.tsx
Normal file
8
src/app/setup/layout.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { globalMetaTitle } from "@utils/meta";
|
||||
import type { Metadata } from "next";
|
||||
import BlankLayout from "@/layouts/BlankLayout";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `Instance Setup - ${globalMetaTitle}`,
|
||||
};
|
||||
export default BlankLayout;
|
||||
22
src/app/setup/page.tsx
Normal file
22
src/app/setup/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import InstanceSetupWizard from "@/modules/instance-setup/InstanceSetupWizard";
|
||||
import { useInstanceSetup } from "@/contexts/InstanceSetupProvider";
|
||||
import { useRouter } from "next/navigation";
|
||||
import FullScreenLoading from "@components/ui/FullScreenLoading";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export default function SetupPage() {
|
||||
const { setupRequired, loading } = useInstanceSetup();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && !setupRequired) router.replace("/peers");
|
||||
}, [loading, setupRequired]);
|
||||
|
||||
return loading || !setupRequired ? (
|
||||
<FullScreenLoading />
|
||||
) : (
|
||||
<InstanceSetupWizard />
|
||||
);
|
||||
}
|
||||
28
src/assets/icons/AuthentikIcon.tsx
Normal file
28
src/assets/icons/AuthentikIcon.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function AuthentikIcon(props: Readonly<IconProps>) {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="-0.03 59.9 512.03 392.1"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<path
|
||||
d="M279.9 141h17.9v51.2h-17.9zm46.6-2.2h17.9v40h-17.9zM65.3 197.3c-24 0-46 13.2-57.4 34.3h30.4c13.5-11.6 33-15 47.1 0h32.2c-12.6-17.1-31.4-34.3-52.3-34.3"
|
||||
fill="#fd4b2d"
|
||||
/>
|
||||
<path
|
||||
d="M108.7 262.4C66.8 350-6.6 275.3 38.3 231.5H7.9C-15.9 273 17 329 65.3 327.8c37.4 0 68.2-55.5 68.2-65.3 0-4.3-6-17.6-16-31H85.4c10.7 9.7 20 23.7 23.3 30.9m1.1-2.6"
|
||||
fill="#fd4b2d"
|
||||
/>
|
||||
<path
|
||||
d="M512 140.3v231.3c0 44.3-36.1 80.4-80.4 80.4h-34.1v-78.8h-163V452h-34.1c-44.4 0-80.4-36.1-80.4-80.4v-72.8h258.4v-139H253.6V238H119.9v-97.6c0-3.1.2-6.2.5-9.2.4-3.7 1.1-7.3 2-10.8.3-1.1.6-2.3 1-3.4.1-.3.2-.6.3-.8.2-.6.4-1.1.5-1.7.2-.5.4-1.1.6-1.7s.5-1.2.7-1.8.5-1.2.8-1.8c2-4.7 4.4-9.3 7.3-13.6l.1-.1c.7-1.1 1.5-2.1 2.3-3.2.7-.9 1.3-1.7 2-2.6.8-.9 1.6-1.9 2.4-2.8s1.6-1.8 2.4-2.6l.1-.1c.4-.5.9-.9 1.4-1.4 3-2.9 6.2-5.6 9.6-8 .9-.7 1.9-1.3 2.8-1.9 1.1-.7 2.2-1.4 3.3-2 2.1-1.2 4.2-2.4 6.5-3.4.7-.3 1.4-.7 2.1-1 3.1-1.3 6.2-2.5 9.4-3.4 1.2-.4 2.5-.7 3.7-1 .6-.2 1.2-.3 1.8-.4 3.6-.8 7.2-1.3 10.9-1.6l1.6-.1h.8c1.2-.1 2.4-.1 3.7-.1h231.3c1.2 0 2.5 0 3.7.1h.8l1.6.1c3.7.3 7.3.8 10.9 1.6.6.1 1.2.3 1.8.4 1.3.3 2.5.6 3.7 1 3.2.9 6.3 2.1 9.4 3.4.7.3 1.4.6 2.1 1 2.2 1 4.4 2.2 6.5 3.4 1.1.7 2.2 1.3 3.3 2 1 .6 1.9 1.3 2.8 1.9 3.9 2.8 7.6 6 11 9.4.8.8 1.7 1.7 2.4 2.6.8.9 1.6 1.9 2.4 2.8.7.8 1.3 1.7 2 2.6.8 1.1 1.5 2.1 2.3 3.2l.1.1c2.9 4.3 5.3 8.8 7.3 13.6.2.6.5 1.2.8 1.8.2.6.5 1.2.7 1.8.2.5.4 1.1.6 1.7s.4 1.1.5 1.7c.1.3.2.6.3.8.3 1.1.7 2.3 1 3.4.9 3.6 1.6 7.2 2 10.8 0 3.1.2 6.1.2 9.2"
|
||||
fill="#fd4b2d"
|
||||
/>
|
||||
<path
|
||||
d="M498.3 95.5H133.5c14.9-22.2 40-35.6 66.7-35.6h231.3c26.9 0 51.9 13.4 66.8 35.6m13.2 35.6H120.4c1.4-12.8 6-25 13.1-35.6h364.8c7.2 10.6 11.7 22.9 13.2 35.6m.5 9.2v26.4H378.3v-6.9H253.6v6.9H119.9v-26.4c0-3.1.2-6.2.5-9.2h391.1c.3 3.1.5 6.1.5 9.2M119.9 166.7h133.7v35.6H119.9zm258.4 0H512v35.6H378.3zm-258.4 35.6h133.7v35.6H119.9zm258.4 0H512v35.6H378.3z"
|
||||
fill="#fd4b2d"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
19
src/assets/icons/DNSZoneIcon.tsx
Normal file
19
src/assets/icons/DNSZoneIcon.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function DNSZoneIcon(props: IconProps) {
|
||||
return (
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M5 5a2 2 0 0 0-2 2v3a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V7a2 2 0 0 0-2-2H5Zm9 2a1 1 0 1 0 0 2h.01a1 1 0 1 0 0-2H14Zm3 0a1 1 0 1 0 0 2h.01a1 1 0 1 0 0-2H17ZM3 17v-3a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Zm11-2a1 1 0 1 0 0 2h.01a1 1 0 1 0 0-2H14Zm3 0a1 1 0 1 0 0 2h.01a1 1 0 1 0 0-2H17Z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
30
src/assets/icons/IdentityProviderIcons.tsx
Normal file
30
src/assets/icons/IdentityProviderIcons.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { SSOIdentityProviderType } from "@/interfaces/IdentityProvider";
|
||||
import React from "react";
|
||||
import GoogleIcon from "@/assets/icons/GoogleIcon";
|
||||
import MicrosoftIcon from "@/assets/icons/MicrosoftIcon";
|
||||
import EntraIcon from "@/assets/icons/EntraIcon";
|
||||
import OktaIcon from "@/assets/icons/OktaIcon";
|
||||
import PocketIdIcon from "@/assets/icons/PocketIdIcon";
|
||||
import ZitadelIcon from "@/assets/icons/ZitadelIcon";
|
||||
import AuthentikIcon from "@/assets/icons/AuthentikIcon";
|
||||
import KeycloakIcon from "@/assets/icons/KeycloakIcon";
|
||||
import { KeyRound } from "lucide-react";
|
||||
|
||||
export const idpIcon = (
|
||||
type: SSOIdentityProviderType,
|
||||
size: number = 16,
|
||||
): React.ReactNode => {
|
||||
const icons: Record<SSOIdentityProviderType, React.ReactNode> = {
|
||||
google: <GoogleIcon size={size} />,
|
||||
microsoft: <MicrosoftIcon size={size} />,
|
||||
entra: <EntraIcon size={size} />,
|
||||
okta: <OktaIcon size={size} className="text-nb-gray-300" />,
|
||||
pocketid: <PocketIdIcon size={size} />,
|
||||
zitadel: <ZitadelIcon size={size} />,
|
||||
authentik: <AuthentikIcon size={size} />,
|
||||
keycloak: <KeycloakIcon size={size} />,
|
||||
oidc: <KeyRound size={size} className="text-nb-gray-400" />,
|
||||
};
|
||||
|
||||
return icons[type];
|
||||
};
|
||||
88
src/assets/icons/KeycloakIcon.tsx
Normal file
88
src/assets/icons/KeycloakIcon.tsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function KeycloakIcon(props: Readonly<IconProps>) {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 512 512"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<g transform="translate(.714 .07)">
|
||||
<path
|
||||
d="M432.9 149.2c-1.4 0-2.7-.7-3.4-2L370.1 44.1c-.7-1.2-2-2-3.5-2H124.2c-1.4 0-2.7.7-3.4 2L58.9 150.9l23.9 34.9c-.7 1.2-6.2 24-5.5 25.2L58.9 360.9l61.9 106.9c.7 1.2 2 2 3.4 2h242.4c1.4 0 2.7-.7 3.5-2l59.4-103.2c.7-1.2 2-2 3.4-2h73.8c2.4 0 4.4-2 4.4-4.4V153.6c0-2.4-2-4.4-4.4-4.4z"
|
||||
fill="#4d4d4d"
|
||||
/>
|
||||
<path d="M72.7 245.3 6.4 269.4l-6.6-11.3c-.7-1.2-.7-2.7 0-3.9l30-52z" fill="#e1e1e1" />
|
||||
<path d="M511.3 258.3V309l-43.7-44.5z" fill="#c8c8c8" />
|
||||
<path
|
||||
d="m467.5 264.5 43.7 44.5v49.6c0 2.4-2 4.4-4.4 4.4H456z"
|
||||
fill="#c2c2c2"
|
||||
/>
|
||||
<path d="M467.5 264.5 456 362.9h-61.2l-18.5-44.7z" fill="#c7c7c7" />
|
||||
<path d="M511.3 211.2v47l-43.7 6.2z" fill="#cecece" />
|
||||
<path
|
||||
d="M511.3 153.6v57.6l-43.7 53.2-33.1-115.3h72.2c2.4-.1 4.5 1.8 4.6 4.3z"
|
||||
fill="#d3d3d3"
|
||||
/>
|
||||
<path d="M394.8 362.9h-32.3l-8.4-12 22.1-32.7z" fill="#c6c6c6" />
|
||||
<path d="m467.5 264.5-121.1-51.2 63.7-64.1h24.4z" fill="#d5d5d5" />
|
||||
<path d="m346.5 213.3 29.8 105 91.2-53.8z" fill="#d0d0d0" />
|
||||
<path d="m353.8 362.9.4-12 8.4 12z" fill="#bfbfbf" />
|
||||
<path d="m410.1 149.2-63.7 64.1-11.4-57.4 24.6-6.8h50.5z" fill="#d9d9d9" />
|
||||
<path d="m346.5 213.3-147 33.9 154.7 103.7z" fill="#d4d4d4" />
|
||||
<path d="m346.5 213.3 7.7 137.6 22.1-32.7z" fill="#d0d0d0" />
|
||||
<path d="m335 155.9-135.5 91.2 147-33.9z" fill="#d9d9d9" />
|
||||
<path d="m199.5 247.2-63.7 115.7H99.6L72.7 245.3z" fill="#d8d8d8" />
|
||||
<path
|
||||
d="m134.3 149.2-61.5 96.1L57.3 155l2.2-3.8c.7-1.2 2-1.9 3.4-1.9z"
|
||||
fill="#e2e2e2"
|
||||
/>
|
||||
<path
|
||||
d="M99.6 362.9H62.7c-1.4 0-2.8-.8-3.5-2L6.4 269.4l66.4-24.1z"
|
||||
fill="#d8d8d8"
|
||||
/>
|
||||
<path d="M29.9 202.1 57.1 155l15.7 90.3z" fill="#e4e4e4" />
|
||||
<path d="m335 155.9-40.8-6.8H159.4l40.1 98z" fill="#dedede" />
|
||||
<path d="m199.5 247.2-40.1-98h-25.1l-61.5 96.1z" fill="#dedede" />
|
||||
<path d="M324.7 362.9h29.1l.4-12z" fill="#c5c5c5" />
|
||||
<path d="M266.7 362.9h58l29.5-12-154.7-103.7 27.9 115.7z" fill="#d0d0d0" />
|
||||
<path d="m227.4 362.9-27.9-115.7-63.7 115.7z" fill="#d1d1d1" />
|
||||
<path d="m335.4 149.2-.4 6.8 24.6-6.8z" fill="#ddd" />
|
||||
<path d="m335 155.9-3.8-6.8h-37z" fill="#e3e3e3" />
|
||||
<path d="m335 155.9.4-6.8h-4.2z" fill="#e2e2e2" />
|
||||
<path
|
||||
d="m223.9 151-59.7 103.4c-.3.5-.4 1.1-.4 1.7h-41.7l82-142q.75.45 1.2 1.2l18.6 32.3c.5 1.1.5 2.4 0 3.4"
|
||||
fill="#00b8e3"
|
||||
/>
|
||||
<path
|
||||
d="M223.8 364.9 205.3 397q-.45.75-1.2 1.2l-82-142.2h41.7c0 .6.1 1.1.4 1.6l59.6 103.2c.8 1.2.9 2.9 0 4.1"
|
||||
fill="#33c6e9"
|
||||
/>
|
||||
<path
|
||||
d="m204 114.2-82 141.9-20.6 35.6-19.6-34c-.3-.5-.4-1-.4-1.6s.1-1.2.4-1.7l19.9-34.4 60.4-104.5c.6-1.1 1.8-1.8 3-1.8h37.2c.6 0 1.2.2 1.7.5"
|
||||
fill="#008aaa"
|
||||
/>
|
||||
<path
|
||||
d="M204 398.2c-.5.3-1.1.5-1.8.5h-37.1c-1.3 0-2.4-.7-3-1.8l-55.2-95.6-5.5-9.5 20.6-35.6z"
|
||||
fill="#00b8e3"
|
||||
/>
|
||||
<path
|
||||
d="m368.9 256.1-82 142q-.75-.45-1.2-1.2L267 364.7c-.5-1-.5-2.3 0-3.3L326.7 258c.3-.5.5-1.2.5-1.8z"
|
||||
fill="#008aaa"
|
||||
/>
|
||||
<path
|
||||
d="M409.4 256.1c0 .6-.2 1.3-.5 1.8l-80.3 139.3c-.6 1-1.8 1.7-3 1.6h-37c-.6 0-1.2-.2-1.8-.5L368.9 256l20.6-35.6 19.5 33.8c.3.7.4 1.3.4 1.9"
|
||||
fill="#00b8e3"
|
||||
/>
|
||||
<path
|
||||
d="M368.9 256.1h-41.7c0-.6-.2-1.2-.5-1.8L267 151.2c-.6-1.1-.6-2.5 0-3.6l18.6-32.2q.45-.75 1.2-1.2z"
|
||||
fill="#00b8e3"
|
||||
/>
|
||||
<path
|
||||
d="m389.4 220.5-20.6 35.6-82-142c.6-.3 1.2-.5 1.8-.5h37.1c1.2 0 2.3.6 3 1.6z"
|
||||
fill="#33c6e9"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
16
src/assets/icons/MicrosoftIcon.tsx
Normal file
16
src/assets/icons/MicrosoftIcon.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function MicrosoftIcon(props: Readonly<IconProps>) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 221 221"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<path fill="#F1511B" d="M104.868 104.868H0V0h104.868z" />
|
||||
<path fill="#80CC28" d="M220.654 104.868H115.788V0h104.866z" />
|
||||
<path fill="#00ADEF" d="M104.865 220.695H0V115.828h104.865z" />
|
||||
<path fill="#FBBC09" d="M220.654 220.695H115.788V115.828h104.866z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
26
src/assets/icons/PeerOSIcon.tsx
Normal file
26
src/assets/icons/PeerOSIcon.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { getOperatingSystem } from "@hooks/useOperatingSystem";
|
||||
import { cn } from "@utils/helpers";
|
||||
import * as React from "react";
|
||||
import { OperatingSystem } from "@/interfaces/OperatingSystem";
|
||||
import { OSLogo } from "@/modules/peers/PeerOSCell";
|
||||
|
||||
type Props = {
|
||||
os: string;
|
||||
};
|
||||
|
||||
export const PeerOSIcon = ({ os }: Props) => {
|
||||
const osType = getOperatingSystem(os);
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-center grayscale brightness-[100%] contrast-[40%]",
|
||||
"w-4 h-4 shrink-0",
|
||||
osType === OperatingSystem.WINDOWS && "p-[2.5px]",
|
||||
osType === OperatingSystem.APPLE && "p-[2.7px]",
|
||||
osType === OperatingSystem.FREEBSD && "p-[1.5px]",
|
||||
)}
|
||||
>
|
||||
<OSLogo os={os} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
19
src/assets/icons/PeerOrResourceIcon.tsx
Normal file
19
src/assets/icons/PeerOrResourceIcon.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react";
|
||||
import { NetworkResource } from "@/interfaces/Network";
|
||||
import { Peer } from "@/interfaces/Peer";
|
||||
import { PeerOSIcon } from "./PeerOSIcon";
|
||||
import { ResourceIcon } from "./ResourceIcon";
|
||||
|
||||
type Props = {
|
||||
peer?: Peer;
|
||||
resource?: NetworkResource;
|
||||
};
|
||||
|
||||
export const PeerOrResourceIcon = ({ peer, resource }: Props) => {
|
||||
return (
|
||||
<>
|
||||
{peer && <PeerOSIcon os={peer.os} />}
|
||||
{resource?.type && <ResourceIcon type={resource.type} />}
|
||||
</>
|
||||
);
|
||||
};
|
||||
17
src/assets/icons/PocketIdIcon.tsx
Normal file
17
src/assets/icons/PocketIdIcon.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function PocketIdIcon(props: Readonly<IconProps>) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 512 512"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<circle cx="256" cy="256" r="256" fill="#fff" />
|
||||
<path
|
||||
d="M268.6 102.4c64.4 0 116.8 52.4 116.8 116.7 0 25.3-8 49.4-23 69.6-14.8 19.9-35 34.3-58.4 41.7l-6.5 2-15.5-76.2 4.3-2c14-6.7 23-21.1 23-36.6 0-22.4-18.2-40.6-40.6-40.6S228 195.2 228 217.6c0 15.5 9 29.8 23 36.6l4.2 2-25 153.4h-69.5V102.4z"
|
||||
fill="#191919"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
20
src/assets/icons/ResourceIcon.tsx
Normal file
20
src/assets/icons/ResourceIcon.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { GlobeIcon, NetworkIcon, WorkflowIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
|
||||
type Props = {
|
||||
type: "domain" | "host" | "subnet";
|
||||
size?: number;
|
||||
};
|
||||
|
||||
export const ResourceIcon = ({ type, size = 15 }: Props) => {
|
||||
switch (type) {
|
||||
case "domain":
|
||||
return <GlobeIcon size={size} />;
|
||||
case "subnet":
|
||||
return <NetworkIcon size={size} />;
|
||||
case "host":
|
||||
return <WorkflowIcon size={size} />;
|
||||
default:
|
||||
return <WorkflowIcon size={size} />;
|
||||
}
|
||||
};
|
||||
15
src/assets/icons/ReverseProxyIcon.tsx
Normal file
15
src/assets/icons/ReverseProxyIcon.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function ReverseProxyIcon(props: IconProps) {
|
||||
return (
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<path d="M11.4488 2.1499C11.7903 1.95003 12.2097 1.95003 12.5513 2.1499L16.5018 4.46123L12 7.03523L7.49823 4.46123L11.4488 2.1499ZM6.44447 6.46472L6.44444 10.2784L2.93531 12.3315L7.53662 14.8399L10.8889 12.8787V9.00593L6.44447 6.46472ZM2 14.3992V18.7395C2 19.1477 2.21366 19.5247 2.55984 19.7272L6.44446 22V16.8223L2 14.3992ZM8.66668 22L12 20.0497L15.3333 22V16.7994L12 14.8492L8.66668 16.7993V22ZM17.5556 22L21.4401 19.7272C21.7863 19.5247 22 19.1477 22 18.7395V14.3992L17.5556 16.8223V22ZM21.0647 12.3315L17.5556 10.2784V6.46474L13.1111 9.00593V12.8787L16.4634 14.8399L21.0647 12.3315Z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
30
src/assets/icons/SlackIcon.tsx
Normal file
30
src/assets/icons/SlackIcon.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function SlackIcon(props: Readonly<IconProps>) {
|
||||
return (
|
||||
<svg
|
||||
width="127"
|
||||
height="127"
|
||||
viewBox="0 0 127 127"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<path
|
||||
d="M27.2 80c0 7.3-5.9 13.2-13.2 13.2C6.7 93.2.8 87.3.8 80c0-7.3 5.9-13.2 13.2-13.2h13.2V80zm6.6 0c0-7.3 5.9-13.2 13.2-13.2 7.3 0 13.2 5.9 13.2 13.2v33c0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V80z"
|
||||
fill="#E01E5A"
|
||||
/>
|
||||
<path
|
||||
d="M47 27c-7.3 0-13.2-5.9-13.2-13.2C33.8 6.5 39.7.6 47 .6c7.3 0 13.2 5.9 13.2 13.2V27H47zm0 6.7c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H13.9C6.6 60.1.7 54.2.7 46.9c0-7.3 5.9-13.2 13.2-13.2H47z"
|
||||
fill="#36C5F0"
|
||||
/>
|
||||
<path
|
||||
d="M99.9 46.9c0-7.3 5.9-13.2 13.2-13.2 7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H99.9V46.9zm-6.6 0c0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V13.8C66.9 6.5 72.8.6 80.1.6c7.3 0 13.2 5.9 13.2 13.2v33.1z"
|
||||
fill="#2EB67D"
|
||||
/>
|
||||
<path
|
||||
d="M80.1 99.8c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V99.8h13.2zm0-6.6c-7.3 0-13.2-5.9-13.2-13.2 0-7.3 5.9-13.2 13.2-13.2h33.1c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H80.1z"
|
||||
fill="#ECB22E"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
32
src/assets/icons/ZitadelIcon.tsx
Normal file
32
src/assets/icons/ZitadelIcon.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { iconProperties, IconProps } from "@/assets/icons/IconProperties";
|
||||
|
||||
export default function ZitadelIcon(props: Readonly<IconProps>) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 80 79"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
{...iconProperties(props)}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="zitadel-grad"
|
||||
x1="3.86"
|
||||
x2="76.88"
|
||||
y1="47.89"
|
||||
y2="47.89"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
>
|
||||
<stop stopColor="#FF8F00" />
|
||||
<stop offset="1" stopColor="#FE00FF" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<path
|
||||
fill="url(#zitadel-grad)"
|
||||
fillRule="evenodd"
|
||||
d="M17.12 39.17l1.42 5.32-6.68 6.68 9.12 2.44 1.43 5.32-19.77-5.3L17.12 39.17zM58.82 22.41l-5.32-1.43-2.44-9.12-6.68 6.68-5.32-1.43 14.47-14.47 5.3 19.77zM52.65 67.11l3.89-3.89 9.12 2.44-2.44-9.12 3.9-3.9 5.29 19.77-19.76-5.3zM36.43 69.54l-1.18-12.07 8.23 2.21-7.05 9.86zM23 23.84l5.02 11.04 6.02-6.02L23 23.84zM69.32 36.2l-12.07-1.18 2.2 8.23 9.87-7.05z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -6,10 +6,8 @@ import {
|
||||
OidcProvider,
|
||||
} from "@axa-fr/react-oidc";
|
||||
import FullScreenLoading from "@components/ui/FullScreenLoading";
|
||||
import { useLocalStorage } from "@hooks/useLocalStorage";
|
||||
import { useRedirect } from "@hooks/useRedirect";
|
||||
import loadConfig, { buildExtras } from "@utils/config";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { OIDCError } from "@/auth/OIDCError";
|
||||
import { SecureProvider } from "@/auth/SecureProvider";
|
||||
@@ -44,39 +42,11 @@ export default function OIDCProvider({ children }: Props) {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const router = useRouter();
|
||||
const path = usePathname();
|
||||
const params = useSearchParams()?.toString();
|
||||
const [, setQueryParams] = useLocalStorage("netbird-query-params", params);
|
||||
|
||||
useEffect(() => {
|
||||
const validParams = [
|
||||
"tab",
|
||||
"search",
|
||||
"id",
|
||||
"invite",
|
||||
"utm_source",
|
||||
"utm_medium",
|
||||
"utm_content",
|
||||
"utm_campaign",
|
||||
"hs_id",
|
||||
"page",
|
||||
"page_size",
|
||||
"user",
|
||||
"port",
|
||||
];
|
||||
|
||||
try {
|
||||
const urlParams = new URLSearchParams(params);
|
||||
if (validParams.some((param) => urlParams.has(param))) {
|
||||
setQueryParams(params);
|
||||
}
|
||||
} catch (e) {}
|
||||
}, []);
|
||||
|
||||
const withCustomHistory = () => {
|
||||
return {
|
||||
replaceState: (url: any) => {
|
||||
router.replace(url);
|
||||
window.dispatchEvent(new Event("popstate"));
|
||||
window?.location?.replace(url);
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -105,16 +75,19 @@ export default function OIDCProvider({ children }: Props) {
|
||||
|
||||
// We bypass authentication for pages that do not require auth.
|
||||
// E.g., when we just want to show installation steps for public.
|
||||
if (path === "/install") return children;
|
||||
// Or the instance setup wizard for first-time setup.
|
||||
// Or the invite acceptance page for new users.
|
||||
if (path === "/install" || path === "/setup" || path?.startsWith("/invite"))
|
||||
return children;
|
||||
|
||||
return mounted && providerConfig ? (
|
||||
<OidcProvider
|
||||
configuration={providerConfig}
|
||||
//withCustomHistory={withCustomHistory}
|
||||
withCustomHistory={withCustomHistory}
|
||||
authenticatingComponent={FullScreenLoading}
|
||||
authenticatingErrorComponent={OIDCError}
|
||||
loadingComponent={FullScreenLoading}
|
||||
callbackSuccessComponent={CallBackSuccess}
|
||||
callbackSuccessComponent={FullScreenLoading}
|
||||
onEvent={onEvent}
|
||||
onSessionLost={() => void 0}
|
||||
//sessionLostComponent={SessionLost}
|
||||
@@ -125,11 +98,3 @@ export default function OIDCProvider({ children }: Props) {
|
||||
<FullScreenLoading />
|
||||
);
|
||||
}
|
||||
|
||||
const CallBackSuccess = () => {
|
||||
const params = useSearchParams();
|
||||
const errorParam = params.get("error");
|
||||
const currentPath = usePathname();
|
||||
useRedirect(currentPath, true, !errorParam);
|
||||
return <FullScreenLoading />;
|
||||
};
|
||||
|
||||
@@ -3,6 +3,24 @@ import { usePathname } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const QUERY_PARAMS_KEY = "netbird-query-params";
|
||||
const PRESERVE_QUERY_PARAMS_PATHS = ["/peer/ssh", "/peer/rdp"];
|
||||
const VALID_PARAMS = [
|
||||
"tab",
|
||||
"search",
|
||||
"id",
|
||||
"invite",
|
||||
"utm_source",
|
||||
"utm_medium",
|
||||
"utm_content",
|
||||
"utm_campaign",
|
||||
"hs_id",
|
||||
"page",
|
||||
"page_size",
|
||||
"user",
|
||||
"port",
|
||||
];
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
@@ -10,6 +28,22 @@ export const SecureProvider = ({ children }: Props) => {
|
||||
const { isAuthenticated, login } = useOidc();
|
||||
const currentPath = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && !PRESERVE_QUERY_PARAMS_PATHS.includes(currentPath)) {
|
||||
localStorage.removeItem(QUERY_PARAMS_KEY);
|
||||
} else if (!isAuthenticated) {
|
||||
try {
|
||||
const params = window.location.search.substring(1);
|
||||
if (params) {
|
||||
const urlParams = new URLSearchParams(params);
|
||||
if (VALID_PARAMS.some((param) => urlParams.has(param))) {
|
||||
localStorage.setItem(QUERY_PARAMS_KEY, JSON.stringify(params));
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}, [isAuthenticated, currentPath]);
|
||||
|
||||
useEffect(() => {
|
||||
let timeout: NodeJS.Timeout | undefined = undefined;
|
||||
if (!isAuthenticated) {
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
import { Checkbox } from "@components/Checkbox";
|
||||
import { Input } from "@components/Input";
|
||||
import { Popover, PopoverContent } from "@components/Popover";
|
||||
import { useElementSize } from "@hooks/useElementSize";
|
||||
import { Anchor } from "@radix-ui/react-popover";
|
||||
import * as React from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { FaWindows } from "react-icons/fa6";
|
||||
|
||||
type Props = {};
|
||||
export const AutoCompleteInput = ({}: Props) => {
|
||||
const [open, setOpen] = useState<boolean>(false);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [elementWidth, { width }] = useElementSize<HTMLDivElement>();
|
||||
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
|
||||
const onFocus = () => {
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
if (input) {
|
||||
inputRef.current.addEventListener("focus", onFocus);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (input) {
|
||||
inputRef.current.removeEventListener("focus", onFocus);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={"z-10 relative"}>
|
||||
<Popover modal={false} open={open} onOpenChange={setOpen}>
|
||||
<Anchor ref={elementWidth}>
|
||||
<Input
|
||||
placeholder={"11"}
|
||||
ref={inputRef}
|
||||
maxWidthClass={"max-w-[200px]"}
|
||||
customPrefix={
|
||||
<div className={"flex items-center gap-2"}>
|
||||
<Checkbox></Checkbox>
|
||||
<div
|
||||
className={"flex gap-2 items-center text-sm text-nb-gray-200"}
|
||||
>
|
||||
<FaWindows className={"text-sky-600 text-lg"} />
|
||||
Windows
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</Anchor>
|
||||
|
||||
<PopoverContent
|
||||
hideWhenDetached={false}
|
||||
className="w-full p-0 shadow-sm shadow-nb-gray-950"
|
||||
style={{
|
||||
width: width,
|
||||
}}
|
||||
forceMount={true}
|
||||
align="start"
|
||||
side={"bottom"}
|
||||
sideOffset={10}
|
||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||
onCloseAutoFocus={(event) => event.preventDefault()}
|
||||
onInteractOutside={(event) => {
|
||||
event.preventDefault();
|
||||
if (event.target !== inputRef.current) {
|
||||
setOpen(false);
|
||||
}
|
||||
}}
|
||||
onPointerDownOutside={(event) => {
|
||||
event.preventDefault();
|
||||
if (event.target !== inputRef.current) {
|
||||
setOpen(false);
|
||||
}
|
||||
}}
|
||||
onFocusOutside={(event) => {
|
||||
event.preventDefault();
|
||||
if (event.target !== inputRef.current) {
|
||||
setOpen(false);
|
||||
}
|
||||
}}
|
||||
></PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cn } from "@utils/helpers";
|
||||
import { ChevronRightIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
@@ -25,8 +25,6 @@ export const Item = ({
|
||||
active,
|
||||
disabled = false,
|
||||
}: ItemProps) => {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -45,7 +43,13 @@ export const Item = ({
|
||||
)}
|
||||
>
|
||||
{icon && icon}
|
||||
{href ? <span onClick={() => router.push(href)}>{label}</span> : label}
|
||||
{href ? (
|
||||
<Link href={href} data-cy={"breadcrumb-item"}>
|
||||
{label}
|
||||
</Link>
|
||||
) : (
|
||||
label
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -34,7 +34,7 @@ export const buttonVariants = cva(
|
||||
secondary: [
|
||||
"bg-white hover:text-black focus:ring-zinc-200/50 hover:bg-gray-100 border-gray-200 text-gray-900",
|
||||
"dark:ring-offset-neutral-950/50 dark:focus:ring-neutral-500/20 ",
|
||||
"dark:bg-nb-gray-920 dark:text-gray-400 dark:border-gray-700/40 dark:hover:text-white dark:hover:bg-zinc-800/50",
|
||||
"dark:bg-nb-gray-920 dark:text-gray-400 dark:border-gray-700/40 dark:hover:text-white dark:hover:bg-nb-gray-910",
|
||||
],
|
||||
secondaryLighter: [
|
||||
"bg-white hover:text-black focus:ring-zinc-200/50 hover:bg-gray-100 border-gray-200 text-gray-900",
|
||||
@@ -54,7 +54,7 @@ export const buttonVariants = cva(
|
||||
dotted: [
|
||||
"bg-white hover:text-black focus:ring-zinc-200/50 hover:bg-gray-100 border-gray-200 text-gray-900 border-dashed",
|
||||
"dark:ring-offset-neutral-950/50 dark:focus:ring-neutral-500/20 ",
|
||||
"dark:bg-nb-gray-900/30 dark:text-gray-400 dark:border-gray-500/40 dark:hover:text-white dark:hover:bg-zinc-800/50",
|
||||
"dark:bg-nb-gray-900/30 dark:text-gray-400 dark:border-gray-500/40 dark:hover:text-white dark:hover:bg-nb-gray-900/50",
|
||||
],
|
||||
tertiary: [
|
||||
"bg-white hover:text-black focus:ring-zinc-200/50 hover:bg-gray-100 border-gray-200 text-gray-900",
|
||||
@@ -73,9 +73,13 @@ export const buttonVariants = cva(
|
||||
"enabled:dark:focus:ring-red-800/20 enabled:dark:focus:bg-red-950/40 enabled:hover:dark:bg-red-950/50 enabled:dark:hover:border-red-800/50 dark:bg-transparent dark:text-red-500",
|
||||
"",
|
||||
],
|
||||
"danger-text": [
|
||||
"dark:bg-transparent dark:text-red-500 dark:hover:text-red-600 dark:border-transparent !px-0 !shadow-none !py-0 focus:ring-red-500/30 dark:ring-offset-neutral-950/50",
|
||||
],
|
||||
"default-outline": [
|
||||
"dark:ring-offset-nb-gray-950/50 dark:focus:ring-nb-gray-500/20",
|
||||
"dark:bg-transparent dark:text-nb-gray-400 dark:border-transparent dark:hover:text-white dark:hover:bg-nb-gray-900/30 dark:hover:border-nb-gray-800/50",
|
||||
"data-[state=open]:dark:text-white data-[state=open]:dark:bg-nb-gray-900/30 data-[state=open]:dark:border-nb-gray-800/50",
|
||||
],
|
||||
danger: [
|
||||
"", // TODO - add danger button styles for light mode
|
||||
|
||||
@@ -19,6 +19,8 @@ export const calloutVariants = cva(
|
||||
default: "bg-nb-gray-900/60 border-nb-gray-800/80 text-nb-gray-300",
|
||||
warning: "bg-netbird-500/10 border-netbird-400/20 text-netbird-150",
|
||||
info: "bg-sky-400/10 border-sky-400/20 text-sky-100",
|
||||
success: "bg-green-400/15 border-green-400/20 text-green-100",
|
||||
error: "bg-red-500/10 border-red-400/20 text-red-100",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -22,11 +22,7 @@ export default function CopyToClipboardText({
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex gap-2 items-center group cursor-pointer transition-all hover:underline underline-offset-4 decoration-dashed decoration-nb-gray-600",
|
||||
!copied && "hover:opacity-90",
|
||||
className,
|
||||
)}
|
||||
className={cn("flex gap-2 items-center group cursor-pointer", className)}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
@@ -34,27 +30,34 @@ export default function CopyToClipboardText({
|
||||
}}
|
||||
ref={wrapper}
|
||||
>
|
||||
{children}
|
||||
<span className="relative truncate">
|
||||
{children}
|
||||
<span className="absolute bottom-0 left-0 right-0 border-b border-dashed border-transparent group-hover:border-nb-gray-500 pointer-events-none" />
|
||||
</span>
|
||||
|
||||
{copied ? (
|
||||
<span
|
||||
className={cn(
|
||||
"shrink-0",
|
||||
iconAlignment === "left" ? "order-first" : "order-last",
|
||||
)}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"text-nb-gray-100 group-hover:opacity-100 shrink-0",
|
||||
iconAlignment === "left" ? "order-first" : "order-last",
|
||||
!alwaysShowIcon && "opacity-0",
|
||||
"text-nb-gray-100 group-hover:opacity-100",
|
||||
!copied && "hidden",
|
||||
!alwaysShowIcon && !copied && "opacity-0",
|
||||
)}
|
||||
size={11}
|
||||
/>
|
||||
) : (
|
||||
<CopyIcon
|
||||
className={cn(
|
||||
"text-nb-gray-100 group-hover:opacity-100 shrink-0",
|
||||
iconAlignment === "left" ? "order-first" : "order-last",
|
||||
"text-nb-gray-100 group-hover:opacity-100",
|
||||
copied && "hidden",
|
||||
!alwaysShowIcon && "opacity-0",
|
||||
)}
|
||||
size={11}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ interface Props {
|
||||
value?: DateRange;
|
||||
onChange?: (range: DateRange | undefined) => void;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const defaultRanges = {
|
||||
@@ -61,6 +62,7 @@ export function DatePickerWithRange({
|
||||
className,
|
||||
value,
|
||||
onChange,
|
||||
disabled = false,
|
||||
}: Readonly<Props>) {
|
||||
const isActive = useMemo(() => {
|
||||
return {
|
||||
@@ -120,6 +122,7 @@ export function DatePickerWithRange({
|
||||
<Button
|
||||
id="date"
|
||||
variant={"secondary"}
|
||||
disabled={disabled}
|
||||
className={cn("max-w-[260px] justify-start text-left font-normal")}
|
||||
>
|
||||
<CalendarIcon size={16} className={"shrink-0"} />
|
||||
|
||||
93
src/components/DeviceCard.tsx
Normal file
93
src/components/DeviceCard.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
import TruncatedText from "@components/ui/TruncatedText";
|
||||
import { cn } from "@utils/helpers";
|
||||
import * as React from "react";
|
||||
import { useMemo } from "react";
|
||||
import RoundedFlag from "@/assets/countries/RoundedFlag";
|
||||
import { PeerOSIcon } from "@/assets/icons/PeerOSIcon";
|
||||
import { ResourceIcon } from "@/assets/icons/ResourceIcon";
|
||||
import { NetworkResource } from "@/interfaces/Network";
|
||||
import type { Peer } from "@/interfaces/Peer";
|
||||
|
||||
type DeviceCardProps = {
|
||||
device?: Peer;
|
||||
resource?: NetworkResource;
|
||||
className?: string;
|
||||
address?: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
export const DeviceCard = ({
|
||||
device,
|
||||
resource,
|
||||
className,
|
||||
address,
|
||||
description,
|
||||
}: DeviceCardProps) => {
|
||||
if (!device && !resource) return null;
|
||||
|
||||
const descriptionText = useMemo(() => {
|
||||
return description !== undefined
|
||||
? description
|
||||
: address || device?.ip || resource?.address;
|
||||
}, [description, address, device]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex shrink-0 items-center gap-2.5 text-nb-gray-200 text-left py-1 pl-3 pr-4 rounded-md group/machine my-0 w-[230px]",
|
||||
!descriptionText && "py-2",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-center rounded-md h-9 w-9 shrink-0 bg-nb-gray-900 transition-all",
|
||||
"group-hover:bg-nb-gray-800 relative",
|
||||
)}
|
||||
>
|
||||
{device ? (
|
||||
<PeerOSIcon os={device.os} />
|
||||
) : resource?.type ? (
|
||||
<ResourceIcon type={resource.type} />
|
||||
) : null}
|
||||
|
||||
{device?.country_code && (
|
||||
<div className={"absolute -bottom-[4px] -right-[4px]"}>
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-center rounded-full border-[3px] shrink-0",
|
||||
"border-nb-gray-940",
|
||||
)}
|
||||
>
|
||||
<RoundedFlag country={device?.country_code} size={10} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={
|
||||
"flex flex-col gap-0 justify-center top-[0.15rem] leading-tight relative"
|
||||
}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
"font-normal text-[0.85rem] text-nb-gray-100 flex items-center gap-2"
|
||||
}
|
||||
>
|
||||
<TruncatedText
|
||||
text={device?.name || resource?.name || "Unknown"}
|
||||
maxWidth={"150px"}
|
||||
hideTooltip={true}
|
||||
/>
|
||||
</span>
|
||||
<span
|
||||
className={
|
||||
"text-sm font-normal text-nb-gray-400 relative whitespace-nowrap"
|
||||
}
|
||||
>
|
||||
<TruncatedText text={descriptionText} maxWidth={"160px"} />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -93,25 +93,53 @@ const DropdownMenuItem = React.forwardRef<
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
variant?: "default" | "danger";
|
||||
href?: string;
|
||||
target?: string;
|
||||
rel?: string;
|
||||
}
|
||||
>(({ className, inset, variant = "default", onClick, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex select-none items-center rounded-md pr-2 pl-3 py-1.5 text-sm outline-none",
|
||||
"transition-colors focus:bg-gray-100 focus:text-gray-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 cursor-pointer ",
|
||||
inset && "pl-8",
|
||||
menuItemVariants({ variant }),
|
||||
>(
|
||||
(
|
||||
{
|
||||
className,
|
||||
)}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onClick && onClick(e);
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
inset,
|
||||
variant = "default",
|
||||
onClick,
|
||||
href,
|
||||
target,
|
||||
rel,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex select-none items-center rounded-md pr-2 pl-3 py-1.5 text-sm outline-none",
|
||||
"transition-colors focus:bg-gray-100 focus:text-gray-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 cursor-pointer ",
|
||||
inset && "pl-8",
|
||||
menuItemVariants({ variant }),
|
||||
className,
|
||||
)}
|
||||
onClick={(e) => {
|
||||
if (href) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onClick && onClick(e);
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
{href ? (
|
||||
<a href={href} target={target} rel={rel}>
|
||||
{props.children}
|
||||
</a>
|
||||
) : (
|
||||
props.children
|
||||
)}
|
||||
</DropdownMenuPrimitive.Item>
|
||||
);
|
||||
},
|
||||
);
|
||||
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
||||
|
||||
const DropdownMenuCheckboxItem = React.forwardRef<
|
||||
|
||||
45
src/components/ExternalLinkText.tsx
Normal file
45
src/components/ExternalLinkText.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { cn } from "@utils/helpers";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
href: string;
|
||||
children: React.ReactNode;
|
||||
iconAlignment?: "left" | "right";
|
||||
className?: string;
|
||||
alwaysShowIcon?: boolean;
|
||||
};
|
||||
|
||||
export default function ExternalLinkText({
|
||||
href,
|
||||
children,
|
||||
iconAlignment = "right",
|
||||
className,
|
||||
alwaysShowIcon = false,
|
||||
}: Props) {
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={cn(
|
||||
"flex gap-2 items-center group/link cursor-pointer hover:opacity-90",
|
||||
className,
|
||||
)}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<span className="relative">
|
||||
{children}
|
||||
<span className="absolute bottom-0 left-0 right-0 border-b border-dashed border-transparent group-hover/link:border-nb-gray-500 pointer-events-none" />
|
||||
</span>
|
||||
<ExternalLinkIcon
|
||||
className={cn(
|
||||
"text-nb-gray-100 group-hover/link:opacity-100 shrink-0",
|
||||
iconAlignment === "left" ? "order-first" : "order-last",
|
||||
!alwaysShowIcon && "opacity-0",
|
||||
)}
|
||||
size={12}
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -99,7 +99,11 @@ export default function FancyToggleSwitch({
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>{children && value ? children : null}</div>
|
||||
{children && value ? (
|
||||
<div className="mt-4" onClick={(e) => e.stopPropagation()}>
|
||||
{children}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
30
src/components/HelpTooltip.tsx
Normal file
30
src/components/HelpTooltip.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import * as React from "react";
|
||||
import FullTooltip from "@components/FullTooltip";
|
||||
|
||||
type Props = {
|
||||
content: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
interactive?: boolean;
|
||||
};
|
||||
export const HelpTooltip = ({
|
||||
content,
|
||||
children,
|
||||
interactive = true,
|
||||
}: Props) => {
|
||||
return (
|
||||
<>
|
||||
<FullTooltip
|
||||
interactive={interactive}
|
||||
side={"top"}
|
||||
align={"start"}
|
||||
alignOffset={0}
|
||||
className={
|
||||
"inline underline decoration-dashed underline-offset-[3px] decoration-nb-gray-300 cursor-help transition-all hover:decoration-white"
|
||||
}
|
||||
content={content}
|
||||
>
|
||||
{children}
|
||||
</FullTooltip>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -27,6 +27,8 @@ export const linkVariants = cva(
|
||||
default: "text-netbird hover:underline font-normal",
|
||||
faded: "text-nb-gray-400 hover:text-nb-gray-300 hover:underline",
|
||||
white: "text-nb-gray-100 hover:text-white hover:underline",
|
||||
dashed:
|
||||
"text-nb-gray-100/90 underline font-normal decoration-dashed hover:text-white",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,8 +2,9 @@ import FullTooltip from "@components/FullTooltip";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { cva, VariantProps } from "class-variance-authority";
|
||||
import { AlertCircle } from "lucide-react";
|
||||
import { AlertCircle, Eye, EyeOff } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
type InputVariants = VariantProps<typeof inputVariants>;
|
||||
|
||||
@@ -16,8 +17,9 @@ export interface InputProps
|
||||
icon?: React.ReactNode;
|
||||
error?: string;
|
||||
errorTooltip?: boolean;
|
||||
errorTooltipPosition?: "top" | "top-right";
|
||||
errorTooltipPosition?: "top" | "top-right" | "bottom";
|
||||
prefixClassName?: string;
|
||||
showPasswordToggle?: boolean;
|
||||
}
|
||||
|
||||
const inputVariants = cva("", {
|
||||
@@ -61,10 +63,29 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
errorTooltipPosition = "top",
|
||||
variant = "default",
|
||||
prefixClassName,
|
||||
showPasswordToggle = false,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const isPasswordType = type === "password";
|
||||
const inputType = isPasswordType && showPassword ? "text" : type;
|
||||
|
||||
const passwordToggle =
|
||||
isPasswordType && showPasswordToggle ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPassword(!showPassword)}
|
||||
className={"hover:text-white transition-all"}
|
||||
aria-label={"Toggle password visibility"}
|
||||
>
|
||||
{showPassword ? <EyeOff size={18} /> : <Eye size={18} />}
|
||||
</button>
|
||||
) : null;
|
||||
|
||||
const suffix = passwordToggle || customSuffix;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={cn("flex relative h-[42px]", maxWidthClass)}>
|
||||
@@ -94,7 +115,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
</div>
|
||||
|
||||
<input
|
||||
type={type}
|
||||
type={inputType}
|
||||
ref={ref}
|
||||
{...props}
|
||||
className={cn(
|
||||
@@ -103,9 +124,11 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
"file:border-0",
|
||||
"focus-visible:ring-2 focus-visible:ring-offset-2",
|
||||
customPrefix && "!border-l-0 !rounded-l-none",
|
||||
customSuffix && "!pr-16",
|
||||
suffix && "!pr-16",
|
||||
icon && "!pl-10",
|
||||
"border",
|
||||
props.readOnly &&
|
||||
"!bg-nb-gray-920 text-nb-gray-400 !border-nb-gray-800",
|
||||
className,
|
||||
)}
|
||||
/>
|
||||
@@ -116,7 +139,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
props.disabled && "opacity-30",
|
||||
)}
|
||||
>
|
||||
{customSuffix}
|
||||
{suffix}
|
||||
</div>
|
||||
{error && errorTooltip && (
|
||||
<div
|
||||
|
||||
@@ -9,17 +9,34 @@ const labelVariants = cva(
|
||||
"text-sm font-medium tracking-wider leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 mb-1.5 inline-block dark:text-nb-gray-200 flex items-center gap-2",
|
||||
);
|
||||
|
||||
const Label = React.forwardRef<
|
||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
||||
VariantProps<typeof labelVariants>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<LabelPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(labelVariants(), className, "select-none")}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
type LabelProps = React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
||||
VariantProps<typeof labelVariants> & {
|
||||
as?: "label" | "div";
|
||||
};
|
||||
|
||||
const Label = React.forwardRef<HTMLElement, LabelProps>(
|
||||
({ className, as = "label", children, ...props }, ref) => {
|
||||
const classes = cn(labelVariants(), className, "select-none");
|
||||
|
||||
if (as === "div") {
|
||||
return (
|
||||
<div ref={ref as React.Ref<HTMLDivElement>} className={classes}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
ref={ref as React.Ref<HTMLLabelElement>}
|
||||
className={classes}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</LabelPrimitive.Root>
|
||||
);
|
||||
},
|
||||
);
|
||||
Label.displayName = LabelPrimitive.Root.displayName;
|
||||
|
||||
export { Label };
|
||||
|
||||
@@ -2,11 +2,11 @@ import { IconCircleX } from "@tabler/icons-react";
|
||||
import type { ErrorResponse } from "@utils/api";
|
||||
import { cn } from "@utils/helpers";
|
||||
import classNames from "classnames";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { motion } from "framer-motion";
|
||||
import { CheckIcon, Loader2, XIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast, { type Toast } from "react-hot-toast";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export interface NotifyProps<T> {
|
||||
title: string;
|
||||
@@ -22,14 +22,15 @@ export interface NotifyProps<T> {
|
||||
}
|
||||
|
||||
interface NotificationProps<T> extends NotifyProps<T> {
|
||||
t: Toast;
|
||||
toastId: string | number;
|
||||
}
|
||||
|
||||
export default function Notification<T>({
|
||||
title,
|
||||
description,
|
||||
icon,
|
||||
backgroundColor,
|
||||
t,
|
||||
toastId,
|
||||
promise,
|
||||
loadingTitle,
|
||||
loadingMessage,
|
||||
@@ -39,17 +40,65 @@ export default function Notification<T>({
|
||||
}: NotificationProps<T>) {
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(!!promise);
|
||||
const [readyToDismiss, setReadyToDismiss] = useState(!promise);
|
||||
|
||||
const [toastDuration] = useState(duration);
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const remainingRef = useRef(duration);
|
||||
const startTimeRef = useRef<number | null>(null);
|
||||
|
||||
const [preventSuccess, setPreventSuccess] = useState(false);
|
||||
const startTimer = useCallback(() => {
|
||||
if (timerRef.current) return;
|
||||
startTimeRef.current = Date.now();
|
||||
timerRef.current = setTimeout(() => {
|
||||
timerRef.current = null;
|
||||
toast.dismiss(toastId);
|
||||
}, Math.max(0, remainingRef.current));
|
||||
}, [toastId]);
|
||||
|
||||
const closeToast = () => {
|
||||
setTimeout(() => {
|
||||
setLoading(false);
|
||||
toast.dismiss(t.id);
|
||||
}, toastDuration);
|
||||
};
|
||||
const pauseTimer = useCallback(() => {
|
||||
if (!timerRef.current || !startTimeRef.current) return;
|
||||
clearTimeout(timerRef.current);
|
||||
timerRef.current = null;
|
||||
remainingRef.current = Math.max(
|
||||
0,
|
||||
remainingRef.current - (Date.now() - startTimeRef.current),
|
||||
);
|
||||
}, []);
|
||||
|
||||
const notificationRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Watch for sonner's expanded state to pause/resume timer
|
||||
useEffect(() => {
|
||||
if (!readyToDismiss) return;
|
||||
|
||||
const toastEl = notificationRef.current?.closest(
|
||||
"[data-sonner-toast]",
|
||||
) as HTMLElement | null;
|
||||
if (!toastEl) {
|
||||
startTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
const expanded = toastEl.getAttribute("data-expanded") === "true";
|
||||
if (expanded) {
|
||||
pauseTimer();
|
||||
} else {
|
||||
startTimer();
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(toastEl, { attributes: true, attributeFilter: ["data-expanded"] });
|
||||
|
||||
// Start immediately if not expanded
|
||||
const expanded = toastEl.getAttribute("data-expanded") === "true";
|
||||
if (!expanded) startTimer();
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
if (timerRef.current) clearTimeout(timerRef.current);
|
||||
};
|
||||
}, [readyToDismiss, toastId, startTimer, pauseTimer]);
|
||||
|
||||
useEffect(() => {
|
||||
// Run the promise
|
||||
@@ -57,8 +106,11 @@ export default function Notification<T>({
|
||||
promise
|
||||
.then(() => {
|
||||
setLoading(false);
|
||||
closeToast();
|
||||
if (preventSuccessToast) setPreventSuccess(true);
|
||||
if (preventSuccessToast) {
|
||||
toast.dismiss(toastId);
|
||||
} else {
|
||||
setReadyToDismiss(true);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
const err = e as ErrorResponse;
|
||||
@@ -78,78 +130,76 @@ export default function Notification<T>({
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
closeToast();
|
||||
setReadyToDismiss(true);
|
||||
});
|
||||
} else {
|
||||
closeToast();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{t.visible && !preventSuccess && (
|
||||
<motion.div
|
||||
initial={{ opacity: 1, y: -50 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -50 }}
|
||||
className={cn(
|
||||
"max-w-md w-full justify-between bg-white dark:bg-nb-gray-940 shadow-lg rounded-md px-4 py-2.5 pointer-events-auto flex border dark:border-nb-gray-900",
|
||||
)}
|
||||
>
|
||||
<div className={"flex items-center gap-4"}>
|
||||
<div
|
||||
className={classNames(
|
||||
"h-8 w-8 shadow-sm text-white flex items-center justify-center rounded-md shrink-0",
|
||||
loading
|
||||
? "bg-nb-gray-900"
|
||||
: error
|
||||
? "bg-red-500"
|
||||
: backgroundColor || "bg-green-500",
|
||||
)}
|
||||
>
|
||||
{loading ? (
|
||||
<Loader2 size={14} className={"animate-spin"} />
|
||||
) : error ? (
|
||||
<IconCircleX size={24} />
|
||||
) : (
|
||||
icon || <CheckIcon size={14} />
|
||||
)}
|
||||
</div>
|
||||
<div className={"flex flex-col text-sm"}>
|
||||
<p>
|
||||
<span className={"font-semibold"}>
|
||||
{loading ? loadingTitle || title : title}
|
||||
</span>
|
||||
</p>
|
||||
<p
|
||||
className={"text-xs dark:text-nb-gray-300 text-gray-600 mt-0.5"}
|
||||
>
|
||||
{loading ? loadingMessage : error ? error : description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="flex dark:border-nb-gray-900 items-center cursor-pointer group"
|
||||
onClick={() => toast.dismiss(t.id)}
|
||||
<motion.div
|
||||
ref={notificationRef}
|
||||
initial={{ y: -20 }}
|
||||
animate={{ y: 0 }}
|
||||
transition={{ type: "spring", stiffness: 400, damping: 20 }}
|
||||
data-toast-notification
|
||||
className="w-[28rem] pb-2"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"w-full justify-between bg-white dark:bg-nb-gray-940 shadow-lg rounded-md px-4 py-2.5 pointer-events-auto flex border dark:border-nb-gray-900",
|
||||
)}
|
||||
>
|
||||
<div className={"flex items-center gap-4"}>
|
||||
<div
|
||||
className={classNames(
|
||||
"h-8 w-8 shadow-sm text-white flex items-center justify-center rounded-md shrink-0",
|
||||
loading
|
||||
? "bg-nb-gray-900"
|
||||
: error
|
||||
? "bg-red-500"
|
||||
: backgroundColor || "bg-green-500",
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"p-2 hover:bg-nb-gray-900 rounded-md opacity-50 group-hover:opacity-100"
|
||||
}
|
||||
>
|
||||
<XIcon size={16} />
|
||||
</div>
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
{loading ? (
|
||||
<Loader2 size={14} className={"animate-spin"} />
|
||||
) : error ? (
|
||||
<IconCircleX size={24} />
|
||||
) : (
|
||||
icon || <CheckIcon size={14} />
|
||||
)}
|
||||
</div>
|
||||
<div className={"flex flex-col text-sm"}>
|
||||
<p>
|
||||
<span className={"font-semibold"}>
|
||||
{loading ? loadingTitle || title : title}
|
||||
</span>
|
||||
</p>
|
||||
<p className={"text-xs dark:text-nb-gray-300 text-gray-600 mt-0.5"}>
|
||||
{loading ? loadingMessage : error ? error : description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="flex dark:border-nb-gray-900 items-center cursor-pointer group"
|
||||
onClick={() => toast.dismiss(toastId)}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"p-2 hover:bg-nb-gray-900 rounded-md opacity-50 group-hover:opacity-100"
|
||||
}
|
||||
>
|
||||
<XIcon size={16} />
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
export function notify<T>(props: NotifyProps<T>) {
|
||||
return toast.custom((t) => <Notification {...props} t={t} />, {
|
||||
return toast.custom((id) => <Notification {...props} toastId={id} />, {
|
||||
duration: Infinity,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,6 +44,9 @@ import { PolicyRuleResource } from "@/interfaces/Policy";
|
||||
import { User } from "@/interfaces/User";
|
||||
import { HorizontalUsersStack } from "@/modules/users/HorizontalUsersStack";
|
||||
import { PeerOperatingSystemIcon } from "@/modules/peers/PeerOperatingSystemIcon";
|
||||
import TruncatedText from "@components/ui/TruncatedText";
|
||||
|
||||
type PeerGroupSelectorTab = "peers" | "groups" | "resources";
|
||||
|
||||
const groupsSearchPredicate = (item: Group, query: string) => {
|
||||
const lowerCaseQuery = query.toLowerCase();
|
||||
@@ -68,6 +71,9 @@ interface MultiSelectProps {
|
||||
showResourceCounter?: boolean;
|
||||
showResources?: boolean;
|
||||
showPeers?: boolean;
|
||||
hideGroupsTab?: boolean;
|
||||
tabOrder?: ("groups" | "peers" | "resources")[];
|
||||
closeOnSelect?: boolean;
|
||||
resource?: PolicyRuleResource;
|
||||
onResourceChange?: (resource?: PolicyRuleResource) => void;
|
||||
placeholder?: string;
|
||||
@@ -76,6 +82,7 @@ interface MultiSelectProps {
|
||||
side?: "top" | "bottom";
|
||||
users?: User[];
|
||||
placeholderForSearch?: string;
|
||||
resourceIds?: string[];
|
||||
}
|
||||
export function PeerGroupSelector({
|
||||
onChange,
|
||||
@@ -94,6 +101,9 @@ export function PeerGroupSelector({
|
||||
showResourceCounter = true,
|
||||
showResources = false,
|
||||
showPeers = false,
|
||||
hideGroupsTab = false,
|
||||
tabOrder,
|
||||
closeOnSelect = false,
|
||||
resource,
|
||||
onResourceChange,
|
||||
placeholder = "Add or select group(s)...",
|
||||
@@ -102,6 +112,7 @@ export function PeerGroupSelector({
|
||||
side = "bottom",
|
||||
users,
|
||||
placeholderForSearch = 'Search groups or add new group by pressing "Enter"...',
|
||||
resourceIds,
|
||||
}: Readonly<MultiSelectProps>) {
|
||||
const { data: resources, isLoading: isResourcesLoading } = useFetchApi<
|
||||
NetworkResource[]
|
||||
@@ -229,7 +240,13 @@ export function PeerGroupSelector({
|
||||
|
||||
const [slice, setSlice] = useState(10);
|
||||
|
||||
const [tab, setTab] = useState("groups");
|
||||
const getDefaultTab = (): PeerGroupSelectorTab => {
|
||||
if (tabOrder?.[0]) return tabOrder[0];
|
||||
if (hideGroupsTab) return showPeers ? "peers" : "resources";
|
||||
return "groups";
|
||||
};
|
||||
|
||||
const [tab, setTab] = useState<PeerGroupSelectorTab>(getDefaultTab);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
@@ -272,6 +289,9 @@ export function PeerGroupSelector({
|
||||
: undefined,
|
||||
);
|
||||
onChange([]);
|
||||
if (closeOnSelect) {
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
const selectPeer = (peer?: Peer) => {
|
||||
@@ -281,6 +301,9 @@ export function PeerGroupSelector({
|
||||
type: "peer",
|
||||
});
|
||||
onChange([]);
|
||||
if (closeOnSelect) {
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -438,11 +461,20 @@ export function PeerGroupSelector({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Tabs defaultValue={"groups"} value={tab} onValueChange={setTab}>
|
||||
<Tabs
|
||||
defaultValue={
|
||||
tabOrder?.[0] ??
|
||||
(hideGroupsTab ? (showPeers ? "peers" : "resources") : "groups")
|
||||
}
|
||||
value={tab}
|
||||
onValueChange={(v) => setTab(v as PeerGroupSelectorTab)}
|
||||
>
|
||||
<TabTriggers
|
||||
searchRef={searchRef}
|
||||
showPeers={showPeers}
|
||||
showResources={showResources}
|
||||
hideGroupsTab={hideGroupsTab}
|
||||
tabOrder={tabOrder}
|
||||
/>
|
||||
<TabsContent value={"groups"} className={"p-0 my-0"}>
|
||||
<CommandGroup>
|
||||
@@ -562,7 +594,11 @@ export function PeerGroupSelector({
|
||||
<TabsContent value={"resources"} className={"p-0 my-0"}>
|
||||
<ResourcesList
|
||||
search={search}
|
||||
resources={resources}
|
||||
resources={
|
||||
resourceIds
|
||||
? resources?.filter((r) => resourceIds.includes(r.id))
|
||||
: resources
|
||||
}
|
||||
isLoading={isResourcesLoading}
|
||||
value={resource}
|
||||
onChange={selectResource}
|
||||
@@ -592,60 +628,89 @@ const TabTriggers = ({
|
||||
searchRef,
|
||||
showResources = false,
|
||||
showPeers = false,
|
||||
hideGroupsTab = false,
|
||||
tabOrder,
|
||||
}: {
|
||||
searchRef: React.MutableRefObject<HTMLInputElement | null>;
|
||||
showResources?: boolean;
|
||||
showPeers?: boolean;
|
||||
hideGroupsTab?: boolean;
|
||||
tabOrder?: ("groups" | "peers" | "resources")[];
|
||||
}) => {
|
||||
if (!showResources && !showPeers) return null;
|
||||
const tabCount =
|
||||
(!hideGroupsTab ? 1 : 0) + (showResources ? 1 : 0) + (showPeers ? 1 : 0);
|
||||
if (tabCount <= 1) return null;
|
||||
|
||||
const groupsTab = !hideGroupsTab && (
|
||||
<TabsTrigger
|
||||
key="groups"
|
||||
value={"groups"}
|
||||
className={"text-[.8rem] font-normal"}
|
||||
onClick={() => searchRef.current?.focus()}
|
||||
>
|
||||
<FolderGit2
|
||||
className={
|
||||
"text-nb-gray-500 group-data-[state=active]/trigger:text-netbird transition-all"
|
||||
}
|
||||
size={14}
|
||||
/>
|
||||
Groups
|
||||
</TabsTrigger>
|
||||
);
|
||||
|
||||
const resourcesTab = showResources && (
|
||||
<TabsTrigger
|
||||
key="resources"
|
||||
value={"resources"}
|
||||
className={"text-[.8rem] font-normal"}
|
||||
onClick={() => searchRef.current?.focus()}
|
||||
>
|
||||
<Layers3Icon
|
||||
className={
|
||||
"text-nb-gray-500 group-data-[state=active]/trigger:text-netbird transition-all"
|
||||
}
|
||||
size={14}
|
||||
/>
|
||||
Resources
|
||||
</TabsTrigger>
|
||||
);
|
||||
|
||||
const peersTab = showPeers && (
|
||||
<TabsTrigger
|
||||
key="peers"
|
||||
value={"peers"}
|
||||
className={"text-[.8rem] font-normal"}
|
||||
onClick={() => searchRef.current?.focus()}
|
||||
>
|
||||
<MonitorSmartphoneIcon
|
||||
className={
|
||||
"text-nb-gray-500 group-data-[state=active]/trigger:text-netbird transition-all"
|
||||
}
|
||||
size={14}
|
||||
/>
|
||||
Peers
|
||||
</TabsTrigger>
|
||||
);
|
||||
|
||||
const tabMap = {
|
||||
groups: groupsTab,
|
||||
peers: peersTab,
|
||||
resources: resourcesTab,
|
||||
};
|
||||
|
||||
if (tabOrder) {
|
||||
return (
|
||||
<TabsList justify={"start"} className={"px-3"}>
|
||||
{tabOrder.map((tab) => tabMap[tab])}
|
||||
</TabsList>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<TabsList justify={"start"} className={"px-3"}>
|
||||
<TabsTrigger
|
||||
value={"groups"}
|
||||
className={"text-[.8rem] font-normal"}
|
||||
onClick={() => searchRef.current?.focus()}
|
||||
>
|
||||
<FolderGit2
|
||||
className={
|
||||
"text-nb-gray-500 group-data-[state=active]/trigger:text-netbird transition-all"
|
||||
}
|
||||
size={14}
|
||||
/>
|
||||
Groups
|
||||
</TabsTrigger>
|
||||
|
||||
{showResources && (
|
||||
<TabsTrigger
|
||||
value={"resources"}
|
||||
className={"text-[.8rem] font-normal"}
|
||||
onClick={() => searchRef.current?.focus()}
|
||||
>
|
||||
<Layers3Icon
|
||||
className={
|
||||
"text-nb-gray-500 group-data-[state=active]/trigger:text-netbird transition-all"
|
||||
}
|
||||
size={14}
|
||||
/>
|
||||
Resources
|
||||
</TabsTrigger>
|
||||
)}
|
||||
|
||||
{showPeers && (
|
||||
<TabsTrigger
|
||||
value={"peers"}
|
||||
className={"text-[.8rem] font-normal"}
|
||||
onClick={() => searchRef.current?.focus()}
|
||||
>
|
||||
<MonitorSmartphoneIcon
|
||||
className={
|
||||
"text-nb-gray-500 group-data-[state=active]/trigger:text-netbird transition-all"
|
||||
}
|
||||
size={14}
|
||||
/>
|
||||
Peers
|
||||
</TabsTrigger>
|
||||
)}
|
||||
{groupsTab}
|
||||
{resourcesTab}
|
||||
{peersTab}
|
||||
</TabsList>
|
||||
);
|
||||
};
|
||||
@@ -787,6 +852,7 @@ const ResourcesList = ({
|
||||
<VirtualScrollAreaList
|
||||
items={filteredItems}
|
||||
onSelect={onChange}
|
||||
estimatedItemHeight={42}
|
||||
itemClassName={"dark:aria-selected:bg-nb-gray-800/20"}
|
||||
renderItem={(res) => {
|
||||
return (
|
||||
@@ -896,6 +962,7 @@ const PeersList = ({
|
||||
<VirtualScrollAreaList
|
||||
items={filteredItems}
|
||||
onSelect={onChange}
|
||||
estimatedItemHeight={42}
|
||||
itemClassName={"dark:aria-selected:bg-nb-gray-800/20"}
|
||||
renderItem={(res) => {
|
||||
if (!res?.id) return;
|
||||
@@ -904,7 +971,7 @@ const PeersList = ({
|
||||
<Fragment key={res.id}>
|
||||
<div className={"flex items-center gap-2"}>
|
||||
<Badge
|
||||
useHover={true}
|
||||
useHover={false}
|
||||
data-cy={"group-badge"}
|
||||
variant={"gray-ghost"}
|
||||
className={cn(
|
||||
@@ -915,7 +982,7 @@ const PeersList = ({
|
||||
}}
|
||||
>
|
||||
<PeerOperatingSystemIcon os={res.os} />
|
||||
<TextWithTooltip text={res?.name || ""} maxChars={20} />
|
||||
<TruncatedText text={res?.name || ""} maxWidth={"270px"} />
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import { ArrowUpCircleIcon, ChevronsUpDown, MapPin } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { memo, useEffect, useState } from "react";
|
||||
import { useElementSize } from "@/hooks/useElementSize";
|
||||
import { OperatingSystem } from "@/interfaces/OperatingSystem";
|
||||
import { Peer } from "@/interfaces/Peer";
|
||||
import { PeerOperatingSystemIcon } from "@/modules/peers/PeerOperatingSystemIcon";
|
||||
|
||||
|
||||
123
src/components/PinCodeInput.tsx
Normal file
123
src/components/PinCodeInput.tsx
Normal file
@@ -0,0 +1,123 @@
|
||||
"use client";
|
||||
|
||||
import { cn } from "@utils/helpers";
|
||||
import React, {
|
||||
ClipboardEvent,
|
||||
forwardRef,
|
||||
KeyboardEvent,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
} from "react";
|
||||
|
||||
export interface PinCodeInputRef {
|
||||
focus: () => void;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
length?: number;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
type?: "text" | "password";
|
||||
}
|
||||
|
||||
const PinCodeInput = forwardRef<PinCodeInputRef, Props>(function PinCodeInput(
|
||||
{ value, onChange, length = 6, disabled = false, className, type = "text" },
|
||||
ref,
|
||||
) {
|
||||
const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
focus: () => {
|
||||
inputRefs.current[0]?.focus();
|
||||
},
|
||||
}));
|
||||
|
||||
const digits = value
|
||||
.split("")
|
||||
.concat(Array(length).fill(""))
|
||||
.slice(0, length);
|
||||
|
||||
const handleChange = (index: number, digit: string) => {
|
||||
if (!/^\d*$/.test(digit)) return;
|
||||
|
||||
const newDigits = [...digits];
|
||||
newDigits[index] = digit.slice(-1);
|
||||
const newValue = newDigits.join("").replace(/\s/g, "");
|
||||
onChange(newValue);
|
||||
|
||||
if (digit && index < length - 1) {
|
||||
inputRefs.current[index + 1]?.focus();
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (index: number, e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === "Backspace" && !digits[index] && index > 0) {
|
||||
inputRefs.current[index - 1]?.focus();
|
||||
}
|
||||
if (e.key === "ArrowLeft" && index > 0) {
|
||||
inputRefs.current[index - 1]?.focus();
|
||||
}
|
||||
if (e.key === "ArrowRight" && index < length - 1) {
|
||||
inputRefs.current[index + 1]?.focus();
|
||||
}
|
||||
if (/^\d$/.test(e.key) && digits[index]) {
|
||||
e.preventDefault();
|
||||
const newDigits = [...digits];
|
||||
newDigits[index] = e.key;
|
||||
onChange(newDigits.join("").replace(/\s/g, ""));
|
||||
if (index < length - 1) {
|
||||
inputRefs.current[index + 1]?.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handlePaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
||||
e.preventDefault();
|
||||
const pastedData = e.clipboardData
|
||||
.getData("text")
|
||||
.replace(/\D/g, "")
|
||||
.slice(0, length);
|
||||
onChange(pastedData);
|
||||
|
||||
const nextIndex = Math.min(pastedData.length, length - 1);
|
||||
inputRefs.current[nextIndex]?.focus();
|
||||
};
|
||||
|
||||
const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {
|
||||
e.target.select();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("flex gap-2", className)}>
|
||||
{digits.map((digit, index) => (
|
||||
<input
|
||||
key={index}
|
||||
ref={(el) => {
|
||||
inputRefs.current[index] = el;
|
||||
}}
|
||||
type={type}
|
||||
inputMode="numeric"
|
||||
maxLength={1}
|
||||
value={digit}
|
||||
onChange={(e) => handleChange(index, e.target.value)}
|
||||
onKeyDown={(e) => handleKeyDown(index, e)}
|
||||
onPaste={handlePaste}
|
||||
onFocus={handleFocus}
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
"w-[42px] h-[42px] text-center text-sm rounded-md",
|
||||
"dark:bg-nb-gray-900 border dark:border-nb-gray-700",
|
||||
"dark:placeholder:text-neutral-400/70",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
|
||||
"ring-offset-neutral-200/20 dark:ring-offset-neutral-950/50 dark:focus-visible:ring-neutral-500/20",
|
||||
"disabled:cursor-not-allowed disabled:opacity-40",
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export default PinCodeInput;
|
||||
@@ -188,7 +188,6 @@ export function PortSelector({
|
||||
"dark:placeholder:text-nb-gray-400 font-light placeholder:text-neutral-500 pl-10",
|
||||
)}
|
||||
data-cy={"port-input"}
|
||||
typeof={"number"}
|
||||
ref={searchRef}
|
||||
value={search}
|
||||
onValueChange={setSearch}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as RadixRadioGroup from "@radix-ui/react-radio-group";
|
||||
import { cn } from "@utils/helpers";
|
||||
import * as React from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
type Props = {
|
||||
value: string;
|
||||
@@ -10,10 +9,8 @@ type Props = {
|
||||
};
|
||||
|
||||
export const RadioGroup = ({ value, onChange, children }: Props) => {
|
||||
const [defaultValue] = useState(value);
|
||||
return (
|
||||
<RadixRadioGroup.Root
|
||||
defaultValue={defaultValue}
|
||||
value={value}
|
||||
onValueChange={onChange}
|
||||
className={
|
||||
|
||||
103
src/components/SettingCard.tsx
Normal file
103
src/components/SettingCard.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
"use client";
|
||||
|
||||
import Button from "@components/Button";
|
||||
import HelpText from "@components/HelpText";
|
||||
import { Label } from "@components/Label";
|
||||
import { SmallBadge } from "@components/ui/SmallBadge";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { PlusCircle, SquarePen } from "lucide-react";
|
||||
import React from "react";
|
||||
|
||||
type SettingCardItemProps = {
|
||||
label: React.ReactNode;
|
||||
description: React.ReactNode;
|
||||
enabled: boolean;
|
||||
onClick: () => void;
|
||||
};
|
||||
|
||||
function SettingCardItem({
|
||||
label,
|
||||
description,
|
||||
enabled,
|
||||
onClick,
|
||||
}: Readonly<SettingCardItemProps>) {
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={onClick}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
onClick();
|
||||
}
|
||||
}}
|
||||
className={
|
||||
"flex justify-between gap-10 px-6 border-t border-nb-gray-920 first:border-t-0 py-5 hover:bg-nb-gray-935 cursor-pointer transition-colors"
|
||||
}
|
||||
>
|
||||
<div className={"max-w-sm"}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label>{label}</Label>
|
||||
{enabled && (
|
||||
<SmallBadge
|
||||
text="Enabled"
|
||||
variant="green"
|
||||
size="md"
|
||||
className={"-top-[0.25rem]"}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<HelpText margin={false}>{description}</HelpText>
|
||||
</div>
|
||||
<div onClick={(e) => e.stopPropagation()}>
|
||||
{enabled ? (
|
||||
<Button
|
||||
variant={"secondaryLighter"}
|
||||
size={"xs"}
|
||||
className={"pl-3 pr-3"}
|
||||
onClick={onClick}
|
||||
>
|
||||
<SquarePen size={12} />
|
||||
Edit
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant={"secondaryLighter"}
|
||||
size={"xs"}
|
||||
className={"pl-3 pr-3"}
|
||||
onClick={onClick}
|
||||
>
|
||||
<PlusCircle size={12} />
|
||||
Add
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type SettingCardProps = {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
function SettingCard({ children, className }: Readonly<SettingCardProps>) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"border-nb-gray-920 bg-nb-gray-800/10 border rounded-md",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const SettingCardWithItem = SettingCard as React.FC<Readonly<SettingCardProps>> & {
|
||||
Item: typeof SettingCardItem;
|
||||
};
|
||||
SettingCardWithItem.Item = SettingCardItem;
|
||||
|
||||
export default SettingCardWithItem;
|
||||
@@ -5,7 +5,7 @@ import { cn } from "@utils/helpers";
|
||||
import classNames from "classnames";
|
||||
import { ChevronDownIcon, ChevronUpIcon, DotIcon } from "lucide-react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import React, { useMemo } from "react";
|
||||
import React, { useEffect, useMemo } from "react";
|
||||
import { useApplicationContext } from "@/contexts/ApplicationProvider";
|
||||
|
||||
export type SidebarItemProps = {
|
||||
@@ -36,8 +36,22 @@ export default function SidebarItem({
|
||||
labelClassName,
|
||||
visible,
|
||||
}: Readonly<SidebarItemProps>) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const path = usePathname();
|
||||
|
||||
// Check if any child route is active (for collapsible items)
|
||||
const hasActiveChild = useMemo(() => {
|
||||
if (!collapsible || !href) return false;
|
||||
return path === href || path.startsWith(href + "/");
|
||||
}, [collapsible, href, path]);
|
||||
|
||||
const [open, setOpen] = React.useState(hasActiveChild);
|
||||
|
||||
// Open the collapsible if a child route becomes active
|
||||
useEffect(() => {
|
||||
if (hasActiveChild && !open) {
|
||||
setOpen(true);
|
||||
}
|
||||
}, [hasActiveChild]);
|
||||
const router = useRouter();
|
||||
const { mobileNavOpen, toggleMobileNav, isNavigationCollapsed } =
|
||||
useApplicationContext();
|
||||
@@ -48,6 +62,7 @@ export default function SidebarItem({
|
||||
? path == href
|
||||
: path.includes(href)
|
||||
: false;
|
||||
if (collapsible && href) return;
|
||||
if (collapsible && mobileNavOpen) return;
|
||||
if (collapsible && open) return;
|
||||
if (preventRedirect) return;
|
||||
@@ -66,7 +81,7 @@ export default function SidebarItem({
|
||||
return (
|
||||
<Collapsible.Root open={open} onOpenChange={setOpen}>
|
||||
<Collapsible.Trigger asChild>
|
||||
<li className={"px-4 cursor-pointer list-none"}>
|
||||
<li className={"px-3 cursor-pointer list-none"}>
|
||||
<button
|
||||
className={classNames(
|
||||
"rounded-lg text-[.87rem] w-full relative font-normal",
|
||||
@@ -79,6 +94,7 @@ export default function SidebarItem({
|
||||
: "text-gray-600 hover:bg-gray-200 dark:text-nb-gray-400 dark:hover:bg-nb-gray-900/50",
|
||||
)}
|
||||
onClick={handleClick}
|
||||
data-cy={"left-navigation-item"}
|
||||
>
|
||||
{isChild && isNavigationCollapsed && !mobileNavOpen && (
|
||||
<div
|
||||
@@ -100,7 +116,7 @@ export default function SidebarItem({
|
||||
|
||||
<span
|
||||
className={cn(
|
||||
"px-4 whitespace-nowrap flex-1 w-full text-left",
|
||||
"px-3 whitespace-nowrap flex-1 w-full text-left",
|
||||
labelClassName,
|
||||
isNavigationCollapsed &&
|
||||
!mobileNavOpen &&
|
||||
|
||||
@@ -53,13 +53,10 @@ const TooltipContent = React.forwardRef<
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
asChild={true}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(tooltipVariants({ variant }), className)}
|
||||
{...props}
|
||||
>
|
||||
<div>{props.children}</div>
|
||||
</TooltipPrimitive.Content>
|
||||
/>
|
||||
</TooltipPrimitive.Portal>
|
||||
),
|
||||
);
|
||||
|
||||
36
src/components/TooltipListItem.tsx
Normal file
36
src/components/TooltipListItem.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { cn } from "@utils/helpers";
|
||||
import * as React from "react";
|
||||
|
||||
export const TooltipListItem = ({
|
||||
icon,
|
||||
label,
|
||||
value,
|
||||
className,
|
||||
labelClassName,
|
||||
}: {
|
||||
icon?: React.ReactNode;
|
||||
label: string;
|
||||
value: string | React.ReactNode;
|
||||
className?: string;
|
||||
labelClassName?: string;
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex justify-between gap-12 border-b border-nb-gray-920 py-2 px-4 last:border-b-0",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-nb-gray-100 font-medium",
|
||||
labelClassName,
|
||||
)}
|
||||
>
|
||||
{icon}
|
||||
{label}
|
||||
</div>
|
||||
<div className={"text-nb-gray-300"}>{value}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
148
src/components/VersionInfo.tsx
Normal file
148
src/components/VersionInfo.tsx
Normal file
@@ -0,0 +1,148 @@
|
||||
"use client";
|
||||
|
||||
import FullTooltip from "@components/FullTooltip";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { ArrowUpCircle } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { isNetBirdHosted } from "@utils/netbird";
|
||||
import { useApplicationContext } from "@/contexts/ApplicationProvider";
|
||||
import { VersionInfo as VersionInfoType } from "@/interfaces/Instance";
|
||||
|
||||
function formatVersion(version: string): string {
|
||||
if (!version) return "";
|
||||
// Add "v" prefix if version starts with a number
|
||||
if (/^\d/.test(version)) return `v${version}`;
|
||||
return version;
|
||||
}
|
||||
|
||||
function compareVersions(current: string, latest: string): boolean {
|
||||
// Returns true if latest is newer than current
|
||||
if (!current || !latest) return false;
|
||||
if (current === "development") return false;
|
||||
|
||||
// Strip "v" prefix if present
|
||||
const normalizedCurrent = current.replace(/^v/, "");
|
||||
const normalizedLatest = latest.replace(/^v/, "");
|
||||
|
||||
const currentParts = normalizedCurrent
|
||||
.split(".")
|
||||
.map((p) => parseInt(p, 10) || 0);
|
||||
const latestParts = normalizedLatest
|
||||
.split(".")
|
||||
.map((p) => parseInt(p, 10) || 0);
|
||||
|
||||
for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
|
||||
const c = currentParts[i] || 0;
|
||||
const l = latestParts[i] || 0;
|
||||
if (l > c) return true;
|
||||
if (l < c) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export const NavigationVersionInfo = () => {
|
||||
const { isNavigationCollapsed, mobileNavOpen } = useApplicationContext();
|
||||
|
||||
// Only show for self-hosted, not cloud
|
||||
if (isNetBirdHosted()) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"px-4 py-4 animate-fade-in",
|
||||
isNavigationCollapsed &&
|
||||
!mobileNavOpen &&
|
||||
"hidden md:group-hover/navigation:block",
|
||||
)}
|
||||
>
|
||||
<NavigationVersionInfoContent />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const NavigationVersionInfoContent = () => {
|
||||
const { data: versionInfo, isLoading } = useFetchApi<VersionInfoType>(
|
||||
"/instance/version",
|
||||
true, // ignore errors
|
||||
false, // don't revalidate on focus
|
||||
);
|
||||
|
||||
const dashboardVersion =
|
||||
process.env.NEXT_PUBLIC_DASHBOARD_VERSION || "development";
|
||||
|
||||
if (isLoading)
|
||||
return <Skeleton height={80} className={"rounded-lg opacity-60"} />;
|
||||
|
||||
if (!versionInfo) return null;
|
||||
|
||||
// Compare versions to detect updates (returns false for "development" versions)
|
||||
const managementUpdateAvailable = compareVersions(
|
||||
versionInfo.management_current_version,
|
||||
versionInfo.management_available_version,
|
||||
);
|
||||
const dashboardUpdateAvailable = compareVersions(
|
||||
dashboardVersion,
|
||||
versionInfo.dashboard_available_version,
|
||||
);
|
||||
const hasUpdate = managementUpdateAvailable || dashboardUpdateAvailable;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"w-full rounded-md text-xs flex flex-col gap-2 whitespace-normal border text-left",
|
||||
"bg-nb-gray-900/20 py-3 px-3 border-nb-gray-800/30",
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-col gap-1 text-nb-gray-400">
|
||||
<FullTooltip
|
||||
content={
|
||||
<span className="text-xs">
|
||||
Latest: {formatVersion(versionInfo.management_available_version)}
|
||||
</span>
|
||||
}
|
||||
side="top"
|
||||
className="w-full"
|
||||
>
|
||||
<div className="flex items-center justify-between w-full cursor-default">
|
||||
<span>Management</span>
|
||||
<span className="text-nb-gray-300 font-medium">
|
||||
{formatVersion(versionInfo.management_current_version)}
|
||||
</span>
|
||||
</div>
|
||||
</FullTooltip>
|
||||
<FullTooltip
|
||||
content={
|
||||
<span className="text-xs">
|
||||
Latest: {formatVersion(versionInfo.dashboard_available_version)}
|
||||
</span>
|
||||
}
|
||||
side="top"
|
||||
className="w-full"
|
||||
>
|
||||
<div className="flex items-center justify-between w-full cursor-default">
|
||||
<span>Dashboard</span>
|
||||
<span className="text-nb-gray-300 font-medium">
|
||||
{formatVersion(dashboardVersion)}
|
||||
</span>
|
||||
</div>
|
||||
</FullTooltip>
|
||||
</div>
|
||||
|
||||
{hasUpdate && (
|
||||
<a
|
||||
href="https://docs.netbird.io/selfhosted/maintenance/upgrade"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center justify-center gap-1.5 text-white font-medium bg-netbird hover:bg-netbird-500 transition-colors rounded-md py-1.5 px-2 mt-1"
|
||||
>
|
||||
<ArrowUpCircle size={12} />
|
||||
<span>Update available</span>
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default NavigationVersionInfo;
|
||||
@@ -1,12 +1,22 @@
|
||||
import {
|
||||
MemoizedScrollArea,
|
||||
MemoizedScrollAreaViewport,
|
||||
} from "@components/ScrollArea";
|
||||
import { MemoizedScrollArea, ScrollAreaViewport } from "@components/ScrollArea";
|
||||
import { cn } from "@utils/helpers";
|
||||
import * as React from "react";
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
forwardRef,
|
||||
memo,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
|
||||
|
||||
const VirtuosoScroller = forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>((props, ref) => <ScrollAreaViewport ref={ref} {...props} />);
|
||||
|
||||
type Props<T extends { id?: string }> = {
|
||||
items: T[];
|
||||
onSelect: (item: T) => void;
|
||||
@@ -183,7 +193,7 @@ export function VirtualScrollAreaList<T extends { id?: string }>({
|
||||
}}
|
||||
style={virtuosoHeight}
|
||||
components={{
|
||||
Scroller: MemoizedScrollAreaViewport,
|
||||
Scroller: VirtuosoScroller,
|
||||
}}
|
||||
/>
|
||||
</MemoizedScrollArea>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { DialogTriggerProps } from "@radix-ui/react-dialog";
|
||||
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { X } from "lucide-react";
|
||||
import * as React from "react";
|
||||
@@ -58,6 +59,7 @@ const ModalContent = React.forwardRef<
|
||||
children,
|
||||
showClose = true,
|
||||
maxWidthClass = "max-w-3xl",
|
||||
onPointerDownOutside,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
@@ -71,21 +73,35 @@ const ModalContent = React.forwardRef<
|
||||
className,
|
||||
maxWidthClass,
|
||||
)}
|
||||
onPointerDownOutside={(e) => {
|
||||
// Prevent closing modal when clicking on toast notifications
|
||||
try {
|
||||
const target = e.target as HTMLElement;
|
||||
if (target?.closest("[data-toast-notification]")) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
onPointerDownOutside?.(e);
|
||||
}}
|
||||
{...props}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<>
|
||||
{children}
|
||||
{showClose && (
|
||||
<DialogPrimitive.Close
|
||||
data-cy={"modal-close"}
|
||||
className="absolute right-4 z-10 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</>
|
||||
<VisuallyHidden asChild>
|
||||
<DialogPrimitive.Title>Dialog</DialogPrimitive.Title>
|
||||
</VisuallyHidden>
|
||||
{children}
|
||||
{showClose && (
|
||||
<DialogPrimitive.Close
|
||||
data-cy={"modal-close"}
|
||||
className="absolute right-4 z-10 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</ModalOverlay>
|
||||
</ModalPortal>
|
||||
@@ -129,18 +145,19 @@ const SidebarModalContent = React.forwardRef<
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<>
|
||||
{children}
|
||||
{showClose && (
|
||||
<DialogPrimitive.Close
|
||||
data-cy={"modal-close"}
|
||||
className="absolute right-4 z-10 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</>
|
||||
<VisuallyHidden asChild>
|
||||
<DialogPrimitive.Title>Dialog</DialogPrimitive.Title>
|
||||
</VisuallyHidden>
|
||||
{children}
|
||||
{showClose && (
|
||||
<DialogPrimitive.Close
|
||||
data-cy={"modal-close"}
|
||||
className="absolute right-4 z-10 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</div>
|
||||
</ModalPortal>
|
||||
|
||||
@@ -14,6 +14,7 @@ import * as React from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
import { useElementSize } from "@/hooks/useElementSize";
|
||||
import { DropdownInfoText } from "@components/DropdownInfoText";
|
||||
|
||||
export interface SelectOption {
|
||||
label: string | React.ReactNode;
|
||||
@@ -23,13 +24,18 @@ export interface SelectOption {
|
||||
width?: number;
|
||||
country?: string;
|
||||
}>;
|
||||
renderItem?: () => React.ReactNode;
|
||||
searchValue?: string;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
interface SelectDropdownProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
disabled?: boolean;
|
||||
popoverWidth?: "auto" | number;
|
||||
popoverWidth?: "auto" | "content" | number;
|
||||
popoverMinWidth?: number;
|
||||
options: SelectOption[];
|
||||
showSearch?: boolean;
|
||||
showValues?: boolean;
|
||||
@@ -41,6 +47,7 @@ interface SelectDropdownProps {
|
||||
size?: "xs" | "sm";
|
||||
children?: React.ReactNode;
|
||||
maxHeight?: number;
|
||||
triggerClassName?: string;
|
||||
}
|
||||
|
||||
export function SelectDropdown({
|
||||
@@ -48,6 +55,7 @@ export function SelectDropdown({
|
||||
value,
|
||||
disabled = false,
|
||||
popoverWidth = "auto",
|
||||
popoverMinWidth,
|
||||
options,
|
||||
showSearch = false,
|
||||
showValues = false,
|
||||
@@ -59,6 +67,7 @@ export function SelectDropdown({
|
||||
size = "sm",
|
||||
children,
|
||||
maxHeight,
|
||||
triggerClassName,
|
||||
}: Readonly<SelectDropdownProps>) {
|
||||
const [inputRef, { width }] = useElementSize<HTMLButtonElement>();
|
||||
|
||||
@@ -82,7 +91,7 @@ export function SelectDropdown({
|
||||
const filteredItems = React.useMemo(() => {
|
||||
if (isEmpty(debouncedSearch)) return options;
|
||||
return options.filter((item) => {
|
||||
const value = `${item.label}${item.value}` || "";
|
||||
const value = item?.searchValue || `${item.label}${item.value}` || "";
|
||||
return value.toLowerCase().includes(debouncedSearch.toLowerCase());
|
||||
});
|
||||
}, [options, debouncedSearch]);
|
||||
@@ -139,7 +148,11 @@ export function SelectDropdown({
|
||||
setOpen(isOpen);
|
||||
}}
|
||||
>
|
||||
<PopoverTrigger asChild={!children} disabled={disabled || isLoading}>
|
||||
<PopoverTrigger
|
||||
asChild={!children}
|
||||
disabled={disabled || isLoading}
|
||||
className={triggerClassName}
|
||||
>
|
||||
{children ? (
|
||||
children
|
||||
) : (
|
||||
@@ -147,7 +160,7 @@ export function SelectDropdown({
|
||||
variant={variant}
|
||||
disabled={disabled || isLoading}
|
||||
ref={inputRef}
|
||||
className={cn("w-full", className)}
|
||||
className={cn("w-full focus:outline-none", className)}
|
||||
>
|
||||
<div className={"w-full flex justify-between items-center gap-2"}>
|
||||
{isLoading && <Loading />}
|
||||
@@ -161,9 +174,18 @@ export function SelectDropdown({
|
||||
)}
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="w-full p-0 shadow-sm shadow-nb-gray-950 focus:outline-none"
|
||||
className={cn(
|
||||
"p-0 shadow-sm shadow-nb-gray-950 focus:outline-none",
|
||||
popoverWidth !== "content" && "w-full",
|
||||
)}
|
||||
style={{
|
||||
width: popoverWidth === "auto" ? width : popoverWidth,
|
||||
width:
|
||||
popoverWidth === "content"
|
||||
? "auto"
|
||||
: popoverWidth === "auto"
|
||||
? width
|
||||
: popoverWidth,
|
||||
minWidth: popoverMinWidth,
|
||||
}}
|
||||
align="start"
|
||||
side={"bottom"}
|
||||
@@ -186,9 +208,10 @@ export function SelectDropdown({
|
||||
)}
|
||||
|
||||
{filteredItems.length == 0 && (
|
||||
<div className={"text-center pb-2 px-3 text-nb-gray-400 text-xs"}>
|
||||
There are no results matching your search.
|
||||
</div>
|
||||
<DropdownInfoText className={"max-w-sm mx-auto px-4"}>
|
||||
There are no results matching your search. Please try a
|
||||
different search term.
|
||||
</DropdownInfoText>
|
||||
)}
|
||||
|
||||
<ScrollArea
|
||||
@@ -201,7 +224,7 @@ export function SelectDropdown({
|
||||
}}
|
||||
>
|
||||
<CommandGroup>
|
||||
<div className={"grid grid-cols-1 gap-1 pb-2"}>
|
||||
<div className={"grid grid-cols-1 gap-1 pb-2 w-full"}>
|
||||
{filteredItems.map((option) => (
|
||||
<SelectDropdownItem
|
||||
option={option}
|
||||
@@ -245,25 +268,35 @@ const SelectDropdownItem = ({
|
||||
}, [isVisible]);
|
||||
|
||||
return (
|
||||
<div ref={elementRef} className={"transition-all"}>
|
||||
<div ref={elementRef} className={"transition-all w-full"}>
|
||||
{visible ? (
|
||||
<CommandItem
|
||||
value={value}
|
||||
value={option?.searchValue ?? value}
|
||||
ref={elementRef}
|
||||
className={"py-1 px-2"}
|
||||
onSelect={() => toggle(option.value)}
|
||||
className={"py-1 px-2 w-full"}
|
||||
onSelect={() => !option?.disabled && toggle(option.value)}
|
||||
onClick={(e) => e.preventDefault()}
|
||||
disabled={option?.disabled}
|
||||
>
|
||||
<div className={"flex items-center gap-2.5 p-1"}>
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center gap-2.5 p-1 w-full",
|
||||
option?.className,
|
||||
option?.disabled && "cursor-not-allowed",
|
||||
)}
|
||||
>
|
||||
{option.icon && <option.icon size={14} width={14} />}
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col text-sm font-medium",
|
||||
size === "xs" && "text-xs",
|
||||
)}
|
||||
>
|
||||
<span className={"text-nb-gray-200"}>{option.label}</span>
|
||||
</div>
|
||||
{option?.renderItem && option.renderItem()}
|
||||
{!option?.renderItem && (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col text-sm font-medium w-full",
|
||||
size === "xs" && "text-xs",
|
||||
)}
|
||||
>
|
||||
<span className={"text-nb-gray-200"}>{option.label}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{showValue && (
|
||||
<div className={"flex items-center gap-2.5 p-1"}>
|
||||
|
||||
16
src/components/skeletons/SkeletonDeviceCard.tsx
Normal file
16
src/components/skeletons/SkeletonDeviceCard.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as React from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
|
||||
export const SkeletonDeviceCard = () => {
|
||||
return (
|
||||
<div className={"min-h-[59px] relative -left-2"}>
|
||||
<div className={"py-2 pr-4 pl-2 flex gap-3"}>
|
||||
<Skeleton height={36} width={36} />
|
||||
<div className={"flex flex-col pr-[1.15rem]"}>
|
||||
<Skeleton height={16} width={70} />
|
||||
<Skeleton height={16} width={140} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -14,11 +14,6 @@ import {
|
||||
TableWrapper,
|
||||
} from "@components/table/Table";
|
||||
import NoResults from "@components/ui/NoResults";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
} from "@radix-ui/react-accordion";
|
||||
import { RankingInfo } from "@tanstack/match-sorter-utils";
|
||||
import {
|
||||
ColumnDef,
|
||||
@@ -138,9 +133,10 @@ interface DataTableProps<TData, TValue> {
|
||||
className?: string;
|
||||
inset?: boolean;
|
||||
isLoading?: boolean;
|
||||
isFetching?: boolean;
|
||||
as?: "div" | "table";
|
||||
paginationClassName?: string;
|
||||
rowClassName?: string;
|
||||
rowClassName?: string | ((row: Row<TData>) => string);
|
||||
wrapperClassName?: string;
|
||||
tableClassName?: string;
|
||||
searchClassName?: string;
|
||||
@@ -155,6 +151,8 @@ interface DataTableProps<TData, TValue> {
|
||||
useRowId?: boolean;
|
||||
headingTarget?: HTMLHeadingElement | null;
|
||||
showResetFilterButton?: boolean;
|
||||
serverSidePagination?: boolean;
|
||||
hasServerSideFilters?: boolean;
|
||||
onFilterReset?: () => void;
|
||||
wrapperComponent?: React.ElementType;
|
||||
wrapperProps?: any;
|
||||
@@ -200,6 +198,7 @@ export function DataTable<TData, TValue>({
|
||||
tableClassName,
|
||||
inset,
|
||||
isLoading = false,
|
||||
isFetching = false,
|
||||
paginationClassName,
|
||||
rowClassName,
|
||||
wrapperClassName,
|
||||
@@ -216,6 +215,8 @@ export function DataTable<TData, TValue>({
|
||||
useRowId,
|
||||
headingTarget,
|
||||
showResetFilterButton = true,
|
||||
serverSidePagination = false,
|
||||
hasServerSideFilters,
|
||||
onFilterReset,
|
||||
showSearchAndFilters = true,
|
||||
wrapperProps,
|
||||
@@ -241,6 +242,19 @@ export function DataTable<TData, TValue>({
|
||||
const path = usePathname();
|
||||
const isInitialRender = useRef(true);
|
||||
|
||||
const [showOverlay, setShowOverlay] = useState(false);
|
||||
const overlayTimer = useRef<ReturnType<typeof setTimeout>>(undefined);
|
||||
useEffect(() => {
|
||||
if (!serverSidePagination) return;
|
||||
if (isFetching && !isLoading) {
|
||||
overlayTimer.current = setTimeout(() => setShowOverlay(true), 500);
|
||||
} else {
|
||||
clearTimeout(overlayTimer.current);
|
||||
setShowOverlay(false);
|
||||
}
|
||||
return () => clearTimeout(overlayTimer.current);
|
||||
}, [serverSidePagination, isFetching, isLoading]);
|
||||
|
||||
const [localColumnFilters, setLocalColumnFilters] =
|
||||
useLocalStorage<ColumnFiltersState>(
|
||||
`netbird-table-columns${uniqueKey ? "/" + (uniqueKey as string) : path}`,
|
||||
@@ -416,12 +430,7 @@ export function DataTable<TData, TValue>({
|
||||
return (
|
||||
<div className={cn("relative table-fixed-scroll", className)}>
|
||||
{showSearchAndFilters && (
|
||||
<div
|
||||
className={cn(
|
||||
"flex gap-x-4 gap-y-6 flex-wrap",
|
||||
!minimal && "p-default",
|
||||
)}
|
||||
>
|
||||
<div className={cn("flex gap-x-4 gap-y-6", !minimal && "p-default")}>
|
||||
<DataTableGlobalSearch
|
||||
className={searchClassName}
|
||||
disabled={false} // Never disable the search input
|
||||
@@ -444,10 +453,14 @@ export function DataTable<TData, TValue>({
|
||||
/>
|
||||
{children?.(table)}
|
||||
{showResetFilterButton && (
|
||||
<DataTableResetFilterButton onClick={resetFilters} table={table} />
|
||||
<DataTableResetFilterButton
|
||||
onClick={resetFilters}
|
||||
table={table}
|
||||
hasServerSideFilters={hasServerSideFilters}
|
||||
/>
|
||||
)}
|
||||
<div className={"flex gap-4 flex-wrap grow"}>
|
||||
<div className={"flex gap-4 flex-wrap"}></div>
|
||||
<div className={"flex gap-4 grow"}>
|
||||
<div className={"flex gap-4"}></div>
|
||||
{rightSide?.(table)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -455,50 +468,48 @@ export function DataTable<TData, TValue>({
|
||||
|
||||
{aboveTable?.(table)}
|
||||
|
||||
<TableWrapper
|
||||
wrapperComponent={wrapperComponent}
|
||||
wrapperProps={wrapperProps}
|
||||
>
|
||||
{isLoading ? (
|
||||
<TableContentSkeleton />
|
||||
) : !hasInitialData ? (
|
||||
getStartedCard
|
||||
) : (
|
||||
<TableComponent
|
||||
className={cn("relative mt-6", tableClassName)}
|
||||
minimal={minimal}
|
||||
>
|
||||
{showHeader && as == "table" && (
|
||||
<TableHeaderComponent minimal={minimal}>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRowComponent key={headerGroup.id} minimal={minimal}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<TableHead
|
||||
key={header.id}
|
||||
minimal={minimal}
|
||||
inset={inset}
|
||||
>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext(),
|
||||
)}
|
||||
</TableHead>
|
||||
);
|
||||
})}
|
||||
</TableRowComponent>
|
||||
))}
|
||||
</TableHeaderComponent>
|
||||
)}
|
||||
|
||||
<Accordion
|
||||
asChild={true}
|
||||
type={"multiple"}
|
||||
value={accordion}
|
||||
onValueChange={setAccordion}
|
||||
<div className="relative">
|
||||
{showOverlay && (
|
||||
<div className="absolute inset-0 bg-nb-gray-950/60 z-10 rounded-md animate-pulse" />
|
||||
)}
|
||||
<TableWrapper
|
||||
wrapperComponent={wrapperComponent}
|
||||
wrapperProps={wrapperProps}
|
||||
>
|
||||
{isLoading ? (
|
||||
<TableContentSkeleton />
|
||||
) : !hasInitialData && !hasServerSideFilters ? (
|
||||
getStartedCard
|
||||
) : (
|
||||
<TableComponent
|
||||
className={cn("relative mt-6", tableClassName)}
|
||||
minimal={minimal}
|
||||
>
|
||||
{showHeader && as == "table" && (
|
||||
<TableHeaderComponent minimal={minimal}>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRowComponent key={headerGroup.id} minimal={minimal}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<TableHead
|
||||
key={header.id}
|
||||
minimal={minimal}
|
||||
inset={inset}
|
||||
>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext(),
|
||||
)}
|
||||
</TableHead>
|
||||
);
|
||||
})}
|
||||
</TableRowComponent>
|
||||
))}
|
||||
</TableHeaderComponent>
|
||||
)}
|
||||
|
||||
<TableBodyComponent
|
||||
className={cn(
|
||||
"relative",
|
||||
@@ -509,98 +520,88 @@ export function DataTable<TData, TValue>({
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row) => {
|
||||
const expandedRow = renderExpandedRow?.(row.original);
|
||||
const rowId = row.original.id ?? row.id;
|
||||
const isExpanded = accordion?.includes(rowId);
|
||||
const rowContent = (
|
||||
<AccordionItem
|
||||
value={row.original.id}
|
||||
asChild={true}
|
||||
key={row.id}
|
||||
>
|
||||
<>
|
||||
<React.Fragment key={row.id}>
|
||||
<TableRowComponent
|
||||
minimal={minimal}
|
||||
data-row-id={rowId}
|
||||
className={cn(
|
||||
(onRowClick || renderExpandedRow) &&
|
||||
"relative group/accordion",
|
||||
(onRowClick || expandedRow) && "cursor-pointer",
|
||||
typeof rowClassName === "function"
|
||||
? rowClassName(row)
|
||||
: rowClassName,
|
||||
)}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
data-accordion={isExpanded ? "opened" : "closed"}
|
||||
onClick={(e) => {
|
||||
if (expandedRow) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setAccordion((prev) => {
|
||||
if (prev?.includes(rowId)) {
|
||||
return prev.filter((item) => item !== rowId);
|
||||
} else {
|
||||
return [...(prev ?? []), rowId];
|
||||
}
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCellComponent
|
||||
key={cell.id}
|
||||
className={cn("relative", tableCellClassName)}
|
||||
minimal={minimal}
|
||||
inset={inset}
|
||||
onClick={() => {
|
||||
onRowClick && onRowClick(row, cell.column.id);
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"absolute left-0 top-0 w-full h-full z-0"
|
||||
}
|
||||
></div>
|
||||
<div className={"relative z-[1]"}>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext(),
|
||||
)}
|
||||
</div>
|
||||
</TableCellComponent>
|
||||
))}
|
||||
</TableRowComponent>
|
||||
|
||||
{expandedRow && isExpanded && (
|
||||
<TableRowComponent
|
||||
data-row-id={row.id + "-expanded-row"}
|
||||
minimal={minimal}
|
||||
data-row-id={row.original.id}
|
||||
className={cn(
|
||||
(onRowClick || renderExpandedRow) &&
|
||||
"relative group/accordion",
|
||||
(onRowClick || expandedRow) && "cursor-pointer",
|
||||
rowClassName,
|
||||
onRowClick && "cursor-pointer relative",
|
||||
typeof rowClassName === "function"
|
||||
? rowClassName(row)
|
||||
: rowClassName,
|
||||
)}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
data-accordion={
|
||||
accordion?.includes(row.original.id)
|
||||
? "opened"
|
||||
: "closed"
|
||||
}
|
||||
onClick={(e) => {
|
||||
if (expandedRow) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setAccordion((prev) => {
|
||||
if (prev?.includes(row.original.id)) {
|
||||
return prev.filter(
|
||||
(item) => item !== row.original.id,
|
||||
);
|
||||
} else {
|
||||
return [...(prev ?? []), row.original.id];
|
||||
}
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
<>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCellComponent
|
||||
key={cell.id}
|
||||
className={cn("relative", tableCellClassName)}
|
||||
minimal={minimal}
|
||||
inset={inset}
|
||||
onClick={() => {
|
||||
onRowClick &&
|
||||
onRowClick(row, cell.column.id);
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"absolute left-0 top-0 w-full h-full z-0"
|
||||
}
|
||||
></div>
|
||||
<div className={"relative z-[1]"}>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext(),
|
||||
)}
|
||||
</div>
|
||||
</TableCellComponent>
|
||||
))}
|
||||
</>
|
||||
<TableDataUnstyledComponent
|
||||
className={"w-full"}
|
||||
colSpan={row.getVisibleCells().length}
|
||||
>
|
||||
{expandedRow}
|
||||
</TableDataUnstyledComponent>
|
||||
</TableRowComponent>
|
||||
|
||||
{expandedRow && (
|
||||
<AccordionContent asChild={true}>
|
||||
<TableRowComponent
|
||||
data-row-id={row.id + "-expanded-row"}
|
||||
key={row.id + "-expanded-row"}
|
||||
minimal={minimal}
|
||||
className={cn(
|
||||
onRowClick && "cursor-pointer relative",
|
||||
rowClassName,
|
||||
)}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
>
|
||||
<TableDataUnstyledComponent
|
||||
className={"w-full"}
|
||||
colSpan={row.getVisibleCells().length}
|
||||
>
|
||||
{expandedRow}
|
||||
</TableDataUnstyledComponent>
|
||||
</TableRowComponent>
|
||||
</AccordionContent>
|
||||
)}
|
||||
</>
|
||||
</AccordionItem>
|
||||
)}
|
||||
</React.Fragment>
|
||||
);
|
||||
|
||||
return renderRow ? renderRow(row.original, rowContent) : rowContent;
|
||||
return renderRow
|
||||
? renderRow(row.original, rowContent)
|
||||
: rowContent;
|
||||
})
|
||||
) : (
|
||||
<TableRowUnstyledComponent>
|
||||
@@ -613,10 +614,10 @@ export function DataTable<TData, TValue>({
|
||||
</TableRowUnstyledComponent>
|
||||
)}
|
||||
</TableBodyComponent>
|
||||
</Accordion>
|
||||
</TableComponent>
|
||||
)}
|
||||
</TableWrapper>
|
||||
</TableComponent>
|
||||
)}
|
||||
</TableWrapper>
|
||||
</div>
|
||||
|
||||
<div className={paginationClassName}>
|
||||
<DataTablePagination
|
||||
@@ -627,7 +628,13 @@ export function DataTable<TData, TValue>({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DataTableHeadingPortal table={table} headingTarget={headingTarget} />
|
||||
<DataTableHeadingPortal
|
||||
table={table}
|
||||
headingTarget={headingTarget}
|
||||
totalRecords={totalRecords}
|
||||
manualPagination={manualPagination}
|
||||
hasActiveFilters={hasServerSideFilters}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ type Props = {
|
||||
tooltip?: string | React.ReactNode;
|
||||
center?: boolean;
|
||||
className?: string;
|
||||
sorting?: boolean;
|
||||
};
|
||||
export default function DataTableHeader({
|
||||
children,
|
||||
@@ -19,23 +20,31 @@ export default function DataTableHeader({
|
||||
tooltip,
|
||||
center,
|
||||
className,
|
||||
sorting = true,
|
||||
}: Props) {
|
||||
return (
|
||||
<FullTooltip content={tooltip} disabled={!tooltip}>
|
||||
<div
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||
onClick={
|
||||
sorting
|
||||
? () => column.toggleSorting(column.getIsSorted() === "asc")
|
||||
: undefined
|
||||
}
|
||||
className={cn(
|
||||
"flex items-center whitespace-nowrap cursor-pointer gap-2 dark:text-gray-400 dark:hover:text-gray-300 transition-all select-none hover:text-nb-gray text-xs tracking-wide",
|
||||
"flex items-center whitespace-nowrap gap-2 dark:text-gray-400 transition-all select-none text-xs tracking-wide",
|
||||
sorting &&
|
||||
"cursor-pointer dark:hover:text-gray-300 hover:text-nb-gray",
|
||||
center && "justify-center w-full",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
{column.getIsSorted() === "desc" ? (
|
||||
<IconSortAscending size={16} />
|
||||
) : (
|
||||
<IconSortDescending size={16} />
|
||||
)}
|
||||
{sorting &&
|
||||
(column.getIsSorted() === "desc" ? (
|
||||
<IconSortAscending size={16} />
|
||||
) : (
|
||||
<IconSortDescending size={16} />
|
||||
))}
|
||||
</div>
|
||||
</FullTooltip>
|
||||
);
|
||||
|
||||
@@ -6,27 +6,57 @@ import { createPortal } from "react-dom";
|
||||
type Props<TData> = {
|
||||
table: Table<TData> | null;
|
||||
headingTarget?: HTMLHeadingElement | null;
|
||||
totalRecords?: number;
|
||||
manualPagination?: boolean;
|
||||
hasActiveFilters?: boolean;
|
||||
};
|
||||
|
||||
export const DataTableHeadingPortal = function <TData>({
|
||||
table,
|
||||
headingTarget,
|
||||
totalRecords,
|
||||
manualPagination,
|
||||
hasActiveFilters,
|
||||
}: Props<TData>) {
|
||||
const hasMounted = useRef(false);
|
||||
const initialTotalRecords = useRef<number | undefined>(undefined);
|
||||
|
||||
if (
|
||||
manualPagination &&
|
||||
totalRecords !== undefined &&
|
||||
initialTotalRecords.current === undefined
|
||||
) {
|
||||
initialTotalRecords.current = totalRecords;
|
||||
}
|
||||
|
||||
if (!headingTarget) return;
|
||||
if (!hasMounted.current) hasMounted.current = true;
|
||||
|
||||
const totalItems = table?.getPreFilteredRowModel().rows.length;
|
||||
const filteredItems = table?.getFilteredRowModel().rows.length;
|
||||
const filteredItems = manualPagination
|
||||
? totalRecords
|
||||
: table?.getFilteredRowModel().rows.length;
|
||||
|
||||
const getTotalRecords = () => {
|
||||
if (Number(initialTotalRecords.current) < Number(filteredItems)) {
|
||||
initialTotalRecords.current = filteredItems;
|
||||
return filteredItems;
|
||||
}
|
||||
return initialTotalRecords.current;
|
||||
};
|
||||
|
||||
const totalItems = manualPagination
|
||||
? getTotalRecords()
|
||||
: table?.getPreFilteredRowModel().rows.length;
|
||||
|
||||
if (!totalItems || totalItems == 1) return;
|
||||
|
||||
const hasAnyFiltersActive =
|
||||
table &&
|
||||
!(
|
||||
table?.getState().columnFilters.length <= 0 &&
|
||||
table?.getState().globalFilter === ""
|
||||
);
|
||||
const hasAnyFiltersActive = manualPagination
|
||||
? hasActiveFilters ?? totalRecords !== initialTotalRecords.current
|
||||
: table &&
|
||||
!(
|
||||
table?.getState().columnFilters.length <= 0 &&
|
||||
table?.getState().globalFilter === ""
|
||||
);
|
||||
|
||||
const portalContainer = document.createElement("span");
|
||||
headingTarget.prepend(portalContainer);
|
||||
|
||||
@@ -104,7 +104,7 @@ const TableRow = React.forwardRef<
|
||||
" transition-colors group/table-row data-[state=selected]:bg-neutral-100 dark:data-[state=selected]:bg-nb-gray-930/70",
|
||||
"dark:data-[state=selected]:border-nb-gray-900",
|
||||
minimal
|
||||
? "dark:hover:bg-nb-gray-900/10"
|
||||
? "dark:hover:bg-nb-gray-910/[15%]"
|
||||
: "border-b dark:border-zinc-700/40 dark:hover:bg-nb-gray-940 hover:bg-neutral-100/50",
|
||||
className,
|
||||
)}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Sparkles } from "lucide-react";
|
||||
import * as React from "react";
|
||||
|
||||
export const AIButton = () => {
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
"animated-gradient-bg gap-2 flex items-center justify-center text-sm font-medium p-[2px] rounded-md group"
|
||||
}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"flex items-center justify-center w-full h-full gap-2 bg-nb-gray-930/70 px-3 py-2.5 rounded-md"
|
||||
}
|
||||
>
|
||||
<Sparkles size={16} />
|
||||
AI Rule Wizard
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -64,8 +64,16 @@ const Time = ({
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
const { ref, ...rootProps } = getRootProps();
|
||||
|
||||
return (
|
||||
<div className={"timescape w-full"} {...getRootProps()}>
|
||||
<div
|
||||
className={"timescape w-full"}
|
||||
ref={(element) => {
|
||||
ref(element);
|
||||
}}
|
||||
{...rootProps}
|
||||
>
|
||||
<div>
|
||||
<input {...getInputProps("years")} />
|
||||
<span className={"separator"}>/</span>
|
||||
|
||||
@@ -12,21 +12,22 @@ const variants = cva(
|
||||
variant: {
|
||||
default:
|
||||
"bg-nb-gray-900/50 border-nb-gray-800/30 border-b text-nb-gray-200",
|
||||
important: "from-netbird to-netbird-400 bg-gradient-to-b text-white",
|
||||
important:
|
||||
"from-netbird to-netbird-400 bg-gradient-to-b text-black font-normal",
|
||||
},
|
||||
tagBadge: {
|
||||
default: "bg-nb-gray-200/10 text-nb-gray-100 font-medium",
|
||||
important: "bg-white text-netbird font-medium",
|
||||
important: "bg-nb-gray-900 text-nb-gray-200 font-medium",
|
||||
},
|
||||
closeButton: {
|
||||
default:
|
||||
"bg-nb-gray-900 rounded-md p-1 text-nb-gray-300 hover:bg-nb-gray-800",
|
||||
important:
|
||||
"bg-netbird-100 rounded-md p-1 text-netbird-600 hover:bg-white",
|
||||
"bg-netbird rounded-md p-1 text-nb-gray-900 hover:bg-nb-gray-900 hover:text-nb-gray-200",
|
||||
},
|
||||
inlineLink: {
|
||||
default: "text-nb-blue-400 hover:underline",
|
||||
important: "!text-white underline hover:opacity-80",
|
||||
important: "!text-black underline hover:opacity-80",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -19,40 +19,46 @@ function Calendar({
|
||||
showOutsideDays={showOutsideDays}
|
||||
className={cn("p-3", className)}
|
||||
classNames={{
|
||||
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
|
||||
month: "space-y-4",
|
||||
caption: "flex justify-center pt-1 relative items-center",
|
||||
months: "flex flex-col sm:flex-row space-y-4 sm:space-y-0 relative",
|
||||
month: "space-y-4 pr-4 last:pr-0",
|
||||
month_caption: "flex justify-center pt-1 relative items-center",
|
||||
caption_label: "text-sm font-medium",
|
||||
nav: "space-x-1 flex items-center",
|
||||
nav_button: cn(
|
||||
button_previous: cn(
|
||||
buttonVariants({ variant: "outline" }),
|
||||
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100",
|
||||
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute left-0 top-0 z-10",
|
||||
),
|
||||
nav_button_previous: "absolute left-1",
|
||||
nav_button_next: "absolute right-1",
|
||||
table: "w-full border-collapse space-y-1",
|
||||
head_row: "flex",
|
||||
head_cell:
|
||||
button_next: cn(
|
||||
buttonVariants({ variant: "outline" }),
|
||||
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute right-0 top-0 z-10",
|
||||
),
|
||||
month_grid: "w-full border-collapse space-y-1",
|
||||
weekdays: "flex",
|
||||
weekday:
|
||||
"text-neutral-500 rounded-md w-9 font-normal text-[0.8rem] dark:text-neutral-400",
|
||||
row: "flex w-full mt-2",
|
||||
cell: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-neutral-100/50 [&:has([aria-selected])]:bg-neutral-100 first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20 dark:[&:has([aria-selected].day-outside)]:bg-neutral-800/50 dark:[&:has([aria-selected])]:bg-neutral-800",
|
||||
day: cn("h-9 w-9 p-0 font-normal aria-selected:opacity-100"),
|
||||
day_range_end: "day-range-end rounded-r-md",
|
||||
day_range_start: "day-range-start rounded-l-md",
|
||||
day_selected:
|
||||
week: "flex w-full mt-2",
|
||||
day: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-neutral-100/50 [&:has([aria-selected])]:bg-neutral-100 first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20 dark:[&:has([aria-selected].day-outside)]:bg-neutral-800/50 dark:[&:has([aria-selected])]:bg-neutral-800",
|
||||
day_button: cn("h-9 w-9 p-0 font-normal aria-selected:opacity-100"),
|
||||
range_end: "day-range-end rounded-r-md",
|
||||
range_start: "day-range-start rounded-l-md",
|
||||
selected:
|
||||
"bg-neutral-900 text-neutral-50 hover:bg-neutral-900 hover:text-neutral-50 focus:bg-neutral-900 focus:text-neutral-50 dark:bg-neutral-50 dark:text-neutral-900 dark:hover:bg-neutral-50 dark:hover:text-neutral-900 dark:focus:bg-neutral-50 dark:focus:text-neutral-900",
|
||||
day_today: "text-neutral-900 dark:text-red-500",
|
||||
day_outside:
|
||||
today: "text-neutral-900 dark:text-red-500",
|
||||
outside:
|
||||
"day-outside text-neutral-500 opacity-50 aria-selected:bg-neutral-100/50 aria-selected:text-neutral-500 aria-selected:opacity-30 dark:text-neutral-400 dark:aria-selected:bg-neutral-800/50 dark:aria-selected:text-neutral-400",
|
||||
day_disabled: "text-neutral-500 opacity-50 dark:text-neutral-400",
|
||||
day_range_middle:
|
||||
disabled: "text-neutral-500 opacity-50 dark:text-neutral-400",
|
||||
range_middle:
|
||||
"aria-selected:bg-neutral-100 aria-selected:text-neutral-900 dark:aria-selected:bg-nb-gray-800 dark:aria-selected:text-neutral-50 rounded-none",
|
||||
day_hidden: "invisible",
|
||||
hidden: "invisible",
|
||||
...classNames,
|
||||
}}
|
||||
components={{
|
||||
IconLeft: () => <ChevronLeft className="h-4 w-4" />,
|
||||
IconRight: () => <ChevronRight className="h-4 w-4" />,
|
||||
Chevron: ({ orientation }) =>
|
||||
orientation === "left" ? (
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
) : (
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
),
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
@@ -2,18 +2,17 @@ import { cn } from "@utils/helpers";
|
||||
import LoadingIcon from "@/assets/icons/LoadingIcon";
|
||||
|
||||
type Props = {
|
||||
height?: "screen" | "auto";
|
||||
fullScreen?: boolean
|
||||
};
|
||||
export default function FullScreenLoading({ height = "screen" }: Props) {
|
||||
export default function FullScreenLoading({ fullScreen = true }: Props) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-center w-screen",
|
||||
height == "screen" && "h-screen",
|
||||
height == "auto" && "h-auto",
|
||||
fullScreen && "h-screen",
|
||||
)}
|
||||
>
|
||||
<LoadingIcon className={"fill-netbird"} size={44} />
|
||||
<LoadingIcon className="fill-netbird" size={44} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export default function GetStartedTest({
|
||||
{description}
|
||||
</Paragraph>
|
||||
</div>
|
||||
<div>{button}</div>
|
||||
{button && <div>{button}</div>}
|
||||
</div>
|
||||
</div>
|
||||
<Paragraph className={"text-sm justify-center pb-5 px-8"}>
|
||||
|
||||
145
src/components/ui/HelpAndSupportButton.tsx
Normal file
145
src/components/ui/HelpAndSupportButton.tsx
Normal file
@@ -0,0 +1,145 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuTrigger,
|
||||
} from "@components/DropdownMenu";
|
||||
import {
|
||||
ArrowUpRightIcon,
|
||||
BookText,
|
||||
CircleQuestionMark,
|
||||
MailIcon,
|
||||
MessageSquareShare,
|
||||
MessagesSquareIcon,
|
||||
TriangleAlert,
|
||||
} from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import Button from "@components/Button";
|
||||
import { cn } from "@utils/helpers";
|
||||
import SlackIcon from "@/assets/icons/SlackIcon";
|
||||
import { isNetBirdHosted } from "@utils/netbird";
|
||||
|
||||
export default function HelpAndSupportButton() {
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<DropdownMenu
|
||||
modal={false}
|
||||
open={dropdownOpen}
|
||||
onOpenChange={setDropdownOpen}
|
||||
>
|
||||
<DropdownMenuTrigger asChild={true}>
|
||||
<Button
|
||||
size={"xs"}
|
||||
variant={"default-outline"}
|
||||
className={cn(
|
||||
"!rounded-full h-[38px] w-[38px] !p-0",
|
||||
dropdownOpen && "text-white",
|
||||
)}
|
||||
>
|
||||
<CircleQuestionMark size={18} />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56" align="end" forceMount>
|
||||
<DropdownMenuLabel className="font-normal">
|
||||
<div className="flex flex-col space-y-1 px-1">
|
||||
<div className="text-sm font-normal leading-none text-nb-gray-200 py-1">
|
||||
Help and Support
|
||||
</div>
|
||||
</div>
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
href="https://docs.netbird.io/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
asChild
|
||||
>
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<BookText size={14} />
|
||||
Documentation
|
||||
</div>
|
||||
<DropdownMenuShortcut>
|
||||
<ArrowUpRightIcon size={16} />
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
href="https://docs.netbird.io/help/troubleshooting-client"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
asChild
|
||||
>
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<TriangleAlert size={14} />
|
||||
Troubleshooting
|
||||
</div>
|
||||
<DropdownMenuShortcut>
|
||||
<ArrowUpRightIcon size={16} />
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
|
||||
{isNetBirdHosted() && (
|
||||
<DropdownMenuItem href="mailto:support@netbird.io?subject=Support Request">
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<MailIcon size={14} />
|
||||
support@netbird.io
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuItem
|
||||
href="https://forum.netbird.io/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
asChild
|
||||
>
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<MessagesSquareIcon size={14} />
|
||||
NetBird Forum
|
||||
</div>
|
||||
<DropdownMenuShortcut>
|
||||
<ArrowUpRightIcon size={16} />
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
href="https://docs.netbird.io/slack-url"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
asChild
|
||||
>
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<SlackIcon size={14} />
|
||||
NetBird Slack
|
||||
</div>
|
||||
<DropdownMenuShortcut>
|
||||
<ArrowUpRightIcon size={16} />
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuItem
|
||||
href={"https://forms.gle/TeLw2zrXEdw6RcQ36"}
|
||||
target={"_blank"}
|
||||
rel="noopener noreferrer"
|
||||
asChild
|
||||
>
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<MessageSquareShare size={14} />
|
||||
Feedback
|
||||
</div>
|
||||
<DropdownMenuShortcut>
|
||||
<ArrowUpRightIcon size={16} />
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import * as React from "react";
|
||||
|
||||
type Props = {
|
||||
text?: string;
|
||||
};
|
||||
export const NewBadge = ({ text = "NEW" }: Props) => {
|
||||
return (
|
||||
<span
|
||||
className={
|
||||
"text-[7px] relative top-[.25px] leading-[0] bg-green-900 border border-green-500/20 py-1.5 px-1 rounded-[3px] text-green-400"
|
||||
}
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import { FilterX } from "lucide-react";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import React, { useCallback } from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
import SquareIcon from "@components/SquareIcon";
|
||||
|
||||
type Props = {
|
||||
icon?: React.ReactNode;
|
||||
@@ -14,7 +15,9 @@ type Props = {
|
||||
className?: string;
|
||||
hasFiltersApplied?: boolean;
|
||||
onResetFilters?: () => void;
|
||||
contentClassName?: string;
|
||||
};
|
||||
|
||||
export default function NoResults({
|
||||
icon,
|
||||
title = "Could not find any results",
|
||||
@@ -23,6 +26,7 @@ export default function NoResults({
|
||||
className,
|
||||
hasFiltersApplied = false,
|
||||
onResetFilters,
|
||||
contentClassName,
|
||||
}: Props) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
@@ -51,7 +55,7 @@ export default function NoResults({
|
||||
<div className={cn("relative overflow-hidden", className)}>
|
||||
<div
|
||||
className={
|
||||
"absolute z-20 bg-gradient-to-b dark:to-nb-gray-950 dark:from-nb-gray-950/70 w-full h-full overflow-hidden top-0"
|
||||
"absolute z-20 bg-gradient-to-b dark:to-nb-gray-950 dark:from-nb-gray-950/50 w-full h-full overflow-hidden top-0"
|
||||
}
|
||||
></div>
|
||||
<div
|
||||
@@ -63,16 +67,21 @@ export default function NoResults({
|
||||
<Skeleton className={"w-full"} height={70} duration={4} />
|
||||
<Skeleton className={"w-full"} height={70} duration={4} />
|
||||
<Skeleton className={"w-full"} height={70} duration={4} />
|
||||
<Skeleton className={"w-full"} height={70} duration={4} />
|
||||
<Skeleton className={"w-full"} height={70} duration={4} />
|
||||
</div>
|
||||
</div>
|
||||
<div className={cn("max-w-md mx-auto relative z-20 py-6")}>
|
||||
<div
|
||||
className={
|
||||
"mx-auto w-14 h-14 bg-nb-gray-930 flex items-center justify-center mb-3 rounded-md"
|
||||
}
|
||||
>
|
||||
{icon ? icon : <FilterX size={24} />}
|
||||
<div
|
||||
className={cn("max-w-md mx-auto relative z-20 py-6", contentClassName)}
|
||||
>
|
||||
<div className={"flex items-center justify-center mb-6"}>
|
||||
<SquareIcon
|
||||
icon={icon ? icon : <FilterX size={24} />}
|
||||
color={"gray"}
|
||||
size={"large"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={"text-center"}>
|
||||
<h1 className={"text-2xl font-medium max-w-lg mx-auto"}>{title}</h1>
|
||||
<Paragraph className={"justify-center my-2 !text-nb-gray-400"}>
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
import Badge, { BadgeVariants } from "@components/Badge";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { EyeIcon, MonitorSmartphoneIcon, SquarePen } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useGroups } from "@/contexts/GroupsProvider";
|
||||
import { Group } from "@/interfaces/Group";
|
||||
import { AssignPeerToGroupModal } from "@/modules/groups/AssignPeerToGroupModal";
|
||||
|
||||
type Props = {
|
||||
children?: React.ReactNode;
|
||||
group?: Group;
|
||||
useSave?: boolean;
|
||||
onAssignmentChange?: (group: Group) => void;
|
||||
} & React.HTMLAttributes<HTMLDivElement> &
|
||||
BadgeVariants;
|
||||
export default function PeerBadge({
|
||||
children,
|
||||
group,
|
||||
variant = "gray",
|
||||
className,
|
||||
useSave = true,
|
||||
onAssignmentChange,
|
||||
}: Props) {
|
||||
const [editGroupPeersModal, setEditGroupPeersModal] = useState(false);
|
||||
|
||||
const { dropdownOptions, addDropdownOptions } = useGroups();
|
||||
|
||||
const currentGroup = useMemo(() => {
|
||||
return dropdownOptions?.find((g) => g.name === group?.name);
|
||||
}, [group, dropdownOptions]);
|
||||
|
||||
const peerCount = useMemo(() => {
|
||||
let peerCount = currentGroup?.peers_count ?? 0;
|
||||
let countedPeers = currentGroup?.peers?.length ?? 0;
|
||||
if (peerCount !== countedPeers) {
|
||||
peerCount = countedPeers;
|
||||
}
|
||||
return peerCount;
|
||||
}, [currentGroup]);
|
||||
|
||||
const updateGroupOptions = (g: Group) => {
|
||||
addDropdownOptions([g]);
|
||||
onAssignmentChange && onAssignmentChange(g);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{currentGroup && editGroupPeersModal && (
|
||||
<AssignPeerToGroupModal
|
||||
useSave={useSave}
|
||||
group={currentGroup}
|
||||
onUpdate={(g) => updateGroupOptions(g)}
|
||||
open={editGroupPeersModal}
|
||||
setOpen={setEditGroupPeersModal}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Badge
|
||||
variant={variant}
|
||||
className={cn(className, "px-3 gap-2 whitespace-nowrap")}
|
||||
onClick={(e) => {
|
||||
if (!currentGroup) return;
|
||||
e.stopPropagation();
|
||||
setEditGroupPeersModal(true);
|
||||
}}
|
||||
useHover={!!currentGroup}
|
||||
>
|
||||
{!currentGroup && <MonitorSmartphoneIcon size={12} />}
|
||||
{currentGroup ? <>{peerCount} Peer(s)</> : children}
|
||||
|
||||
{currentGroup && (
|
||||
<>
|
||||
{currentGroup.name == "All" ? (
|
||||
<EyeIcon size={12} />
|
||||
) : (
|
||||
<SquarePen size={12} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Badge>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -19,11 +19,12 @@ export default function PeerCountBadge({
|
||||
className,
|
||||
}: Props) {
|
||||
const router = useRouter();
|
||||
const { dropdownOptions } = useGroups();
|
||||
const { dropdownOptions, groups } = useGroups();
|
||||
|
||||
const currentGroup = useMemo(() => {
|
||||
return dropdownOptions?.find((g) => g.name === group?.name);
|
||||
}, [group, dropdownOptions]);
|
||||
const options = dropdownOptions?.find((g) => g.name === group?.name);
|
||||
return options ?? groups?.find((g) => g.name === group?.name);
|
||||
}, [group, dropdownOptions, groups]);
|
||||
|
||||
const peerCount = useMemo(() => {
|
||||
let peerCount = currentGroup?.peers_count ?? 0;
|
||||
|
||||
@@ -10,6 +10,12 @@ const smallBadgeVariants = cva("", {
|
||||
white: "bg-white/20 border border-white/10 text-white",
|
||||
sky: "bg-sky-900 border border-sky-500/20 text-white",
|
||||
netbird: "bg-netbird-900 border border-netbird-400 text-netbird-300",
|
||||
yellow: "bg-yellow-900 border border-yellow-500/20 text-yellow-400",
|
||||
},
|
||||
size: {
|
||||
default:
|
||||
"text-[0.4rem] relative -top-[.25px] leading-[0] py-[0.39rem] px-1 rounded-[3px]",
|
||||
md: "text-[0.55rem] relative -top-[.25px] leading-[0] py-[0.45rem] px-1 rounded-[3px]",
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -27,15 +33,10 @@ export const SmallBadge = ({
|
||||
textClassName,
|
||||
variant = "green",
|
||||
children,
|
||||
size = "default",
|
||||
}: Props) => {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
smallBadgeVariants({ variant }),
|
||||
"text-[7px] relative -top-[.25px] leading-[0] py-[0.39rem] px-1 rounded-[3px]",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<span className={cn(smallBadgeVariants({ variant, size }), className)}>
|
||||
{children}
|
||||
<span className={cn("relative top-[0.4px]", textClassName)}>{text}</span>
|
||||
</span>
|
||||
|
||||
@@ -4,22 +4,38 @@ import React, { useMemo, useState } from "react";
|
||||
|
||||
type Props = {
|
||||
text?: string;
|
||||
children?: React.ReactNode;
|
||||
tooltipContent?: React.ReactNode;
|
||||
className?: string;
|
||||
maxChars?: number;
|
||||
maxWidth?: string; // Optional CSS width value
|
||||
hideTooltip?: boolean;
|
||||
align?: "start" | "center" | "end";
|
||||
alignOffset?: number;
|
||||
side?: "top" | "right" | "bottom" | "left";
|
||||
sideOffset?: number;
|
||||
};
|
||||
|
||||
export default function TruncatedText({
|
||||
text,
|
||||
children,
|
||||
tooltipContent,
|
||||
className,
|
||||
maxChars = 40,
|
||||
maxWidth,
|
||||
hideTooltip = false,
|
||||
align,
|
||||
alignOffset = 20,
|
||||
side,
|
||||
sideOffset = 4,
|
||||
}: Readonly<Props>) {
|
||||
const [isOverflowing, setIsOverflowing] = useState(false);
|
||||
const [open, setOpen] = useState(false);
|
||||
const contentRef = React.useRef<HTMLDivElement>(null);
|
||||
const measureRef = React.useRef<HTMLSpanElement>(null);
|
||||
|
||||
const hasCustomChildren = !!children;
|
||||
const content = children ?? text;
|
||||
|
||||
const charCount = useMemo(() => {
|
||||
if (!text) return 0;
|
||||
@@ -27,12 +43,17 @@ export default function TruncatedText({
|
||||
}, [text]);
|
||||
|
||||
// Check for overflow on mount and when text/maxWidth changes
|
||||
// When custom children are provided, use a hidden measurement element
|
||||
// to detect overflow independently of children's own truncation
|
||||
React.useEffect(() => {
|
||||
const element = contentRef.current;
|
||||
if (element) {
|
||||
setIsOverflowing(element.scrollWidth > element.clientWidth);
|
||||
const container = contentRef.current;
|
||||
const measure = measureRef.current;
|
||||
if (hasCustomChildren && container && measure) {
|
||||
setIsOverflowing(measure.scrollWidth > container.clientWidth);
|
||||
} else if (container) {
|
||||
setIsOverflowing(container.scrollWidth > container.clientWidth);
|
||||
}
|
||||
}, [text, maxWidth]);
|
||||
}, [text, children, maxWidth, hasCustomChildren]);
|
||||
|
||||
// If maxWidth is provided, use overflow detection
|
||||
// Otherwise, fall back to character count logic
|
||||
@@ -44,11 +65,28 @@ export default function TruncatedText({
|
||||
? { maxWidth }
|
||||
: { maxWidth: `${maxChars - 2}ch` };
|
||||
|
||||
const measureElement = hasCustomChildren && text && (
|
||||
<span
|
||||
ref={measureRef}
|
||||
className="absolute invisible whitespace-nowrap pointer-events-none h-0 overflow-hidden"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
|
||||
if (isDisabled) {
|
||||
return (
|
||||
<div className="w-full min-w-0 inline-block" style={containerStyle}>
|
||||
<div
|
||||
className={cn(
|
||||
"w-full min-w-0 inline-block",
|
||||
hasCustomChildren && "relative",
|
||||
)}
|
||||
style={containerStyle}
|
||||
>
|
||||
{measureElement}
|
||||
<div ref={contentRef} className={cn(className, "truncate")}>
|
||||
{text}
|
||||
{content}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -57,25 +95,36 @@ export default function TruncatedText({
|
||||
return (
|
||||
<Tooltip delayDuration={650} open={open} onOpenChange={setOpen}>
|
||||
<TooltipTrigger asChild={true}>
|
||||
<div className="w-full min-w-0 inline-block" style={containerStyle}>
|
||||
<div
|
||||
className={cn(
|
||||
"w-full min-w-0 inline-block",
|
||||
hasCustomChildren && "relative",
|
||||
)}
|
||||
style={containerStyle}
|
||||
>
|
||||
{measureElement}
|
||||
<div ref={contentRef} className={cn(className, "truncate")}>
|
||||
{text}
|
||||
{content}
|
||||
</div>
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent
|
||||
alignOffset={20}
|
||||
sideOffset={4}
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
className={cn(className, "px-3 py-1.5")}
|
||||
>
|
||||
<div className="text-neutral-300 flex flex-col gap-1">
|
||||
<div className="max-w-xs break-all whitespace-normal text-xs">
|
||||
{text}
|
||||
{tooltipContent ?? (
|
||||
<div className="text-neutral-300 flex flex-col gap-1">
|
||||
<div className="max-w-xs break-all whitespace-normal text-xs">
|
||||
{text}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cn, generateColorFromUser } from "@utils/helpers";
|
||||
import { Avatar } from "flowbite-react";
|
||||
import * as React from "react";
|
||||
import { useState } from "react";
|
||||
import Image from "next/image";
|
||||
import { useApplicationContext } from "@/contexts/ApplicationProvider";
|
||||
|
||||
type Props = {
|
||||
@@ -13,26 +13,27 @@ export const UserAvatar = ({ size = "default" }: Props) => {
|
||||
const [pictureLoaded, setPictureLoaded] = useState(true);
|
||||
|
||||
const getAvatarSize = () => {
|
||||
if (size === "small") return "sm";
|
||||
if (size === "large") return "lg";
|
||||
return "md";
|
||||
if (size === "small") return 32;
|
||||
if (size === "default") return 40;
|
||||
if (size === "large") return 48;
|
||||
return 35.2;
|
||||
};
|
||||
|
||||
return pictureLoaded ? (
|
||||
<Avatar
|
||||
alt=""
|
||||
img={user?.picture}
|
||||
rounded
|
||||
return pictureLoaded && user?.picture ? (
|
||||
<Image
|
||||
src={user?.picture}
|
||||
alt={""}
|
||||
onError={() => setPictureLoaded(false)}
|
||||
size={getAvatarSize()}
|
||||
className={"shrink-0"}
|
||||
width={getAvatarSize()}
|
||||
height={getAvatarSize()}
|
||||
className={"rounded-full"}
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-full flex items-center justify-center bg-nb-gray-900 text-netbird uppercase",
|
||||
size == "small" && "w-8 h-8",
|
||||
size == "medium" && "w-[2.3rem] h-[2.3rem]",
|
||||
size == "medium" && "w-[2.2rem] h-[2.2rem]",
|
||||
size == "default" && "w-10 h-10",
|
||||
size == "large" && "w-12 h-12",
|
||||
)}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from "@components/DropdownMenu";
|
||||
import TextWithTooltip from "@components/ui/TextWithTooltip";
|
||||
import { UserAvatar } from "@components/ui/UserAvatar";
|
||||
import { LogOutIcon, User2 } from "lucide-react";
|
||||
import { KeyRound, LogOutIcon, User2 } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useHotkeys } from "react-hotkeys-hook";
|
||||
@@ -19,9 +19,13 @@ import { useApplicationContext } from "@/contexts/ApplicationProvider";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { useLoggedInUser } from "@/contexts/UsersProvider";
|
||||
import useOSDetection from "@/hooks/useOperatingSystem";
|
||||
import { ChangePasswordModalContent } from "@/modules/users/ChangePasswordModal";
|
||||
import { isNetBirdHosted } from "@utils/netbird";
|
||||
import { Modal } from "@components/modal/Modal";
|
||||
|
||||
export default function UserDropdown() {
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
const [changePasswordModal, setChangePasswordModal] = useState(false);
|
||||
const { user } = useApplicationContext();
|
||||
const { loggedInUser, logout } = useLoggedInUser();
|
||||
const { isRestricted, permission } = usePermissions();
|
||||
@@ -31,17 +35,28 @@ export default function UserDropdown() {
|
||||
useHotkeys("shift+mod+l", () => logout(), []);
|
||||
|
||||
return (
|
||||
<DropdownMenu
|
||||
modal={false}
|
||||
open={dropdownOpen}
|
||||
onOpenChange={setDropdownOpen}
|
||||
>
|
||||
<>
|
||||
<Modal
|
||||
open={changePasswordModal}
|
||||
onOpenChange={setChangePasswordModal}
|
||||
key={changePasswordModal ? 1 : 0}
|
||||
>
|
||||
<ChangePasswordModalContent
|
||||
userId={loggedInUser?.id}
|
||||
onSuccess={() => setChangePasswordModal(false)}
|
||||
/>
|
||||
</Modal>
|
||||
<DropdownMenu
|
||||
modal={false}
|
||||
open={dropdownOpen}
|
||||
onOpenChange={setDropdownOpen}
|
||||
>
|
||||
<DropdownMenuTrigger>
|
||||
<UserAvatar size={"medium"} />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56" align="end" forceMount>
|
||||
<DropdownMenuLabel className="font-normal">
|
||||
<div className="flex flex-col space-y-1">
|
||||
<div className="flex flex-col space-y-0.5 px-1">
|
||||
<div className="text-sm font-medium leading-none dark:text-gray-300">
|
||||
<TextWithTooltip
|
||||
text={user?.name}
|
||||
@@ -72,6 +87,20 @@ export default function UserDropdown() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{!isNetBirdHosted() && loggedInUser?.idp_id === "local" && (
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setDropdownOpen(false);
|
||||
setChangePasswordModal(true);
|
||||
}}
|
||||
>
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<KeyRound size={14} />
|
||||
Change Password
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
|
||||
<DropdownMenuItem onClick={logout}>
|
||||
<div className={"flex gap-3 items-center"}>
|
||||
<LogOutIcon size={14} />
|
||||
@@ -81,6 +110,7 @@ export default function UserDropdown() {
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ export default function AnalyticsProvider({ children }: Readonly<Props>) {
|
||||
});
|
||||
}
|
||||
if (hjid && window._DATADOG_SYNTHETICS_BROWSER === undefined) {
|
||||
hotjar.initialize(hjid, 6);
|
||||
hotjar.initialize({ id: hjid, sv: 6 });
|
||||
}
|
||||
setInitialized(true);
|
||||
}, []);
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import { AnnouncementVariant } from "@components/ui/AnnouncementBanner";
|
||||
import { useLocalStorage } from "@hooks/useLocalStorage";
|
||||
import md5 from "crypto-js/md5";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { isLocalDev, isNetBirdHosted } from "@utils/netbird";
|
||||
import announcementFile from "../../announcements.json";
|
||||
|
||||
const initialAnnouncements: Announcement[] = [
|
||||
{
|
||||
tag: "New",
|
||||
text: "NetBird v0.60.0 - Identity-aware, private SSH over your NetBird network.",
|
||||
link: "https://docs.netbird.io/how-to/ssh",
|
||||
linkText: "Documentation",
|
||||
variant: "default", // "default" or "important"
|
||||
isExternal: true,
|
||||
closeable: true,
|
||||
isCloudOnly: false,
|
||||
},
|
||||
];
|
||||
const ANNOUNCEMENTS_URL =
|
||||
"https://raw.githubusercontent.com/netbirdio/dashboard/main/announcements.json";
|
||||
const STORAGE_KEY = "netbird-announcements";
|
||||
const CACHE_DURATION_MS = 30 * 60 * 1000;
|
||||
const BANNER_HEIGHT = 40;
|
||||
|
||||
interface AnnouncementStore {
|
||||
timestamp: number;
|
||||
announcements: Announcement[];
|
||||
closedAnnouncements: string[];
|
||||
}
|
||||
|
||||
export interface Announcement extends AnnouncementVariant {
|
||||
tag: string;
|
||||
@@ -36,7 +42,7 @@ type Props = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
const AnnouncementContext = React.createContext(
|
||||
const AnnouncementContext = createContext(
|
||||
{} as {
|
||||
bannerHeight: number;
|
||||
announcements?: AnnouncementInfo[];
|
||||
@@ -47,59 +53,101 @@ const AnnouncementContext = React.createContext(
|
||||
},
|
||||
);
|
||||
|
||||
const bannerHeight = 40;
|
||||
const getAnnouncements = async (): Promise<AnnouncementInfo[]> => {
|
||||
try {
|
||||
let stored: AnnouncementStore | null = null;
|
||||
try {
|
||||
const data = localStorage.getItem(STORAGE_KEY);
|
||||
stored = data ? JSON.parse(data) : null;
|
||||
} catch {}
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
let raw: Announcement[];
|
||||
|
||||
if (isLocalDev()) {
|
||||
raw = announcementFile as Announcement[];
|
||||
} else if (stored && now - stored.timestamp < CACHE_DURATION_MS) {
|
||||
raw = stored.announcements;
|
||||
} else {
|
||||
const response = await fetch(ANNOUNCEMENTS_URL);
|
||||
if (!response.ok) return [];
|
||||
|
||||
raw = await response.json();
|
||||
}
|
||||
|
||||
const isCloud = isNetBirdHosted();
|
||||
const filtered = raw.filter((a) => !a.isCloudOnly || isCloud);
|
||||
const hashes = new Set(filtered.map((a) => md5(a.text).toString()));
|
||||
const closed = (stored?.closedAnnouncements ?? []).filter((h) =>
|
||||
hashes.has(h),
|
||||
);
|
||||
|
||||
try {
|
||||
localStorage.setItem(
|
||||
STORAGE_KEY,
|
||||
JSON.stringify({
|
||||
timestamp: now,
|
||||
announcements: raw,
|
||||
closedAnnouncements: closed,
|
||||
}),
|
||||
);
|
||||
} catch {}
|
||||
|
||||
return filtered.map((a) => {
|
||||
const hash = md5(a.text).toString();
|
||||
return { ...a, hash, isOpen: !closed.includes(hash) };
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const saveAnnouncements = (closedAnnouncements: string[]) => {
|
||||
try {
|
||||
const data = localStorage.getItem(STORAGE_KEY);
|
||||
const stored: AnnouncementStore | null = data ? JSON.parse(data) : null;
|
||||
if (stored) {
|
||||
localStorage.setItem(
|
||||
STORAGE_KEY,
|
||||
JSON.stringify({ ...stored, closedAnnouncements }),
|
||||
);
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
|
||||
export default function AnnouncementProvider({ children }: Readonly<Props>) {
|
||||
const [height, setHeight] = useState(0);
|
||||
const [closedAnnouncements, setClosedAnnouncements] = useLocalStorage<
|
||||
string[]
|
||||
>("netbird-closed-announcements", []);
|
||||
const [announcements, setAnnouncements] = useState<AnnouncementInfo[]>();
|
||||
const { isRestricted } = usePermissions();
|
||||
const fetchingRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (announcements && announcements.length > 0) return;
|
||||
|
||||
if (isRestricted) return;
|
||||
const initial = initialAnnouncements.map((announcement) => {
|
||||
const hash = md5(announcement.text).toString();
|
||||
const isOpen = !closedAnnouncements.some((h) => h === hash);
|
||||
return {
|
||||
...announcement,
|
||||
hash,
|
||||
isOpen,
|
||||
} as AnnouncementInfo;
|
||||
});
|
||||
if (initial.length > 0) {
|
||||
setAnnouncements(initial);
|
||||
}
|
||||
}, [closedAnnouncements, announcements]);
|
||||
if (announcements !== undefined || isRestricted || fetchingRef.current)
|
||||
return;
|
||||
fetchingRef.current = true;
|
||||
getAnnouncements()
|
||||
.then((a) => setAnnouncements(a))
|
||||
.finally(() => (fetchingRef.current = false));
|
||||
}, [announcements, isRestricted]);
|
||||
|
||||
const closeAnnouncement = (hash: string) => {
|
||||
setClosedAnnouncements([...closedAnnouncements, hash]);
|
||||
setAnnouncements(() => {
|
||||
return announcements?.map((a) => {
|
||||
if (a.hash === hash) {
|
||||
return { ...a, isOpen: false };
|
||||
}
|
||||
return a;
|
||||
});
|
||||
});
|
||||
if (!announcements) return;
|
||||
const updated = announcements.map((a) =>
|
||||
a.hash === hash ? { ...a, isOpen: false } : a,
|
||||
);
|
||||
const closedAnnouncements = updated
|
||||
.filter((a) => !a.isOpen)
|
||||
.map((a) => a.hash);
|
||||
saveAnnouncements(closedAnnouncements);
|
||||
setAnnouncements(updated);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const isAnnouncementOpen = announcements?.some((a) => a.isOpen);
|
||||
if (isAnnouncementOpen) {
|
||||
setHeight(bannerHeight);
|
||||
} else {
|
||||
setHeight(0);
|
||||
}
|
||||
}, [announcements]);
|
||||
const bannerHeight = announcements?.some((a) => a.isOpen) ? BANNER_HEIGHT : 0;
|
||||
|
||||
return (
|
||||
<AnnouncementContext.Provider
|
||||
value={{
|
||||
bannerHeight: height,
|
||||
bannerHeight,
|
||||
announcements,
|
||||
closeAnnouncement,
|
||||
setAnnouncements,
|
||||
@@ -110,6 +158,4 @@ export default function AnnouncementProvider({ children }: Readonly<Props>) {
|
||||
);
|
||||
}
|
||||
|
||||
export const useAnnouncement = () => {
|
||||
return React.useContext(AnnouncementContext);
|
||||
};
|
||||
export const useAnnouncement = () => useContext(AnnouncementContext);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user