Skip to content

Commit 5caeab1

Browse files
authored
UX changes for modals and refactoring (#380)
1 parent 3f943bb commit 5caeab1

27 files changed

+455
-257
lines changed

next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const nextConfig = {
55
unoptimized: true,
66
},
77
reactStrictMode: false,
8+
env: {
9+
APP_ENV: process.env.APP_ENV || "production",
10+
},
811
};
912

1013
module.exports = nextConfig;

src/app/not-found.tsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
"use client";
22

33
import FullScreenLoading from "@components/ui/FullScreenLoading";
4-
import { useRouter } from "next/navigation";
5-
import { useEffect } from "react";
4+
import { useLocalStorage } from "@hooks/useLocalStorage";
5+
import { useRedirect } from "@hooks/useRedirect";
6+
import { useEffect, useState } from "react";
67

8+
type Props = {
9+
url: string;
10+
queryParams?: string;
11+
};
712
export default function NotFound() {
8-
const router = useRouter();
13+
const [mounted, setMounted] = useState(false);
14+
const [tempQueryParams, setTempQueryParams] = useLocalStorage(
15+
"netbird-query-params",
16+
"",
17+
);
18+
const [queryParams, setQueryParams] = useState("");
19+
920
useEffect(() => {
10-
router.push("/peers");
11-
});
21+
setQueryParams(tempQueryParams);
22+
setTempQueryParams("");
23+
setMounted(true);
24+
// eslint-disable-next-line react-hooks/exhaustive-deps
25+
}, []);
1226

13-
return <FullScreenLoading />;
27+
return mounted ? (
28+
<Redirect
29+
url={window?.location?.pathname || "/"}
30+
queryParams={queryParams}
31+
/>
32+
) : (
33+
<FullScreenLoading />
34+
);
1435
}
36+
37+
const Redirect = ({ url, queryParams }: Props) => {
38+
useRedirect(url == "/" ? "/peers" : url + (queryParams && `?${queryParams}`));
39+
return <FullScreenLoading />;
40+
};

src/assets/icons/CircleIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export default function CircleIcon({
1616
return (
1717
<span
1818
style={{ width: size + "px", height: size + "px" }}
19+
data-cy="circle-icon"
20+
data-cy-status={active ? "active" : "inactive"}
1921
className={cn(
2022
"rounded-full",
2123
active

src/components/ButtonGroup.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import React, { forwardRef } from "react";
55
type Props = {
66
children: React.ReactNode;
77
disabled?: boolean;
8+
className?: string;
89
};
910

10-
function ButtonGroup({ children, disabled }: Props) {
11+
function ButtonGroup({ children, disabled, className }: Props) {
1112
return (
1213
<div
1314
className={cn(
1415
"rounded-lg border-[1px] dark:border-nb-gray-900 border-neutral-200 overflow-hidden flex items-center justify-center shrink-0 border-separate",
1516
disabled ? "opacity-100 !border-nb-gray-900/20" : "",
17+
className,
1618
)}
1719
>
1820
{children}
@@ -21,7 +23,10 @@ function ButtonGroup({ children, disabled }: Props) {
2123
}
2224

2325
const ButtonGroupButton = forwardRef(
24-
({ ...props }: ButtonProps, ref: React.ForwardedRef<HTMLButtonElement>) => {
26+
(
27+
{ className, ...props }: ButtonProps,
28+
ref: React.ForwardedRef<HTMLButtonElement>,
29+
) => {
2530
return (
2631
<Button
2732
ref={ref}
@@ -31,6 +36,7 @@ const ButtonGroupButton = forwardRef(
3136
className={cn(
3237
"first:border-l-0 last:border-r-0 border-t-0 border-b-0 h-[41px]",
3338
"!py-2.5 !px-4",
39+
className,
3440
)}
3541
/>
3642
);

src/components/PeerGroupSelector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export function PeerGroupSelector({
198198
<CommandList className={"w-full"}>
199199
<div className={"relative"}>
200200
<CommandInput
201+
data-cy={"group-search-input"}
201202
className={cn(
202203
"min-h-[42px] w-full relative",
203204
"border-b-0 border-t-0 border-r-0 border-l-0 border-neutral-200 dark:border-nb-gray-700 items-center",

src/components/SegmentedTabs.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ function SegmentedTabs({ value, onChange, children }: Props) {
2121
);
2222
}
2323

24-
function List({ children }: { children: React.ReactNode }) {
24+
function List({
25+
children,
26+
className = "",
27+
}: {
28+
children: React.ReactNode;
29+
className?: string;
30+
}) {
2531
return (
2632
<TabsList
27-
className={
28-
"bg-nb-gray-930/70 p-1.5 rounded-t-lg flex justify-center gap-1 border border-b-0 border-nb-gray-900"
29-
}
33+
className={cn(
34+
"bg-nb-gray-930/70 p-1.5 rounded-t-lg flex justify-center gap-1 border border-b-0 border-nb-gray-900",
35+
className,
36+
)}
3037
>
3138
{children}
3239
</TabsList>

src/components/modal/Modal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ const ModalContent = React.forwardRef<
7575
<>
7676
{children}
7777
{showClose && (
78-
<DialogPrimitive.Close className="absolute right-4 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">
78+
<DialogPrimitive.Close
79+
data-cy={"modal-close"}
80+
className="absolute right-4 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"
81+
>
7982
<X className="h-4 w-4" />
8083
<span className="sr-only">Close</span>
8184
</DialogPrimitive.Close>

src/components/table/DataTableRowsPerPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export function DataTableRowsPerPage<TData>({
2828
role="combobox"
2929
aria-expanded={open}
3030
disabled={disabled}
31+
data-cy={"rows-per-page"}
3132
className="w-[200px] justify-between"
3233
>
33-
<RowsIcon size={15} className={"text-nb-gray-300"} />
34+
<RowsIcon size={15} className={"text-nb-gray-300 shrink-0"} />
3435
<div>
3536
<span className={"text-white"}>
3637
{table.getState().pagination.pageSize}
@@ -47,6 +48,7 @@ export function DataTableRowsPerPage<TData>({
4748
<CommandItem
4849
key={val}
4950
value={val.toString()}
51+
data-cy={`rows-per-page-value`}
5052
onSelect={(currentValue) => {
5153
table.setPageSize(Number(currentValue));
5254
setOpen(false);

src/contexts/DialogProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export default function DialogProvider({ children }: Props) {
9494
className={"w-full"}
9595
size={"sm"}
9696
tabIndex={-1}
97+
data-cy={"confirmation.cancel"}
9798
onClick={() => fn.current && fn.current(false)}
9899
>
99100
{dialogOptions.cancelText || "Cancel"}
@@ -109,6 +110,7 @@ export default function DialogProvider({ children }: Props) {
109110
}
110111
className={"w-full"}
111112
size={"sm"}
113+
data-cy={"confirmation.confirm"}
112114
onClick={() => fn.current && fn.current(true)}
113115
>
114116
{dialogOptions.confirmText || "Confirm"}

src/contexts/PeerProvider.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ export default function PeerProvider({ children, peer }: Props) {
7777
? loginExpiration
7878
: peer.login_expiration_enabled,
7979
approval_required:
80-
approval_required != undefined
81-
? approval_required
82-
: peer.approval_required,
80+
approval_required == undefined ? undefined : approval_required,
8381
},
8482
`/${peer.id}`,
8583
);

0 commit comments

Comments
 (0)