Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38e14a6c64 | ||
|
|
b79c6615b4 | ||
|
|
5d4e491611 | ||
|
|
9b1f920863 | ||
|
|
7c7f0a0f10 | ||
|
|
76541c701c | ||
|
|
d2046fee21 | ||
|
|
8e2cbe1d2a |
662
LICENSE
662
LICENSE
@@ -1,13 +1,661 @@
|
||||
BSD 3-Clause License
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (c) 2024 Wiretrustee UG (haftungsbeschränkt) & AUTHORS
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
Preamble
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
142
package-lock.json
generated
142
package-lock.json
generated
@@ -513,9 +513,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@next/env": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.28.tgz",
|
||||
"integrity": "sha512-PAmWhJfJQlP+kxZwCjrVd9QnR5x0R3u0mTXTiZDgSd4h5LdXmjxCCWbN9kq6hkZBOax8Rm3xDW5HagWyJuT37g==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.32.tgz",
|
||||
"integrity": "sha512-n9mQdigI6iZ/DF6pCTwMKeWgF2e8lg7qgt5M7HXMLtyhZYMnf/u905M18sSpPmHL9MKp9JHo56C6jrD2EvWxng==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@next/eslint-plugin-next": {
|
||||
@@ -529,9 +529,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/eslint-plugin-next/node_modules/brace-expansion": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
||||
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -578,9 +578,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-darwin-arm64": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.28.tgz",
|
||||
"integrity": "sha512-kzGChl9setxYWpk3H6fTZXXPFFjg7urptLq5o5ZgYezCrqlemKttwMT5iFyx/p1e/JeglTwDFRtb923gTJ3R1w==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.32.tgz",
|
||||
"integrity": "sha512-osHXveM70zC+ilfuFa/2W6a1XQxJTvEhzEycnjUaVE8kpUS09lDpiDDX2YLdyFCzoUbvbo5r0X1Kp4MllIOShw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -594,9 +594,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-darwin-x64": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.28.tgz",
|
||||
"integrity": "sha512-z6FXYHDJlFOzVEOiiJ/4NG8aLCeayZdcRSMjPDysW297Up6r22xw6Ea9AOwQqbNsth8JNgIK8EkWz2IDwaLQcw==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.32.tgz",
|
||||
"integrity": "sha512-P9NpCAJuOiaHHpqtrCNncjqtSBi1f6QUdHK/+dNabBIXB2RUFWL19TY1Hkhu74OvyNQEYEzzMJCMQk5agjw1Qg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -610,9 +610,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-arm64-gnu": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.28.tgz",
|
||||
"integrity": "sha512-9ARHLEQXhAilNJ7rgQX8xs9aH3yJSj888ssSjJLeldiZKR4D7N08MfMqljk77fAwZsWwsrp8ohHsMvurvv9liQ==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.32.tgz",
|
||||
"integrity": "sha512-v7JaO0oXXt6d+cFjrrKqYnR2ubrD+JYP7nQVRZgeo5uNE5hkCpWnHmXm9vy3g6foMO8SPwL0P3MPw1c+BjbAzA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -626,9 +626,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-arm64-musl": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.28.tgz",
|
||||
"integrity": "sha512-p6gvatI1nX41KCizEe6JkF0FS/cEEF0u23vKDpl+WhPe/fCTBeGkEBh7iW2cUM0rvquPVwPWdiUR6Ebr/kQWxQ==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.32.tgz",
|
||||
"integrity": "sha512-tA6sIKShXtSJBTH88i0DRd6I9n3ZTirmwpwAqH5zdJoQF7/wlJXR8DkPmKwYl5mFWhEKr5IIa3LfpMW9RRwKmQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -642,9 +642,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-x64-gnu": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.28.tgz",
|
||||
"integrity": "sha512-nsiSnz2wO6GwMAX2o0iucONlVL7dNgKUqt/mDTATGO2NY59EO/ZKnKEr80BJFhuA5UC1KZOMblJHWZoqIJddpA==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.32.tgz",
|
||||
"integrity": "sha512-7S1GY4TdnlGVIdeXXKQdDkfDysoIVFMD0lJuVVMeb3eoVjrknQ0JNN7wFlhCvea0hEk0Sd4D1hedVChDKfV2jw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -658,9 +658,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-x64-musl": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.28.tgz",
|
||||
"integrity": "sha512-+IuGQKoI3abrXFqx7GtlvNOpeExUH1mTIqCrh1LGFf8DnlUcTmOOCApEnPJUSLrSbzOdsF2ho2KhnQoO0I1RDw==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.32.tgz",
|
||||
"integrity": "sha512-OHHC81P4tirVa6Awk6eCQ6RBfWl8HpFsZtfEkMpJ5GjPsJ3nhPe6wKAJUZ/piC8sszUkAgv3fLflgzPStIwfWg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -674,9 +674,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-arm64-msvc": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.28.tgz",
|
||||
"integrity": "sha512-l61WZ3nevt4BAnGksUVFKy2uJP5DPz2E0Ma/Oklvo3sGj9sw3q7vBWONFRgz+ICiHpW5mV+mBrkB3XEubMrKaA==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.32.tgz",
|
||||
"integrity": "sha512-rORQjXsAFeX6TLYJrCG5yoIDj+NKq31Rqwn8Wpn/bkPNy5rTHvOXkW8mLFonItS7QC6M+1JIIcLe+vOCTOYpvg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -690,9 +690,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-ia32-msvc": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.28.tgz",
|
||||
"integrity": "sha512-+Kcp1T3jHZnJ9v9VTJ/yf1t/xmtFAc/Sge4v7mVc1z+NYfYzisi8kJ9AsY8itbgq+WgEwMtOpiLLJsUy2qnXZw==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.32.tgz",
|
||||
"integrity": "sha512-jHUeDPVHrgFltqoAqDB6g6OStNnFxnc7Aks3p0KE0FbwAvRg6qWKYF5mSTdCTxA3axoSAUwxYdILzXJfUwlHhA==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
@@ -706,9 +706,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-x64-msvc": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.28.tgz",
|
||||
"integrity": "sha512-1gCmpvyhz7DkB1srRItJTnmR2UwQPAUXXIg9r0/56g3O8etGmwlX68skKXJOp9EejW3hhv7nSQUJ2raFiz4MoA==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.32.tgz",
|
||||
"integrity": "sha512-2N0lSoU4GjfLSO50wvKpMQgKd4HdI2UHEhQPPPnlgfBJlOgJxkjpkYBqzk08f1gItBB6xF/n+ykso2hgxuydsA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -2809,9 +2809,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
||||
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -3396,9 +3396,10 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||
"version": "1.1.12",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
|
||||
"integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
@@ -4532,14 +4533,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/es-set-tostringtag": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.0.2.tgz",
|
||||
"integrity": "sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==",
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
||||
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.2.2",
|
||||
"has-tostringtag": "^1.0.0",
|
||||
"hasown": "^2.0.0"
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.6",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"hasown": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
@@ -5310,14 +5313,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
|
||||
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"es-set-tostringtag": "^2.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
@@ -5683,12 +5688,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/has-tostringtag": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz",
|
||||
"integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==",
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
||||
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"has-symbols": "^1.0.2"
|
||||
"has-symbols": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
@@ -6783,12 +6789,12 @@
|
||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw=="
|
||||
},
|
||||
"node_modules/next": {
|
||||
"version": "14.2.28",
|
||||
"resolved": "https://registry.npmjs.org/next/-/next-14.2.28.tgz",
|
||||
"integrity": "sha512-QLEIP/kYXynIxtcKB6vNjtWLVs3Y4Sb+EClTC/CSVzdLD1gIuItccpu/n1lhmduffI32iPGEK2cLLxxt28qgYA==",
|
||||
"version": "14.2.32",
|
||||
"resolved": "https://registry.npmjs.org/next/-/next-14.2.32.tgz",
|
||||
"integrity": "sha512-fg5g0GZ7/nFc09X8wLe6pNSU8cLWbLRG3TZzPJ1BJvi2s9m7eF991se67wliM9kR5yLHRkyGKU49MMx58s3LJg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@next/env": "14.2.28",
|
||||
"@next/env": "14.2.32",
|
||||
"@swc/helpers": "0.5.5",
|
||||
"busboy": "1.6.0",
|
||||
"caniuse-lite": "^1.0.30001579",
|
||||
@@ -6803,15 +6809,15 @@
|
||||
"node": ">=18.17.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@next/swc-darwin-arm64": "14.2.28",
|
||||
"@next/swc-darwin-x64": "14.2.28",
|
||||
"@next/swc-linux-arm64-gnu": "14.2.28",
|
||||
"@next/swc-linux-arm64-musl": "14.2.28",
|
||||
"@next/swc-linux-x64-gnu": "14.2.28",
|
||||
"@next/swc-linux-x64-musl": "14.2.28",
|
||||
"@next/swc-win32-arm64-msvc": "14.2.28",
|
||||
"@next/swc-win32-ia32-msvc": "14.2.28",
|
||||
"@next/swc-win32-x64-msvc": "14.2.28"
|
||||
"@next/swc-darwin-arm64": "14.2.32",
|
||||
"@next/swc-darwin-x64": "14.2.32",
|
||||
"@next/swc-linux-arm64-gnu": "14.2.32",
|
||||
"@next/swc-linux-arm64-musl": "14.2.32",
|
||||
"@next/swc-linux-x64-gnu": "14.2.32",
|
||||
"@next/swc-linux-x64-musl": "14.2.32",
|
||||
"@next/swc-win32-arm64-msvc": "14.2.32",
|
||||
"@next/swc-win32-ia32-msvc": "14.2.32",
|
||||
"@next/swc-win32-x64-msvc": "14.2.32"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.1.0",
|
||||
@@ -8565,9 +8571,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tmp": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz",
|
||||
"integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==",
|
||||
"version": "0.2.5",
|
||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.5.tgz",
|
||||
"integrity": "sha512-voyz6MApa1rQGUxT3E+BK7/ROe8itEx7vD8/HEvt4xwXucvQ5G5oeEiHkmHZJuBO21RpOf+YYm9MOivj709jow==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import Breadcrumbs from "@components/Breadcrumbs";
|
||||
import Button from "@components/Button";
|
||||
import { Callout } from "@components/Callout";
|
||||
import Card from "@components/Card";
|
||||
import FancyToggleSwitch from "@components/FancyToggleSwitch";
|
||||
import FullTooltip from "@components/FullTooltip";
|
||||
@@ -219,7 +220,7 @@ const PeerGeneralInformation = () => {
|
||||
<ModalTrigger>
|
||||
<div
|
||||
className={
|
||||
"flex items-center gap-2 dark:text-neutral-300 text-neutral-500 hover:text-neutral-100 transition-all hover:bg-nb-gray-800/60 py-2 px-3 rounded-md cursor-pointer"
|
||||
"flex h-8 w-8 items-center justify-center gap-2 dark:text-neutral-300 text-neutral-500 hover:text-neutral-100 transition-all hover:bg-nb-gray-800/60 rounded-md cursor-pointer"
|
||||
}
|
||||
>
|
||||
<PencilIcon size={16} />
|
||||
@@ -324,7 +325,7 @@ const PeerGeneralInformation = () => {
|
||||
}
|
||||
interactive={false}
|
||||
className={"w-full block"}
|
||||
disabled={!permission.peers.update}
|
||||
disabled={permission.peers.update}
|
||||
>
|
||||
<FancyToggleSwitch
|
||||
value={ssh}
|
||||
@@ -415,158 +416,200 @@ const PeerOverviewTabs = () => {
|
||||
|
||||
function PeerInformationCard({ peer }: Readonly<{ peer: Peer }>) {
|
||||
const { isLoading, getRegionByPeer } = useCountries();
|
||||
const { update } = usePeer();
|
||||
const { mutate } = useSWRConfig();
|
||||
const [showEditIPModal, setShowEditIPModal] = useState(false);
|
||||
const { permission } = usePermissions();
|
||||
|
||||
const countryText = useMemo(() => {
|
||||
return getRegionByPeer(peer);
|
||||
}, [getRegionByPeer, peer]);
|
||||
|
||||
return (
|
||||
<Card className={"w-full xl:w-1/2"}>
|
||||
<Card.List>
|
||||
<Card.ListItem
|
||||
copy
|
||||
copyText={"NetBird IP-Address"}
|
||||
label={
|
||||
<>
|
||||
<MapPin size={16} />
|
||||
NetBird IP-Address
|
||||
</>
|
||||
}
|
||||
value={peer.ip}
|
||||
<>
|
||||
<Modal open={showEditIPModal} onOpenChange={setShowEditIPModal}>
|
||||
<EditIPModal
|
||||
onSuccess={(newIP) => {
|
||||
notify({
|
||||
title: peer.name,
|
||||
description: "Peer IP was successfully updated",
|
||||
promise: update({ ip: newIP }).then(() => {
|
||||
mutate("/peers/" + peer.id);
|
||||
setShowEditIPModal(false);
|
||||
}),
|
||||
loadingMessage: "Updating peer IP...",
|
||||
});
|
||||
}}
|
||||
peer={peer}
|
||||
key={showEditIPModal ? 1 : 0}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
copy
|
||||
copyText={"Public IP-Address"}
|
||||
label={
|
||||
<>
|
||||
<NetworkIcon size={16} />
|
||||
Public IP-Address
|
||||
</>
|
||||
}
|
||||
value={peer.connection_ip}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
copy
|
||||
copyText={"DNS label"}
|
||||
label={
|
||||
<>
|
||||
<Globe size={16} />
|
||||
Domain Name
|
||||
</>
|
||||
}
|
||||
className={
|
||||
peer?.extra_dns_labels && peer.extra_dns_labels.length > 0
|
||||
? "items-start"
|
||||
: ""
|
||||
}
|
||||
value={peer.dns_label}
|
||||
extraText={peer?.extra_dns_labels}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
copy
|
||||
copyText={"Hostname"}
|
||||
label={
|
||||
<>
|
||||
<MonitorSmartphoneIcon size={16} />
|
||||
Hostname
|
||||
</>
|
||||
}
|
||||
value={peer.hostname}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<FlagIcon size={16} />
|
||||
Region
|
||||
</>
|
||||
}
|
||||
tooltip={false}
|
||||
value={
|
||||
isEmpty(peer.country_code) ? (
|
||||
"Unknown"
|
||||
) : (
|
||||
</Modal>
|
||||
<Card className={"w-full xl:w-1/2"}>
|
||||
<Card.List>
|
||||
<Card.ListItem
|
||||
copy
|
||||
tooltip={false}
|
||||
copyText={"NetBird IP Address"}
|
||||
label={
|
||||
<>
|
||||
{isLoading ? (
|
||||
<Skeleton width={140} />
|
||||
) : (
|
||||
<div className={"flex gap-2 items-center"}>
|
||||
<div className={"border-0 border-nb-gray-800 rounded-full"}>
|
||||
<RoundedFlag country={peer.country_code} size={12} />
|
||||
</div>
|
||||
{countryText}
|
||||
</div>
|
||||
)}
|
||||
<MapPin size={16} />
|
||||
NetBird IP Address
|
||||
</>
|
||||
)
|
||||
}
|
||||
/>
|
||||
}
|
||||
valueToCopy={peer.ip}
|
||||
value={
|
||||
<div className="flex items-center gap-2 justify-between w-full">
|
||||
<span>{peer.ip}</span>
|
||||
{permission.peers.update && (
|
||||
<button
|
||||
className="flex w-7 h-7 items-center justify-center gap-2 text-nb-gray-400 hover:text-neutral-100 transition-all hover:bg-nb-gray-800/60 rounded-md cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowEditIPModal(true);
|
||||
}}
|
||||
>
|
||||
<PencilIcon size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<Cpu size={16} />
|
||||
Operating System
|
||||
</>
|
||||
}
|
||||
value={peer.os}
|
||||
/>
|
||||
<Card.ListItem
|
||||
copy
|
||||
copyText={"Public IP Address"}
|
||||
label={
|
||||
<>
|
||||
<NetworkIcon size={16} />
|
||||
Public IP Address
|
||||
</>
|
||||
}
|
||||
value={peer.connection_ip}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
copy
|
||||
copyText={"DNS label"}
|
||||
label={
|
||||
<>
|
||||
<Globe size={16} />
|
||||
Domain Name
|
||||
</>
|
||||
}
|
||||
className={
|
||||
peer?.extra_dns_labels && peer.extra_dns_labels.length > 0
|
||||
? "items-start"
|
||||
: ""
|
||||
}
|
||||
value={peer.dns_label}
|
||||
extraText={peer?.extra_dns_labels}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
copy
|
||||
copyText={"Hostname"}
|
||||
label={
|
||||
<>
|
||||
<MonitorSmartphoneIcon size={16} />
|
||||
Hostname
|
||||
</>
|
||||
}
|
||||
value={peer.hostname}
|
||||
/>
|
||||
|
||||
{peer.serial_number && peer.serial_number !== "" && (
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<Barcode size={16} />
|
||||
Serial Number
|
||||
<FlagIcon size={16} />
|
||||
Region
|
||||
</>
|
||||
}
|
||||
value={peer.serial_number}
|
||||
tooltip={false}
|
||||
value={
|
||||
isEmpty(peer.country_code) ? (
|
||||
"Unknown"
|
||||
) : (
|
||||
<>
|
||||
{isLoading ? (
|
||||
<Skeleton width={140} />
|
||||
) : (
|
||||
<div className={"flex gap-2 items-center"}>
|
||||
<div
|
||||
className={"border-0 border-nb-gray-800 rounded-full"}
|
||||
>
|
||||
<RoundedFlag country={peer.country_code} size={12} />
|
||||
</div>
|
||||
{countryText}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<History size={16} />
|
||||
Last seen
|
||||
</>
|
||||
}
|
||||
value={
|
||||
peer.connected
|
||||
? "just now"
|
||||
: dayjs(peer.last_seen).format("D MMMM, YYYY [at] h:mm A") +
|
||||
" (" +
|
||||
dayjs().to(peer.last_seen) +
|
||||
")"
|
||||
}
|
||||
/>
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<Cpu size={16} />
|
||||
Operating System
|
||||
</>
|
||||
}
|
||||
value={peer.os}
|
||||
/>
|
||||
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<NetBirdIcon size={16} />
|
||||
Agent Version
|
||||
</>
|
||||
}
|
||||
value={peer.version}
|
||||
/>
|
||||
{peer.serial_number && peer.serial_number !== "" && (
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<Barcode size={16} />
|
||||
Serial Number
|
||||
</>
|
||||
}
|
||||
value={peer.serial_number}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<History size={16} />
|
||||
Last seen
|
||||
</>
|
||||
}
|
||||
value={
|
||||
peer.connected
|
||||
? "just now"
|
||||
: dayjs(peer.last_seen).format("D MMMM, YYYY [at] h:mm A") +
|
||||
" (" +
|
||||
dayjs().to(peer.last_seen) +
|
||||
")"
|
||||
}
|
||||
/>
|
||||
|
||||
{peer.ui_version && (
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<NetBirdIcon size={16} />
|
||||
UI Version
|
||||
Agent Version
|
||||
</>
|
||||
}
|
||||
value={peer.ui_version?.replace("netbird-desktop-ui/", "")}
|
||||
value={peer.version}
|
||||
/>
|
||||
)}
|
||||
</Card.List>
|
||||
</Card>
|
||||
|
||||
{peer.ui_version && (
|
||||
<Card.ListItem
|
||||
label={
|
||||
<>
|
||||
<NetBirdIcon size={16} />
|
||||
UI Version
|
||||
</>
|
||||
}
|
||||
value={peer.ui_version?.replace("netbird-desktop-ui/", "")}
|
||||
/>
|
||||
)}
|
||||
</Card.List>
|
||||
</Card>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -654,3 +697,83 @@ function EditNameModal({ onSuccess, peer, initialName }: Readonly<ModalProps>) {
|
||||
</ModalContent>
|
||||
);
|
||||
}
|
||||
|
||||
interface EditIPModalProps {
|
||||
onSuccess: (ip: string) => void;
|
||||
peer: Peer;
|
||||
}
|
||||
|
||||
function EditIPModal({ onSuccess, peer }: Readonly<EditIPModalProps>) {
|
||||
const [ip, setIP] = useState(peer.ip);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
const validateIP = (ipAddress: string) => {
|
||||
const ipRegex =
|
||||
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
return ipRegex.test(ipAddress);
|
||||
};
|
||||
|
||||
const isDisabled = useMemo(() => {
|
||||
if (ip === peer.ip) return true;
|
||||
const trimmedIP = trim(ip);
|
||||
return trimmedIP.length === 0 || !validateIP(ip);
|
||||
}, [ip, peer.ip]);
|
||||
|
||||
React.useEffect(() => {
|
||||
switch (true) {
|
||||
case ip === peer.ip:
|
||||
setError("");
|
||||
break;
|
||||
case !validateIP(ip):
|
||||
setError("Please enter a valid IP, e.g., 100.64.0.15");
|
||||
break;
|
||||
default:
|
||||
setError("");
|
||||
break;
|
||||
}
|
||||
}, [ip, peer.ip]);
|
||||
|
||||
return (
|
||||
<ModalContent maxWidthClass={"max-w-md"}>
|
||||
<form>
|
||||
<ModalHeader
|
||||
title={"Edit Peer IP Address"}
|
||||
description={"Update the NetBird IP address for this peer."}
|
||||
color={"blue"}
|
||||
/>
|
||||
|
||||
<div className={"p-default flex flex-col gap-4"}>
|
||||
<div>
|
||||
<Input
|
||||
placeholder={"e.g., 100.64.0.15"}
|
||||
value={ip}
|
||||
onChange={(e) => setIP(e.target.value)}
|
||||
error={error}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Callout>Changes take effect when the peer reconnects.</Callout>
|
||||
</div>
|
||||
|
||||
<ModalFooter className={"items-center"} separator={false}>
|
||||
<div className={"flex gap-3 w-full justify-end"}>
|
||||
<ModalClose asChild={true}>
|
||||
<Button variant={"secondary"} className={"w-full"}>
|
||||
Cancel
|
||||
</Button>
|
||||
</ModalClose>
|
||||
|
||||
<Button
|
||||
variant={"primary"}
|
||||
className={"w-full"}
|
||||
onClick={() => onSuccess(ip)}
|
||||
disabled={isDisabled}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</ModalFooter>
|
||||
</form>
|
||||
</ModalContent>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 stepper-bg-variant"
|
||||
"rounded-md border border-nb-gray-900/70 grid w-full bg-nb-gray-930/40"
|
||||
}
|
||||
>
|
||||
<SetupModalContent header={false} footer={false} />
|
||||
|
||||
@@ -289,6 +289,7 @@ function UserInformationCard({ user }: Readonly<{ user: User }>) {
|
||||
const neverLoggedIn = dayjs(user.last_login).isBefore(
|
||||
dayjs().subtract(1000, "years"),
|
||||
);
|
||||
const isPendingApproval = user?.pending_approval;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
@@ -328,18 +329,20 @@ function UserInformationCard({ user }: Readonly<{ user: User }>) {
|
||||
|
||||
{!isServiceUser && (
|
||||
<>
|
||||
{!user.is_current && user.role != Role.Owner && (
|
||||
<Card.ListItem
|
||||
tooltip={false}
|
||||
label={
|
||||
<>
|
||||
<Ban size={16} />
|
||||
Block User
|
||||
</>
|
||||
}
|
||||
value={<UserBlockCell user={user} isUserPage={true} />}
|
||||
/>
|
||||
)}
|
||||
{!user.is_current &&
|
||||
user.role != Role.Owner &&
|
||||
!isPendingApproval && (
|
||||
<Card.ListItem
|
||||
tooltip={false}
|
||||
label={
|
||||
<>
|
||||
<Ban size={16} />
|
||||
Block User
|
||||
</>
|
||||
}
|
||||
value={<UserBlockCell user={user} isUserPage={true} />}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Card.ListItem
|
||||
label={
|
||||
|
||||
115
src/app/error/page.tsx
Normal file
115
src/app/error/page.tsx
Normal file
@@ -0,0 +1,115 @@
|
||||
"use client";
|
||||
|
||||
import { useOidc } from "@axa-fr/react-oidc";
|
||||
import Button from "@components/Button";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import loadConfig from "@utils/config";
|
||||
import { ArrowRightIcon, RefreshCw } from "lucide-react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import NetBirdIcon from "@/assets/icons/NetBirdIcon";
|
||||
|
||||
const config = loadConfig();
|
||||
|
||||
export default function ErrorPage() {
|
||||
const { logout, isAuthenticated } = useOidc();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const [error, setError] = useState<{
|
||||
code: number;
|
||||
message: string;
|
||||
type: string;
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Get error details from URL params
|
||||
const code = searchParams.get("code");
|
||||
const message = searchParams.get("message");
|
||||
const type = searchParams.get("type");
|
||||
|
||||
if (code && message) {
|
||||
setError({
|
||||
code: parseInt(code),
|
||||
message: decodeURIComponent(message),
|
||||
type: type || "error",
|
||||
});
|
||||
}
|
||||
}, [searchParams]);
|
||||
|
||||
const handleLogout = () => {
|
||||
// Use the same logout pattern as OIDCError
|
||||
logout("/", { client_id: config.clientId });
|
||||
};
|
||||
|
||||
const handleRetry = () => {
|
||||
router.push("/");
|
||||
};
|
||||
|
||||
if (!isAuthenticated) {
|
||||
// If not authenticated, redirect to home
|
||||
router.push("/");
|
||||
return null;
|
||||
}
|
||||
|
||||
const isBlockedUser =
|
||||
error?.code === 403 && error?.message?.toLowerCase().includes("blocked");
|
||||
const isPendingApproval =
|
||||
error?.code === 403 &&
|
||||
error?.message?.toLowerCase().includes("pending approval");
|
||||
|
||||
const getTitle = () => {
|
||||
if (isBlockedUser) return "User Account Blocked";
|
||||
if (isPendingApproval) return "User Approval Pending";
|
||||
return "Access Error";
|
||||
};
|
||||
|
||||
const getDescription = () => {
|
||||
if (isBlockedUser) {
|
||||
return "Your access has been blocked by the NetBird account administrator, possibly due to new user approval requirements or security policies. Please contact your administrator to regain access.";
|
||||
}
|
||||
if (isPendingApproval) {
|
||||
return "Your account is pending approval from an administrator. Please wait for approval before accessing the dashboard.";
|
||||
}
|
||||
return "An error occurred while trying to access the dashboard. Please try again or contact your administrator.";
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center flex-col h-screen max-w-xl mx-auto">
|
||||
<div className="bg-nb-gray-930 mb-3 border border-nb-gray-900 h-12 w-12 rounded-md flex items-center justify-center">
|
||||
<NetBirdIcon size={23} />
|
||||
</div>
|
||||
|
||||
<h1 className="text-center mt-2">{getTitle()}</h1>
|
||||
|
||||
<Paragraph className="text-center mt-2 block">
|
||||
{getDescription()}
|
||||
</Paragraph>
|
||||
|
||||
{error && (
|
||||
<div className="bg-nb-gray-930 border border-nb-gray-800 rounded-md p-4 mt-4 max-w-md font-mono mb-2">
|
||||
<div className="text-center text-sm text-netbird">
|
||||
<div>response_message: {error.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Paragraph className="text-center mt-2 text-sm">
|
||||
If you believe this is an error, please contact your administrator.
|
||||
</Paragraph>
|
||||
|
||||
<div className="mt-5 space-y-3">
|
||||
{!isBlockedUser && !isPendingApproval && (
|
||||
<Button variant="default-outline" size="sm" onClick={handleRetry}>
|
||||
<RefreshCw size={16} className="mr-2" />
|
||||
Try Again
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button variant="primary" size="sm" onClick={handleLogout}>
|
||||
{isBlockedUser || isPendingApproval ? "Sign Out" : "Logout"}
|
||||
<ArrowRightIcon size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ p {
|
||||
}
|
||||
|
||||
.stepper-bg-variant .step-circle {
|
||||
@apply !border-[#1d2024];
|
||||
@apply !border-nb-gray-940;
|
||||
}
|
||||
|
||||
.webkit-scroll{
|
||||
@@ -117,4 +117,43 @@ p {
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.animate-slow-ping {
|
||||
animation: ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite
|
||||
}
|
||||
|
||||
@keyframes ping {
|
||||
75%, 100% {
|
||||
transform: scale(2);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.animate-slow-pulse {
|
||||
animation: pulse 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite
|
||||
}
|
||||
|
||||
|
||||
@keyframes pulse {
|
||||
60% {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes bg-scroll {
|
||||
0% {
|
||||
background-position: 0% 100%;
|
||||
}
|
||||
100% {
|
||||
background-position: 0% 0%;
|
||||
}
|
||||
}
|
||||
|
||||
.animate-bg-scroll {
|
||||
animation: bg-scroll 4s linear infinite;
|
||||
}
|
||||
.animate-bg-scroll-faster {
|
||||
animation: bg-scroll 1.8s linear infinite;
|
||||
}
|
||||
|
||||
12
src/assets/nameservers/dns0-zero.svg
Normal file
12
src/assets/nameservers/dns0-zero.svg
Normal file
@@ -0,0 +1,12 @@
|
||||
<svg width="573" height="148" viewBox="0 0 573 148" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_4_4)">
|
||||
<path d="M0.739014 125.602V33.09H28.239C34.491 33.09 39.919 34.274 44.524 36.638C49.128 39.004 52.698 42.341 55.233 46.65C57.767 50.958 59.034 56.071 59.034 61.984V96.58C59.034 102.41 57.767 107.5 55.233 111.85C52.698 116.203 49.128 119.581 44.523 121.99C39.918 124.397 34.491 125.601 28.239 125.601L0.739014 125.602ZM16.58 111.028H28.24C32.801 111.028 36.433 109.741 39.138 107.163C41.841 104.587 43.193 101.06 43.193 96.581V61.984C43.193 57.592 41.841 54.107 39.138 51.529C36.433 48.952 32.801 47.663 28.239 47.663H16.58V111.028ZM76.396 125.602V33.09H95.786L121.512 107.86C121.216 104.673 120.942 101.483 120.688 98.292C120.386 94.5366 120.154 90.776 119.991 87.012C119.821 83.169 119.738 79.812 119.738 76.938V33.09H134.185V125.602H114.795L89.323 50.832C89.491 53.283 89.703 56.239 89.956 59.702C90.2137 63.2478 90.4251 66.7967 90.59 70.348C90.758 73.982 90.844 77.318 90.844 80.36V125.602H76.396ZM181.582 126.869C175.245 126.869 169.752 125.812 165.107 123.701C160.46 121.591 156.889 118.569 154.398 114.64C151.905 110.711 150.616 106.086 150.533 100.763H166.374C166.374 104.565 167.747 107.543 170.494 109.698C173.238 111.852 176.976 112.929 181.709 112.929C186.271 112.929 189.839 111.874 192.417 109.761C194.993 107.65 196.282 104.735 196.282 101.017C196.282 97.892 195.374 95.167 193.558 92.842C191.74 90.52 189.142 88.936 185.764 88.09L175.119 85.175C167.852 83.318 162.256 79.979 158.327 75.164C154.398 70.348 152.434 64.518 152.434 57.675C152.434 52.438 153.616 47.875 155.982 43.988C158.347 40.103 161.705 37.103 166.058 34.99C170.408 32.88 175.54 31.822 181.455 31.822C190.409 31.822 197.506 34.125 202.745 38.729C207.983 43.335 210.645 49.523 210.73 57.295H194.888C194.888 53.663 193.704 50.812 191.34 48.741C188.974 46.671 185.637 45.636 181.328 45.636C177.188 45.636 173.978 46.608 171.697 48.551C169.416 50.495 168.275 53.24 168.275 56.788C168.275 60 169.141 62.724 170.873 64.962C172.603 67.202 175.119 68.786 178.413 69.714L189.439 72.756C196.789 74.616 202.407 77.932 206.294 82.704C210.179 87.478 212.124 93.371 212.124 100.383C212.124 105.623 210.856 110.248 208.322 114.26C205.787 118.273 202.239 121.378 197.677 123.574C193.114 125.77 187.748 126.869 181.582 126.869ZM257.366 126.869C251.366 126.869 246.17 125.729 241.778 123.448C237.384 121.167 233.985 117.957 231.577 113.816C229.169 109.678 227.965 104.818 227.965 99.242V59.45C227.965 53.874 229.169 49.017 231.577 44.876C233.984 40.738 237.384 37.526 241.778 35.245C246.17 32.964 251.366 31.823 257.366 31.823C263.449 31.823 268.665 32.963 273.017 35.245C277.367 37.526 280.747 40.738 283.156 44.876C285.563 49.016 286.767 53.874 286.767 59.45V99.243C286.767 104.819 285.563 109.679 283.156 113.817C280.748 117.957 277.346 121.167 272.954 123.449C268.56 125.729 263.364 126.869 257.366 126.869ZM257.366 113.183C261.758 113.183 265.265 111.915 267.885 109.381C270.502 106.846 271.813 103.468 271.813 99.242V59.45C271.813 55.227 270.503 51.846 267.885 49.312C265.265 46.777 261.758 45.51 257.366 45.51C252.972 45.51 249.466 46.777 246.848 49.312C244.228 51.846 242.918 55.227 242.918 59.45V99.243C242.918 103.469 244.228 106.847 246.848 109.382C249.465 111.916 252.972 113.183 257.366 113.183ZM257.366 87.583C254.915 87.583 252.909 86.781 251.346 85.175C249.782 83.571 249.002 81.5 249.002 78.965C249.002 76.431 249.762 74.403 251.283 72.883C252.803 71.362 254.831 70.601 257.366 70.601C259.901 70.601 261.928 71.361 263.449 72.883C264.969 74.403 265.73 76.431 265.73 78.966C265.73 81.5 264.97 83.571 263.45 85.176C261.928 86.781 259.9 87.583 257.366 87.583Z" fill="black"/>
|
||||
<path d="M332.69 126.999C329.057 126.999 326.164 125.941 324.01 123.831C321.855 121.72 320.778 118.847 320.778 115.213C320.778 111.581 321.855 108.686 324.01 106.532C326.164 104.378 329.057 103.3 332.69 103.3C336.322 103.3 339.217 104.378 341.372 106.532C343.526 108.686 344.603 111.582 344.603 115.213C344.603 118.847 343.526 121.72 341.372 123.831C339.217 125.941 336.322 126.999 332.691 126.999H332.69ZM381.862 125.732V33.219H437.369V47.032H397.449V71.112H432.934V84.798H397.45V111.918H437.37V125.732H381.862ZM484.766 126.999C475.725 126.999 468.65 124.528 463.539 119.585C458.426 114.643 455.872 107.906 455.872 99.372V33.219H471.84V99.245C471.84 103.639 472.937 107.061 475.135 109.51C477.331 111.962 480.54 113.185 484.766 113.185C488.905 113.185 492.095 111.962 494.334 109.51C496.572 107.06 497.693 103.639 497.693 99.245V33.219H513.66V99.372C513.66 107.906 511.126 114.642 506.057 119.585C500.987 124.528 493.891 126.999 484.767 126.999H484.766Z" fill="#686868"/>
|
||||
<path d="M549 0H573V148H549V0Z" fill="#FFCC03"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_4_4">
|
||||
<rect width="573" height="148" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.7 KiB |
12
src/assets/nameservers/dns0.svg
Normal file
12
src/assets/nameservers/dns0.svg
Normal file
@@ -0,0 +1,12 @@
|
||||
<svg width="573" height="148" viewBox="0 0 573 148" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_4_4)">
|
||||
<path d="M0.739014 125.602V33.09H28.239C34.491 33.09 39.919 34.274 44.524 36.638C49.128 39.004 52.698 42.341 55.233 46.65C57.767 50.958 59.034 56.071 59.034 61.984V96.58C59.034 102.41 57.767 107.5 55.233 111.85C52.698 116.203 49.128 119.581 44.523 121.99C39.918 124.397 34.491 125.601 28.239 125.601L0.739014 125.602ZM16.58 111.028H28.24C32.801 111.028 36.433 109.741 39.138 107.163C41.841 104.587 43.193 101.06 43.193 96.581V61.984C43.193 57.592 41.841 54.107 39.138 51.529C36.433 48.952 32.801 47.663 28.239 47.663H16.58V111.028ZM76.396 125.602V33.09H95.786L121.512 107.86C121.216 104.673 120.942 101.483 120.688 98.292C120.386 94.5366 120.154 90.776 119.991 87.012C119.821 83.169 119.738 79.812 119.738 76.938V33.09H134.185V125.602H114.795L89.323 50.832C89.491 53.283 89.703 56.239 89.956 59.702C90.2137 63.2478 90.4251 66.7967 90.59 70.348C90.758 73.982 90.844 77.318 90.844 80.36V125.602H76.396ZM181.582 126.869C175.245 126.869 169.752 125.812 165.107 123.701C160.46 121.591 156.889 118.569 154.398 114.64C151.905 110.711 150.616 106.086 150.533 100.763H166.374C166.374 104.565 167.747 107.543 170.494 109.698C173.238 111.852 176.976 112.929 181.709 112.929C186.271 112.929 189.839 111.874 192.417 109.761C194.993 107.65 196.282 104.735 196.282 101.017C196.282 97.892 195.374 95.167 193.558 92.842C191.74 90.52 189.142 88.936 185.764 88.09L175.119 85.175C167.852 83.318 162.256 79.979 158.327 75.164C154.398 70.348 152.434 64.518 152.434 57.675C152.434 52.438 153.616 47.875 155.982 43.988C158.347 40.103 161.705 37.103 166.058 34.99C170.408 32.88 175.54 31.822 181.455 31.822C190.409 31.822 197.506 34.125 202.745 38.729C207.983 43.335 210.645 49.523 210.73 57.295H194.888C194.888 53.663 193.704 50.812 191.34 48.741C188.974 46.671 185.637 45.636 181.328 45.636C177.188 45.636 173.978 46.608 171.697 48.551C169.416 50.495 168.275 53.24 168.275 56.788C168.275 60 169.141 62.724 170.873 64.962C172.603 67.202 175.119 68.786 178.413 69.714L189.439 72.756C196.789 74.616 202.407 77.932 206.294 82.704C210.179 87.478 212.124 93.371 212.124 100.383C212.124 105.623 210.856 110.248 208.322 114.26C205.787 118.273 202.239 121.378 197.677 123.574C193.114 125.77 187.748 126.869 181.582 126.869ZM257.366 126.869C251.366 126.869 246.17 125.729 241.778 123.448C237.384 121.167 233.985 117.957 231.577 113.816C229.169 109.678 227.965 104.818 227.965 99.242V59.45C227.965 53.874 229.169 49.017 231.577 44.876C233.984 40.738 237.384 37.526 241.778 35.245C246.17 32.964 251.366 31.823 257.366 31.823C263.449 31.823 268.665 32.963 273.017 35.245C277.367 37.526 280.747 40.738 283.156 44.876C285.563 49.016 286.767 53.874 286.767 59.45V99.243C286.767 104.819 285.563 109.679 283.156 113.817C280.748 117.957 277.346 121.167 272.954 123.449C268.56 125.729 263.364 126.869 257.366 126.869ZM257.366 113.183C261.758 113.183 265.265 111.915 267.885 109.381C270.502 106.846 271.813 103.468 271.813 99.242V59.45C271.813 55.227 270.503 51.846 267.885 49.312C265.265 46.777 261.758 45.51 257.366 45.51C252.972 45.51 249.466 46.777 246.848 49.312C244.228 51.846 242.918 55.227 242.918 59.45V99.243C242.918 103.469 244.228 106.847 246.848 109.382C249.465 111.916 252.972 113.183 257.366 113.183ZM257.366 87.583C254.915 87.583 252.909 86.781 251.346 85.175C249.782 83.571 249.002 81.5 249.002 78.965C249.002 76.431 249.762 74.403 251.283 72.883C252.803 71.362 254.831 70.601 257.366 70.601C259.901 70.601 261.928 71.361 263.449 72.883C264.969 74.403 265.73 76.431 265.73 78.966C265.73 81.5 264.97 83.571 263.45 85.176C261.928 86.781 259.9 87.583 257.366 87.583Z" fill="black"/>
|
||||
<path d="M332.69 126.999C329.057 126.999 326.164 125.941 324.01 123.831C321.855 121.72 320.778 118.847 320.778 115.213C320.778 111.581 321.855 108.686 324.01 106.532C326.164 104.378 329.057 103.3 332.69 103.3C336.322 103.3 339.217 104.378 341.372 106.532C343.526 108.686 344.603 111.582 344.603 115.213C344.603 118.847 343.526 121.72 341.372 123.831C339.217 125.941 336.322 126.999 332.691 126.999H332.69ZM381.862 125.732V33.219H437.369V47.032H397.449V71.112H432.934V84.798H397.45V111.918H437.37V125.732H381.862ZM484.766 126.999C475.725 126.999 468.65 124.528 463.539 119.585C458.426 114.643 455.872 107.906 455.872 99.372V33.219H471.84V99.245C471.84 103.639 472.937 107.061 475.135 109.51C477.331 111.962 480.54 113.185 484.766 113.185C488.905 113.185 492.095 111.962 494.334 109.51C496.572 107.06 497.693 103.639 497.693 99.245V33.219H513.66V99.372C513.66 107.906 511.126 114.642 506.057 119.585C500.987 124.528 493.891 126.999 484.767 126.999H484.766Z" fill="#359CEF"/>
|
||||
<path d="M549 0H573V148H549V0Z" fill="#FFCC03"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_4_4">
|
||||
<rect width="573" height="148" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.7 KiB |
@@ -61,9 +61,9 @@ export default function Badge({
|
||||
<div
|
||||
className={cn(
|
||||
"relative z-10 cursor-inherit whitespace-nowrap rounded-md text-[12px] py-1.5 px-3 font-normal flex gap-1.5 items-center justify-center transition-all",
|
||||
className,
|
||||
variants({ variant, hover: useHover ? variant : "none" }),
|
||||
disabled && "cursor-not-allowed opacity-50 select-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { cva, VariantProps } from "class-variance-authority";
|
||||
import classNames from "classnames";
|
||||
import React, { forwardRef } from "react";
|
||||
|
||||
type ButtonVariants = VariantProps<typeof buttonVariants>;
|
||||
export type ButtonVariants = VariantProps<typeof buttonVariants>;
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
@@ -28,7 +28,7 @@ export const buttonVariants = cva(
|
||||
"dark:focus:ring-zinc-800/50 dark:bg-nb-gray dark:text-gray-400 dark:border-gray-700/30 dark:hover:text-white dark:hover:bg-zinc-800/50",
|
||||
],
|
||||
primary: [
|
||||
"dark:focus:ring-netbird-600/50 dark:ring-offset-neutral-950/50 enabled:dark:bg-netbird disabled:dark:bg-nb-gray-920 dark:text-gray-100 enabled:dark:hover:text-white enabled:dark:hover:bg-netbird-500/80",
|
||||
"dark:focus:ring-netbird-600/50 dark:ring-offset-neutral-950/50 enabled:dark:bg-netbird disabled:dark:bg-nb-gray-910 dark:text-gray-100 enabled:dark:hover:text-white enabled:dark:hover:bg-netbird-500/80",
|
||||
"enabled:bg-netbird enabled:text-white enabled:focus:ring-netbird-400/50 enabled:hover:bg-netbird-500",
|
||||
],
|
||||
secondary: [
|
||||
@@ -49,7 +49,7 @@ export const buttonVariants = cva(
|
||||
dropdown: [
|
||||
"bg-white hover:text-black focus:ring-zinc-200/50 hover:bg-gray-100 border-neutral-200 text-gray-900",
|
||||
"dark:ring-offset-neutral-950/50 dark:focus:ring-neutral-500/20 ",
|
||||
"dark:bg-nb-gray-900/40 dark:text-gray-400 dark:border-nb-gray-800 dark:hover:bg-nb-gray-900/50",
|
||||
"dark:bg-nb-gray-900/40 dark:text-gray-400 dark:border-nb-gray-900 dark:hover:bg-nb-gray-900/50",
|
||||
],
|
||||
dotted: [
|
||||
"bg-white hover:text-black focus:ring-zinc-200/50 hover:bg-gray-100 border-gray-200 text-gray-900 border-dashed",
|
||||
|
||||
@@ -1,26 +1,37 @@
|
||||
import { cn } from "@utils/helpers";
|
||||
import { cva, VariantProps } from "class-variance-authority";
|
||||
import { InfoIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
|
||||
type CalloutVariants = VariantProps<typeof calloutVariants>;
|
||||
|
||||
type Props = {
|
||||
icon?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
} & CalloutVariants;
|
||||
|
||||
export const calloutVariants = cva(
|
||||
["px-4 py-3.5 rounded-md border text-sm font-normal flex gap-3 font-light"],
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
export const Callout = ({
|
||||
children,
|
||||
icon = <InfoIcon size={14} className={"shrink-0 relative top-[1px]"} />,
|
||||
icon = <InfoIcon size={14} className={"shrink-0 relative top-[2px]"} />,
|
||||
className,
|
||||
variant = "default",
|
||||
}: Props) => {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"px-4 py-3 rounded-md border text-sm font-normal flex gap-3",
|
||||
"bg-nb-gray-900/60 border-nb-gray-800/80 text-nb-gray-300",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div className={cn(calloutVariants({ variant }), className)}>
|
||||
{icon}
|
||||
<div>{children}</div>
|
||||
</div>
|
||||
|
||||
@@ -29,6 +29,7 @@ function CardList({ children }: Props) {
|
||||
type CardListItemProps = {
|
||||
label: React.ReactNode;
|
||||
value: React.ReactNode;
|
||||
valueToCopy?: string;
|
||||
className?: string;
|
||||
copy?: boolean;
|
||||
copyText?: string;
|
||||
@@ -39,6 +40,7 @@ type CardListItemProps = {
|
||||
function CardListItem({
|
||||
label,
|
||||
value,
|
||||
valueToCopy,
|
||||
className,
|
||||
copy = false,
|
||||
copyText,
|
||||
@@ -57,6 +59,7 @@ function CardListItem({
|
||||
<CardTextItem
|
||||
label={label}
|
||||
value={value}
|
||||
valueToCopy={valueToCopy}
|
||||
copy={copy}
|
||||
copyText={copyText}
|
||||
tooltip={tooltip}
|
||||
@@ -79,6 +82,7 @@ function CardListItem({
|
||||
type CardTextItemProps = {
|
||||
label: React.ReactNode;
|
||||
value: React.ReactNode;
|
||||
valueToCopy?: string;
|
||||
copy?: boolean;
|
||||
copyText?: string;
|
||||
tooltip?: boolean;
|
||||
@@ -88,10 +92,11 @@ const CardTextItem = ({
|
||||
label,
|
||||
value,
|
||||
copy = false,
|
||||
valueToCopy,
|
||||
copyText,
|
||||
tooltip = true,
|
||||
}: CardTextItemProps) => {
|
||||
const [, copyToClipBoard] = useCopyToClipboard(value as string);
|
||||
const [, copyToClipBoard] = useCopyToClipboard(valueToCopy ?? `${value}`);
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
|
||||
@@ -34,6 +34,10 @@ const defaultRanges = {
|
||||
from: dayjs().subtract(2, "day").startOf("day").toDate(),
|
||||
to: dayjs().endOf("day").toDate(),
|
||||
},
|
||||
last7Days: {
|
||||
from: dayjs().subtract(7, "day").startOf("day").toDate(),
|
||||
to: dayjs().endOf("day").toDate(),
|
||||
},
|
||||
lastMonth: {
|
||||
from: dayjs().subtract(1, "month").startOf("day").toDate(),
|
||||
to: dayjs().endOf("day").toDate(),
|
||||
@@ -64,6 +68,7 @@ export function DatePickerWithRange({
|
||||
yesterday: isEqualDateRange(value, defaultRanges.yesterday),
|
||||
last14Days: isEqualDateRange(value, defaultRanges.last14Days),
|
||||
last2Days: isEqualDateRange(value, defaultRanges.last2Days),
|
||||
last7Days: isEqualDateRange(value, defaultRanges.last7Days),
|
||||
lastMonth: isEqualDateRange(value, defaultRanges.lastMonth),
|
||||
allTime: isEqualDateRange(value, defaultRanges.allTime),
|
||||
};
|
||||
@@ -76,6 +81,7 @@ export function DatePickerWithRange({
|
||||
if (isActive.lastMonth) return "Last Month";
|
||||
if (isActive.last14Days) return "Last 14 Days";
|
||||
if (isActive.last2Days) return "Last 2 Days";
|
||||
if (isActive.last7Days) return "Last 7 Days";
|
||||
if (isActive.yesterday) return "Yesterday";
|
||||
if (isActive.today) return "Today";
|
||||
|
||||
@@ -88,12 +94,11 @@ export function DatePickerWithRange({
|
||||
const [calendarOpen, setCalendarOpen] = useState(false);
|
||||
|
||||
const updateRangeAndClose = (range: DateRange) => {
|
||||
setCalendarOpen(false);
|
||||
onChange?.(range);
|
||||
};
|
||||
|
||||
const debouncedOnChange = useMemo(() => {
|
||||
return onChange ? debounce(onChange, 300) : undefined;
|
||||
return onChange ? debounce(onChange, 500) : undefined;
|
||||
}, [onChange]);
|
||||
|
||||
const handleOnSelect = (range?: DateRange) => {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
TooltipVariants,
|
||||
} from "@components/Tooltip";
|
||||
import { TooltipProps } from "@radix-ui/react-tooltip";
|
||||
import { cn } from "@utils/helpers";
|
||||
@@ -24,7 +25,9 @@ type Props = {
|
||||
customOnOpenChange?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
delayDuration?: number;
|
||||
skipDelayDuration?: number;
|
||||
} & TooltipProps;
|
||||
} & TooltipProps &
|
||||
TooltipVariants;
|
||||
|
||||
export default function FullTooltip({
|
||||
children,
|
||||
content,
|
||||
@@ -41,6 +44,7 @@ export default function FullTooltip({
|
||||
customOnOpenChange,
|
||||
delayDuration = 1,
|
||||
skipDelayDuration = 300,
|
||||
variant = "default",
|
||||
}: Props) {
|
||||
const [open, setOpen] = useState(!!keepOpen);
|
||||
|
||||
@@ -66,7 +70,7 @@ export default function FullTooltip({
|
||||
<div
|
||||
className={cn(
|
||||
isAction ? "cursor-pointer" : "cursor-default",
|
||||
"inline-flex items-center gap-2 dark:text-neutral-300 text-neutral-500 hover:text-neutral-100 transition-all hover:bg-nb-gray-800/60 py-2 px-3 rounded-md",
|
||||
"inline-flex items-center gap-2 dark:text-neutral-300 text-neutral-500 hover:text-neutral-100 transition-all hover:bg-nb-gray-800/60 py-2 px-3 rounded-md",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
@@ -82,6 +86,7 @@ export default function FullTooltip({
|
||||
alignOffset={20}
|
||||
forceMount={true}
|
||||
className={contentClassName}
|
||||
variant={variant}
|
||||
align={align}
|
||||
side={side}
|
||||
>
|
||||
|
||||
@@ -12,6 +12,7 @@ const variants = cva("", {
|
||||
variants: {
|
||||
variant: {
|
||||
default: ["bg-nb-gray-800 border-nb-gray-700 text-nb-gray-300 "],
|
||||
darker: ["bg-nb-gray-930 border-nb-gray-900 text-nb-gray-250 "],
|
||||
netbird: ["bg-netbird-100 text-netbird border-netbird "],
|
||||
},
|
||||
size: {
|
||||
@@ -30,7 +31,7 @@ export default function Kbd({
|
||||
size = "default",
|
||||
disabled = false,
|
||||
className,
|
||||
}: Props) {
|
||||
}: Readonly<Props>) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
|
||||
42
src/components/NetBirdLogo.tsx
Normal file
42
src/components/NetBirdLogo.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { cn } from "@utils/helpers";
|
||||
import Image from "next/image";
|
||||
import * as React from "react";
|
||||
import NetBirdLogoMark from "@/assets/netbird.svg";
|
||||
import NetBirdLogoFull from "@/assets/netbird-full.svg";
|
||||
|
||||
type Props = {
|
||||
size?: "default" | "large";
|
||||
mobile?: boolean;
|
||||
};
|
||||
|
||||
const sizes = {
|
||||
default: {
|
||||
desktop: 22,
|
||||
mobile: 30,
|
||||
},
|
||||
large: {
|
||||
desktop: 24,
|
||||
mobile: 40,
|
||||
},
|
||||
};
|
||||
|
||||
export const NetBirdLogo = ({ size = "default", mobile = true }: Props) => {
|
||||
return (
|
||||
<>
|
||||
<Image
|
||||
src={NetBirdLogoFull}
|
||||
height={sizes[size].desktop}
|
||||
alt={"NetBird Logo"}
|
||||
className={cn(mobile && "hidden md:block")}
|
||||
/>
|
||||
{mobile && (
|
||||
<Image
|
||||
src={NetBirdLogoMark}
|
||||
width={sizes[size].mobile}
|
||||
alt={"NetBird Logo"}
|
||||
className={cn(mobile && "md:hidden ml-4")}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -172,6 +172,7 @@ export function PeerSelector({
|
||||
{filteredItems.length > 0 && (
|
||||
<VirtualScrollAreaList
|
||||
items={filteredItems}
|
||||
estimatedItemHeight={37}
|
||||
onSelect={(item) => {
|
||||
const isSupported = isRoutingPeerSupported(
|
||||
item.version,
|
||||
|
||||
@@ -1,261 +1,328 @@
|
||||
import Badge from "@components/Badge";
|
||||
import { Callout } from "@components/Callout";
|
||||
import { Checkbox } from "@components/Checkbox";
|
||||
import { CommandItem } from "@components/Command";
|
||||
import { DropdownInfoText } from "@components/DropdownInfoText";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@components/Popover";
|
||||
import { IconArrowBack } from "@tabler/icons-react";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { Command, CommandGroup, CommandInput, CommandList } from "cmdk";
|
||||
import { trim } from "lodash";
|
||||
import { orderBy, trim } from "lodash";
|
||||
import { ChevronsUpDown, SearchIcon, XIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useElementSize } from "@/hooks/useElementSize";
|
||||
import { PortRange } from "@/interfaces/Policy";
|
||||
|
||||
interface MultiSelectProps {
|
||||
values: number[];
|
||||
onChange: React.Dispatch<React.SetStateAction<number[]>>;
|
||||
ports: number[];
|
||||
onPortsChange: React.Dispatch<React.SetStateAction<number[]>>;
|
||||
portRanges?: PortRange[];
|
||||
onPortRangesChange?: React.Dispatch<React.SetStateAction<PortRange[]>>;
|
||||
max?: number;
|
||||
disabled?: boolean;
|
||||
popoverWidth?: "auto" | number;
|
||||
showAll?: boolean;
|
||||
}
|
||||
|
||||
const isValidPort = (p: number) => p >= 1 && p <= 65535;
|
||||
|
||||
const parseRange = (value: string): PortRange | undefined => {
|
||||
const parts = value.split("-").map((x) => Number(trim(x)));
|
||||
if (parts.length !== 2) return undefined;
|
||||
const [start, end] = parts;
|
||||
if (!isValidPort(start) || !isValidPort(end) || start >= end)
|
||||
return undefined;
|
||||
return { start, end };
|
||||
};
|
||||
|
||||
const parsePortInput = (value: string): number | PortRange | undefined => {
|
||||
const trimmed = trim(value);
|
||||
if (/^\d{1,5}-\d{1,5}$/.test(trimmed)) return parseRange(trimmed);
|
||||
const port = Number(trimmed);
|
||||
return isValidPort(port) ? port : undefined;
|
||||
};
|
||||
|
||||
export function PortSelector({
|
||||
onChange,
|
||||
values,
|
||||
max,
|
||||
onPortsChange,
|
||||
ports,
|
||||
portRanges = [],
|
||||
onPortRangesChange,
|
||||
disabled = false,
|
||||
popoverWidth = "auto",
|
||||
showAll = false,
|
||||
}: MultiSelectProps) {
|
||||
}: Readonly<MultiSelectProps>) {
|
||||
const searchRef = React.useRef<HTMLInputElement>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [inputRef, { width }] = useElementSize<HTMLButtonElement>();
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
const toggle = (x: number) => {
|
||||
if (isNaN(Number(x))) return;
|
||||
const port = Number(x);
|
||||
if (port < 1 || port > 65535) return;
|
||||
const [portsInput, setPortsInput] = useState<string[]>(() => {
|
||||
const p = ports.map(String);
|
||||
const pr = portRanges.map((r) => {
|
||||
if (r.start === r.end) return String(r.start);
|
||||
return `${r.start}-${r.end}`;
|
||||
});
|
||||
return orderBy([...p, ...pr], [(x) => Number(x.split("-")[0])], ["asc"]);
|
||||
});
|
||||
|
||||
const isSelected = values.includes(port);
|
||||
if (isSelected) {
|
||||
onChange((previous) => previous.filter((y) => y !== port));
|
||||
} else {
|
||||
onChange((previous) => [...previous, port]);
|
||||
setSearch("");
|
||||
}
|
||||
useEffect(() => {
|
||||
const parsed = portsInput.map(parsePortInput).filter(Boolean);
|
||||
const newPorts: number[] = [];
|
||||
const newRanges: PortRange[] = [];
|
||||
parsed.forEach((entry) => {
|
||||
if (typeof entry === "number") newPorts.push(entry);
|
||||
else if (entry !== undefined) newRanges.push(entry);
|
||||
});
|
||||
onPortsChange(newPorts);
|
||||
onPortRangesChange?.(newRanges);
|
||||
}, [portsInput]);
|
||||
|
||||
const toggle = (value: string) => {
|
||||
if (disabled) return;
|
||||
setPortsInput((prev) =>
|
||||
prev.includes(value) ? prev.filter((e) => e !== value) : [...prev, value],
|
||||
);
|
||||
setSearch("");
|
||||
};
|
||||
|
||||
const notFound = useMemo(() => {
|
||||
const isSearching = search.length > 0;
|
||||
const found =
|
||||
values.filter((item) => item == Number(trim(search))).length == 0;
|
||||
return isSearching && found;
|
||||
}, [search, values]);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const trimmed = trim(search);
|
||||
return (
|
||||
trimmed &&
|
||||
!portsInput.includes(trimmed) &&
|
||||
parsePortInput(trimmed) &&
|
||||
isSearching
|
||||
);
|
||||
}, [search, portsInput]);
|
||||
|
||||
return (
|
||||
<Popover
|
||||
open={open}
|
||||
onOpenChange={(isOpen) => {
|
||||
if (!isOpen) {
|
||||
setTimeout(() => {
|
||||
setSearch("");
|
||||
}, 100);
|
||||
}
|
||||
setOpen(isOpen);
|
||||
}}
|
||||
>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className={cn(
|
||||
"min-h-[48px] w-full relative items-center",
|
||||
"border border-neutral-200 dark:border-nb-gray-700 justify-between py-2 px-3",
|
||||
"rounded-md bg-white text-sm dark:bg-nb-gray-900/40 flex dark:text-neutral-400/70 text-neutral-500 cursor-pointer hover:dark:bg-nb-gray-900/50",
|
||||
)}
|
||||
data-cy={"port-selector"}
|
||||
disabled={disabled}
|
||||
ref={inputRef}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"flex items-center gap-2 border-nb-gray-700 flex-wrap h-full"
|
||||
}
|
||||
>
|
||||
{values.length === 0 && showAll && (
|
||||
<Badge
|
||||
variant={"gray"}
|
||||
className={"uppercase tracking-wider font-medium py-1"}
|
||||
>
|
||||
All
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
{values.map((x) => (
|
||||
<Badge
|
||||
key={x}
|
||||
variant={"gray"}
|
||||
onClick={() => toggle(x)}
|
||||
className={"uppercase tracking-wider font-medium py-1"}
|
||||
>
|
||||
{x}
|
||||
<XIcon
|
||||
size={12}
|
||||
className={"cursor-pointer group-hover:text-black"}
|
||||
/>
|
||||
</Badge>
|
||||
))}
|
||||
{values.length == 0 && <span>Select ports...</span>}
|
||||
</div>
|
||||
|
||||
<ChevronsUpDown size={18} className={"shrink-0"} />
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="w-full p-0 shadow-sm shadow-nb-gray-950"
|
||||
style={{
|
||||
width: popoverWidth === "auto" ? width : popoverWidth,
|
||||
<>
|
||||
<Popover
|
||||
open={open}
|
||||
onOpenChange={(isOpen) => {
|
||||
if (!isOpen) {
|
||||
setTimeout(() => {
|
||||
setSearch("");
|
||||
}, 100);
|
||||
}
|
||||
setOpen(isOpen);
|
||||
}}
|
||||
align="start"
|
||||
side={"top"}
|
||||
sideOffset={10}
|
||||
>
|
||||
<Command
|
||||
className={"w-full flex"}
|
||||
loop
|
||||
filter={(value, search) => {
|
||||
const formatValue = trim(value.toLowerCase());
|
||||
const formatSearch = trim(search.toLowerCase());
|
||||
if (formatValue.includes(formatSearch)) return 1;
|
||||
return 0;
|
||||
}}
|
||||
>
|
||||
<CommandList className={"w-full"}>
|
||||
<div className={"relative"}>
|
||||
<CommandInput
|
||||
className={cn(
|
||||
"min-h-[42px] w-full relative",
|
||||
"border-b-0 border-t-0 border-r-0 border-l-0 border-neutral-200 dark:border-nb-gray-700 items-center",
|
||||
"bg-transparent text-sm outline-none focus-visible:outline-none ring-0 focus-visible:ring-0",
|
||||
"dark:placeholder:text-neutral-500 font-light placeholder:text-neutral-500 pl-10",
|
||||
)}
|
||||
data-cy={"port-input"}
|
||||
typeof={"number"}
|
||||
ref={searchRef}
|
||||
value={search}
|
||||
onValueChange={setSearch}
|
||||
placeholder={'Add new ports by pressing "Enter"...'}
|
||||
/>
|
||||
<div
|
||||
className={
|
||||
"absolute left-0 top-0 h-full flex items-center pl-4"
|
||||
}
|
||||
>
|
||||
<div className={"flex items-center"}>
|
||||
<SearchIcon size={14} />
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={
|
||||
"absolute right-0 top-0 h-full flex items-center pr-4"
|
||||
}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"flex items-center bg-nb-gray-800 py-1 px-1.5 rounded-[4px] border border-nb-gray-500"
|
||||
}
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className={cn(
|
||||
"min-h-[48px] w-full relative items-center",
|
||||
"border border-neutral-200 dark:border-nb-gray-700 justify-between py-2 px-3",
|
||||
"rounded-md bg-white text-sm dark:bg-nb-gray-900/40 flex dark:text-neutral-400/70 text-neutral-500 cursor-pointer hover:dark:bg-nb-gray-900/50",
|
||||
)}
|
||||
data-cy={"port-selector"}
|
||||
disabled={disabled}
|
||||
ref={inputRef}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"flex items-center gap-2 border-nb-gray-700 flex-wrap h-full"
|
||||
}
|
||||
>
|
||||
{portsInput.length === 0 && showAll && (
|
||||
<Badge
|
||||
variant={"gray"}
|
||||
className={"uppercase tracking-wider font-medium py-1"}
|
||||
>
|
||||
<IconArrowBack size={10} />
|
||||
</div>
|
||||
</div>
|
||||
All
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
{portsInput.map((x) => (
|
||||
<Badge
|
||||
key={x}
|
||||
variant={"gray"}
|
||||
onClick={() => toggle(x)}
|
||||
className={"uppercase tracking-wider font-medium py-1"}
|
||||
>
|
||||
{x}
|
||||
<XIcon
|
||||
size={12}
|
||||
className={"cursor-pointer group-hover:text-black"}
|
||||
/>
|
||||
</Badge>
|
||||
))}
|
||||
{ports.length == 0 && <span>Select ports...</span>}
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col gap-2",
|
||||
values.length != 0 && "p-2",
|
||||
values.length != 0 && search && "p-2",
|
||||
values.length == 0 && search && "p-2",
|
||||
)}
|
||||
>
|
||||
{notFound && (
|
||||
<ChevronsUpDown size={18} className={"shrink-0"} />
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="w-full p-0 shadow-sm shadow-nb-gray-950"
|
||||
style={{
|
||||
width: popoverWidth === "auto" ? width : popoverWidth,
|
||||
}}
|
||||
align="start"
|
||||
side={"top"}
|
||||
sideOffset={10}
|
||||
>
|
||||
<Command
|
||||
className={"w-full flex"}
|
||||
loop
|
||||
filter={(value, search) => {
|
||||
const formatValue = trim(value.toLowerCase());
|
||||
const formatSearch = trim(search.toLowerCase());
|
||||
if (formatValue.includes(formatSearch)) return 1;
|
||||
return 0;
|
||||
}}
|
||||
>
|
||||
<CommandList className={"w-full"}>
|
||||
<div className={"relative"}>
|
||||
<CommandInput
|
||||
className={cn(
|
||||
"min-h-[42px] w-full relative",
|
||||
"border-b-0 border-t-0 border-r-0 border-l-0 border-neutral-200 dark:border-nb-gray-700 items-center",
|
||||
"bg-transparent text-sm outline-none focus-visible:outline-none ring-0 focus-visible:ring-0",
|
||||
"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}
|
||||
placeholder={
|
||||
'Add a port or a range e.g. 80 or 1-1023 and press "Enter" to add...'
|
||||
}
|
||||
/>
|
||||
<div
|
||||
className={
|
||||
"absolute left-0 top-0 h-full flex items-center pl-4"
|
||||
}
|
||||
>
|
||||
<div className={"flex items-center"}>
|
||||
<SearchIcon size={14} />
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={
|
||||
"absolute right-0 top-0 h-full flex items-center pr-4"
|
||||
}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"flex items-center bg-nb-gray-800 py-1 px-1.5 rounded-[4px] border border-nb-gray-500"
|
||||
}
|
||||
>
|
||||
<IconArrowBack size={10} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col gap-2",
|
||||
portsInput.length != 0 && "p-2",
|
||||
portsInput.length != 0 && search && "p-2",
|
||||
notFound && "p-2",
|
||||
)}
|
||||
>
|
||||
{!notFound && search && !portsInput.includes(search) && (
|
||||
<div className={"text-sm"}>
|
||||
<DropdownInfoText className={"mb-[18px] pt-[4px]"}>
|
||||
{
|
||||
"Please add a valid port or port range (e.g. 80, 443, 1-1023)"
|
||||
}
|
||||
</DropdownInfoText>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{notFound && (
|
||||
<CommandGroup>
|
||||
<div
|
||||
className={cn(
|
||||
"max-h-[180px] overflow-y-auto flex flex-col gap-1",
|
||||
)}
|
||||
>
|
||||
<CommandItem
|
||||
key={search}
|
||||
onSelect={() => {
|
||||
toggle(search);
|
||||
searchRef.current?.focus();
|
||||
}}
|
||||
value={search}
|
||||
onClick={(e) => e.preventDefault()}
|
||||
>
|
||||
<Badge
|
||||
variant={"gray"}
|
||||
className={
|
||||
"uppercase tracking-wider font-medium py-1"
|
||||
}
|
||||
>
|
||||
{search}
|
||||
</Badge>
|
||||
<div
|
||||
className={"text-neutral-500 dark:text-nb-gray-300"}
|
||||
>
|
||||
Add this port or range by pressing{" "}
|
||||
<span className={"font-bold text-netbird"}>
|
||||
{"'Enter'"}
|
||||
</span>
|
||||
</div>
|
||||
</CommandItem>
|
||||
</div>
|
||||
</CommandGroup>
|
||||
)}
|
||||
|
||||
<CommandGroup>
|
||||
<div
|
||||
className={cn(
|
||||
"max-h-[180px] overflow-y-auto flex flex-col gap-1",
|
||||
)}
|
||||
>
|
||||
<CommandItem
|
||||
key={search}
|
||||
onSelect={() => {
|
||||
toggle(Number(search));
|
||||
searchRef.current?.focus();
|
||||
}}
|
||||
value={search}
|
||||
onClick={(e) => e.preventDefault()}
|
||||
>
|
||||
<Badge
|
||||
variant={"gray"}
|
||||
className={"uppercase tracking-wider font-medium py-1"}
|
||||
>
|
||||
{search}
|
||||
</Badge>
|
||||
<div className={"text-neutral-500 dark:text-nb-gray-300"}>
|
||||
Add this port by pressing{" "}
|
||||
<span className={"font-bold text-netbird"}>
|
||||
{"'Enter'"}
|
||||
</span>
|
||||
</div>
|
||||
</CommandItem>
|
||||
</div>
|
||||
</CommandGroup>
|
||||
)}
|
||||
{portsInput.map((option) => {
|
||||
const isSelected = portsInput.includes(option);
|
||||
return (
|
||||
<CommandItem
|
||||
key={option}
|
||||
value={option.toString()}
|
||||
onSelect={() => {
|
||||
toggle(option);
|
||||
searchRef.current?.focus();
|
||||
}}
|
||||
onClick={(e) => e.preventDefault()}
|
||||
>
|
||||
<div className={"flex items-center gap-2"}>
|
||||
<Badge
|
||||
variant={"gray"}
|
||||
className={
|
||||
"uppercase tracking-wider font-medium py-1"
|
||||
}
|
||||
>
|
||||
{option}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<CommandGroup>
|
||||
<div
|
||||
className={cn(
|
||||
"max-h-[180px] overflow-y-auto flex flex-col gap-1",
|
||||
)}
|
||||
>
|
||||
{values.map((option) => {
|
||||
const isSelected = values.includes(option);
|
||||
return (
|
||||
<CommandItem
|
||||
key={option}
|
||||
value={option.toString()}
|
||||
onSelect={() => {
|
||||
toggle(option);
|
||||
searchRef.current?.focus();
|
||||
}}
|
||||
onClick={(e) => e.preventDefault()}
|
||||
>
|
||||
<div className={"flex items-center gap-2"}>
|
||||
<Badge
|
||||
variant={"gray"}
|
||||
<div
|
||||
className={
|
||||
"uppercase tracking-wider font-medium py-1"
|
||||
"text-neutral-500 dark:text-nb-gray-300 font-medium flex items-center gap-2"
|
||||
}
|
||||
>
|
||||
{option}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={
|
||||
"text-neutral-500 dark:text-nb-gray-300 font-medium flex items-center gap-2"
|
||||
}
|
||||
>
|
||||
<Checkbox checked={isSelected} />
|
||||
</div>
|
||||
</CommandItem>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CommandGroup>
|
||||
</div>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Checkbox checked={isSelected} />
|
||||
</div>
|
||||
</CommandItem>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CommandGroup>
|
||||
</div>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
{portRanges?.length > 0 && (
|
||||
<Callout variant={"info"} className={"mt-4"}>
|
||||
Port ranges requires NetBird client{" "}
|
||||
<span className={"text-white font-normal"}>v0.48</span> or higher.
|
||||
</Callout>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
67
src/components/RadioCard.tsx
Normal file
67
src/components/RadioCard.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
import * as RadioGroup from "@radix-ui/react-radio-group";
|
||||
import { ReactNode } from "react"; // or replace with clsx or similar
|
||||
import { cn } from "@/utils/helpers";
|
||||
|
||||
type Props = {
|
||||
value: string;
|
||||
title: ReactNode;
|
||||
description: ReactNode;
|
||||
icon?: ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export const RadioCard = ({
|
||||
value,
|
||||
title,
|
||||
description,
|
||||
className,
|
||||
icon,
|
||||
}: Props) => {
|
||||
return (
|
||||
<RadioGroup.Item
|
||||
value={value}
|
||||
className={cn(
|
||||
"peer relative block cursor-pointer rounded-lg border border-nb-gray-900 bg-nb-gray-930/60 px-5 py-3 transition-all focus:outline-none",
|
||||
"data-[state=checked]:border-nb-gray-400 data-[state=checked]:bg-nb-gray-920",
|
||||
"outline-none focus:ring-0 focus:bg-nb-gray-930 focus:border-nb-gray-920",
|
||||
"hover:bg-nb-gray-930",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div className="text-nb-gray-100 font-normal text-sm text-left gap-2 flex items-center">
|
||||
{icon}
|
||||
{title}
|
||||
</div>
|
||||
<div className="text-nb-gray-300 text-[0.8rem] text-left">
|
||||
{description}
|
||||
</div>
|
||||
</RadioGroup.Item>
|
||||
);
|
||||
};
|
||||
|
||||
type RadioCardGroupProps = {
|
||||
value: string;
|
||||
onValueChange: (val: string) => void;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
"aria-label"?: string;
|
||||
};
|
||||
|
||||
export const RadioCardGroup = ({
|
||||
value,
|
||||
onValueChange,
|
||||
children,
|
||||
className,
|
||||
"aria-label": ariaLabel = "Options",
|
||||
}: RadioCardGroupProps) => {
|
||||
return (
|
||||
<RadioGroup.Root
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
value={value}
|
||||
onValueChange={onValueChange}
|
||||
aria-label={ariaLabel}
|
||||
>
|
||||
{children}
|
||||
</RadioGroup.Root>
|
||||
);
|
||||
};
|
||||
@@ -24,6 +24,8 @@ type StepProps = {
|
||||
line?: boolean;
|
||||
center?: boolean;
|
||||
horizontal?: boolean;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
const Step = ({
|
||||
@@ -32,6 +34,8 @@ const Step = ({
|
||||
line = true,
|
||||
center = false,
|
||||
horizontal,
|
||||
disabled = false,
|
||||
className,
|
||||
}: StepProps) => {
|
||||
return (
|
||||
<div
|
||||
@@ -39,6 +43,8 @@ const Step = ({
|
||||
"flex gap-4 items-start justify-start relative pb-6 -mx-1.5 group px-[2px]",
|
||||
center && "items-center",
|
||||
horizontal ? "flex-col items-center" : "min-w-full",
|
||||
disabled && "opacity-40 pointer-events-none",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{line && (
|
||||
@@ -57,6 +63,7 @@ const Step = ({
|
||||
"h-[34px] w-[34px] shrink-0 rounded-full flex items-center justify-center font-medium text-xs relative z-0 border-4 transition-all",
|
||||
"dark:bg-nb-gray-900 dark:text-nb-gray-400 dark:border-nb-gray dark:group-hover:bg-nb-gray-800",
|
||||
"bg-nb-gray-100 text-nb-gray-400 border-white group-hover:bg-nb-gray-200 step-circle",
|
||||
"[.stepper-bg-variant]:border-nb-gray-940",
|
||||
)}
|
||||
>
|
||||
{step}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { cva, VariantProps } from "class-variance-authority";
|
||||
import * as React from "react";
|
||||
|
||||
const TooltipProvider = TooltipPrimitive.Provider;
|
||||
@@ -10,25 +11,58 @@ const Tooltip = TooltipPrimitive.Root;
|
||||
|
||||
const TooltipTrigger = TooltipPrimitive.Trigger;
|
||||
|
||||
export const tooltipClasses =
|
||||
"z-[9999] overflow-hidden rounded-md border border-neutral-200 bg-white text-sm text-neutral-950 shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-nb-gray-930 dark:bg-nb-gray-940 dark:text-neutral-50";
|
||||
export type TooltipVariants = VariantProps<typeof tooltipVariants>;
|
||||
|
||||
export const tooltipVariants = cva(
|
||||
[
|
||||
"z-[9999] overflow-hidden rounded-md border text-sm shadow-md",
|
||||
"animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
],
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: [
|
||||
"bg-white dark:bg-nb-gray-940",
|
||||
"text-neutral-950 dark:text-neutral-50",
|
||||
"border-neutral-200 dark:border-nb-gray-930",
|
||||
],
|
||||
lighter: [
|
||||
"bg-white dark:bg-nb-gray-920",
|
||||
"text-neutral-950 dark:text-neutral-50",
|
||||
"border-neutral-200 dark:border-nb-gray-900",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const TooltipContent = React.forwardRef<
|
||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||
>(({ className = "px-4 py-2.5", sideOffset = 7, ...props }, ref) => (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
asChild={true}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(tooltipClasses, className)}
|
||||
{...props}
|
||||
>
|
||||
<div>{props.children}</div>
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
));
|
||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content> &
|
||||
TooltipVariants
|
||||
>(
|
||||
(
|
||||
{
|
||||
className = "px-4 py-2.5",
|
||||
sideOffset = 7,
|
||||
variant = "default",
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) => (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
asChild={true}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(tooltipVariants({ variant }), className)}
|
||||
{...props}
|
||||
>
|
||||
<div>{props.children}</div>
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
),
|
||||
);
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
||||
|
||||
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
||||
|
||||
@@ -11,12 +11,16 @@ type Props<T extends { id?: string }> = {
|
||||
items: T[];
|
||||
onSelect: (item: T) => void;
|
||||
renderItem?: (item: T, selected?: boolean) => React.ReactNode;
|
||||
renderHeading?: (item: T) => React.ReactNode;
|
||||
renderBeforeItem?: (item: T) => React.ReactNode;
|
||||
itemClassName?: string;
|
||||
itemWrapperClassName?: string;
|
||||
scrollAreaClassName?: string;
|
||||
maxHeight?: number;
|
||||
estimatedItemHeight?: number;
|
||||
estimatedHeadingHeight?: number;
|
||||
heightAdjustment?: number;
|
||||
groupKey?: (item: T) => string | undefined;
|
||||
};
|
||||
|
||||
export function VirtualScrollAreaList<T extends { id?: string }>({
|
||||
@@ -24,13 +28,20 @@ export function VirtualScrollAreaList<T extends { id?: string }>({
|
||||
onSelect,
|
||||
renderItem,
|
||||
renderBeforeItem,
|
||||
renderHeading,
|
||||
itemClassName,
|
||||
itemWrapperClassName,
|
||||
scrollAreaClassName,
|
||||
maxHeight,
|
||||
estimatedItemHeight = 36,
|
||||
estimatedHeadingHeight = 16,
|
||||
heightAdjustment = 8,
|
||||
groupKey,
|
||||
}: Readonly<Props<T>>) {
|
||||
const virtuosoRef = useRef<VirtuosoHandle>(null);
|
||||
const [lastInputMethod, setLastInputMethod] = useState<"mouse" | "keyboard">(
|
||||
"mouse",
|
||||
);
|
||||
const [selected, setSelected] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -47,6 +58,7 @@ export function VirtualScrollAreaList<T extends { id?: string }>({
|
||||
|
||||
const navigation = useCallback(
|
||||
(e: KeyboardEvent) => {
|
||||
setLastInputMethod("keyboard");
|
||||
if (items.length === 0) return;
|
||||
const length = items.length - 1;
|
||||
if (e.code === "ArrowUp" || (e.key === "Tab" && e.shiftKey)) {
|
||||
@@ -69,20 +81,54 @@ export function VirtualScrollAreaList<T extends { id?: string }>({
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleMouse = () => setLastInputMethod("mouse");
|
||||
|
||||
window.addEventListener("keydown", navigation);
|
||||
window.addEventListener("mousemove", handleMouse);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", navigation);
|
||||
window.removeEventListener("mousemove", handleMouse);
|
||||
};
|
||||
}, [navigation]);
|
||||
|
||||
const headingCount = useMemo(() => {
|
||||
if (!groupKey) return 0;
|
||||
|
||||
let count = 0;
|
||||
let prev: string | undefined;
|
||||
|
||||
for (const item of items) {
|
||||
const key = groupKey(item);
|
||||
if (key !== prev) {
|
||||
count++;
|
||||
prev = key;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}, [items, groupKey]);
|
||||
|
||||
const renderMemoizedItem = useMemo(() => renderItem, [renderItem]);
|
||||
|
||||
const scrollAreaHeight = { maxHeight: maxHeight ?? 195 };
|
||||
|
||||
const virtuosoHeight = {
|
||||
height: Math.min(items.length * estimatedItemHeight + 8, maxHeight ?? 195),
|
||||
height: Math.min(
|
||||
items.length * estimatedItemHeight +
|
||||
headingCount * estimatedHeadingHeight +
|
||||
+(8 + heightAdjustment),
|
||||
maxHeight ?? 195,
|
||||
),
|
||||
};
|
||||
|
||||
const fixedItemHeight = useMemo(() => {
|
||||
if (!groupKey) return estimatedItemHeight;
|
||||
if (items.length === 0) return 0;
|
||||
const h = virtuosoHeight.height / items.length;
|
||||
if (isNaN(h)) return estimatedItemHeight;
|
||||
return h;
|
||||
}, [estimatedItemHeight, groupKey, items.length, virtuosoHeight.height]);
|
||||
|
||||
return (
|
||||
<MemoizedScrollArea
|
||||
withoutViewport={true}
|
||||
@@ -93,16 +139,26 @@ export function VirtualScrollAreaList<T extends { id?: string }>({
|
||||
ref={virtuosoRef}
|
||||
overscan={50}
|
||||
data={items}
|
||||
defaultItemHeight={fixedItemHeight}
|
||||
totalCount={items.length}
|
||||
fixedItemHeight={estimatedItemHeight}
|
||||
computeItemKey={(index) => items[index].id as string}
|
||||
context={{ selected, setSelected, onClick: onSelect }}
|
||||
itemContent={(index, option, { selected, setSelected, onClick }) => {
|
||||
const group = groupKey?.(option);
|
||||
const prevGroup =
|
||||
index > 0 ? groupKey?.(items[index - 1]) : undefined;
|
||||
const showHeading = group && group !== prevGroup;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{showHeading && renderHeading?.(option)}
|
||||
{renderBeforeItem?.(option)}
|
||||
<VirtualScrollListItemWrapper
|
||||
onMouseEnter={() => setSelected(index)}
|
||||
onMouseEnter={() => {
|
||||
if (lastInputMethod === "mouse") {
|
||||
setSelected(index);
|
||||
}
|
||||
}}
|
||||
id={option.id}
|
||||
onClick={() => onClick(option)}
|
||||
ariaSelected={selected === index}
|
||||
@@ -151,17 +207,13 @@ export const VirtualScrollListItemWrapper = memo(
|
||||
return (
|
||||
<div
|
||||
key={id ?? undefined}
|
||||
className={cn(
|
||||
"pr-3 pl-2 webkit-scroll group/list-item",
|
||||
isLast && "pb-2",
|
||||
className,
|
||||
)}
|
||||
onMouseEnter={onMouseEnter}
|
||||
className={cn("pr-3 pl-2 webkit-scroll", isLast && "pb-2", className)}
|
||||
onMouseOver={onMouseEnter}
|
||||
onClick={onClick}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"text-xs flex justify-between py-2 px-3 cursor-pointer items-center rounded-md",
|
||||
"text-xs flex justify-between py-2 px-3 cursor-pointer items-center rounded-md group/list-item",
|
||||
"bg-transparent dark:aria-selected:bg-nb-gray-800/50",
|
||||
itemClassName,
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Button from "@components/Button";
|
||||
import Button, { ButtonVariants } from "@components/Button";
|
||||
import { CommandItem } from "@components/Command";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@components/Popover";
|
||||
@@ -36,6 +36,7 @@ interface SelectDropdownProps {
|
||||
placeholder?: string;
|
||||
searchPlaceholder?: string;
|
||||
isLoading?: boolean;
|
||||
variant?: ButtonVariants["variant"];
|
||||
}
|
||||
|
||||
export function SelectDropdown({
|
||||
@@ -49,15 +50,13 @@ export function SelectDropdown({
|
||||
placeholder = "Select...",
|
||||
searchPlaceholder = "Search...",
|
||||
isLoading = false,
|
||||
}: SelectDropdownProps) {
|
||||
variant = "input",
|
||||
}: Readonly<SelectDropdownProps>) {
|
||||
const [inputRef, { width }] = useElementSize<HTMLButtonElement>();
|
||||
|
||||
const toggle = (selectedValue: string) => {
|
||||
const isSelected = value == selectedValue;
|
||||
if (isSelected) {
|
||||
} else {
|
||||
onChange && onChange(selectedValue);
|
||||
}
|
||||
if (!isSelected) onChange?.(selectedValue);
|
||||
setTimeout(() => {
|
||||
setSearch("");
|
||||
}, 100);
|
||||
@@ -66,18 +65,6 @@ export function SelectDropdown({
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const [slice, setSlice] = useState(10);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setTimeout(() => {
|
||||
setSlice(options.length);
|
||||
}, 100);
|
||||
} else {
|
||||
setSlice(10);
|
||||
}
|
||||
}, [open, options]);
|
||||
|
||||
const selected = options.find((o) => o.value === value);
|
||||
|
||||
const searchRef = React.useRef<HTMLInputElement>(null);
|
||||
@@ -96,7 +83,6 @@ export function SelectDropdown({
|
||||
<Popover
|
||||
open={open}
|
||||
onOpenChange={(isOpen) => {
|
||||
setSlice(10);
|
||||
if (!isOpen) {
|
||||
setTimeout(() => {
|
||||
setSearch("");
|
||||
@@ -107,7 +93,7 @@ export function SelectDropdown({
|
||||
>
|
||||
<PopoverTrigger asChild={true} disabled={disabled || isLoading}>
|
||||
<Button
|
||||
variant={"input"}
|
||||
variant={variant}
|
||||
disabled={disabled || isLoading}
|
||||
ref={inputRef}
|
||||
className={"w-full"}
|
||||
@@ -146,7 +132,7 @@ export function SelectDropdown({
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="w-full p-0 shadow-sm shadow-nb-gray-950"
|
||||
className="w-full p-0 shadow-sm shadow-nb-gray-950 focus:outline-none"
|
||||
style={{
|
||||
width: popoverWidth === "auto" ? width : popoverWidth,
|
||||
}}
|
||||
|
||||
@@ -6,16 +6,26 @@ type Props = {
|
||||
withHeader?: boolean;
|
||||
};
|
||||
|
||||
export default function SkeletonTable({ withHeader = true }: Props) {
|
||||
export default function SkeletonTable({ withHeader = true }: Readonly<Props>) {
|
||||
return (
|
||||
<div className={"w-full"}>
|
||||
{withHeader && <SkeletonTableHeader />}
|
||||
<Skeleton
|
||||
height={48}
|
||||
containerClassName={"flex"}
|
||||
className={cn(withHeader && "mt-8")}
|
||||
/>
|
||||
<div>
|
||||
<div className={"mt-6"}>
|
||||
<TableSkeletonRow />
|
||||
<TableSkeletonRow odd />
|
||||
<TableSkeletonRow />
|
||||
<TableSkeletonRow odd />
|
||||
<TableSkeletonRow />
|
||||
<TableSkeletonRow odd />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TableContentSkeleton() {
|
||||
return (
|
||||
<div className={"w-full"}>
|
||||
<div className={"mt-6"}>
|
||||
<TableSkeletonRow />
|
||||
<TableSkeletonRow odd />
|
||||
<TableSkeletonRow />
|
||||
@@ -31,7 +41,7 @@ type RowProps = {
|
||||
odd?: boolean;
|
||||
};
|
||||
|
||||
export function TableSkeletonRow({ odd = false }: RowProps) {
|
||||
export function TableSkeletonRow({ odd = false }: Readonly<RowProps>) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client";
|
||||
import SkeletonTable from "@components/skeletons/SkeletonTable";
|
||||
import { TableContentSkeleton } from "@components/skeletons/SkeletonTable";
|
||||
import DataTableGlobalSearch from "@components/table/DataTableGlobalSearch";
|
||||
import { DataTableHeadingPortal } from "@components/table/DataTableHeadingPortal";
|
||||
import { DataTablePagination } from "@components/table/DataTablePagination";
|
||||
@@ -40,10 +40,10 @@ import {
|
||||
import { FilterFn } from "@tanstack/table-core";
|
||||
import { cn, removeAllSpaces } from "@utils/helpers";
|
||||
import dayjs from "dayjs";
|
||||
import { trim } from "lodash";
|
||||
import { isEqual, trim } from "lodash";
|
||||
import { usePathname } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||
|
||||
declare module "@tanstack/table-core" {
|
||||
@@ -84,7 +84,6 @@ const isWithinRange: FilterFn<any> = (
|
||||
) => {
|
||||
const date = dayjs(row.getValue(columnId));
|
||||
const [start, end] = value;
|
||||
//If one filter defined and date is null filter it
|
||||
if ((start || end) && !date) return false;
|
||||
if (start && !end) {
|
||||
return date.isAfter(dayjs(start));
|
||||
@@ -147,6 +146,8 @@ interface DataTableProps<TData, TValue> {
|
||||
showSearchAndFilters?: boolean;
|
||||
rightSide?: (table: TanStackTable<TData>) => React.ReactNode;
|
||||
manualPagination?: boolean;
|
||||
manualFiltering?: boolean;
|
||||
manualColumnFiltering?: boolean;
|
||||
showHeader?: boolean;
|
||||
rowSelection?: RowSelectionState;
|
||||
setRowSelection?: React.Dispatch<React.SetStateAction<RowSelectionState>>;
|
||||
@@ -163,14 +164,23 @@ interface DataTableProps<TData, TValue> {
|
||||
initialPageSize?: number;
|
||||
uniqueKey?: string;
|
||||
resetRowSelectionOnSearch?: boolean;
|
||||
pageCount?: number;
|
||||
pagination?: { pageIndex: number; pageSize: number };
|
||||
onPaginationChange?: (pagination: {
|
||||
pageIndex: number;
|
||||
pageSize: number;
|
||||
}) => void;
|
||||
totalRecords?: number;
|
||||
globalFilter?: string;
|
||||
onGlobalFilterChange?: (value: string) => void;
|
||||
columnFilters?: ColumnFiltersState;
|
||||
onColumnFiltersChange?: (filters: ColumnFiltersState) => void;
|
||||
initialFilters?: ColumnFiltersState;
|
||||
initialSearch?: string;
|
||||
onSearchClick?: () => void;
|
||||
}
|
||||
|
||||
export function DataTable<TData, TValue>(props: DataTableProps<TData, TValue>) {
|
||||
if (props.isLoading) return <SkeletonTable withHeader={!props.minimal} />;
|
||||
return <DataTableContent {...props} />;
|
||||
}
|
||||
|
||||
export function DataTableContent<TData, TValue>({
|
||||
export function DataTable<TData, TValue>({
|
||||
columns,
|
||||
data,
|
||||
children,
|
||||
@@ -196,6 +206,8 @@ export function DataTableContent<TData, TValue>({
|
||||
searchClassName,
|
||||
rightSide,
|
||||
manualPagination = false,
|
||||
manualFiltering = false,
|
||||
manualColumnFiltering = false,
|
||||
showHeader = true,
|
||||
rowSelection,
|
||||
setRowSelection,
|
||||
@@ -212,18 +224,33 @@ export function DataTableContent<TData, TValue>({
|
||||
initialPageSize = 10,
|
||||
uniqueKey,
|
||||
resetRowSelectionOnSearch = true,
|
||||
}: DataTableProps<TData, TValue>) {
|
||||
pageCount,
|
||||
pagination,
|
||||
onPaginationChange,
|
||||
totalRecords,
|
||||
globalFilter,
|
||||
onGlobalFilterChange,
|
||||
columnFilters: externalColumnFilters,
|
||||
onColumnFiltersChange: externalOnColumnFiltersChange,
|
||||
initialFilters,
|
||||
initialSearch,
|
||||
onSearchClick,
|
||||
}: Readonly<DataTableProps<TData, TValue>>) {
|
||||
const path = usePathname();
|
||||
const isInitialRender = useRef(true);
|
||||
|
||||
const [columnFilters, setColumnFilters] = useLocalStorage<ColumnFiltersState>(
|
||||
`netbird-table-columns${uniqueKey ? "/" + (uniqueKey as string) : path}`,
|
||||
[],
|
||||
keepStateInLocalStorage,
|
||||
);
|
||||
const [globalSearch, setGlobalSearch] = useLocalStorage(
|
||||
const [localColumnFilters, setLocalColumnFilters] =
|
||||
useLocalStorage<ColumnFiltersState>(
|
||||
`netbird-table-columns${uniqueKey ? "/" + (uniqueKey as string) : path}`,
|
||||
[],
|
||||
keepStateInLocalStorage && !manualColumnFiltering,
|
||||
initialFilters,
|
||||
);
|
||||
const [localGlobalSearch, setLocalGlobalSearch] = useLocalStorage(
|
||||
`netbird-table-search${uniqueKey ? "/" + (uniqueKey as string) : path}`,
|
||||
"",
|
||||
keepStateInLocalStorage,
|
||||
globalFilter || "",
|
||||
keepStateInLocalStorage && !manualFiltering,
|
||||
initialSearch,
|
||||
);
|
||||
|
||||
const [paginationState, setPaginationState] =
|
||||
@@ -232,10 +259,10 @@ export function DataTableContent<TData, TValue>({
|
||||
uniqueKey ? "/" + (uniqueKey as string) : path
|
||||
}`,
|
||||
{
|
||||
pageIndex: 0,
|
||||
pageSize: 10,
|
||||
pageIndex: pagination?.pageIndex ?? 0,
|
||||
pageSize: pagination?.pageSize ?? initialPageSize,
|
||||
},
|
||||
keepStateInLocalStorage,
|
||||
keepStateInLocalStorage && !manualPagination,
|
||||
);
|
||||
|
||||
const hasInitialData = !!(data && data.length > 0);
|
||||
@@ -253,19 +280,30 @@ export function DataTableContent<TData, TValue>({
|
||||
autoResetAll: false,
|
||||
autoResetExpanded: false,
|
||||
manualPagination: manualPagination,
|
||||
manualFiltering: manualFiltering || manualColumnFiltering,
|
||||
pageCount: pageCount,
|
||||
state: {
|
||||
sorting,
|
||||
rowSelection: rowSelection ?? {},
|
||||
columnFilters,
|
||||
columnFilters: manualColumnFiltering
|
||||
? externalColumnFilters || []
|
||||
: localColumnFilters,
|
||||
columnVisibility: columnVisibility,
|
||||
globalFilter: globalSearch,
|
||||
pagination: paginationState,
|
||||
globalFilter: manualFiltering ? globalFilter : localGlobalSearch,
|
||||
pagination: manualPagination
|
||||
? {
|
||||
pageIndex: pagination?.pageIndex ?? 0,
|
||||
pageSize: pagination?.pageSize ?? initialPageSize,
|
||||
}
|
||||
: paginationState,
|
||||
},
|
||||
initialState: {
|
||||
pagination: {
|
||||
pageIndex: 0,
|
||||
pageSize: initialPageSize || 10,
|
||||
pageIndex: pagination?.pageIndex ?? 0,
|
||||
pageSize: pagination?.pageSize ?? initialPageSize,
|
||||
},
|
||||
columnFilters: initialFilters,
|
||||
globalFilter: initialSearch,
|
||||
},
|
||||
sortingFns: {
|
||||
checkbox: checkboxSort,
|
||||
@@ -273,8 +311,36 @@ export function DataTableContent<TData, TValue>({
|
||||
getRowId: useRowId ? (row) => row.id : undefined,
|
||||
onRowSelectionChange: setRowSelection,
|
||||
onSortingChange: setSorting,
|
||||
onPaginationChange: setPaginationState,
|
||||
onColumnFiltersChange: setColumnFilters,
|
||||
onPaginationChange: (updater) => {
|
||||
if (manualPagination) {
|
||||
if (isInitialRender.current) {
|
||||
isInitialRender.current = false;
|
||||
return;
|
||||
}
|
||||
if (typeof updater === "function") {
|
||||
const newState = updater(pagination!);
|
||||
onPaginationChange?.(newState);
|
||||
} else {
|
||||
onPaginationChange?.(updater);
|
||||
}
|
||||
} else {
|
||||
setPaginationState(updater);
|
||||
}
|
||||
},
|
||||
onColumnFiltersChange: (filters) => {
|
||||
if (manualColumnFiltering) {
|
||||
externalOnColumnFiltersChange?.(filters as ColumnFiltersState);
|
||||
} else {
|
||||
setLocalColumnFilters(filters as ColumnFiltersState);
|
||||
}
|
||||
},
|
||||
onGlobalFilterChange: (value) => {
|
||||
if (manualFiltering) {
|
||||
onGlobalFilterChange?.(value);
|
||||
} else {
|
||||
setLocalGlobalSearch(value);
|
||||
}
|
||||
},
|
||||
globalFilterFn: fuzzyFilter,
|
||||
onColumnVisibilityChange: setColumnVisibility,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
@@ -298,8 +364,16 @@ export function DataTableContent<TData, TValue>({
|
||||
*/
|
||||
const resetFilters = () => {
|
||||
table.setPageIndex(0);
|
||||
setColumnFilters([]);
|
||||
setGlobalSearch("");
|
||||
if (manualColumnFiltering) {
|
||||
externalOnColumnFiltersChange?.([]);
|
||||
} else {
|
||||
setLocalColumnFilters([]);
|
||||
}
|
||||
if (manualFiltering) {
|
||||
onGlobalFilterChange?.("");
|
||||
} else {
|
||||
setLocalGlobalSearch("");
|
||||
}
|
||||
setRowSelection?.({});
|
||||
onFilterReset?.();
|
||||
setSearchKey((prev) => (prev === 0 ? 1 : 0));
|
||||
@@ -307,6 +381,36 @@ export function DataTableContent<TData, TValue>({
|
||||
|
||||
const [searchKey, setSearchKey] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (manualPagination && pagination) {
|
||||
const currentPagination = table.getState().pagination;
|
||||
if (isEqual(currentPagination, pagination)) return;
|
||||
|
||||
table.setPagination({
|
||||
pageIndex: pagination.pageIndex,
|
||||
pageSize: pagination.pageSize,
|
||||
});
|
||||
}
|
||||
}, [manualPagination, pagination, table]);
|
||||
|
||||
useEffect(() => {
|
||||
if (manualFiltering && globalFilter !== undefined) {
|
||||
const currentGlobalFilter = table.getState().globalFilter;
|
||||
if (currentGlobalFilter !== globalFilter) {
|
||||
table.setGlobalFilter(globalFilter);
|
||||
}
|
||||
}
|
||||
}, [manualFiltering, globalFilter, table]);
|
||||
|
||||
useEffect(() => {
|
||||
if (manualColumnFiltering && externalColumnFilters) {
|
||||
const currentFilters = table.getState().columnFilters;
|
||||
if (!isEqual(currentFilters, externalColumnFilters)) {
|
||||
table.setColumnFilters(externalColumnFilters);
|
||||
}
|
||||
}
|
||||
}, [manualColumnFiltering, externalColumnFilters, table]);
|
||||
|
||||
return (
|
||||
<div className={cn("relative table-fixed-scroll", className)}>
|
||||
{showSearchAndFilters && (
|
||||
@@ -318,45 +422,48 @@ export function DataTableContent<TData, TValue>({
|
||||
>
|
||||
<DataTableGlobalSearch
|
||||
className={searchClassName}
|
||||
disabled={!hasInitialData}
|
||||
disabled={false} // Never disable the search input
|
||||
key={searchKey}
|
||||
globalSearch={globalSearch}
|
||||
onClick={onSearchClick}
|
||||
isLoading={isLoading}
|
||||
globalSearch={
|
||||
manualFiltering ? globalFilter || "" : localGlobalSearch
|
||||
}
|
||||
setGlobalSearch={(val) => {
|
||||
table.setPageIndex(0);
|
||||
setGlobalSearch(val);
|
||||
if (manualFiltering) {
|
||||
onGlobalFilterChange?.(val);
|
||||
} else {
|
||||
setLocalGlobalSearch(val);
|
||||
}
|
||||
resetRowSelectionOnSearch && setRowSelection?.({});
|
||||
}}
|
||||
placeholder={searchPlaceholder}
|
||||
/>
|
||||
{children && children(table)}
|
||||
{children?.(table)}
|
||||
{showResetFilterButton && (
|
||||
<DataTableResetFilterButton onClick={resetFilters} table={table} />
|
||||
)}
|
||||
<div className={"flex gap-4 flex-wrap grow"}>
|
||||
<div className={"flex gap-4 flex-wrap"}></div>
|
||||
{rightSide && rightSide(table)}
|
||||
{rightSide?.(table)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{aboveTable && aboveTable(table)}
|
||||
{aboveTable?.(table)}
|
||||
|
||||
{!hasInitialData && !isLoading && (
|
||||
<TableWrapper
|
||||
wrapperComponent={wrapperComponent}
|
||||
wrapperProps={wrapperProps}
|
||||
>
|
||||
{getStartedCard}
|
||||
</TableWrapper>
|
||||
)}
|
||||
|
||||
{hasInitialData && !isLoading && (
|
||||
<TableWrapper
|
||||
wrapperComponent={wrapperComponent}
|
||||
wrapperProps={wrapperProps}
|
||||
>
|
||||
<TableWrapper
|
||||
wrapperComponent={wrapperComponent}
|
||||
wrapperProps={wrapperProps}
|
||||
>
|
||||
{isLoading ? (
|
||||
<TableContentSkeleton />
|
||||
) : !hasInitialData ? (
|
||||
getStartedCard
|
||||
) : (
|
||||
<TableComponent
|
||||
className={cn("relative mt-8", tableClassName)}
|
||||
className={cn("relative mt-6", tableClassName)}
|
||||
minimal={minimal}
|
||||
>
|
||||
{showHeader && as == "table" && (
|
||||
@@ -398,94 +505,99 @@ export function DataTableContent<TData, TValue>({
|
||||
)}
|
||||
>
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<AccordionItem
|
||||
value={row.original.id}
|
||||
asChild={true}
|
||||
key={row.original.id}
|
||||
>
|
||||
<>
|
||||
<TableRowComponent
|
||||
minimal={minimal}
|
||||
data-row-id={row.original.id}
|
||||
className={cn(
|
||||
(onRowClick || renderExpandedRow) &&
|
||||
"cursor-pointer relative group/accordion",
|
||||
rowClassName,
|
||||
)}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
data-accordion={
|
||||
accordion?.includes(row.original.id)
|
||||
? "opened"
|
||||
: "closed"
|
||||
}
|
||||
onClick={(e) => {
|
||||
if (renderExpandedRow) {
|
||||
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];
|
||||
}
|
||||
});
|
||||
table.getRowModel().rows.map((row) => {
|
||||
const expandedRow = renderExpandedRow?.(row.original);
|
||||
return (
|
||||
<AccordionItem
|
||||
value={row.original.id}
|
||||
asChild={true}
|
||||
key={row.id}
|
||||
>
|
||||
<>
|
||||
<TableRowComponent
|
||||
minimal={minimal}
|
||||
data-row-id={row.original.id}
|
||||
className={cn(
|
||||
(onRowClick || renderExpandedRow) &&
|
||||
"relative group/accordion",
|
||||
(onRowClick || expandedRow) && "cursor-pointer",
|
||||
rowClassName,
|
||||
)}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
data-accordion={
|
||||
accordion?.includes(row.original.id)
|
||||
? "opened"
|
||||
: "closed"
|
||||
}
|
||||
}}
|
||||
>
|
||||
<>
|
||||
{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"
|
||||
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];
|
||||
}
|
||||
></div>
|
||||
<div className={"relative z-[1]"}>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext(),
|
||||
)}
|
||||
</div>
|
||||
</TableCellComponent>
|
||||
))}
|
||||
</>
|
||||
</TableRowComponent>
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
<>
|
||||
{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>
|
||||
|
||||
{renderExpandedRow && (
|
||||
<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 && (
|
||||
<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"}
|
||||
>
|
||||
{renderExpandedRow(row.original)}
|
||||
</TableDataUnstyledComponent>
|
||||
</TableRowComponent>
|
||||
</AccordionContent>
|
||||
)}
|
||||
</>
|
||||
</AccordionItem>
|
||||
))
|
||||
<TableDataUnstyledComponent
|
||||
className={"w-full"}
|
||||
colSpan={row.getVisibleCells().length}
|
||||
>
|
||||
{expandedRow}
|
||||
</TableDataUnstyledComponent>
|
||||
</TableRowComponent>
|
||||
</AccordionContent>
|
||||
)}
|
||||
</>
|
||||
</AccordionItem>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<TableRowUnstyledComponent>
|
||||
<TableCellComponent
|
||||
@@ -499,14 +611,15 @@ export function DataTableContent<TData, TValue>({
|
||||
</TableBodyComponent>
|
||||
</Accordion>
|
||||
</TableComponent>
|
||||
</TableWrapper>
|
||||
)}
|
||||
)}
|
||||
</TableWrapper>
|
||||
|
||||
<div className={paginationClassName}>
|
||||
<DataTablePagination
|
||||
table={table}
|
||||
text={text}
|
||||
paginationPadding={paginationPaddingClassName}
|
||||
totalRecords={totalRecords}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -9,38 +9,66 @@ interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
setGlobalSearch: (value: string) => void;
|
||||
globalSearch?: string;
|
||||
className?: string;
|
||||
isLoading?: boolean;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
export default function DataTableGlobalSearch({
|
||||
setGlobalSearch,
|
||||
globalSearch,
|
||||
className = "min-w-[300px] max-w-[400px] grow",
|
||||
isLoading,
|
||||
onClick,
|
||||
...props
|
||||
}: Props) {
|
||||
}: Readonly<Props>) {
|
||||
const ref = React.useRef<HTMLInputElement>(null);
|
||||
const [inputValue, setInputValue] = useState(globalSearch || "");
|
||||
const debouncedValue = useDebounce(inputValue, 300);
|
||||
const debouncedValue = useDebounce(inputValue, 800);
|
||||
|
||||
// Call setGlobalSearch when debounced value changes
|
||||
useEffect(() => {
|
||||
setGlobalSearch(debouncedValue);
|
||||
}, [debouncedValue]);
|
||||
|
||||
useEffect(() => {
|
||||
if (globalSearch !== undefined && globalSearch !== inputValue) {
|
||||
setInputValue(globalSearch);
|
||||
}
|
||||
}, [globalSearch]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setInputValue(e.target.value);
|
||||
};
|
||||
|
||||
useHotkeys("mod+k", () => ref.current?.focus(), []);
|
||||
useHotkeys(
|
||||
"mod+k",
|
||||
() => {
|
||||
if (onClick) {
|
||||
onClick?.();
|
||||
} else {
|
||||
ref.current?.focus();
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<Input
|
||||
{...props}
|
||||
ref={ref}
|
||||
onFocus={(e) => {
|
||||
if (onClick) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onClick?.();
|
||||
}
|
||||
}}
|
||||
icon={<Search size={15} />}
|
||||
value={inputValue} // Shows immediate updates
|
||||
onChange={handleChange}
|
||||
maxWidthClass={className}
|
||||
customSuffix={<Kbd>⌘ K</Kbd>}
|
||||
disabled={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,78 +7,83 @@ import {
|
||||
ChevronsLeft,
|
||||
ChevronsRight,
|
||||
} from "lucide-react";
|
||||
import { useEffect } from "react";
|
||||
|
||||
interface DataTablePaginationProps<TData> {
|
||||
table: Table<TData>;
|
||||
text?: string;
|
||||
paginationPadding?: string;
|
||||
totalRecords?: number;
|
||||
}
|
||||
|
||||
export function DataTablePagination<TData>({
|
||||
table,
|
||||
text = "rows",
|
||||
paginationPadding = "px-8 py-8",
|
||||
totalRecords,
|
||||
}: DataTablePaginationProps<TData>) {
|
||||
const allRows = table.getFilteredRowModel().rows.length;
|
||||
const rowsPerPage = table.getState().pagination.pageSize;
|
||||
const currentPage = table.getState().pagination.pageIndex + 1;
|
||||
const isLastPage = currentPage === table.getPageCount();
|
||||
const showingFrom = (currentPage - 1) * rowsPerPage + 1;
|
||||
const showingTo = isLastPage ? allRows : showingFrom + rowsPerPage - 1;
|
||||
const pageCount = table.getPageCount();
|
||||
|
||||
// Reset page index if it's greater than the page count
|
||||
useEffect(() => {
|
||||
if (currentPage > pageCount) {
|
||||
table.setPageIndex(0);
|
||||
}
|
||||
}, []);
|
||||
const totalRows =
|
||||
totalRecords !== undefined
|
||||
? totalRecords
|
||||
: table.getFilteredRowModel().rows.length;
|
||||
|
||||
return pageCount > 1 ? (
|
||||
<div className={cn("flex items-center justify-between", paginationPadding)}>
|
||||
<div className="text-nb-gray-400">
|
||||
Showing{" "}
|
||||
<span className={"font-medium text-white"}>
|
||||
{showingFrom} to {showingTo}
|
||||
</span>{" "}
|
||||
of <span className={"font-medium text-white"}>{allRows}</span> {text}
|
||||
</div>
|
||||
<div className={"flex items-center gap-3"}>
|
||||
<div className="flex items-center space-x-2">
|
||||
<ButtonGroup>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.setPageIndex(0)}
|
||||
disabled={!table.getCanPreviousPage()}
|
||||
>
|
||||
<ChevronsLeft size={16} />
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.previousPage()}
|
||||
disabled={!table.getCanPreviousPage()}
|
||||
>
|
||||
<ChevronLeft size={18} />
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button>
|
||||
<div>
|
||||
{currentPage} of {pageCount}
|
||||
</div>
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.nextPage()}
|
||||
disabled={!table.getCanNextPage()}
|
||||
>
|
||||
<ChevronRight size={18} />
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
|
||||
disabled={!table.getCanNextPage()}
|
||||
>
|
||||
<ChevronsRight size={18} />
|
||||
</ButtonGroup.Button>
|
||||
</ButtonGroup>
|
||||
const showingFrom = totalRows === 0 ? 0 : (currentPage - 1) * rowsPerPage + 1;
|
||||
const showingTo = Math.min(currentPage * rowsPerPage, totalRows);
|
||||
|
||||
return (
|
||||
pageCount > 1 && (
|
||||
<div
|
||||
className={cn("flex items-center justify-between", paginationPadding)}
|
||||
>
|
||||
<div className="text-nb-gray-400">
|
||||
Showing{" "}
|
||||
<span className={"font-medium text-white"}>
|
||||
{showingFrom} to {showingTo}
|
||||
</span>{" "}
|
||||
of <span className={"font-medium text-white"}>{totalRows}</span>{" "}
|
||||
{text}
|
||||
</div>
|
||||
{pageCount > 1 && (
|
||||
<div className={"flex items-center gap-3"}>
|
||||
<div className="flex items-center space-x-2">
|
||||
<ButtonGroup>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.setPageIndex(0)}
|
||||
disabled={!table.getCanPreviousPage()}
|
||||
>
|
||||
<ChevronsLeft size={16} />
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.previousPage()}
|
||||
disabled={!table.getCanPreviousPage()}
|
||||
>
|
||||
<ChevronLeft size={18} />
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button>
|
||||
<div>
|
||||
{currentPage} of {pageCount}
|
||||
</div>
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.nextPage()}
|
||||
disabled={!table.getCanNextPage()}
|
||||
>
|
||||
<ChevronRight size={18} />
|
||||
</ButtonGroup.Button>
|
||||
<ButtonGroup.Button
|
||||
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
|
||||
disabled={!table.getCanNextPage()}
|
||||
>
|
||||
<ChevronsRight size={18} />
|
||||
</ButtonGroup.Button>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : null;
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,48 +8,54 @@ import { useState } from "react";
|
||||
interface Props<TData> {
|
||||
table: Table<TData>;
|
||||
onClick: () => void;
|
||||
hasServerSideFilters?: boolean;
|
||||
}
|
||||
|
||||
export default function DataTableResetFilterButton<TData>({
|
||||
table,
|
||||
onClick,
|
||||
hasServerSideFilters = undefined,
|
||||
}: Props<TData>) {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const isDisabled =
|
||||
table.getState().columnFilters.length <= 0 &&
|
||||
table.getState().globalFilter === "";
|
||||
|
||||
return !isDisabled ? (
|
||||
<Tooltip delayDuration={1}>
|
||||
<TooltipTrigger
|
||||
asChild={true}
|
||||
onMouseOver={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
className={"h-[42px]"}
|
||||
variant={"secondary"}
|
||||
disabled={isDisabled}
|
||||
onClick={onClick}
|
||||
const hasClientSideFilters =
|
||||
table.getState().globalFilter !== "" ||
|
||||
table.getState().columnFilters.length > 0;
|
||||
|
||||
const showButton = hasServerSideFilters ?? hasClientSideFilters;
|
||||
|
||||
return (
|
||||
showButton && (
|
||||
<Tooltip delayDuration={1}>
|
||||
<TooltipTrigger
|
||||
asChild={true}
|
||||
onMouseOver={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<FilterX size={16} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<Button
|
||||
className={"h-[42px]"}
|
||||
variant={"secondary"}
|
||||
onClick={onClick}
|
||||
>
|
||||
<FilterX size={16} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
|
||||
<TooltipContent
|
||||
sideOffset={10}
|
||||
className={"px-3 py-2"}
|
||||
onPointerDownOutside={(event) => {
|
||||
if (hovered) event.preventDefault();
|
||||
}}
|
||||
>
|
||||
<span className={"text-xs text-neutral-300"}>
|
||||
Reset Filters & Search
|
||||
</span>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null;
|
||||
<TooltipContent
|
||||
sideOffset={10}
|
||||
className={"px-3 py-2"}
|
||||
onPointerDownOutside={(event) => {
|
||||
if (hovered) event.preventDefault();
|
||||
}}
|
||||
>
|
||||
<span className={"text-xs text-neutral-300"}>
|
||||
Reset Filters & Search
|
||||
</span>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { cn } from "@utils/helpers";
|
||||
import * as React from "react";
|
||||
|
||||
export const GradientFadedBackground = () => {
|
||||
type Props = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export const GradientFadedBackground = ({ className }: Props) => {
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
"h-full w-full absolute left-0 top-0 rounded-md overflow-hidden z-0 pointer-events-none"
|
||||
}
|
||||
className={cn(
|
||||
"h-full w-full absolute left-0 top-0 rounded-md overflow-hidden z-0 pointer-events-none",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
|
||||
@@ -14,6 +14,7 @@ type Props = {
|
||||
onError?: (error: boolean) => void;
|
||||
error?: string;
|
||||
disabled?: boolean;
|
||||
showRemoveButton?: boolean;
|
||||
preventLeadingAndTrailingDots?: boolean;
|
||||
allowWildcard?: boolean;
|
||||
};
|
||||
@@ -44,6 +45,7 @@ export default function InputDomain({
|
||||
disabled,
|
||||
preventLeadingAndTrailingDots,
|
||||
allowWildcard = true,
|
||||
showRemoveButton = true,
|
||||
}: Readonly<Props>) {
|
||||
const [name, setName] = useState(value?.name || "");
|
||||
|
||||
@@ -88,14 +90,16 @@ export default function InputDomain({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
className={"h-[42px]"}
|
||||
variant={"default-outline"}
|
||||
onClick={onRemove}
|
||||
disabled={disabled}
|
||||
>
|
||||
<MinusCircleIcon size={15} />
|
||||
</Button>
|
||||
{showRemoveButton && (
|
||||
<Button
|
||||
className={"h-[42px]"}
|
||||
variant={"default-outline"}
|
||||
onClick={onRemove}
|
||||
disabled={disabled}
|
||||
>
|
||||
<MinusCircleIcon size={15} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import {
|
||||
import GroupBadge from "@components/ui/GroupBadge";
|
||||
import PeerBadge from "@components/ui/PeerBadge";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { orderBy } from "lodash";
|
||||
import { ArrowRightIcon } from "lucide-react";
|
||||
import { ArrowRightIcon, PencilLineIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { Group } from "@/interfaces/Group";
|
||||
import EmptyRow from "@/modules/common-table-rows/EmptyRow";
|
||||
|
||||
@@ -30,8 +30,17 @@ export default function MultipleGroups({
|
||||
onClick,
|
||||
className,
|
||||
}: Readonly<Props>) {
|
||||
if (!groups) return <EmptyRow />;
|
||||
const orderedGroups = orderBy(groups, ["peers_count", "name"], ["desc"]);
|
||||
const { permission } = usePermissions();
|
||||
|
||||
if (!groups || groups?.length === 0) return <EmptyRow />;
|
||||
const orderedGroups = groups.sort((a, b) => {
|
||||
if (a.name === "All") return 1;
|
||||
if (b.name === "All") return -1;
|
||||
const aPeerCount = a.peers_count ?? 0;
|
||||
const bPeerCount = b.peers_count ?? 0;
|
||||
if (aPeerCount !== bPeerCount) return bPeerCount - aPeerCount;
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
const firstGroup = orderedGroups.length > 0 ? orderedGroups[0] : undefined;
|
||||
const otherGroups = orderedGroups.length > 0 ? orderedGroups.slice(1) : [];
|
||||
|
||||
@@ -48,12 +57,22 @@ export default function MultipleGroups({
|
||||
data-cy={"multiple-groups"}
|
||||
onClick={onClick}
|
||||
>
|
||||
{firstGroup && <GroupBadge group={firstGroup} />}
|
||||
{firstGroup && (
|
||||
<GroupBadge
|
||||
group={firstGroup}
|
||||
className={
|
||||
permission.groups.update ? "group-hover:bg-nb-gray-800" : ""
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{otherGroups && otherGroups.length > 0 && (
|
||||
<Badge
|
||||
variant={"gray-ghost"}
|
||||
useHover={true}
|
||||
className={"px-3 gap-2 whitespace-nowrap"}
|
||||
className={cn(
|
||||
"px-3 gap-2 whitespace-nowrap",
|
||||
permission.groups.update ? "group-hover:bg-nb-gray-800" : "",
|
||||
)}
|
||||
>
|
||||
+ {otherGroups.length}
|
||||
</Badge>
|
||||
@@ -98,3 +117,15 @@ export default function MultipleGroups({
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export const TransparentEditIconButton = () => {
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
"h-[34px] w-[34px] !p-0 opacity-0 group-hover:opacity-100 flex items-center justify-center text-nb-gray-400 hover:text-nb-gray-100"
|
||||
}
|
||||
>
|
||||
<PencilLineIcon size={16} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import Button from "@components/Button";
|
||||
import Paragraph from "@components/Paragraph";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { FilterX } from "lucide-react";
|
||||
import React from "react";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import React, { useCallback } from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
|
||||
type Props = {
|
||||
@@ -10,6 +12,8 @@ type Props = {
|
||||
description?: string;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
hasFiltersApplied?: boolean;
|
||||
onResetFilters?: () => void;
|
||||
};
|
||||
export default function NoResults({
|
||||
icon,
|
||||
@@ -17,7 +21,32 @@ export default function NoResults({
|
||||
description = "We couldn't find any results. Please try a different search term or change your filters.",
|
||||
children,
|
||||
className,
|
||||
hasFiltersApplied = false,
|
||||
onResetFilters,
|
||||
}: Props) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const handleResetClick = useCallback(() => {
|
||||
if (onResetFilters) {
|
||||
onResetFilters();
|
||||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
const page_size = searchParams.get("page_size");
|
||||
|
||||
params.set("page", "1");
|
||||
|
||||
if (page_size) {
|
||||
params.set("page_size", page_size);
|
||||
}
|
||||
|
||||
const newUrl = `${pathname}?${params.toString()}`;
|
||||
router.push(newUrl);
|
||||
}
|
||||
}, [onResetFilters, router, pathname, searchParams]);
|
||||
|
||||
return (
|
||||
<div className={cn("relative overflow-hidden", className)}>
|
||||
<div
|
||||
@@ -49,6 +78,16 @@ export default function NoResults({
|
||||
<Paragraph className={"justify-center my-2 !text-nb-gray-400"}>
|
||||
{description}
|
||||
</Paragraph>
|
||||
{hasFiltersApplied && onResetFilters && (
|
||||
<Button
|
||||
onClick={handleResetClick}
|
||||
variant="secondary"
|
||||
className="mt-4"
|
||||
>
|
||||
<FilterX size={16} />
|
||||
Reset Filters & Search
|
||||
</Button>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,12 +8,12 @@ export const NotificationCountBadge = ({ count = 0 }: Props) => {
|
||||
return count ? (
|
||||
<div
|
||||
className={cn(
|
||||
count <= 9 ? "w-5 h-5" : "py-2.5 px-2",
|
||||
"relative bg-netbird flex items-center justify-center rounded-full text-white !leading-[0] text-xs font-semibold",
|
||||
count <= 9 ? "w-4 h-4" : "py-2 px-1.5",
|
||||
"relative bg-netbird flex items-center justify-center rounded-full text-white !leading-[0] text-[0.6rem] font-semibold",
|
||||
)}
|
||||
>
|
||||
<span className="animate-ping absolute left-0 inline-flex h-full w-full rounded-full bg-netbird opacity-20"></span>
|
||||
{count || 0}
|
||||
<span className={"relative -left-[0.5px]"}>{count || 0}</span>
|
||||
</div>
|
||||
) : null;
|
||||
};
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import Badge from "@components/Badge";
|
||||
import { cn } from "@utils/helpers";
|
||||
import React, { useEffect } from "react";
|
||||
import React, { useEffect, useMemo } from "react";
|
||||
import LongArrowLeftIcon from "@/assets/icons/LongArrowLeftIcon";
|
||||
import { PolicyRuleResource } from "@/interfaces/Policy";
|
||||
|
||||
type Props = {
|
||||
disabled?: boolean;
|
||||
value: Direction;
|
||||
onChange: (value: Direction) => void;
|
||||
className?: string;
|
||||
destinationResource?: PolicyRuleResource;
|
||||
};
|
||||
|
||||
export type Direction = "bi" | "in" | "out";
|
||||
@@ -17,31 +19,8 @@ export default function PolicyDirection({
|
||||
value,
|
||||
onChange,
|
||||
className,
|
||||
}: Props) {
|
||||
const toggleIn = () => {
|
||||
if (value == "in") {
|
||||
onChange("out");
|
||||
return;
|
||||
}
|
||||
if (value == "bi") {
|
||||
onChange("out");
|
||||
} else {
|
||||
onChange("bi");
|
||||
}
|
||||
};
|
||||
|
||||
const toggleOut = () => {
|
||||
if (value == "out") {
|
||||
onChange("in");
|
||||
return;
|
||||
}
|
||||
if (value == "bi") {
|
||||
onChange("in");
|
||||
} else {
|
||||
onChange("bi");
|
||||
}
|
||||
};
|
||||
|
||||
destinationResource,
|
||||
}: Readonly<Props>) {
|
||||
const toggleDirection = () => {
|
||||
if (value == "bi") {
|
||||
onChange("in");
|
||||
@@ -55,8 +34,34 @@ export default function PolicyDirection({
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [disabled]);
|
||||
|
||||
const topBadgeClass = useMemo(() => {
|
||||
if (destinationResource) return "blueDark";
|
||||
if (value === "bi") return "green";
|
||||
if (value === "in") return "blueDark";
|
||||
return "gray";
|
||||
}, [value, destinationResource]);
|
||||
|
||||
const topArrowClass = useMemo(() => {
|
||||
if (destinationResource) return "fill-sky-500";
|
||||
if (value === "bi") return "fill-green-500";
|
||||
if (value === "in") return "fill-sky-500";
|
||||
return "fill-gray-500";
|
||||
}, [value, destinationResource]);
|
||||
|
||||
const bottomBadgeClass = useMemo(() => {
|
||||
if (destinationResource) return "gray";
|
||||
if (value === "bi") return "green";
|
||||
return "gray";
|
||||
}, [value, destinationResource]);
|
||||
|
||||
const bottomArrowClass = useMemo(() => {
|
||||
if (destinationResource) return "fill-gray-500";
|
||||
if (value === "bi") return "fill-green-500";
|
||||
return "fill-gray-500";
|
||||
}, [value, destinationResource]);
|
||||
|
||||
return (
|
||||
<div
|
||||
<button
|
||||
className={cn(
|
||||
"flex flex-col gap-2 mt-[23px] cursor-pointer select-none",
|
||||
disabled && "opacity-50 pointer-events-none",
|
||||
@@ -66,39 +71,20 @@ export default function PolicyDirection({
|
||||
onClick={toggleDirection}
|
||||
data-cy={"policy-direction"}
|
||||
>
|
||||
<Badge
|
||||
variant={value == "bi" ? "green" : value == "in" ? "blueDark" : "gray"}
|
||||
className={"px-4 py-1"}
|
||||
>
|
||||
<Badge variant={topBadgeClass} className={"px-4 py-1"}>
|
||||
<LongArrowLeftIcon
|
||||
size={40}
|
||||
autoHeight={true}
|
||||
className={cn(
|
||||
value == "bi"
|
||||
? "fill-green-500"
|
||||
: value == "in"
|
||||
? "fill-sky-500"
|
||||
: "fill-gray-500",
|
||||
"rotate-180",
|
||||
)}
|
||||
className={cn(topArrowClass, "rotate-180")}
|
||||
/>
|
||||
</Badge>
|
||||
<Badge
|
||||
variant={value == "bi" ? "green" : value == "out" ? "blueDark" : "gray"}
|
||||
className={"px-4 py-1"}
|
||||
>
|
||||
<Badge variant={bottomBadgeClass} className={"px-4 py-1"}>
|
||||
<LongArrowLeftIcon
|
||||
size={40}
|
||||
autoHeight={true}
|
||||
className={cn(
|
||||
value == "bi"
|
||||
? "fill-green-500"
|
||||
: value == "out"
|
||||
? "fill-sky-500"
|
||||
: "fill-gray-500",
|
||||
)}
|
||||
className={cn(bottomArrowClass)}
|
||||
/>
|
||||
</Badge>
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ const PeerContext = React.createContext(
|
||||
loginExpiration?: boolean;
|
||||
inactivityExpiration?: boolean;
|
||||
approval_required?: boolean;
|
||||
ip?: string;
|
||||
}) => Promise<Peer>;
|
||||
openSSHDialog: () => Promise<boolean>;
|
||||
deletePeer: () => void;
|
||||
@@ -36,7 +37,7 @@ const PeerContext = React.createContext(
|
||||
export default function PeerProvider({ children, peer }: Props) {
|
||||
const user = usePeerUser(peer);
|
||||
const { peerGroups, isLoading } = usePeerGroups(peer);
|
||||
const peerRequest = useApiCall<Peer>("/peers");
|
||||
const peerRequest = useApiCall<Peer>("/peers", true);
|
||||
const { confirm } = useDialog();
|
||||
const { mutate } = useSWRConfig();
|
||||
|
||||
@@ -68,6 +69,7 @@ export default function PeerProvider({ children, peer }: Props) {
|
||||
loginExpiration?: boolean;
|
||||
inactivityExpiration?: boolean;
|
||||
approval_required?: boolean;
|
||||
ip?: string;
|
||||
}) => {
|
||||
return peerRequest.put(
|
||||
{
|
||||
@@ -86,6 +88,7 @@ export default function PeerProvider({ children, peer }: Props) {
|
||||
props?.approval_required == undefined
|
||||
? undefined
|
||||
: props.approval_required,
|
||||
ip: props.ip != undefined ? props.ip : undefined,
|
||||
},
|
||||
`/${peer.id}`,
|
||||
);
|
||||
|
||||
@@ -61,6 +61,7 @@ export default function RoutesProvider({ children }: Readonly<Props>) {
|
||||
: toUpdate.access_control_groups ??
|
||||
route.access_control_groups ??
|
||||
undefined,
|
||||
skip_auto_apply: toUpdate.skip_auto_apply ?? route.skip_auto_apply ?? true,
|
||||
},
|
||||
`/${route.id}`,
|
||||
)
|
||||
@@ -94,6 +95,7 @@ export default function RoutesProvider({ children }: Readonly<Props>) {
|
||||
masquerade: route.masquerade,
|
||||
groups: route.groups || [],
|
||||
access_control_groups: route?.access_control_groups || undefined,
|
||||
skip_auto_apply: route.skip_auto_apply ?? true,
|
||||
})
|
||||
.then((route) => {
|
||||
mutate("/routes");
|
||||
|
||||
@@ -62,18 +62,24 @@ const UserProfileProvider = ({ children }: Props) => {
|
||||
}
|
||||
}, [user, error, users, isLoading, isAllUsersLoading]);
|
||||
|
||||
|
||||
const data = useMemo(() => {
|
||||
return {
|
||||
loggedInUser,
|
||||
};
|
||||
}, [loggedInUser]);
|
||||
|
||||
return !isLoading && loggedInUser ? (
|
||||
// Show loading only when we're still loading and don't have user data
|
||||
if (isLoading || !loggedInUser) {
|
||||
return <FullScreenLoading />;
|
||||
}
|
||||
|
||||
// For blocked or pending approval users, we still need to provide the context
|
||||
// so they can access their user data on the blocked page
|
||||
return (
|
||||
<UserProfileContext.Provider value={data}>
|
||||
<PermissionsProvider user={loggedInUser}>{children}</PermissionsProvider>
|
||||
</UserProfileContext.Provider>
|
||||
) : (
|
||||
<FullScreenLoading />
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
type SetStateAction,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useEventCallback } from "@/hooks/useEventCallback";
|
||||
@@ -20,8 +21,10 @@ export function useLocalStorage<T>(
|
||||
key: string,
|
||||
initialValue: T,
|
||||
enabled: boolean = true,
|
||||
overrideValue?: T,
|
||||
): [T, SetValue<T>] {
|
||||
const [tempValue, setTempValue] = useState(initialValue);
|
||||
const [tempValue, setTempValue] = useState(overrideValue ?? initialValue);
|
||||
const isInitialRender = useRef(true);
|
||||
|
||||
// Get from local storage then
|
||||
// parse stored json or return initialValue
|
||||
@@ -31,6 +34,11 @@ export function useLocalStorage<T>(
|
||||
return initialValue;
|
||||
}
|
||||
|
||||
if (isInitialRender.current && overrideValue !== undefined) {
|
||||
isInitialRender.current = false;
|
||||
return overrideValue;
|
||||
}
|
||||
|
||||
try {
|
||||
const item = window.localStorage.getItem(key);
|
||||
return item ? (parseJSON(item) as T) : initialValue;
|
||||
@@ -95,6 +103,13 @@ export function useLocalStorage<T>(
|
||||
[key, readValue],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (overrideValue) {
|
||||
setValue(overrideValue);
|
||||
setStoredValue(overrideValue);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// this only works for other documents, not the current one
|
||||
useEventListener("storage", handleStorageChange);
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ export function useSearch<T>(
|
||||
string,
|
||||
(event: ChangeEvent<HTMLInputElement> | string) => void,
|
||||
(querty: string) => void,
|
||||
boolean,
|
||||
] {
|
||||
const [isSearching, setIsSearching] = useState<boolean>(false);
|
||||
const isMounted = useRef<boolean>(false);
|
||||
const [query, setQuery] = useState<string>(initialQuery);
|
||||
const prevCollection = usePrevious(collection);
|
||||
@@ -62,6 +64,7 @@ export function useSearch<T>(
|
||||
setFilteredCollection(
|
||||
filterCollection(collection, predicate, query, filter),
|
||||
);
|
||||
setIsSearching(false);
|
||||
}
|
||||
},
|
||||
debounce,
|
||||
@@ -75,8 +78,10 @@ export function useSearch<T>(
|
||||
!isEqual(predicate, prevPredicate) ||
|
||||
!isEqual(query, prevQuery) ||
|
||||
!isEqual(filter, prevFilter)
|
||||
)
|
||||
) {
|
||||
if (!isEqual(query, prevQuery)) setIsSearching(true);
|
||||
debouncedFilterCollection(collection, predicate, query, filter);
|
||||
}
|
||||
}, [collection, predicate, query, filter]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -87,5 +92,5 @@ export function useSearch<T>(
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [filteredCollection, query, handleChange, setQuery];
|
||||
return [filteredCollection, query, handleChange, setQuery, isSearching];
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface Account {
|
||||
settings: {
|
||||
extra: {
|
||||
peer_approval_enabled: boolean;
|
||||
user_approval_required: boolean;
|
||||
};
|
||||
peer_login_expiration_enabled: boolean;
|
||||
peer_login_expiration: number;
|
||||
@@ -19,6 +20,7 @@ export interface Account {
|
||||
regular_users_view_blocked: boolean;
|
||||
routing_peer_dns_resolution_enabled: boolean;
|
||||
dns_domain: string;
|
||||
network_range?: string;
|
||||
lazy_connection_enabled: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -104,4 +104,50 @@ export const NameserverPresets: Record<string, NameserverGroup> = {
|
||||
enabled: true,
|
||||
search_domains_enabled: false,
|
||||
},
|
||||
DNS0: {
|
||||
name: "DNS0.EU",
|
||||
description: "DNS0.EU DNS Servers",
|
||||
primary: true,
|
||||
domains: [],
|
||||
nameservers: [
|
||||
{
|
||||
ip: "193.110.81.0",
|
||||
ns_type: "udp",
|
||||
port: 53,
|
||||
id: "1",
|
||||
},
|
||||
{
|
||||
ip: "185.253.5.0",
|
||||
ns_type: "udp",
|
||||
port: 53,
|
||||
id: "2",
|
||||
},
|
||||
],
|
||||
groups: [],
|
||||
enabled: true,
|
||||
search_domains_enabled: false,
|
||||
},
|
||||
DNS0Zero: {
|
||||
name: "DNS0.EU Zero",
|
||||
description: "DNS0.EU Zero DNS Servers",
|
||||
primary: true,
|
||||
domains: [],
|
||||
nameservers: [
|
||||
{
|
||||
ip: "193.110.81.9",
|
||||
ns_type: "udp",
|
||||
port: 53,
|
||||
id: "1",
|
||||
},
|
||||
{
|
||||
ip: "185.253.5.9",
|
||||
ns_type: "udp",
|
||||
port: 53,
|
||||
id: "2",
|
||||
},
|
||||
],
|
||||
groups: [],
|
||||
enabled: true,
|
||||
search_domains_enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -22,10 +22,16 @@ export interface PolicyRule {
|
||||
action: string;
|
||||
protocol: Protocol;
|
||||
ports: string[];
|
||||
port_ranges?: PortRange[];
|
||||
sourceResource?: PolicyRuleResource;
|
||||
destinationResource?: PolicyRuleResource;
|
||||
}
|
||||
|
||||
export interface PortRange {
|
||||
start: number;
|
||||
end: number;
|
||||
}
|
||||
|
||||
export interface PolicyRuleResource {
|
||||
id: string;
|
||||
type: "domain" | "host" | "subnet" | undefined;
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface Route {
|
||||
groups: string[];
|
||||
keep_route?: boolean;
|
||||
access_control_groups?: string[];
|
||||
skip_auto_apply?: boolean;
|
||||
// Frontend only
|
||||
peer_groups?: string[];
|
||||
routesGroups?: string[];
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface User {
|
||||
is_current?: boolean;
|
||||
is_service_user?: boolean;
|
||||
is_blocked?: boolean;
|
||||
pending_approval?: boolean;
|
||||
last_login?: Date;
|
||||
permissions: Permissions;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import Button from "@components/Button";
|
||||
import { NetBirdLogo } from "@components/NetBirdLogo";
|
||||
import { AnnouncementBanner } from "@components/ui/AnnouncementBanner";
|
||||
import UserDropdown from "@components/ui/UserDropdown";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { MenuIcon, PanelLeftCloseIcon, PanelLeftOpenIcon } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/navigation";
|
||||
import React, { useMemo } from "react";
|
||||
import NetBirdLogo from "@/assets/netbird.svg";
|
||||
import NetBirdLogoFull from "@/assets/netbird-full.svg";
|
||||
import React from "react";
|
||||
import { useAnnouncement } from "@/contexts/AnnouncementProvider";
|
||||
import { useApplicationContext } from "@/contexts/ApplicationProvider";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
@@ -18,25 +16,6 @@ export const headerHeight = 75;
|
||||
|
||||
export default function NavbarWithDropdown() {
|
||||
const router = useRouter();
|
||||
const Logo = useMemo(() => {
|
||||
return (
|
||||
<>
|
||||
<Image
|
||||
src={NetBirdLogoFull}
|
||||
height={22}
|
||||
alt={"NetBird Logo"}
|
||||
className={"hidden md:block"}
|
||||
/>
|
||||
<Image
|
||||
src={NetBirdLogo}
|
||||
width={30}
|
||||
alt={"NetBird Logo"}
|
||||
className={"md:hidden ml-4"}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}, []);
|
||||
|
||||
const { toggleMobileNav } = useApplicationContext();
|
||||
const { bannerHeight } = useAnnouncement();
|
||||
const { isRestricted } = usePermissions();
|
||||
@@ -78,7 +57,7 @@ export default function NavbarWithDropdown() {
|
||||
"cursor-pointer hover:opacity-70 transition-all mr-auto"
|
||||
}
|
||||
>
|
||||
{Logo}
|
||||
<NetBirdLogo />
|
||||
</button>
|
||||
<ToggleCollapsableNavigationButton />
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Button from "@components/Button";
|
||||
import { Callout } from "@components/Callout";
|
||||
import FancyToggleSwitch from "@components/FancyToggleSwitch";
|
||||
import HelpText from "@components/HelpText";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
@@ -29,6 +30,7 @@ import { Textarea } from "@components/Textarea";
|
||||
import PolicyDirection from "@components/ui/PolicyDirection";
|
||||
import { cn } from "@utils/helpers";
|
||||
import {
|
||||
AlertCircleIcon,
|
||||
ArrowRightLeft,
|
||||
ExternalLinkIcon,
|
||||
FolderDown,
|
||||
@@ -130,11 +132,13 @@ export function AccessControlModalContent({
|
||||
const { permission } = usePermissions();
|
||||
|
||||
const {
|
||||
portAndDirectionDisabled,
|
||||
portDisabled,
|
||||
destinationGroups,
|
||||
direction,
|
||||
ports,
|
||||
sourceGroups,
|
||||
destinationHasResources,
|
||||
destinationOnlyResources,
|
||||
setSourceGroups,
|
||||
setDestinationGroups,
|
||||
setPorts,
|
||||
@@ -154,6 +158,9 @@ export function AccessControlModalContent({
|
||||
getPolicyData,
|
||||
destinationResource,
|
||||
setDestinationResource,
|
||||
portRanges,
|
||||
setPortRanges,
|
||||
hasPortSupport,
|
||||
} = useAccessControl({
|
||||
policy,
|
||||
postureCheckTemplates,
|
||||
@@ -166,15 +173,13 @@ export function AccessControlModalContent({
|
||||
const [tab, setTab] = useState(() => {
|
||||
if (!cell) return "policy";
|
||||
if (cell == "posture_checks") return "posture_checks";
|
||||
if (cell == "name") return "general";
|
||||
return "policy";
|
||||
});
|
||||
|
||||
const continuePostureChecksDisabled = useMemo(() => {
|
||||
if (direction != "bi" && ports.length == 0) return true;
|
||||
if (sourceGroups.length > 0 && destinationResource) return false;
|
||||
if (sourceGroups.length == 0 || destinationGroups.length == 0) return true;
|
||||
}, [sourceGroups, destinationGroups, direction, ports, destinationResource]);
|
||||
}, [sourceGroups, destinationGroups, destinationResource]);
|
||||
|
||||
const submitDisabled = useMemo(() => {
|
||||
if (name.length == 0) return true;
|
||||
@@ -183,14 +188,9 @@ export function AccessControlModalContent({
|
||||
|
||||
const handleProtocolChange = (p: Protocol) => {
|
||||
setProtocol(p);
|
||||
if (p == "icmp") {
|
||||
if (!hasPortSupport(p)) {
|
||||
setPorts([]);
|
||||
}
|
||||
if (p == "all") {
|
||||
setPorts([]);
|
||||
}
|
||||
if (p == "tcp" || p == "udp") {
|
||||
setDirection("in");
|
||||
setPortRanges([]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -299,7 +299,8 @@ export function AccessControlModalContent({
|
||||
<PolicyDirection
|
||||
value={direction}
|
||||
onChange={setDirection}
|
||||
disabled={portAndDirectionDisabled}
|
||||
disabled={destinationOnlyResources}
|
||||
destinationResource={destinationResource}
|
||||
/>
|
||||
|
||||
<div className={"w-full self-start"}>
|
||||
@@ -327,10 +328,28 @@ export function AccessControlModalContent({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{destinationHasResources &&
|
||||
!destinationOnlyResources &&
|
||||
direction === "bi" && (
|
||||
<Callout
|
||||
variant={"warning"}
|
||||
icon={
|
||||
<AlertCircleIcon
|
||||
size={14}
|
||||
className={"shrink-0 relative top-[3px] text-netbird"}
|
||||
/>
|
||||
}
|
||||
className="mb-4"
|
||||
>
|
||||
Some destination groups contain resources. Resources only
|
||||
support incoming traffic and cannot initiate connections.
|
||||
</Callout>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"mb-2",
|
||||
portAndDirectionDisabled && "opacity-30 pointer-events-none",
|
||||
portDisabled && "opacity-30 pointer-events-none",
|
||||
)}
|
||||
>
|
||||
<div>
|
||||
@@ -340,15 +359,17 @@ export function AccessControlModalContent({
|
||||
</Label>
|
||||
<HelpText>
|
||||
Allow network traffic and access only to specified ports.
|
||||
Select ports between 1 and 65535.
|
||||
Select ports or port ranges between 1 and 65535.
|
||||
</HelpText>
|
||||
</div>
|
||||
<div className={""}>
|
||||
<PortSelector
|
||||
showAll={direction == "bi"}
|
||||
values={ports}
|
||||
onChange={setPorts}
|
||||
disabled={portAndDirectionDisabled}
|
||||
showAll={true}
|
||||
ports={ports}
|
||||
onPortsChange={setPorts}
|
||||
portRanges={portRanges}
|
||||
onPortRangesChange={setPortRanges}
|
||||
disabled={portDisabled}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,17 +7,20 @@ import { Policy } from "@/interfaces/Policy";
|
||||
type Props = {
|
||||
policy: Policy;
|
||||
};
|
||||
export default function AccessControlDirectionCell({ policy }: Props) {
|
||||
export default function AccessControlDirectionCell({
|
||||
policy,
|
||||
}: Readonly<Props>) {
|
||||
const firstRule = useMemo(() => {
|
||||
if (policy.rules.length > 0) return policy.rules[0];
|
||||
return undefined;
|
||||
}, [policy]);
|
||||
|
||||
const bidirectional = firstRule ? firstRule.bidirectional : false;
|
||||
const isSingleResource = !!firstRule?.destinationResource;
|
||||
|
||||
return (
|
||||
<div className={"flex h-full"}>
|
||||
{bidirectional ? (
|
||||
{bidirectional && !isSingleResource ? (
|
||||
<Badge variant={"green"} className={"py-2 px-4"}>
|
||||
<LongArrowBidirectionalIcon
|
||||
size={60}
|
||||
|
||||
@@ -5,29 +5,45 @@ import {
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@components/Tooltip";
|
||||
import { orderBy } from "lodash";
|
||||
import React, { useMemo } from "react";
|
||||
import { Policy } from "@/interfaces/Policy";
|
||||
|
||||
type Props = {
|
||||
policy: Policy;
|
||||
};
|
||||
export default function AccessControlPortsCell({ policy }: Props) {
|
||||
const firstRule = useMemo(() => {
|
||||
|
||||
export default function AccessControlPortsCell({ policy }: Readonly<Props>) {
|
||||
const rule = useMemo(() => {
|
||||
if (policy.rules.length > 0) return policy.rules[0];
|
||||
return undefined;
|
||||
}, [policy]);
|
||||
|
||||
const hasPorts = firstRule?.ports && firstRule?.ports.length > 0;
|
||||
const hasPorts = rule?.ports && rule?.ports?.length > 0;
|
||||
const hasPortRanges = rule?.port_ranges && rule?.port_ranges?.length > 0;
|
||||
const hasAnyPorts = hasPorts || hasPortRanges;
|
||||
|
||||
const allPorts = useMemo(() => {
|
||||
const ports = rule?.ports ?? [];
|
||||
const portRanges =
|
||||
rule?.port_ranges?.map((r) => {
|
||||
if (r.start === r.end) return `${r.start}`;
|
||||
return `${r.start}-${r.end}`;
|
||||
}) ?? [];
|
||||
return orderBy(
|
||||
[...portRanges, ...ports],
|
||||
[(p) => Number(p.split("-")[0])],
|
||||
["asc"],
|
||||
);
|
||||
}, [rule]);
|
||||
|
||||
const firstTwoPorts = useMemo(() => {
|
||||
if (!hasPorts) return [];
|
||||
return firstRule?.ports.slice(0, 2) ?? [];
|
||||
}, [hasPorts, firstRule]);
|
||||
return allPorts?.slice(0, 2) ?? [];
|
||||
}, [allPorts]);
|
||||
|
||||
const otherPorts = useMemo(() => {
|
||||
if (!hasPorts) return [];
|
||||
return firstRule?.ports.slice(2) ?? [];
|
||||
}, [hasPorts, firstRule]);
|
||||
return allPorts?.slice(2) ?? [];
|
||||
}, [allPorts]);
|
||||
|
||||
return (
|
||||
<div className={"flex-1"}>
|
||||
@@ -35,7 +51,7 @@ export default function AccessControlPortsCell({ policy }: Props) {
|
||||
<Tooltip delayDuration={1}>
|
||||
<TooltipTrigger asChild={true}>
|
||||
<div className={"inline-flex items-center gap-2"}>
|
||||
{!hasPorts && (
|
||||
{!hasAnyPorts && (
|
||||
<Badge
|
||||
variant={"gray"}
|
||||
className={"uppercase tracking-wider font-medium"}
|
||||
@@ -44,20 +60,19 @@ export default function AccessControlPortsCell({ policy }: Props) {
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
{firstTwoPorts &&
|
||||
firstTwoPorts.map((port) => {
|
||||
return (
|
||||
<Badge
|
||||
key={port}
|
||||
variant={"gray"}
|
||||
className={
|
||||
"px-3 gap-2 whitespace-nowrap uppercase tracking-wider font-medium"
|
||||
}
|
||||
>
|
||||
{port}
|
||||
</Badge>
|
||||
);
|
||||
})}
|
||||
{firstTwoPorts?.map((port) => {
|
||||
return (
|
||||
<Badge
|
||||
key={port}
|
||||
variant={"gray"}
|
||||
className={
|
||||
"px-3 gap-2 whitespace-nowrap uppercase tracking-wider font-medium"
|
||||
}
|
||||
>
|
||||
{port}
|
||||
</Badge>
|
||||
);
|
||||
})}
|
||||
|
||||
{otherPorts && otherPorts.length > 0 && (
|
||||
<Badge
|
||||
@@ -73,9 +88,17 @@ export default function AccessControlPortsCell({ policy }: Props) {
|
||||
</TooltipTrigger>
|
||||
{otherPorts && otherPorts.length > 0 && (
|
||||
<TooltipContent>
|
||||
<div className={"flex flex-col gap-2 items-start mt-3 mb-2"}>
|
||||
<div
|
||||
className={
|
||||
"flex gap-2 items-start mt-3 mb-2 flex-wrap max-w-sm"
|
||||
}
|
||||
>
|
||||
{otherPorts.map((port) => {
|
||||
return <Badge key={port}>{port}</Badge>;
|
||||
return (
|
||||
<Badge key={port} variant={"gray"}>
|
||||
{port}
|
||||
</Badge>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</TooltipContent>
|
||||
|
||||
@@ -10,7 +10,7 @@ import GetStartedTest from "@components/ui/GetStartedTest";
|
||||
import type { ColumnDef, SortingState } from "@tanstack/react-table";
|
||||
import { removeAllSpaces } from "@utils/helpers";
|
||||
import { ExternalLinkIcon, PlusCircle } from "lucide-react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
import React, { useState } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import AccessControlIcon from "@/assets/icons/AccessControlIcon";
|
||||
@@ -162,6 +162,12 @@ export const AccessControlTableColumns: ColumnDef<Policy>[] = [
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
filterFn: "exactMatch",
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
accessorKey: "id",
|
||||
header: "",
|
||||
cell: ({ cell }) => <AccessControlActionCell policy={cell.row.original} />,
|
||||
@@ -176,6 +182,8 @@ export default function AccessControlTable({
|
||||
const { mutate } = useSWRConfig();
|
||||
const path = usePathname();
|
||||
const { permission } = usePermissions();
|
||||
const params = useSearchParams();
|
||||
const idParam = params.get("id") ?? undefined;
|
||||
|
||||
// Default sorting state of the table
|
||||
const [sorting, setSorting] = useLocalStorage<SortingState>(
|
||||
@@ -205,12 +213,25 @@ export default function AccessControlTable({
|
||||
<DataTable
|
||||
headingTarget={headingTarget}
|
||||
isLoading={isLoading}
|
||||
keepStateInLocalStorage={!idParam}
|
||||
initialSearch={idParam ? "" : undefined}
|
||||
initialFilters={
|
||||
idParam
|
||||
? [
|
||||
{
|
||||
id: "id",
|
||||
value: idParam,
|
||||
},
|
||||
]
|
||||
: undefined
|
||||
}
|
||||
text={"Access Control Policies"}
|
||||
sorting={sorting}
|
||||
setSorting={setSorting}
|
||||
columns={AccessControlTableColumns}
|
||||
columnVisibility={{
|
||||
description: false,
|
||||
id: false,
|
||||
}}
|
||||
data={policies}
|
||||
onRowClick={(row, cell) => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { usePolicies } from "@/contexts/PoliciesProvider";
|
||||
import { Group } from "@/interfaces/Group";
|
||||
import { Policy, Protocol } from "@/interfaces/Policy";
|
||||
import { Policy, PortRange, Protocol } from "@/interfaces/Policy";
|
||||
import { PostureCheck } from "@/interfaces/PostureCheck";
|
||||
import useGroupHelper from "@/modules/groups/useGroupHelper";
|
||||
import { usePostureCheck } from "@/modules/posture-checks/usePostureCheck";
|
||||
@@ -83,13 +83,22 @@ export const useAccessControl = ({
|
||||
return [];
|
||||
});
|
||||
|
||||
const [portRanges, setPortRanges] = useState<PortRange[]>(() => {
|
||||
if (!firstRule) return [];
|
||||
if (firstRule.port_ranges == undefined) return [];
|
||||
if (firstRule.port_ranges.length > 0) {
|
||||
return firstRule.port_ranges;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
const [protocol, setProtocol] = useState<Protocol>(
|
||||
firstRule ? firstRule.protocol : "all",
|
||||
);
|
||||
const [direction, setDirection] = useState<Direction>(() => {
|
||||
if (firstRule && firstRule?.bidirectional) return "bi";
|
||||
if (firstRule && firstRule?.bidirectional == false) return "in";
|
||||
return "bi";
|
||||
if (!firstRule) return "bi";
|
||||
if (firstRule.bidirectional) return "bi";
|
||||
return "in";
|
||||
});
|
||||
const [name, setName] = useState(policy?.name || initialName || "");
|
||||
const [description, setDescription] = useState(
|
||||
@@ -139,6 +148,11 @@ export const useAccessControl = ({
|
||||
destinations = tmp;
|
||||
}
|
||||
|
||||
const [newPorts, newPortRanges] = parseAccessControlPorts(
|
||||
ports,
|
||||
portRanges,
|
||||
);
|
||||
|
||||
return {
|
||||
name,
|
||||
description,
|
||||
@@ -155,7 +169,8 @@ export const useAccessControl = ({
|
||||
action: "accept",
|
||||
protocol,
|
||||
enabled,
|
||||
ports: ports.length > 0 ? ports.map((p) => p.toString()) : undefined,
|
||||
ports: newPorts,
|
||||
port_ranges: newPortRanges,
|
||||
},
|
||||
],
|
||||
} as Policy;
|
||||
@@ -206,6 +221,11 @@ export const useAccessControl = ({
|
||||
destinations = tmp;
|
||||
}
|
||||
|
||||
const [newPorts, newPortRanges] = parseAccessControlPorts(
|
||||
ports,
|
||||
portRanges,
|
||||
);
|
||||
|
||||
const policyObj = {
|
||||
name,
|
||||
description,
|
||||
@@ -224,7 +244,8 @@ export const useAccessControl = ({
|
||||
sources,
|
||||
destinations: destinationResource ? undefined : destinations,
|
||||
destinationResource: destinationResource || undefined,
|
||||
ports: ports.length > 0 ? ports.map((p) => p.toString()) : undefined,
|
||||
ports: newPorts,
|
||||
port_ranges: newPortRanges,
|
||||
},
|
||||
],
|
||||
} as Policy;
|
||||
@@ -252,7 +273,52 @@ export const useAccessControl = ({
|
||||
}
|
||||
};
|
||||
|
||||
const portAndDirectionDisabled = protocol == "icmp" || protocol == "all";
|
||||
const hasPortSupport = (p: Protocol) => p === "tcp" || p === "udp";
|
||||
const portDisabled = !hasPortSupport(protocol);
|
||||
|
||||
const destinationHasResources = useMemo(() => {
|
||||
if (destinationResource) return true;
|
||||
|
||||
return destinationGroups.some((group) => {
|
||||
if (group.resources_count !== undefined) {
|
||||
return group.resources_count > 0;
|
||||
}
|
||||
if (group.resources && Array.isArray(group.resources)) {
|
||||
return group.resources.length > 0;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}, [destinationGroups, destinationResource]);
|
||||
|
||||
const destinationOnlyResources = useMemo(() => {
|
||||
if (destinationResource) return true;
|
||||
|
||||
return (
|
||||
destinationGroups.length > 0 &&
|
||||
destinationGroups.every((group) => {
|
||||
const hasPeers =
|
||||
group.peers_count !== undefined
|
||||
? group.peers_count > 0
|
||||
: group.peers &&
|
||||
Array.isArray(group.peers) &&
|
||||
group.peers.length > 0;
|
||||
const hasResources =
|
||||
group.resources_count !== undefined
|
||||
? group.resources_count > 0
|
||||
: group.resources &&
|
||||
Array.isArray(group.resources) &&
|
||||
group.resources.length > 0;
|
||||
|
||||
return hasResources && !hasPeers;
|
||||
})
|
||||
);
|
||||
}, [destinationGroups, destinationResource]);
|
||||
|
||||
useEffect(() => {
|
||||
if (destinationOnlyResources && direction !== "in") {
|
||||
setDirection("in");
|
||||
}
|
||||
}, [destinationOnlyResources, direction, setDirection]);
|
||||
|
||||
return {
|
||||
protocol,
|
||||
@@ -267,6 +333,8 @@ export const useAccessControl = ({
|
||||
setEnabled,
|
||||
ports,
|
||||
setPorts,
|
||||
portRanges,
|
||||
setPortRanges,
|
||||
sourceGroups,
|
||||
setSourceGroups,
|
||||
destinationGroups,
|
||||
@@ -275,9 +343,28 @@ export const useAccessControl = ({
|
||||
setPostureChecks,
|
||||
submit,
|
||||
getPolicyData,
|
||||
portAndDirectionDisabled,
|
||||
portDisabled,
|
||||
isPostureChecksLoading,
|
||||
destinationResource,
|
||||
setDestinationResource,
|
||||
destinationHasResources,
|
||||
destinationOnlyResources,
|
||||
hasPortSupport,
|
||||
} as const;
|
||||
};
|
||||
|
||||
const parseAccessControlPorts = (ports: number[], portRanges: PortRange[]) => {
|
||||
const hasRanges = portRanges.length > 0;
|
||||
const hasPorts = ports.length > 0;
|
||||
if (!hasPorts && !hasRanges) return [undefined, undefined];
|
||||
if (!hasRanges) return [ports.map(String), undefined];
|
||||
if (!hasPorts) return [undefined, portRanges];
|
||||
|
||||
const portRangesFromPorts = ports.map((port) => ({
|
||||
start: port,
|
||||
end: port,
|
||||
})) as PortRange[];
|
||||
|
||||
const allRanges = [...portRanges, ...portRangesFromPorts];
|
||||
return [undefined, allRanges];
|
||||
};
|
||||
|
||||
@@ -63,11 +63,12 @@ export default function ActivityDescription({ event }: Props) {
|
||||
</div>
|
||||
);
|
||||
|
||||
if (event.activity_code == "setupkey.peer.add")
|
||||
if (event.activity_code == "peer.setupkey.add")
|
||||
return (
|
||||
<div className={"inline"}>
|
||||
Peer <Value>{m.name}</Value> <PeerConnectionInfo meta={m} /> was added
|
||||
with the NetBird IP <Value>{m.ip}</Value>
|
||||
with the NetBird IP <Value>{m.ip}</Value> using the setup key{" "}
|
||||
<Value>{m.setup_key_name}</Value>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -252,6 +253,22 @@ export default function ActivityDescription({ event }: Props) {
|
||||
</div>
|
||||
);
|
||||
|
||||
if (event.activity_code == "user.approve")
|
||||
return (
|
||||
<div className={"inline"}>
|
||||
User <Value>{event.meta.username}</Value>{" "}
|
||||
<Value>{event.meta.email}</Value> was approved
|
||||
</div>
|
||||
);
|
||||
|
||||
if (event.activity_code == "user.reject")
|
||||
return (
|
||||
<div className={"inline"}>
|
||||
User <Value>{event.meta.username}</Value>{" "}
|
||||
<Value>{event.meta.email}</Value> was rejected
|
||||
</div>
|
||||
);
|
||||
|
||||
/**
|
||||
* Service User
|
||||
*/
|
||||
@@ -340,6 +357,14 @@ export default function ActivityDescription({ event }: Props) {
|
||||
</div>
|
||||
);
|
||||
|
||||
if (event.activity_code == "peer.ip.update")
|
||||
return (
|
||||
<div className={"inline"}>
|
||||
Peer <Value>{m.name}</Value> IP address was updated from{" "}
|
||||
<Value>{m.old_ip}</Value> to <Value>{m.ip}</Value>
|
||||
</div>
|
||||
);
|
||||
|
||||
/**
|
||||
* Group
|
||||
*/
|
||||
@@ -378,6 +403,15 @@ export default function ActivityDescription({ event }: Props) {
|
||||
if (event.activity_code == "account.setting.peer.login.expiration.disable")
|
||||
return <div className={"inline"}>Global login expiration was disabled</div>;
|
||||
|
||||
if (event.activity_code == "account.network.range.update")
|
||||
return (
|
||||
<div className={"inline"}>
|
||||
Account network range was updated from{" "}
|
||||
<Value>{m.old_network_range}</Value> to{" "}
|
||||
<Value>{m.new_network_range}</Value>
|
||||
</div>
|
||||
);
|
||||
|
||||
/**
|
||||
* Nameserver
|
||||
*/
|
||||
|
||||
@@ -121,13 +121,13 @@ export default function ActivityTable({
|
||||
return (
|
||||
<DataTable
|
||||
headingTarget={headingTarget}
|
||||
wrapperClassName={"gap-0 flex flex-col"}
|
||||
tableClassName={"px-8 mt-10"}
|
||||
paginationClassName={"max-w-[800px]"}
|
||||
as={"div"}
|
||||
text={"Audit Events"}
|
||||
sorting={sorting}
|
||||
setSorting={setSorting}
|
||||
wrapperClassName={"gap-0 flex flex-col"}
|
||||
tableClassName={"px-8 pt-4"}
|
||||
columns={ActivityFeedColumnsTable}
|
||||
data={events}
|
||||
searchPlaceholder={"Search by audit name, user, peer, meta..."}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import Button from "@components/Button";
|
||||
import { CommandItem } from "@components/Command";
|
||||
import { DropdownInfoText } from "@components/DropdownInfoText";
|
||||
import { DropdownInput } from "@components/DropdownInput";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@components/Popover";
|
||||
import { ScrollArea } from "@components/ScrollArea";
|
||||
import { SmallBadge } from "@components/ui/SmallBadge";
|
||||
import TextWithTooltip from "@components/ui/TextWithTooltip";
|
||||
import { cn, generateColorFromString } from "@utils/helpers";
|
||||
import { Command, CommandGroup, CommandInput, CommandList } from "cmdk";
|
||||
import { sortBy, trim, uniqBy } from "lodash";
|
||||
import { ChevronsUpDown, Cog, SearchIcon, UserCircle2 } from "lucide-react";
|
||||
import { VirtualScrollAreaList } from "@components/VirtualScrollAreaList";
|
||||
import { useSearch } from "@hooks/useSearch";
|
||||
import { generateColorFromString } from "@utils/helpers";
|
||||
import { sortBy, uniqBy } from "lodash";
|
||||
import { ChevronsUpDown, Cog, UserCircle2 } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useElementSize } from "@/hooks/useElementSize";
|
||||
@@ -28,16 +29,35 @@ export type UserSelectOption = {
|
||||
external?: boolean;
|
||||
};
|
||||
|
||||
const searchPredicate = (item: UserSelectOption, query: string) => {
|
||||
const lowerCaseQuery = query.toLowerCase();
|
||||
if (
|
||||
item.email === "NetBird" &&
|
||||
"NetBird System".toLowerCase().includes(lowerCaseQuery)
|
||||
)
|
||||
return true;
|
||||
if (item.name.toLowerCase().includes(lowerCaseQuery)) return true;
|
||||
if (item.email?.toLowerCase().includes(lowerCaseQuery)) return true;
|
||||
return item.id.toLowerCase().startsWith(lowerCaseQuery);
|
||||
};
|
||||
|
||||
export function UsersDropdownSelector({
|
||||
onChange,
|
||||
value,
|
||||
disabled = false,
|
||||
popoverWidth = 250,
|
||||
options,
|
||||
}: Props) {
|
||||
const searchRef = React.useRef<HTMLInputElement>(null);
|
||||
}: Readonly<Props>) {
|
||||
const [filteredItems, search, setSearch] = useSearch(
|
||||
options.concat({
|
||||
id: "all-users",
|
||||
name: "All Users",
|
||||
email: "Include all users",
|
||||
}),
|
||||
searchPredicate,
|
||||
{ filter: true, debounce: 150 },
|
||||
);
|
||||
const [inputRef, { width }] = useElementSize<HTMLButtonElement>();
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
const toggle = (item: string | undefined) => {
|
||||
const isSelected = value == item;
|
||||
@@ -53,11 +73,17 @@ export function UsersDropdownSelector({
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const sortedOptions = useMemo(() => {
|
||||
return sortBy(
|
||||
uniqBy(options, (o) => o.email),
|
||||
const sorted = sortBy(
|
||||
uniqBy(filteredItems, (o) => o.email),
|
||||
["external", "name"],
|
||||
);
|
||||
}, [options]);
|
||||
const allUsersIndex = sorted.findIndex((o) => o.id === "all-users");
|
||||
if (allUsersIndex > -1) {
|
||||
const allUsers = sorted.splice(allUsersIndex, 1)[0];
|
||||
sorted.unshift(allUsers);
|
||||
}
|
||||
return sorted;
|
||||
}, [filteredItems]);
|
||||
|
||||
const selectedUser = useMemo(() => {
|
||||
return options.find((user) => user.email == value);
|
||||
@@ -135,147 +161,105 @@ export function UsersDropdownSelector({
|
||||
side={"bottom"}
|
||||
sideOffset={10}
|
||||
>
|
||||
<Command
|
||||
className={"w-full flex"}
|
||||
loop
|
||||
filter={(value, search) => {
|
||||
const formatValue = trim(value.toLowerCase());
|
||||
const formatSearch = trim(search.toLowerCase());
|
||||
if (formatValue.includes(formatSearch)) return 1;
|
||||
return 0;
|
||||
}}
|
||||
>
|
||||
<CommandList className={"w-full"}>
|
||||
<div className={"relative"}>
|
||||
<CommandInput
|
||||
className={cn(
|
||||
"min-h-[42px] w-full relative",
|
||||
"border-b-0 border-t-0 border-r-0 border-l-0 border-neutral-200 dark:border-nb-gray-700 items-center",
|
||||
"bg-transparent text-sm outline-none focus-visible:outline-none ring-0 focus-visible:ring-0",
|
||||
"dark:placeholder:text-nb-gray-400 font-light placeholder:text-neutral-500 pl-10",
|
||||
)}
|
||||
ref={searchRef}
|
||||
value={search}
|
||||
onValueChange={setSearch}
|
||||
placeholder={"Search user..."}
|
||||
/>
|
||||
<div
|
||||
className={
|
||||
"absolute left-0 top-0 h-full flex items-center pl-4"
|
||||
}
|
||||
>
|
||||
<div className={"flex items-center"}>
|
||||
<SearchIcon size={14} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className={"w-full"}>
|
||||
<DropdownInput
|
||||
value={search}
|
||||
onChange={setSearch}
|
||||
placeholder={"Search user..."}
|
||||
hideEnterIcon={true}
|
||||
/>
|
||||
|
||||
<ScrollArea
|
||||
className={
|
||||
"max-h-[380px] overflow-y-hidden flex flex-col gap-1 pl-2 py-2 pr-3"
|
||||
}
|
||||
>
|
||||
<CommandGroup>
|
||||
<div className={"grid grid-cols-1 gap-1"}>
|
||||
<CommandItem
|
||||
value={undefined}
|
||||
className={"py-1 px-2"}
|
||||
onSelect={() => {
|
||||
toggle(undefined);
|
||||
searchRef.current?.focus();
|
||||
}}
|
||||
onClick={(e) => e.preventDefault()}
|
||||
>
|
||||
<div className={"flex items-center gap-2"}>
|
||||
{options.length == 0 && !search && (
|
||||
<div className={"max-w-xs mx-auto"}>
|
||||
<DropdownInfoText>
|
||||
{"No users available to select."}
|
||||
</DropdownInfoText>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{filteredItems.length == 0 && search != "" && (
|
||||
<div className={"px-10"}>
|
||||
<DropdownInfoText>
|
||||
There are no users matching your search.
|
||||
</DropdownInfoText>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{sortedOptions.length > 0 && (
|
||||
<VirtualScrollAreaList
|
||||
items={sortedOptions}
|
||||
estimatedItemHeight={52}
|
||||
maxHeight={380}
|
||||
scrollAreaClassName={"pt-0"}
|
||||
onSelect={(item) => {
|
||||
if (item.id === "all-users") {
|
||||
toggle(undefined);
|
||||
return;
|
||||
}
|
||||
toggle(item.email);
|
||||
}}
|
||||
renderItem={(user) => {
|
||||
const isSystemUser = user.email === "NetBird";
|
||||
|
||||
return (
|
||||
<div className={"flex items-center gap-2 w-full"}>
|
||||
{user.id === "all-users" ? (
|
||||
<div
|
||||
className={
|
||||
"w-7 h-7 rounded-full flex items-center justify-center uppercase text-[9px] font-medium bg-sky-400 text-white"
|
||||
"w-7 h-7 shrink-0 rounded-full flex items-center justify-center uppercase text-[9px] font-medium bg-sky-400 text-white"
|
||||
}
|
||||
>
|
||||
<UserCircle2 size={16} />
|
||||
</div>
|
||||
) : (
|
||||
<SmallUserAvatar
|
||||
name={user?.name}
|
||||
email={user?.email}
|
||||
id={user?.id}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className={"flex flex-col text-xs"}>
|
||||
<span className={"text-nb-gray-200"}>All Users</span>
|
||||
<span className={"text-nb-gray-400 font-light"}>
|
||||
Include all users
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</CommandItem>
|
||||
|
||||
{sortedOptions.map((user) => {
|
||||
const isSystemUser = user.email === "NetBird";
|
||||
const searchValue = isSystemUser
|
||||
? "NetBird System"
|
||||
: user.name + " " + user.id + " " + user.email;
|
||||
|
||||
return (
|
||||
<CommandItem
|
||||
key={user.id}
|
||||
value={searchValue}
|
||||
className={"py-1 px-2"}
|
||||
onSelect={() => {
|
||||
toggle(user.email);
|
||||
searchRef.current?.focus();
|
||||
}}
|
||||
onClick={(e) => e.preventDefault()}
|
||||
<div className={"flex flex-col text-xs w-full"}>
|
||||
<span
|
||||
className={
|
||||
"text-nb-gray-200 flex items-center gap-1.5 w-full"
|
||||
}
|
||||
>
|
||||
<div className={"flex items-center gap-2 w-full"}>
|
||||
<SmallUserAvatar
|
||||
name={user?.name}
|
||||
email={user?.email}
|
||||
id={user?.id}
|
||||
/>
|
||||
|
||||
<div className={"flex flex-col text-xs w-full"}>
|
||||
<span
|
||||
className={
|
||||
"text-nb-gray-200 flex items-center gap-1.5 w-full"
|
||||
}
|
||||
>
|
||||
<TextWithTooltip
|
||||
text={
|
||||
isSystemUser
|
||||
? "System"
|
||||
: user?.name || user?.id
|
||||
}
|
||||
maxChars={20}
|
||||
/>
|
||||
</span>
|
||||
<span
|
||||
className={
|
||||
"text-nb-gray-400 font-light flex items-center gap-1"
|
||||
}
|
||||
>
|
||||
<TextWithTooltip
|
||||
text={user?.email || "NetBird"}
|
||||
maxChars={20}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
{user.external && (
|
||||
<span
|
||||
className={"flex items-center ml-auto relative"}
|
||||
>
|
||||
<SmallBadge
|
||||
text={"External"}
|
||||
variant={"sky"}
|
||||
className={
|
||||
"text-[8.5px] py-[0.15rem] px-[.32rem] leading-none rounded-full -top-0"
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</CommandItem>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CommandGroup>
|
||||
</ScrollArea>
|
||||
</CommandList>
|
||||
</Command>
|
||||
<TextWithTooltip
|
||||
text={
|
||||
isSystemUser ? "System" : user?.name || user?.id
|
||||
}
|
||||
maxChars={20}
|
||||
/>
|
||||
</span>
|
||||
<span
|
||||
className={
|
||||
"text-nb-gray-400 font-light flex items-center gap-1"
|
||||
}
|
||||
>
|
||||
<TextWithTooltip
|
||||
text={user?.email || "NetBird"}
|
||||
maxChars={20}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
{user.external && (
|
||||
<span className={"flex items-center ml-auto relative"}>
|
||||
<SmallBadge
|
||||
text={"External"}
|
||||
variant={"sky"}
|
||||
className={
|
||||
"text-[8.5px] py-[0.15rem] px-[.32rem] leading-none rounded-full -top-0"
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
|
||||
@@ -19,6 +19,7 @@ const ACTION_COLOR_MAPPING: Record<string, ActionStatus> = {
|
||||
delete: ActionStatus.ERROR,
|
||||
revoke: ActionStatus.ERROR,
|
||||
block: ActionStatus.ERROR,
|
||||
reject: ActionStatus.ERROR,
|
||||
|
||||
// Warning actions
|
||||
overuse: ActionStatus.WARNING,
|
||||
|
||||
@@ -10,8 +10,11 @@ import {
|
||||
import ModalHeader from "@components/modal/ModalHeader";
|
||||
import { PeerGroupSelector } from "@components/PeerGroupSelector";
|
||||
import Separator from "@components/Separator";
|
||||
import MultipleGroups from "@components/ui/MultipleGroups";
|
||||
import MultipleGroups, {
|
||||
TransparentEditIconButton,
|
||||
} from "@components/ui/MultipleGroups";
|
||||
import { IconCirclePlus } from "@tabler/icons-react";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { FolderGit2 } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useMemo } from "react";
|
||||
@@ -64,7 +67,7 @@ export default function GroupsRow({
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setModal && permission.groups.update && setModal(true);
|
||||
setModal && permission.groups.update && !disabled && setModal(true);
|
||||
}}
|
||||
>
|
||||
{foundGroups?.length == 0 && showAddGroupButton ? (
|
||||
@@ -73,7 +76,15 @@ export default function GroupsRow({
|
||||
Add Groups
|
||||
</Badge>
|
||||
) : (
|
||||
<MultipleGroups groups={foundGroups} label={label} />
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center gap-1",
|
||||
disabled ? "cursor-default" : "group",
|
||||
)}
|
||||
>
|
||||
<MultipleGroups groups={foundGroups} label={label} />
|
||||
{!disabled && <TransparentEditIconButton />}
|
||||
</div>
|
||||
)}
|
||||
</ModalTrigger>
|
||||
<EditGroupsModal
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import { Modal, ModalContent, ModalTrigger } from "@components/modal/Modal";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { GlobeIcon } from "lucide-react";
|
||||
import { ExternalLinkIcon, GlobeIcon } from "lucide-react";
|
||||
import Image, { StaticImageData } from "next/image";
|
||||
import React, { useState } from "react";
|
||||
import CloudflareLogo from "@/assets/nameservers/cloudflare.svg";
|
||||
import DNS0Logo from "@/assets/nameservers/dns0.svg";
|
||||
import DNS0ZeroLogo from "@/assets/nameservers/dns0-zero.svg";
|
||||
import GoogleLogo from "@/assets/nameservers/google.svg";
|
||||
import Quad9Logo from "@/assets/nameservers/quad9.svg";
|
||||
import { NameserverGroup, NameserverPresets } from "@/interfaces/Nameserver";
|
||||
@@ -13,7 +16,7 @@ type Props = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export default function NameserverTemplateModal({ children }: Props) {
|
||||
export default function NameserverTemplateModal({ children }: Readonly<Props>) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [presetModal, setPresetModal] = useState(false);
|
||||
const [preset, setPreset] = useState(NameserverPresets.Default);
|
||||
@@ -49,11 +52,11 @@ type ModalProps = {
|
||||
|
||||
export function NameserverTemplateModalContent({
|
||||
onePresetSelection,
|
||||
}: ModalProps) {
|
||||
}: Readonly<ModalProps>) {
|
||||
return (
|
||||
<ModalContent maxWidthClass={"max-w-xl"} showClose={true}>
|
||||
<ModalContent maxWidthClass={"max-w-5xl"} showClose={true}>
|
||||
<div className={"px-8 py-3 flex flex-col gap-6 mt-4"}>
|
||||
<div className={"grid grid-cols-1 gap-4"}>
|
||||
<div className={"grid grid-cols-1 md:grid-cols-2 gap-4"}>
|
||||
<NameserverTemplate
|
||||
onClick={() => onePresetSelection(NameserverPresets.Google)}
|
||||
src={GoogleLogo}
|
||||
@@ -61,6 +64,7 @@ export function NameserverTemplateModalContent({
|
||||
description={
|
||||
"A free, global DNS resolution service by Google that implements a number of security, performance, and compliance improvements."
|
||||
}
|
||||
href={"https://developers.google.com/speed/public-dns"}
|
||||
/>
|
||||
<NameserverTemplate
|
||||
onClick={() => onePresetSelection(NameserverPresets.Cloudflare)}
|
||||
@@ -69,6 +73,26 @@ export function NameserverTemplateModalContent({
|
||||
description={
|
||||
"Enterprise-grade DNS service that offers the fastest response time, unparalleled redundancy, and advanced security with built-in DDoS mitigation and DNSSEC."
|
||||
}
|
||||
href={"https://www.cloudflare.com/learning/dns/what-is-1.1.1.1/"}
|
||||
/>
|
||||
|
||||
<NameserverTemplate
|
||||
onClick={() => onePresetSelection(NameserverPresets.DNS0)}
|
||||
src={DNS0Logo}
|
||||
title={"DNS0.EU DNS"}
|
||||
description={
|
||||
"A free, sovereign and GDPR-compliant DNS resolver with a strong focus on security to protect the citizens and organizations of the European Union."
|
||||
}
|
||||
href={"https://www.dns0.eu/"}
|
||||
/>
|
||||
<NameserverTemplate
|
||||
onClick={() => onePresetSelection(NameserverPresets.DNS0Zero)}
|
||||
src={DNS0ZeroLogo}
|
||||
title={"DNS0.EU Zero DNS"}
|
||||
description={
|
||||
"Increase the catch rate for malicious domains by combining human-vetted threat intelligence with advanced heuristics that automatically identify high-risk patterns."
|
||||
}
|
||||
href={"https://www.dns0.eu/zero"}
|
||||
/>
|
||||
<NameserverTemplate
|
||||
onClick={() => onePresetSelection(NameserverPresets.Quad9)}
|
||||
@@ -77,6 +101,7 @@ export function NameserverTemplateModalContent({
|
||||
description={
|
||||
"The Quad9 DNS service is operated by the Swiss-based Quad9 Foundation, whose mission is to provide a safer and more robust Internet for everyone."
|
||||
}
|
||||
href={"https://quad9.net/"}
|
||||
/>
|
||||
<NameserverTemplate
|
||||
onClick={() => onePresetSelection(NameserverPresets.Default)}
|
||||
@@ -98,15 +123,19 @@ function NameserverTemplate({
|
||||
title,
|
||||
description,
|
||||
onClick,
|
||||
}: {
|
||||
href,
|
||||
hrefTitle,
|
||||
}: Readonly<{
|
||||
src?: StaticImageData;
|
||||
icon?: React.ReactNode;
|
||||
title: string;
|
||||
description?: string;
|
||||
onClick?: () => void;
|
||||
}) {
|
||||
href?: string;
|
||||
hrefTitle?: string;
|
||||
}>) {
|
||||
return (
|
||||
<div
|
||||
<button
|
||||
className={
|
||||
"bg-nb-gray-930/90 h-full hover:bg-nb-gray-900 border transition-all cursor-pointer border-nb-gray-900 hover:border-nb-gray-800 flex items-center rounded-lg overflow-hidden"
|
||||
}
|
||||
@@ -115,18 +144,35 @@ function NameserverTemplate({
|
||||
<div
|
||||
className={cn(
|
||||
"w-1/4",
|
||||
"bg-gradient-to-b h-full flex items-center justify-center from-white to-nb-gray-200 overflow-hidden p-6 border-r border-nb-gray-800",
|
||||
"bg-gradient-to-b h-full flex items-center justify-center from-white to-nb-gray-200 overflow-hidden p-4 border-r border-nb-gray-800",
|
||||
)}
|
||||
>
|
||||
{src && <Image src={src} alt={title} width={100} />}
|
||||
{icon && icon}
|
||||
</div>
|
||||
<div className={"h-full flex flex-col text-left p-4 w-3/4"}>
|
||||
<p className={"font-medium text-sm"}>{title}</p>
|
||||
<div className={"h-full flex flex-col text-left px-4 py-3 w-3/4"}>
|
||||
<div className={"flex items-center"}>
|
||||
<p className={"font-medium text-sm"}>{title}</p>
|
||||
</div>
|
||||
{description && (
|
||||
<p className={"text-xs !text-nb-gray-300 mt-1"}>{description}</p>
|
||||
)}
|
||||
{href && (
|
||||
<div className={"relative mt-auto"}>
|
||||
<InlineLink
|
||||
href={href}
|
||||
className={"text-xs inline-flex"}
|
||||
target={"_blank"}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
{hrefTitle || "Learn more"}
|
||||
<ExternalLinkIcon size={12} />
|
||||
</InlineLink>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ type Props = {
|
||||
|
||||
export const ExitNodeDropdownButton = ({ peer }: Props) => {
|
||||
const [modal, setModal] = useState(false);
|
||||
const hasExitNodes = useHasExitNodes(peer);
|
||||
const exitNodeInfo = useHasExitNodes(peer);
|
||||
const { permission } = usePermissions();
|
||||
|
||||
return (
|
||||
@@ -25,7 +25,7 @@ export const ExitNodeDropdownButton = ({ peer }: Props) => {
|
||||
disabled={!permission.routes.create}
|
||||
>
|
||||
<div className={"flex gap-3 items-center w-full"}>
|
||||
{hasExitNodes ? (
|
||||
{exitNodeInfo.hasExitNode ? (
|
||||
<>
|
||||
<IconCirclePlus size={14} className={"shrink-0"} />
|
||||
<div className={"flex justify-between items-center w-full"}>
|
||||
|
||||
@@ -8,18 +8,22 @@ type Props = {
|
||||
peer: Peer;
|
||||
};
|
||||
export const ExitNodePeerIndicator = ({ peer }: Props) => {
|
||||
const hasExitNode = useHasExitNodes(peer);
|
||||
const exitNodeInfo = useHasExitNodes(peer);
|
||||
|
||||
return hasExitNode ? (
|
||||
<FullTooltip
|
||||
content={
|
||||
<div className={"text-xs max-w-xs"}>
|
||||
This peer is an exit node. Traffic from the configured distribution
|
||||
groups will be routed through this peer.
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<IconDirectionSign size={15} className={"text-yellow-400 shrink-0"} />
|
||||
if (!exitNodeInfo.hasExitNode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const tooltipContent = exitNodeInfo.skipAutoApply === false
|
||||
? "This peer is an auto-applied exit node. Traffic from the configured distribution groups will be routed through this peer."
|
||||
: "This peer is an exit node. Traffic from the configured distribution groups will be routed through this peer.";
|
||||
|
||||
return (
|
||||
<FullTooltip content={<div className={"text-xs max-w-xs"}>{tooltipContent}</div>}>
|
||||
<IconDirectionSign
|
||||
size={15}
|
||||
className={`shrink-0 ${exitNodeInfo.skipAutoApply === false ? "text-green-400" : "text-yellow-400"}`}
|
||||
/>
|
||||
</FullTooltip>
|
||||
) : null;
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,12 @@ import { useLoggedInUser } from "@/contexts/UsersProvider";
|
||||
import { Peer } from "@/interfaces/Peer";
|
||||
import { Route } from "@/interfaces/Route";
|
||||
|
||||
export const useHasExitNodes = (peer?: Peer) => {
|
||||
export interface ExitNodeInfo {
|
||||
hasExitNode: boolean;
|
||||
skipAutoApply?: boolean;
|
||||
}
|
||||
|
||||
export const useHasExitNodes = (peer?: Peer): ExitNodeInfo => {
|
||||
const { isOwnerOrAdmin } = useLoggedInUser();
|
||||
const { data: routes } = useFetchApi<Route[]>(
|
||||
`/routes`,
|
||||
@@ -11,9 +16,17 @@ export const useHasExitNodes = (peer?: Peer) => {
|
||||
true,
|
||||
isOwnerOrAdmin,
|
||||
);
|
||||
return peer
|
||||
? routes?.some(
|
||||
(route) => route?.peer === peer.id && route?.network === "0.0.0.0/0",
|
||||
) || false
|
||||
: false;
|
||||
|
||||
if (!peer || !routes) {
|
||||
return { hasExitNode: false };
|
||||
}
|
||||
|
||||
const exitNodeRoute = routes.find(
|
||||
(route) => route?.peer === peer.id && route?.network === "0.0.0.0/0",
|
||||
);
|
||||
|
||||
return {
|
||||
hasExitNode: !!exitNodeRoute,
|
||||
skipAutoApply: exitNodeRoute?.skip_auto_apply,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import TruncatedText from "@components/ui/TruncatedText";
|
||||
import DescriptionWithTooltip from "@components/ui/DescriptionWithTooltip";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { ArrowRightIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
@@ -45,25 +45,22 @@ export const NetworkInformationSquare = ({
|
||||
<div
|
||||
className={cn(
|
||||
"h-3 w-3 bg-nb-gray-950 rounded-tl-[8px] rounded-br absolute bottom-0 right-0 transition-all",
|
||||
onClick && "group-hover/network:bg-nb-gray-910",
|
||||
onClick && "group-hover/table-row:bg-nb-gray-940",
|
||||
onClick && "group-hover/network:!bg-nb-gray-910",
|
||||
)}
|
||||
></div>
|
||||
</div>
|
||||
<div className={"mt-[0px] flex items-center flex-wrap"}>
|
||||
<TruncatedText
|
||||
<p
|
||||
className={cn(
|
||||
"font-medium text-white text-left",
|
||||
"font-medium",
|
||||
size == "md" ? "text-sm" : "text-xl leading-none mb-0.5",
|
||||
)}
|
||||
maxChars={24}
|
||||
text={name}
|
||||
/>
|
||||
<TruncatedText
|
||||
className={cn(
|
||||
"text-left text-sm text-nb-gray-400",
|
||||
size == "lg" && "text-md mt-0.5",
|
||||
)}
|
||||
>
|
||||
{name}
|
||||
</p>
|
||||
<DescriptionWithTooltip
|
||||
className={cn("text-left", size == "lg" && "text-md mt-0.5")}
|
||||
maxChars={24}
|
||||
text={description}
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import MultipleGroups from "@components/ui/MultipleGroups";
|
||||
import MultipleGroups, {
|
||||
TransparentEditIconButton,
|
||||
} from "@components/ui/MultipleGroups";
|
||||
import * as React from "react";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { Group } from "@/interfaces/Group";
|
||||
@@ -15,13 +17,14 @@ export const ResourceGroupCell = ({ resource }: Props) => {
|
||||
|
||||
return (
|
||||
<button
|
||||
className={"flex cursor-pointer"}
|
||||
className={"flex cursor-pointer items-center justify-center gap-1 group"}
|
||||
onClick={() => {
|
||||
if (!network || !permission.networks.update) return;
|
||||
openResourceGroupModal(network, resource);
|
||||
}}
|
||||
>
|
||||
<MultipleGroups groups={resource?.groups as Group[]} />
|
||||
{permission.networks.update && <TransparentEditIconButton />}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -5,13 +5,26 @@ import { validator } from "@utils/helpers";
|
||||
import cidr from "ip-cidr";
|
||||
import { GlobeIcon, NetworkIcon, WorkflowIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useMemo } from "react";
|
||||
import { useEffect, useMemo } from "react";
|
||||
|
||||
type Props = {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
label?: string;
|
||||
className?: string;
|
||||
onError?: (error: string) => void;
|
||||
description?: string;
|
||||
placeholder?: string;
|
||||
};
|
||||
export const ResourceSingleAddressInput = ({ value, onChange }: Props) => {
|
||||
export const ResourceSingleAddressInput = ({
|
||||
value,
|
||||
onChange,
|
||||
label = "Address",
|
||||
className = "",
|
||||
onError,
|
||||
description = "Enter a single IP address, CIDR block or domain name",
|
||||
placeholder = "Address (IP, CIDR or Domain)",
|
||||
}: Props) => {
|
||||
const hasChars = useMemo(() => {
|
||||
return !!value.match(/[a-z*]/i);
|
||||
}, [value]);
|
||||
@@ -31,35 +44,39 @@ export const ResourceSingleAddressInput = ({ value, onChange }: Props) => {
|
||||
|
||||
// Case 1: If it has characters (potential domain) but is not a CIDR block
|
||||
if (hasChars && !isCIDRBlock) {
|
||||
if (!validator.isValidDomain(value)) {
|
||||
return "Please enter a valid domain, e.g. intra.example.com or *.example.com";
|
||||
if (
|
||||
!validator.isValidDomain(value) ||
|
||||
!value.includes(".") ||
|
||||
value.endsWith(".")
|
||||
) {
|
||||
return "Please enter a valid domain, e.g. service.internal, example.com or *.example.com";
|
||||
}
|
||||
return ""; // Valid domain
|
||||
}
|
||||
|
||||
// Case 2: If it's not a valid domain, check if it's a valid CIDR
|
||||
if (!cidr.isValidAddress(value)) {
|
||||
return "Please enter a valid IP or CIDR, e.g., 192.168.1.0/24";
|
||||
return "Please enter a valid IP or CIDR, e.g., 10.0.0.21, 192.168.1.0/24";
|
||||
}
|
||||
|
||||
return ""; // Valid CIDR
|
||||
}, [value, hasChars, isCIDRBlock]);
|
||||
|
||||
useEffect(() => {
|
||||
onError?.(error);
|
||||
}, [error]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<Label>Address</Label>
|
||||
<HelpText>
|
||||
Enter a single IP address, CIDR block or domain name
|
||||
</HelpText>
|
||||
<Input
|
||||
customPrefix={PrefixIcon}
|
||||
error={error}
|
||||
placeholder={"Address (IP, CIDR or Domain)"}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
<div className={className}>
|
||||
<Label>{label}</Label>
|
||||
<HelpText>{description}</HelpText>
|
||||
<Input
|
||||
customPrefix={PrefixIcon}
|
||||
error={error}
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import { IconCirclePlus } from "@tabler/icons-react";
|
||||
import { ColumnDef, SortingState } from "@tanstack/react-table";
|
||||
import { removeAllSpaces } from "@utils/helpers";
|
||||
import { Layers3Icon } from "lucide-react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import { useState } from "react";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
@@ -30,6 +31,11 @@ type Props = {
|
||||
const NetworkResourceColumns: ColumnDef<NetworkResource>[] = [
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
filterFn: "exactMatch",
|
||||
},
|
||||
{
|
||||
id: "name",
|
||||
accessorKey: "name",
|
||||
header: ({ column }) => {
|
||||
return <DataTableHeader column={column}>Resource</DataTableHeader>;
|
||||
@@ -101,6 +107,8 @@ export default function ResourcesTable({
|
||||
headingTarget,
|
||||
}: Readonly<Props>) {
|
||||
const { permission } = usePermissions();
|
||||
const params = useSearchParams();
|
||||
const resourceId = params.get("resource") ?? undefined;
|
||||
|
||||
const [sorting, setSorting] = useState<SortingState>([]);
|
||||
const { openResourceModal, network } = useNetworksContext();
|
||||
@@ -119,6 +127,10 @@ export default function ResourcesTable({
|
||||
text={"Resources"}
|
||||
columns={NetworkResourceColumns}
|
||||
keepStateInLocalStorage={false}
|
||||
initialFilters={
|
||||
resourceId ? [{ id: "id", value: resourceId }] : undefined
|
||||
}
|
||||
initialSearch={resourceId}
|
||||
data={resources}
|
||||
searchPlaceholder={"Search by name, address or group..."}
|
||||
isLoading={isLoading}
|
||||
@@ -134,6 +146,7 @@ export default function ResourcesTable({
|
||||
}
|
||||
columnVisibility={{
|
||||
description: false,
|
||||
id: false,
|
||||
}}
|
||||
paginationPaddingClassName={"px-0 pt-8"}
|
||||
rightSide={() => (
|
||||
|
||||
@@ -314,6 +314,7 @@ function RoutingPeerModalContent({
|
||||
value={masquerade}
|
||||
onChange={setMasquerade}
|
||||
disabled={isNonLinuxRoutingPeer}
|
||||
routingPeerGroupId={routingPeerGroups?.[0]?.id}
|
||||
/>
|
||||
|
||||
<div className={cn("flex justify-between")}>
|
||||
|
||||
@@ -1,34 +1,51 @@
|
||||
import { Callout } from "@components/Callout";
|
||||
import FancyToggleSwitch from "@components/FancyToggleSwitch";
|
||||
import FullTooltip from "@components/FullTooltip";
|
||||
import { VenetianMask } from "lucide-react";
|
||||
import { getOperatingSystem } from "@hooks/useOperatingSystem";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { AlertCircleIcon, VenetianMask } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useGroups } from "@/contexts/GroupsProvider";
|
||||
import { GroupPeer } from "@/interfaces/Group";
|
||||
import { OperatingSystem } from "@/interfaces/OperatingSystem";
|
||||
import { Peer } from "@/interfaces/Peer";
|
||||
|
||||
type Props = {
|
||||
value: boolean;
|
||||
onChange: (value: boolean) => void;
|
||||
disabled?: boolean;
|
||||
routingPeerGroupId?: string;
|
||||
};
|
||||
export const RoutingPeerMasqueradeSwitch = ({
|
||||
disabled = false,
|
||||
value,
|
||||
onChange,
|
||||
routingPeerGroupId,
|
||||
}: Props) => {
|
||||
return (
|
||||
<RoutingPeerMasqueradeTooltip show={disabled}>
|
||||
<FancyToggleSwitch
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
disabled={disabled}
|
||||
label={
|
||||
<>
|
||||
<VenetianMask size={15} />
|
||||
Masquerade
|
||||
</>
|
||||
}
|
||||
helpText={
|
||||
"Allow access to your private networks without configuring routes on your local routers or other devices."
|
||||
}
|
||||
/>
|
||||
<div className={"flex flex-col gap-4"}>
|
||||
<FancyToggleSwitch
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
disabled={disabled}
|
||||
label={
|
||||
<>
|
||||
<VenetianMask size={15} />
|
||||
Masquerade
|
||||
</>
|
||||
}
|
||||
helpText={
|
||||
"Allow access to your private networks without configuring routes on your local routers or other devices."
|
||||
}
|
||||
/>
|
||||
{routingPeerGroupId && !value && (
|
||||
<RoutingPeerGroupNonLinuxWarning
|
||||
routingPeerGroupId={routingPeerGroupId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</RoutingPeerMasqueradeTooltip>
|
||||
);
|
||||
};
|
||||
@@ -52,9 +69,51 @@ export const RoutingPeerMasqueradeTooltip = ({
|
||||
delayDuration={250}
|
||||
skipDelayDuration={350}
|
||||
disabled={!show}
|
||||
className={"cursor-help"}
|
||||
className={cn(show && "cursor-help")}
|
||||
>
|
||||
{children}
|
||||
</FullTooltip>
|
||||
);
|
||||
};
|
||||
|
||||
const RoutingPeerGroupNonLinuxWarning = ({
|
||||
routingPeerGroupId,
|
||||
}: {
|
||||
routingPeerGroupId: string;
|
||||
}) => {
|
||||
const { groups } = useGroups();
|
||||
const { data: peers } = useFetchApi<Peer[]>("/peers", true);
|
||||
const group = groups?.find((g) => g.id === routingPeerGroupId);
|
||||
|
||||
const hasNonLinuxPeer = React.useMemo(() => {
|
||||
try {
|
||||
return group?.peers?.some((groupPeer) => {
|
||||
const peer = peers?.find((p) => p.id === (groupPeer as GroupPeer).id);
|
||||
if (!peer) return false;
|
||||
const os = getOperatingSystem(peer.os);
|
||||
return os !== OperatingSystem.LINUX;
|
||||
});
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}, [group?.peers, peers]);
|
||||
|
||||
return (
|
||||
hasNonLinuxPeer && (
|
||||
<Callout
|
||||
variant={"warning"}
|
||||
icon={
|
||||
<AlertCircleIcon
|
||||
size={14}
|
||||
className={"shrink-0 relative top-[3px] text-netbird"}
|
||||
/>
|
||||
}
|
||||
>
|
||||
Group <span className={"text-netbird font-normal"}>{group?.name}</span>{" "}
|
||||
contains at least one non-Linux peer.
|
||||
<br /> Disabled Masquerade will have no effect on non-Linux routing
|
||||
peers.
|
||||
</Callout>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ColumnDef, SortingState } from "@tanstack/react-table";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { ExternalLinkIcon, PlusCircle } from "lucide-react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import NetworkRoutesIcon from "@/assets/icons/NetworkRoutesIcon";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
@@ -25,6 +25,7 @@ import NetworkNameCell from "@/modules/networks/table/NetworkNameCell";
|
||||
import { NetworkPolicyCell } from "@/modules/networks/table/NetworkPolicyCell";
|
||||
import { NetworkResourceCell } from "@/modules/networks/table/NetworkResourceCell";
|
||||
import NetworkRoutingPeerCell from "@/modules/networks/table/NetworkRoutingPeerCell";
|
||||
import { GlobalSearchModal } from "@/modules/search/GlobalSearchModal";
|
||||
|
||||
export const NetworkTableColumns: ColumnDef<Network>[] = [
|
||||
{
|
||||
@@ -79,9 +80,10 @@ export default function NetworksTable({
|
||||
isLoading,
|
||||
data,
|
||||
headingTarget,
|
||||
}: Props) {
|
||||
}: Readonly<Props>) {
|
||||
const { mutate } = useSWRConfig();
|
||||
const path = usePathname();
|
||||
const [searchModal, setSearchModal] = useState(false);
|
||||
|
||||
// Default sorting state of the table
|
||||
const [sorting, setSorting] = useLocalStorage<SortingState>(
|
||||
@@ -95,75 +97,85 @@ export default function NetworksTable({
|
||||
);
|
||||
|
||||
return (
|
||||
<NetworkProvider>
|
||||
<DataTable
|
||||
headingTarget={headingTarget}
|
||||
isLoading={isLoading}
|
||||
text={"Networks"}
|
||||
sorting={sorting}
|
||||
setSorting={setSorting}
|
||||
columns={NetworkTableColumns}
|
||||
data={data}
|
||||
searchPlaceholder={"Search by network name or description..."}
|
||||
columnVisibility={{
|
||||
description: false,
|
||||
}}
|
||||
getStartedCard={
|
||||
<GetStartedTest
|
||||
icon={
|
||||
<SquareIcon
|
||||
icon={
|
||||
<NetworkRoutesIcon className={"fill-nb-gray-200"} size={20} />
|
||||
}
|
||||
color={"gray"}
|
||||
size={"large"}
|
||||
/>
|
||||
}
|
||||
title={"Create New Network"}
|
||||
description={
|
||||
"It looks like you don't have any networks. Access internal resources in your LANs and VPC by adding a network."
|
||||
}
|
||||
button={
|
||||
<div className={"gap-x-4 flex items-center justify-center"}>
|
||||
<>
|
||||
<GlobalSearchModal open={searchModal} setOpen={setSearchModal} />
|
||||
<NetworkProvider>
|
||||
<DataTable
|
||||
headingTarget={headingTarget}
|
||||
isLoading={isLoading}
|
||||
text={"Networks"}
|
||||
sorting={sorting}
|
||||
setSorting={setSorting}
|
||||
columns={NetworkTableColumns}
|
||||
data={data}
|
||||
searchPlaceholder={"Search by network name or description..."}
|
||||
columnVisibility={{
|
||||
description: false,
|
||||
}}
|
||||
onSearchClick={() => setSearchModal(true)}
|
||||
getStartedCard={
|
||||
<GetStartedTest
|
||||
icon={
|
||||
<SquareIcon
|
||||
icon={
|
||||
<NetworkRoutesIcon
|
||||
className={"fill-nb-gray-200"}
|
||||
size={20}
|
||||
/>
|
||||
}
|
||||
color={"gray"}
|
||||
size={"large"}
|
||||
/>
|
||||
}
|
||||
title={"Create New Network"}
|
||||
description={
|
||||
"It looks like you don't have any networks. Access internal resources in your LANs and VPC by adding a network."
|
||||
}
|
||||
button={
|
||||
<div className={"gap-x-4 flex items-center justify-center"}>
|
||||
<AddNetworkButton />
|
||||
</div>
|
||||
}
|
||||
learnMore={
|
||||
<>
|
||||
Learn more about
|
||||
<InlineLink
|
||||
href={"https://docs.netbird.io/how-to/networks"}
|
||||
target={"_blank"}
|
||||
>
|
||||
Networks
|
||||
<ExternalLinkIcon size={12} />
|
||||
</InlineLink>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
}
|
||||
rightSide={() =>
|
||||
data &&
|
||||
data.length > 0 && (
|
||||
<div className={cn("gap-x-4 ml-auto flex")}>
|
||||
<AddNetworkButton />
|
||||
</div>
|
||||
}
|
||||
learnMore={
|
||||
<>
|
||||
Learn more about
|
||||
<InlineLink
|
||||
href={"https://docs.netbird.io/how-to/networks"}
|
||||
target={"_blank"}
|
||||
>
|
||||
Networks
|
||||
<ExternalLinkIcon size={12} />
|
||||
</InlineLink>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
}
|
||||
rightSide={() =>
|
||||
data &&
|
||||
data.length > 0 && (
|
||||
<div className={cn("gap-x-4 ml-auto flex")}>
|
||||
<AddNetworkButton />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
>
|
||||
{(table) => (
|
||||
<>
|
||||
<DataTableRowsPerPage table={table} disabled={data?.length == 0} />
|
||||
<DataTableRefreshButton
|
||||
isDisabled={data?.length == 0}
|
||||
onClick={() => {
|
||||
mutate("/networks").then();
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</DataTable>
|
||||
</NetworkProvider>
|
||||
)
|
||||
}
|
||||
>
|
||||
{(table) => (
|
||||
<>
|
||||
<DataTableRowsPerPage
|
||||
table={table}
|
||||
disabled={data?.length == 0}
|
||||
/>
|
||||
<DataTableRefreshButton
|
||||
isDisabled={data?.length == 0}
|
||||
onClick={() => {
|
||||
mutate("/networks").then();
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</DataTable>
|
||||
</NetworkProvider>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ type Props = {
|
||||
|
||||
export const PeerNetworkRoutesSection = ({ peer }: Props) => {
|
||||
const { peerRoutes, isLoading } = usePeerRoutes({ peer });
|
||||
const hasExitNodes = useHasExitNodes(peer);
|
||||
const exitNodeInfo = useHasExitNodes(peer);
|
||||
const { ref: headingRef, portalTarget } =
|
||||
usePortalElement<HTMLHeadingElement>();
|
||||
|
||||
@@ -34,7 +34,7 @@ export const PeerNetworkRoutesSection = ({ peer }: Props) => {
|
||||
</div>
|
||||
<div className={"inline-flex gap-4 justify-end"}>
|
||||
<div className={"gap-4 flex"}>
|
||||
<AddExitNodeButton peer={peer} firstTime={!hasExitNodes} />
|
||||
<AddExitNodeButton peer={peer} firstTime={!exitNodeInfo.hasExitNode} />
|
||||
<AddRouteDropdownButton />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -366,7 +366,7 @@ export const OperatingSystemTab = ({
|
||||
|
||||
useEffect(() => {
|
||||
onError(versionError);
|
||||
}, [versionError]);
|
||||
}, [versionError, onError]);
|
||||
|
||||
return (
|
||||
<div className={""}>
|
||||
|
||||
53
src/modules/routes/RouteAutoApplyCell.tsx
Normal file
53
src/modules/routes/RouteAutoApplyCell.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import { ToggleSwitch } from "@components/ToggleSwitch";
|
||||
import React, { useMemo } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { useRoutes } from "@/contexts/RoutesProvider";
|
||||
import { Route } from "@/interfaces/Route";
|
||||
|
||||
type Props = {
|
||||
route: Route;
|
||||
};
|
||||
|
||||
export default function RouteAutoApplyCell({ route }: Readonly<Props>) {
|
||||
const { permission } = usePermissions();
|
||||
const { updateRoute } = useRoutes();
|
||||
const { mutate } = useSWRConfig();
|
||||
|
||||
const isExitNode = useMemo(() => route.network === "0.0.0.0/0", [route]);
|
||||
|
||||
const isChecked = useMemo(() => {
|
||||
// Checked means Auto Apply is ON, which maps to skip_auto_apply === false
|
||||
return route.skip_auto_apply === false;
|
||||
}, [route]);
|
||||
|
||||
const update = async (checked: boolean) => {
|
||||
// When toggled ON (checked === true), we want skip_auto_apply = false
|
||||
const nextSkipAutoApply = !checked;
|
||||
updateRoute(
|
||||
route,
|
||||
{ skip_auto_apply: nextSkipAutoApply },
|
||||
() => {
|
||||
mutate("/routes");
|
||||
},
|
||||
checked
|
||||
? "Auto Apply was enabled for the route"
|
||||
: "Auto Apply was disabled for the route",
|
||||
);
|
||||
};
|
||||
|
||||
if (!isExitNode) return null;
|
||||
|
||||
return (
|
||||
<div className={"flex items-center"}>
|
||||
<ToggleSwitch
|
||||
checked={isChecked}
|
||||
size={"small"}
|
||||
onClick={() => update(!isChecked)}
|
||||
disabled={!permission.routes.update}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -227,6 +227,7 @@ export function RouteModalContent({
|
||||
const [enabled, setEnabled] = useState<boolean>(true);
|
||||
const [metric, setMetric] = useState("9999");
|
||||
const [masquerade, setMasquerade] = useState<boolean>(true);
|
||||
const [isForced, setIsForced] = useState<boolean>(true);
|
||||
|
||||
const isNonLinuxRoutingPeer = useMemo(() => {
|
||||
if (!routingPeer) return false;
|
||||
@@ -304,6 +305,7 @@ export function RouteModalContent({
|
||||
masquerade: useSinglePeer && isNonLinuxRoutingPeer ? true : masquerade,
|
||||
groups: groupIds,
|
||||
access_control_groups: accessControlGroupIds || undefined,
|
||||
skip_auto_apply: !isForced,
|
||||
},
|
||||
onSuccess,
|
||||
);
|
||||
@@ -718,11 +720,26 @@ export function RouteModalContent({
|
||||
helpText={"Use this switch to enable or disable the route."}
|
||||
/>
|
||||
|
||||
{exitNode && (
|
||||
<FancyToggleSwitch
|
||||
value={isForced}
|
||||
onChange={setIsForced}
|
||||
label={
|
||||
<>
|
||||
<IconDirectionSign size={15} />
|
||||
Auto Apply Route
|
||||
</>
|
||||
}
|
||||
helpText={"Automatically apply this exit node to your distribution groups. This requires NetBird client v0.55.0 or higher."}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!exitNode && (
|
||||
<RoutingPeerMasqueradeSwitch
|
||||
value={masquerade}
|
||||
onChange={setMasquerade}
|
||||
disabled={isNonLinuxRoutingPeer}
|
||||
routingPeerGroupId={routingPeerGroups?.[0]?.id}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { GroupedRoute, Route } from "@/interfaces/Route";
|
||||
import RouteAccessControlGroups from "@/modules/routes/RouteAccessControlGroups";
|
||||
import RouteActionCell from "@/modules/routes/RouteActionCell";
|
||||
import RouteActiveCell from "@/modules/routes/RouteActiveCell";
|
||||
import RouteAutoApplyCell from "@/modules/routes/RouteAutoApplyCell";
|
||||
import RouteDistributionGroupsCell from "@/modules/routes/RouteDistributionGroupsCell";
|
||||
import RouteMetricCell from "@/modules/routes/RouteMetricCell";
|
||||
import RoutePeerCell from "@/modules/routes/RoutePeerCell";
|
||||
@@ -77,6 +78,15 @@ export const RouteTableColumns: ColumnDef<Route>[] = [
|
||||
},
|
||||
cell: ({ row }) => <RouteAccessControlGroups route={row.original} />,
|
||||
},
|
||||
{
|
||||
id: "skipAutoApply",
|
||||
accessorKey: "skip_auto_apply",
|
||||
header: ({ column }) => {
|
||||
return <DataTableHeader column={column}>Auto Apply</DataTableHeader>;
|
||||
},
|
||||
cell: ({ row }) => <RouteAutoApplyCell route={row.original} />,
|
||||
sortingFn: "basic",
|
||||
},
|
||||
{
|
||||
id: "group_names",
|
||||
accessorFn: (row) => {
|
||||
@@ -104,6 +114,10 @@ export default function RouteTable({ row }: Props) {
|
||||
desc: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const hasAtLeastOneExitNode = useMemo(() => {
|
||||
return row.routes?.some((route) => route.network === "0.0.0.0/0");
|
||||
}, [row.routes]);
|
||||
|
||||
const data = useMemo(() => {
|
||||
if (!row.routes) return [];
|
||||
@@ -144,6 +158,7 @@ export default function RouteTable({ row }: Props) {
|
||||
domains: false,
|
||||
domain_search: false,
|
||||
network: false,
|
||||
skipAutoApply: !!hasAtLeastOneExitNode,
|
||||
}}
|
||||
setSorting={setSorting}
|
||||
columns={RouteTableColumns}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@components/Tabs";
|
||||
import { Textarea } from "@components/Textarea";
|
||||
import { DomainsTooltip } from "@components/ui/DomainListBadge";
|
||||
import { getOperatingSystem } from "@hooks/useOperatingSystem";
|
||||
import { IconDirectionSign } from "@tabler/icons-react";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { uniqBy } from "lodash";
|
||||
import {
|
||||
@@ -193,6 +194,7 @@ function RouteUpdateModalContent({ onSuccess, route, cell }: ModalProps) {
|
||||
const [masquerade, setMasquerade] = useState<boolean>(
|
||||
route?.masquerade ?? true,
|
||||
);
|
||||
const [isForced, setIsForced] = useState<boolean>(route?.skip_auto_apply === false);
|
||||
|
||||
// Refs to manage focus on tab change
|
||||
const networkRangeRef = useRef<HTMLInputElement>(null);
|
||||
@@ -257,6 +259,7 @@ function RouteUpdateModalContent({ onSuccess, route, cell }: ModalProps) {
|
||||
masquerade: useSinglePeer && isNonLinuxRoutingPeer ? true : masquerade,
|
||||
groups: groupIds,
|
||||
access_control_groups: accessControlGroupIds || undefined,
|
||||
skip_auto_apply: !isForced,
|
||||
},
|
||||
(r) => {
|
||||
onSuccess && onSuccess(r);
|
||||
@@ -456,11 +459,27 @@ function RouteUpdateModalContent({ onSuccess, route, cell }: ModalProps) {
|
||||
}
|
||||
helpText={"Use this switch to enable or disable the route."}
|
||||
/>
|
||||
|
||||
{isExitNode && (
|
||||
<FancyToggleSwitch
|
||||
value={isForced}
|
||||
onChange={setIsForced}
|
||||
label={
|
||||
<>
|
||||
<IconDirectionSign size={15} />
|
||||
Auto Apply Route
|
||||
</>
|
||||
}
|
||||
helpText={"Automatically apply this exit node to your distribution groups. This requires NetBird client v0.55.0 or higher."}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!isExitNode && (
|
||||
<RoutingPeerMasqueradeSwitch
|
||||
value={masquerade}
|
||||
onChange={setMasquerade}
|
||||
disabled={isNonLinuxRoutingPeer}
|
||||
routingPeerGroupId={routingPeerGroups?.[0]?.id}
|
||||
/>
|
||||
)}
|
||||
<div className={cn("flex justify-between")}>
|
||||
|
||||
391
src/modules/search/GlobalSearchModal.tsx
Normal file
391
src/modules/search/GlobalSearchModal.tsx
Normal file
@@ -0,0 +1,391 @@
|
||||
import { DropdownInput } from "@components/DropdownInput";
|
||||
import Kbd from "@components/Kbd";
|
||||
import { Modal, ModalContent } from "@components/modal/Modal";
|
||||
import { VirtualScrollAreaList } from "@components/VirtualScrollAreaList";
|
||||
import { useSearch } from "@hooks/useSearch";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { removeAllSpaces } from "@utils/helpers";
|
||||
import {
|
||||
ArrowDownIcon,
|
||||
ArrowUpIcon,
|
||||
CornerDownLeft,
|
||||
GlobeIcon,
|
||||
LayersIcon,
|
||||
NetworkIcon,
|
||||
TextSearchIcon,
|
||||
WorkflowIcon,
|
||||
} from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import { useMemo } from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
import { Network, NetworkResource } from "@/interfaces/Network";
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
};
|
||||
|
||||
enum SearchType {
|
||||
Network = "network",
|
||||
NetworkResource = "network-resource",
|
||||
}
|
||||
|
||||
type SearchResult<T, U extends SearchType> = {
|
||||
type: U;
|
||||
id: string;
|
||||
data: T;
|
||||
onAction?: (item: T) => void;
|
||||
};
|
||||
|
||||
type NetworkSearchResult = SearchResult<Network, SearchType.Network>;
|
||||
type ResourceSearchResult = SearchResult<
|
||||
NetworkResource,
|
||||
SearchType.NetworkResource
|
||||
>;
|
||||
type AnySearchResult = NetworkSearchResult | ResourceSearchResult;
|
||||
|
||||
const searchPredicate = (item: AnySearchResult, query: string) => {
|
||||
if (!query) return false;
|
||||
const lower = removeAllSpaces(query.toLowerCase());
|
||||
const { name, description, id } = item.data;
|
||||
const find = (s: string | undefined) =>
|
||||
removeAllSpaces(s?.toLowerCase()).includes(lower);
|
||||
|
||||
if (item.type === SearchType.Network) {
|
||||
if (find(name)) return true;
|
||||
if (find(description)) return true;
|
||||
if (find(id)) return true;
|
||||
}
|
||||
|
||||
if (item.type === SearchType.NetworkResource) {
|
||||
if (find(name)) return true;
|
||||
if (find(description)) return true;
|
||||
if (find(item.data?.address)) return true;
|
||||
if (find(id)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export const GlobalSearchModal = ({ open, setOpen }: Props) => {
|
||||
return open && <GlobalSearchModalContent open={open} setOpen={setOpen} />;
|
||||
};
|
||||
|
||||
const GlobalSearchModalContent = ({ open, setOpen }: Props) => {
|
||||
const router = useRouter();
|
||||
|
||||
const { data: networks, isLoading: isNetworksLoading } = useFetchApi<
|
||||
Network[]
|
||||
>("/networks", true, false, open, {
|
||||
key: "global-search-networks",
|
||||
});
|
||||
const { data: resources, isLoading: isResourcesLoading } = useFetchApi<
|
||||
NetworkResource[]
|
||||
>("/networks/resources", true, false, open, {
|
||||
key: "global-search-resources",
|
||||
});
|
||||
|
||||
const findNetworkByResourceId = (resourceId: string) => {
|
||||
return networks?.find(
|
||||
(network) => network.resources?.some((res) => res === resourceId),
|
||||
);
|
||||
};
|
||||
|
||||
const items: AnySearchResult[] = useMemo(() => {
|
||||
if (isNetworksLoading || isResourcesLoading) return [];
|
||||
const networkResults: NetworkSearchResult[] = (networks ?? []).map(
|
||||
(network) => ({
|
||||
type: SearchType.Network,
|
||||
id: network.id,
|
||||
data: network,
|
||||
onAction: () => router.push(`/network?id=${network.id}`),
|
||||
}),
|
||||
);
|
||||
|
||||
const resourceResults: ResourceSearchResult[] = (resources ?? []).map(
|
||||
(resource) => ({
|
||||
type: SearchType.NetworkResource,
|
||||
id: resource.id,
|
||||
data: resource,
|
||||
onAction: () => {
|
||||
const network = findNetworkByResourceId(resource.id);
|
||||
if (network)
|
||||
router.push(`/network?id=${network.id}&resource=${resource.id}`);
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
return [...networkResults, ...resourceResults];
|
||||
}, [isNetworksLoading, isResourcesLoading, networks, resources]);
|
||||
|
||||
const [filteredItems, search, setSearch, setQuery, isSearching] = useSearch(
|
||||
items,
|
||||
searchPredicate,
|
||||
{
|
||||
filter: false,
|
||||
debounce: 350,
|
||||
},
|
||||
);
|
||||
|
||||
const isLoading = isNetworksLoading || isResourcesLoading || isSearching;
|
||||
|
||||
const networksCount = useMemo(() => {
|
||||
return filteredItems.filter((i) => i.type === SearchType.Network).length;
|
||||
}, [filteredItems]);
|
||||
|
||||
const resourcesCount = useMemo(() => {
|
||||
return filteredItems.filter((i) => i.type === SearchType.NetworkResource)
|
||||
.length;
|
||||
}, [filteredItems]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Modal
|
||||
open={open}
|
||||
onOpenChange={(isOpen) => {
|
||||
if (!isOpen) setSearch("");
|
||||
setOpen(isOpen);
|
||||
}}
|
||||
>
|
||||
<ModalContent
|
||||
showClose={false}
|
||||
className={"py-0 overflow-hidden"}
|
||||
maxWidthClass={"max-w-xl"}
|
||||
>
|
||||
<DropdownInput
|
||||
hideEnterIcon={true}
|
||||
value={search}
|
||||
onChange={setSearch}
|
||||
autoFocus={true}
|
||||
/>
|
||||
|
||||
{search === "" && <BlankState />}
|
||||
|
||||
{isLoading && search !== "" && <LoadingState />}
|
||||
|
||||
{!isSearching && search !== "" && filteredItems.length === 0 && (
|
||||
<NotFoundState />
|
||||
)}
|
||||
|
||||
{!isSearching && search != "" && filteredItems.length !== 0 && (
|
||||
<VirtualScrollAreaList
|
||||
items={filteredItems}
|
||||
maxHeight={400}
|
||||
scrollAreaClassName={"pt-0"}
|
||||
groupKey={(i) => i.type}
|
||||
estimatedItemHeight={48}
|
||||
estimatedHeadingHeight={32}
|
||||
heightAdjustment={5}
|
||||
onSelect={(item) => {
|
||||
const { onAction, data, type } = item;
|
||||
if (type === SearchType.Network) onAction?.(data);
|
||||
if (type === SearchType.NetworkResource) onAction?.(data);
|
||||
}}
|
||||
renderHeading={(item) => {
|
||||
return (
|
||||
<div className={"text-xs text-nb-gray-400 px-4 py-2"}>
|
||||
{item.type === SearchType.Network &&
|
||||
`Networks (${networksCount})`}
|
||||
{item.type === SearchType.NetworkResource &&
|
||||
`Resources (${resourcesCount})`}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
renderItem={(item) => {
|
||||
const network = findNetworkByResourceId(item.id);
|
||||
|
||||
return (
|
||||
<div className={"flex justify-between items-center w-full"}>
|
||||
<div className={"flex justify-between items-center gap-3"}>
|
||||
<div
|
||||
className={
|
||||
"h-8 w-8 bg-nb-gray-850 group-aria-selected/list-item:bg-nb-gray-700 flex items-center justify-center rounded-md"
|
||||
}
|
||||
>
|
||||
{item.type === SearchType.Network && (
|
||||
<div className={"uppercase font-medium"}>
|
||||
{item.data.name.substring(0, 2)}
|
||||
</div>
|
||||
)}
|
||||
{item.type === SearchType.NetworkResource && (
|
||||
<ResourceIcon type={item.data.type} />
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<div>
|
||||
{item.data.name} {network && ` - ${network.name}`}
|
||||
</div>
|
||||
<div className={"text-nb-gray-400"}>
|
||||
{item.data.description}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className={"flex items-center justify-center gap-4"}>
|
||||
{item.type === SearchType.Network && (
|
||||
<div>
|
||||
<div
|
||||
className={
|
||||
"text-[0.65rem] text-nb-gray-250 flex items-center gap-2 leading-none"
|
||||
}
|
||||
>
|
||||
<LayersIcon
|
||||
size={12}
|
||||
className={"relative -top-[1px]"}
|
||||
/>
|
||||
{item.data?.resources?.length} Resource(s)
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{item.type === SearchType.NetworkResource && (
|
||||
<div>
|
||||
<div
|
||||
className={
|
||||
"text-[0.62rem] font-mono text-nb-gray-250"
|
||||
}
|
||||
>
|
||||
{item.data?.address}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<CornerDownLeft
|
||||
size={14}
|
||||
className={
|
||||
"opacity-0 group-aria-selected/list-item:opacity-100 group-list-item-aria-selected:opacity-100"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<KeyboardShortcutsFooter />
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ResourceIcon = ({ type }: { type: NetworkResource["type"] }) => {
|
||||
const size = 14;
|
||||
switch (type) {
|
||||
case "host":
|
||||
return <WorkflowIcon size={size} />;
|
||||
case "domain":
|
||||
return <GlobeIcon size={size} />;
|
||||
case "subnet":
|
||||
return <NetworkIcon size={size} />;
|
||||
default:
|
||||
return <WorkflowIcon size={size} />;
|
||||
}
|
||||
};
|
||||
|
||||
const BlankState = () => {
|
||||
return (
|
||||
<div className={"flex items-center justify-center pb-8"}>
|
||||
<div className={"text-center"}>
|
||||
<div className={"flex items-center justify-center mb-3 mt-3 gap-3"}>
|
||||
<div
|
||||
className={
|
||||
"bg-nb-gray-920 h-8 w-8 flex items-center justify-center rounded-md"
|
||||
}
|
||||
>
|
||||
<NetworkIcon size={16} />
|
||||
</div>
|
||||
<div
|
||||
className={
|
||||
"bg-nb-gray-920 h-8 w-8 flex items-center justify-center rounded-md"
|
||||
}
|
||||
>
|
||||
<WorkflowIcon size={16} />
|
||||
</div>
|
||||
<div
|
||||
className={
|
||||
"bg-nb-gray-920 h-8 w-8 flex items-center justify-center rounded-md"
|
||||
}
|
||||
>
|
||||
<GlobeIcon size={16} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={"text-nb-gray-100 mb-1"}>
|
||||
Search for Networks and Resources
|
||||
</div>
|
||||
<div className={"text-sm text-nb-gray-350 font-light"}>
|
||||
Quickly find networks and associated resources. <br />
|
||||
Start typing to search by name, description or address.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const NotFoundState = () => {
|
||||
return (
|
||||
<div className={"flex items-center justify-center pb-8"}>
|
||||
<div className={"text-center"}>
|
||||
<div className={"flex items-center justify-center mb-3 mt-3 gap-3"}>
|
||||
<div
|
||||
className={
|
||||
"bg-nb-gray-920 h-8 w-8 flex items-center justify-center rounded-md"
|
||||
}
|
||||
>
|
||||
<TextSearchIcon size={16} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={"text-nb-gray-100 mb-1"}>
|
||||
Could not find any results
|
||||
</div>
|
||||
<div className={"text-sm text-nb-gray-350 font-light max-w-xs"}>
|
||||
{`We couldn't find any results. Please try a different search term.`}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const LoadingState = () => {
|
||||
return (
|
||||
<div className={"flex flex-col gap-1 px-3 mb-4 opacity-50"}>
|
||||
<Skeleton width={"100%"} height={40} />
|
||||
<Skeleton width={"100%"} height={40} />
|
||||
<Skeleton width={"100%"} height={40} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const KeyboardShortcutsFooter = () => {
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
"bg-nb-gray-940 border-t border-nb-gray-910 px-4 py-3 text-xs text-nb-gray-300 flex items-center gap-5"
|
||||
}
|
||||
>
|
||||
<div className={"flex items-center gap-1.5"}>
|
||||
<Kbd variant={"darker"}>
|
||||
<ArrowUpIcon size={12} />
|
||||
</Kbd>
|
||||
<Kbd variant={"darker"}>
|
||||
<ArrowDownIcon size={12} />
|
||||
</Kbd>
|
||||
<div className={"ml-1"}>Navigate</div>
|
||||
</div>
|
||||
<div className={"flex items-center gap-1.5"}>
|
||||
<Kbd variant={"darker"}>
|
||||
<CornerDownLeft size={12} />
|
||||
</Kbd>
|
||||
<div className={"ml-1"}>Open</div>
|
||||
</div>
|
||||
<div className={"flex items-center gap-1.5"}>
|
||||
<Kbd variant={"darker"} className={"text-[0.65rem] font-medium"}>
|
||||
esc
|
||||
</Kbd>
|
||||
<div className={"ml-1"}>Close</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
CalendarClock,
|
||||
ExternalLinkIcon,
|
||||
ShieldIcon,
|
||||
ShieldUserIcon,
|
||||
TimerResetIcon,
|
||||
} from "lucide-react";
|
||||
import React, { useState } from "react";
|
||||
@@ -52,6 +53,19 @@ export default function AuthenticationTab({ account }: Readonly<Props>) {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* User approval required
|
||||
*/
|
||||
const [userApprovalRequired, setUserApprovalRequired] = useState<boolean>(
|
||||
() => {
|
||||
try {
|
||||
return account?.settings?.extra?.user_approval_required || false;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Peer Expiration
|
||||
const [
|
||||
loginExpiration,
|
||||
@@ -86,6 +100,7 @@ export default function AuthenticationTab({ account }: Readonly<Props>) {
|
||||
|
||||
const { hasChanges, updateRef } = useHasChanges([
|
||||
peerApproval,
|
||||
userApprovalRequired,
|
||||
loginExpiration,
|
||||
expiresIn,
|
||||
expireInterval,
|
||||
@@ -118,6 +133,7 @@ export default function AuthenticationTab({ account }: Readonly<Props>) {
|
||||
extra: {
|
||||
...account.settings?.extra,
|
||||
peer_approval_enabled: peerApproval,
|
||||
user_approval_required: userApprovalRequired,
|
||||
},
|
||||
},
|
||||
} as Account)
|
||||
@@ -125,6 +141,7 @@ export default function AuthenticationTab({ account }: Readonly<Props>) {
|
||||
mutate("/accounts");
|
||||
updateRef([
|
||||
peerApproval,
|
||||
userApprovalRequired,
|
||||
loginExpiration,
|
||||
expiresIn,
|
||||
expireInterval,
|
||||
@@ -181,6 +198,27 @@ export default function AuthenticationTab({ account }: Readonly<Props>) {
|
||||
</div>
|
||||
|
||||
<div className={"flex flex-col gap-6 w-full mt-8 mb-3"}>
|
||||
<div className={"flex flex-col"}>
|
||||
<FancyToggleSwitch
|
||||
value={userApprovalRequired}
|
||||
onChange={setUserApprovalRequired}
|
||||
dataCy={"user-approval-required"}
|
||||
label={
|
||||
<>
|
||||
<ShieldUserIcon size={15} />
|
||||
User Approval Required
|
||||
</>
|
||||
}
|
||||
helpText={
|
||||
<>
|
||||
Require manual approval for new users joining via <br />
|
||||
domain matching. Users will be blocked until approved.
|
||||
</>
|
||||
}
|
||||
disabled={!permission.settings.update}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={"flex flex-col"}>
|
||||
<FancyToggleSwitch
|
||||
value={loginExpiration}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useOidc } from "@axa-fr/react-oidc";
|
||||
import Breadcrumbs from "@components/Breadcrumbs";
|
||||
import Button from "@components/Button";
|
||||
import Card from "@components/Card";
|
||||
@@ -29,6 +28,13 @@ export default function DangerZoneTab({ account }: Props) {
|
||||
.del()
|
||||
.catch((error) => reject(error))
|
||||
.then(() => {
|
||||
// Clear browser storage after account deletion
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
// Optionally, clear cookies if needed
|
||||
// document.cookie = ... (set cookies to expire)
|
||||
}
|
||||
logout().then();
|
||||
resolve();
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import FullTooltip from "@components/FullTooltip";
|
||||
import { notify } from "@components/Notification";
|
||||
import { useApiCall } from "@utils/api";
|
||||
import { Trash2 } from "lucide-react";
|
||||
import React from "react";
|
||||
import React, { useMemo } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { useDialog } from "@/contexts/DialogProvider";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
@@ -50,7 +50,12 @@ export default function GroupsActionCell({ group, in_use }: Readonly<Props>) {
|
||||
issued: group?.issued,
|
||||
});
|
||||
|
||||
const isDisabled = in_use || !isRegularGroup || !permission.groups.delete;
|
||||
const isDisabled = useMemo(() => {
|
||||
if (!permission.groups.delete) return true;
|
||||
if (in_use) return true;
|
||||
if (isJWTGroup) return false;
|
||||
return !isRegularGroup;
|
||||
}, [permission, in_use, isJWTGroup, isRegularGroup]);
|
||||
|
||||
const getDisabledText = () => {
|
||||
if (isRegularGroup) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import * as Tabs from "@radix-ui/react-tabs";
|
||||
import { useApiCall } from "@utils/api";
|
||||
import { validator } from "@utils/helpers";
|
||||
import { isNetBirdHosted } from "@utils/netbird";
|
||||
import cidr from "ip-cidr";
|
||||
import { ExternalLinkIcon, GlobeIcon, NetworkIcon } from "lucide-react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
@@ -34,6 +35,9 @@ export default function NetworkSettingsTab({ account }: Readonly<Props>) {
|
||||
const [customDNSDomain, setCustomDNSDomain] = useState(
|
||||
account.settings.dns_domain || "",
|
||||
);
|
||||
const [networkRange, setNetworkRange] = useState(
|
||||
account.settings.network_range || "",
|
||||
);
|
||||
|
||||
const toggleNetworkDNSSetting = async (toggle: boolean) => {
|
||||
notify({
|
||||
@@ -57,25 +61,37 @@ export default function NetworkSettingsTab({ account }: Readonly<Props>) {
|
||||
});
|
||||
};
|
||||
|
||||
const { hasChanges, updateRef } = useHasChanges([customDNSDomain]);
|
||||
const { hasChanges, updateRef } = useHasChanges([
|
||||
customDNSDomain,
|
||||
networkRange,
|
||||
]);
|
||||
|
||||
const saveChanges = async () => {
|
||||
const updatedSettings = {
|
||||
...account.settings,
|
||||
};
|
||||
|
||||
if (customDNSDomain !== "" || account.settings.dns_domain) {
|
||||
updatedSettings.dns_domain = customDNSDomain;
|
||||
}
|
||||
|
||||
if (networkRange !== "") {
|
||||
updatedSettings.network_range = networkRange;
|
||||
}
|
||||
|
||||
notify({
|
||||
title: "Custom DNS Domain",
|
||||
description: `Custom DNS Domain successfully updated.`,
|
||||
title: "Network Settings",
|
||||
description: `Network settings successfully updated.`,
|
||||
promise: saveRequest
|
||||
.put({
|
||||
id: account.id,
|
||||
settings: {
|
||||
...account.settings,
|
||||
dns_domain: customDNSDomain || "",
|
||||
},
|
||||
settings: updatedSettings,
|
||||
})
|
||||
.then(() => {
|
||||
mutate("/accounts");
|
||||
updateRef([customDNSDomain]);
|
||||
updateRef([customDNSDomain, networkRange]);
|
||||
}),
|
||||
loadingMessage: "Updating Custom DNS domain...",
|
||||
loadingMessage: "Updating network settings...",
|
||||
});
|
||||
};
|
||||
|
||||
@@ -90,6 +106,24 @@ export default function NetworkSettingsTab({ account }: Readonly<Props>) {
|
||||
}
|
||||
}, [customDNSDomain]);
|
||||
|
||||
const networkRangeError = useMemo(() => {
|
||||
if (networkRange == "") {
|
||||
if (account.settings.network_range) {
|
||||
return "Network range cannot be empty";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
const validCIDR = cidr.isValidCIDR(networkRange);
|
||||
if (!validCIDR) {
|
||||
return "Please enter a valid IPv4 CIDR range, e.g. 100.64.0.0/16 or 192.168.1.0/24";
|
||||
}
|
||||
} catch (error) {
|
||||
return "Please enter a valid IPv4 CIDR range, e.g. 100.64.0.0/16 or 192.168.1.0/24";
|
||||
}
|
||||
}, [networkRange, account.settings.network_range]);
|
||||
|
||||
return (
|
||||
<Tabs.Content value={"networks"}>
|
||||
<div className={"p-default py-6 max-w-2xl"}>
|
||||
@@ -112,7 +146,12 @@ export default function NetworkSettingsTab({ account }: Readonly<Props>) {
|
||||
</div>
|
||||
<Button
|
||||
variant={"primary"}
|
||||
disabled={!hasChanges || !permission.settings.update}
|
||||
disabled={
|
||||
!hasChanges ||
|
||||
!permission.settings.update ||
|
||||
!!domainError ||
|
||||
!!networkRangeError
|
||||
}
|
||||
onClick={saveChanges}
|
||||
>
|
||||
Save Changes
|
||||
@@ -130,7 +169,8 @@ export default function NetworkSettingsTab({ account }: Readonly<Props>) {
|
||||
<Label>DNS Domain</Label>
|
||||
<HelpText>
|
||||
Specify a custom peer DNS domain for your network. This should
|
||||
not point to a domain that is already in use elsewhere, to avoid overriding DNS results.
|
||||
not point to a domain that is already in use elsewhere, to
|
||||
avoid overriding DNS results.
|
||||
</HelpText>
|
||||
</div>
|
||||
<div className={"w-full"}>
|
||||
@@ -149,6 +189,33 @@ export default function NetworkSettingsTab({ account }: Readonly<Props>) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div
|
||||
className={
|
||||
"flex flex-col gap-1 sm:flex-row w-full sm:gap-4 items-center"
|
||||
}
|
||||
>
|
||||
<div className={"min-w-[330px]"}>
|
||||
<Label>Network Range</Label>
|
||||
<HelpText>
|
||||
Specify a custom IPv4 range for your network in CIDR format.
|
||||
All peer IPs will be re-allocated when changed.
|
||||
</HelpText>
|
||||
</div>
|
||||
<div className={"w-full"}>
|
||||
<Input
|
||||
placeholder={"e.g. 100.64.0.0/16"}
|
||||
errorTooltip={true}
|
||||
errorTooltipPosition={"top"}
|
||||
error={networkRangeError}
|
||||
value={networkRange}
|
||||
disabled={!permission.settings.update}
|
||||
onChange={(e) => setNetworkRange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FancyToggleSwitch
|
||||
value={routingPeerDNSSetting}
|
||||
onChange={toggleNetworkDNSSetting}
|
||||
|
||||
@@ -14,11 +14,13 @@ import { RoutingPeerSetupKeyInfo } from "@/modules/setup-netbird-modal/SetupModa
|
||||
type Props = {
|
||||
setupKey?: string;
|
||||
showSetupKeyInfo?: boolean;
|
||||
hostname?: string;
|
||||
};
|
||||
|
||||
export default function DockerTab({
|
||||
setupKey,
|
||||
showSetupKeyInfo = false,
|
||||
hostname,
|
||||
}: Readonly<Props>) {
|
||||
return (
|
||||
<TabsContent value={String(OperatingSystem.DOCKER)}>
|
||||
@@ -59,7 +61,16 @@ export default function DockerTab({
|
||||
</span>{" "}
|
||||
\
|
||||
</Code.Line>
|
||||
<Code.Line> -v netbird-client:/etc/netbird \</Code.Line>
|
||||
|
||||
{hostname && (
|
||||
<Code.Line>
|
||||
{" "}
|
||||
-e NB_HOSTNAME=
|
||||
<span className={"text-netbird"}>{`'${hostname}'`}</span> \
|
||||
</Code.Line>
|
||||
)}
|
||||
|
||||
<Code.Line> -v netbird-client:/var/lib/netbird \</Code.Line>
|
||||
{GRPC_API_ORIGIN && (
|
||||
<Code.Line>
|
||||
{" "}
|
||||
@@ -73,9 +84,7 @@ export default function DockerTab({
|
||||
<Steps.Step step={3} line={false}>
|
||||
<p>Read our documentation</p>
|
||||
<InlineLink
|
||||
href={
|
||||
"https://docs.netbird.io/how-to/getting-started#running-net-bird-in-docker"
|
||||
}
|
||||
href={"https://docs.netbird.io/how-to/installation/docker"}
|
||||
passHref={true}
|
||||
target={"_blank"}
|
||||
>
|
||||
|
||||
@@ -14,6 +14,7 @@ import { TerminalSquareIcon } from "lucide-react";
|
||||
import React from "react";
|
||||
import { OperatingSystem } from "@/interfaces/OperatingSystem";
|
||||
import {
|
||||
HostnameParameter,
|
||||
RoutingPeerSetupKeyInfo,
|
||||
SetupKeyParameter,
|
||||
} from "@/modules/setup-netbird-modal/SetupModal";
|
||||
@@ -21,11 +22,13 @@ import {
|
||||
type Props = {
|
||||
setupKey?: string;
|
||||
showSetupKeyInfo?: boolean;
|
||||
hostname?: string;
|
||||
};
|
||||
|
||||
export default function LinuxTab({
|
||||
setupKey,
|
||||
showSetupKeyInfo = false,
|
||||
hostname,
|
||||
}: Readonly<Props>) {
|
||||
return (
|
||||
<TabsContent value={String(OperatingSystem.LINUX)}>
|
||||
@@ -47,6 +50,7 @@ export default function LinuxTab({
|
||||
<Code.Line>
|
||||
{getNetBirdUpCommand()}
|
||||
<SetupKeyParameter setupKey={setupKey} />
|
||||
<HostnameParameter hostname={hostname} />
|
||||
</Code.Line>
|
||||
</Code>
|
||||
</Steps.Step>
|
||||
@@ -104,6 +108,7 @@ export default function LinuxTab({
|
||||
<Code.Line>
|
||||
{getNetBirdUpCommand()}
|
||||
<SetupKeyParameter setupKey={setupKey} />
|
||||
<HostnameParameter hostname={hostname} />
|
||||
</Code.Line>
|
||||
</Code>
|
||||
</Steps.Step>
|
||||
|
||||
@@ -24,6 +24,7 @@ import Link from "next/link";
|
||||
import React from "react";
|
||||
import { OperatingSystem } from "@/interfaces/OperatingSystem";
|
||||
import {
|
||||
HostnameParameter,
|
||||
RoutingPeerSetupKeyInfo,
|
||||
SetupKeyParameter,
|
||||
} from "@/modules/setup-netbird-modal/SetupModal";
|
||||
@@ -31,10 +32,12 @@ import {
|
||||
type Props = {
|
||||
setupKey?: string;
|
||||
showSetupKeyInfo?: boolean;
|
||||
hostname?: string;
|
||||
};
|
||||
export default function MacOSTab({
|
||||
setupKey,
|
||||
showSetupKeyInfo,
|
||||
hostname,
|
||||
}: Readonly<Props>) {
|
||||
return (
|
||||
<TabsContent value={String(OperatingSystem.APPLE)}>
|
||||
@@ -120,6 +123,7 @@ export default function MacOSTab({
|
||||
<Code.Line>
|
||||
{getNetBirdUpCommand()}
|
||||
<SetupKeyParameter setupKey={setupKey} />
|
||||
<HostnameParameter hostname={hostname} />
|
||||
</Code.Line>
|
||||
</Code>
|
||||
</Steps.Step>
|
||||
@@ -162,6 +166,7 @@ export default function MacOSTab({
|
||||
<Code.Line>
|
||||
{getNetBirdUpCommand()}
|
||||
<SetupKeyParameter setupKey={setupKey} />
|
||||
<HostnameParameter hostname={hostname} />
|
||||
</Code.Line>
|
||||
</Code>
|
||||
</Steps.Step>
|
||||
@@ -222,6 +227,7 @@ export default function MacOSTab({
|
||||
<Code.Line>
|
||||
{getNetBirdUpCommand()}
|
||||
<SetupKeyParameter setupKey={setupKey} />
|
||||
<HostnameParameter hostname={hostname} />
|
||||
</Code.Line>
|
||||
</Code>
|
||||
</Steps.Step>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Tabs, TabsList, TabsTrigger } from "@components/Tabs";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import React from "react";
|
||||
import React, { useMemo } from "react";
|
||||
import AndroidIcon from "@/assets/icons/AndroidIcon";
|
||||
import AppleIcon from "@/assets/icons/AppleIcon";
|
||||
import DockerIcon from "@/assets/icons/DockerIcon";
|
||||
@@ -34,6 +34,7 @@ type Props = {
|
||||
user?: OidcUserInfo;
|
||||
setupKey?: string;
|
||||
showOnlyRoutingPeerOS?: boolean;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export default function SetupModal({
|
||||
@@ -41,9 +42,10 @@ export default function SetupModal({
|
||||
user,
|
||||
setupKey,
|
||||
showOnlyRoutingPeerOS = false,
|
||||
className,
|
||||
}: Readonly<Props>) {
|
||||
return (
|
||||
<ModalContent showClose={showClose}>
|
||||
<ModalContent showClose={showClose} className={className}>
|
||||
<SetupModalContent
|
||||
user={user}
|
||||
setupKey={setupKey}
|
||||
@@ -60,6 +62,9 @@ type SetupModalContentProps = {
|
||||
tabAlignment?: "center" | "start" | "end";
|
||||
setupKey?: string;
|
||||
showOnlyRoutingPeerOS?: boolean;
|
||||
title?: string;
|
||||
hostname?: string;
|
||||
hideDocker?: boolean;
|
||||
};
|
||||
|
||||
export function SetupModalContent({
|
||||
@@ -69,12 +74,30 @@ export function SetupModalContent({
|
||||
tabAlignment = "center",
|
||||
setupKey,
|
||||
showOnlyRoutingPeerOS,
|
||||
title,
|
||||
hostname,
|
||||
hideDocker = false,
|
||||
}: Readonly<SetupModalContentProps>) {
|
||||
const os = useOperatingSystem();
|
||||
const [isFirstRun] = useLocalStorage<boolean>("netbird-first-run", true);
|
||||
const pathname = usePathname();
|
||||
const isInstallPage = pathname === "/install";
|
||||
|
||||
const titleMessage = useMemo(() => {
|
||||
if (title) return title;
|
||||
|
||||
if (isFirstRun && !isInstallPage) {
|
||||
let name = user?.given_name || "there";
|
||||
return (
|
||||
<>
|
||||
Hello {name}! 👋 <br /> It's time to add your first device.
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return setupKey ? "Install NetBird with Setup Key" : "Install NetBird";
|
||||
}, [isFirstRun, isInstallPage, setupKey, title, user?.given_name]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{header && (
|
||||
@@ -85,14 +108,7 @@ export function SetupModalContent({
|
||||
setupKey ? "text-2xl" : "text-3xl",
|
||||
)}
|
||||
>
|
||||
{isFirstRun && !isInstallPage ? (
|
||||
<>
|
||||
Hello {user?.given_name || "there"}! 👋 <br />
|
||||
{`It's time to add your first device.`}
|
||||
</>
|
||||
) : (
|
||||
<>Install NetBird{setupKey && " with Setup Key"}</>
|
||||
)}
|
||||
{titleMessage}
|
||||
</h2>
|
||||
<Paragraph
|
||||
className={cn("mx-auto mt-3", setupKey ? "max-w-sm" : "max-w-xs")}
|
||||
@@ -153,27 +169,32 @@ export function SetupModalContent({
|
||||
</>
|
||||
)}
|
||||
|
||||
<TabsTrigger value={String(OperatingSystem.DOCKER)}>
|
||||
<DockerIcon
|
||||
className={
|
||||
"fill-nb-gray-500 group-data-[state=active]/trigger:fill-netbird transition-all"
|
||||
}
|
||||
/>
|
||||
Docker
|
||||
</TabsTrigger>
|
||||
{!hideDocker && (
|
||||
<TabsTrigger value={String(OperatingSystem.DOCKER)}>
|
||||
<DockerIcon
|
||||
className={
|
||||
"fill-nb-gray-500 group-data-[state=active]/trigger:fill-netbird transition-all"
|
||||
}
|
||||
/>
|
||||
Docker
|
||||
</TabsTrigger>
|
||||
)}
|
||||
</TabsList>
|
||||
|
||||
<LinuxTab
|
||||
setupKey={setupKey}
|
||||
showSetupKeyInfo={showOnlyRoutingPeerOS}
|
||||
hostname={hostname}
|
||||
/>
|
||||
<WindowsTab
|
||||
setupKey={setupKey}
|
||||
showSetupKeyInfo={showOnlyRoutingPeerOS}
|
||||
hostname={hostname}
|
||||
/>
|
||||
<MacOSTab
|
||||
setupKey={setupKey}
|
||||
showSetupKeyInfo={showOnlyRoutingPeerOS}
|
||||
hostname={hostname}
|
||||
/>
|
||||
|
||||
{!setupKey && (
|
||||
@@ -183,10 +204,13 @@ export function SetupModalContent({
|
||||
</>
|
||||
)}
|
||||
|
||||
<DockerTab
|
||||
setupKey={setupKey}
|
||||
showSetupKeyInfo={showOnlyRoutingPeerOS}
|
||||
/>
|
||||
{!hideDocker && (
|
||||
<DockerTab
|
||||
setupKey={setupKey}
|
||||
showSetupKeyInfo={showOnlyRoutingPeerOS}
|
||||
hostname={hostname}
|
||||
/>
|
||||
)}
|
||||
</Tabs>
|
||||
{footer && (
|
||||
<ModalFooter variant={"setup"}>
|
||||
@@ -227,6 +251,22 @@ export const SetupKeyParameter = ({ setupKey }: SetupKeyParameterProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const HostnameParameter = ({ hostname }: { hostname?: string }) => {
|
||||
return (
|
||||
hostname && (
|
||||
<>
|
||||
{" "}
|
||||
--hostname{" "}
|
||||
<span className={"text-netbird"}>
|
||||
{"'"}
|
||||
{hostname}
|
||||
{"'"}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const RoutingPeerSetupKeyInfo = () => {
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -8,6 +8,7 @@ import Link from "next/link";
|
||||
import React from "react";
|
||||
import { OperatingSystem } from "@/interfaces/OperatingSystem";
|
||||
import {
|
||||
HostnameParameter,
|
||||
RoutingPeerSetupKeyInfo,
|
||||
SetupKeyParameter,
|
||||
} from "@/modules/setup-netbird-modal/SetupModal";
|
||||
@@ -15,11 +16,13 @@ import {
|
||||
type Props = {
|
||||
setupKey?: string;
|
||||
showSetupKeyInfo?: boolean;
|
||||
hostname?: string;
|
||||
};
|
||||
|
||||
export default function WindowsTab({
|
||||
setupKey,
|
||||
showSetupKeyInfo,
|
||||
hostname,
|
||||
}: Readonly<Props>) {
|
||||
return (
|
||||
<TabsContent value={String(OperatingSystem.WINDOWS)}>
|
||||
@@ -67,6 +70,7 @@ export default function WindowsTab({
|
||||
<Code.Line>
|
||||
{getNetBirdUpCommand()}
|
||||
<SetupKeyParameter setupKey={setupKey} />
|
||||
<HostnameParameter hostname={hostname} />
|
||||
</Code.Line>
|
||||
</Code>
|
||||
</Steps.Step>
|
||||
|
||||
@@ -6,6 +6,7 @@ import DataTableHeader from "@components/table/DataTableHeader";
|
||||
import DataTableRefreshButton from "@components/table/DataTableRefreshButton";
|
||||
import { DataTableRowsPerPage } from "@components/table/DataTableRowsPerPage";
|
||||
import GetStartedTest from "@components/ui/GetStartedTest";
|
||||
import { NotificationCountBadge } from "@components/ui/NotificationCountBadge";
|
||||
import { ColumnDef, SortingState } from "@tanstack/react-table";
|
||||
import useFetchApi from "@utils/api";
|
||||
import { isLocalDev, isNetBirdHosted } from "@utils/netbird";
|
||||
@@ -88,6 +89,12 @@ export const UsersTableColumns: ColumnDef<User>[] = [
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "approval_required",
|
||||
accessorKey: "approval_required",
|
||||
sortingFn: "basic",
|
||||
accessorFn: (u) => u?.pending_approval,
|
||||
},
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "",
|
||||
@@ -127,6 +134,8 @@ export default function UsersTable({
|
||||
);
|
||||
|
||||
const router = useRouter();
|
||||
const pendingApprovalCount =
|
||||
users?.filter((u) => u.pending_approval).length || 0;
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
@@ -139,6 +148,7 @@ export default function UsersTable({
|
||||
data={users}
|
||||
columnVisibility={{
|
||||
is_current: false,
|
||||
approval_required: false,
|
||||
}}
|
||||
onRowClick={(row) => {
|
||||
router.push(`/team/user?id=${row.original.id}`);
|
||||
@@ -185,18 +195,56 @@ export default function UsersTable({
|
||||
/>
|
||||
)}
|
||||
>
|
||||
{(table) => (
|
||||
<>
|
||||
<DataTableRowsPerPage table={table} disabled={users?.length == 0} />
|
||||
<DataTableRefreshButton
|
||||
isDisabled={users?.length == 0}
|
||||
onClick={() => {
|
||||
mutate("/users?service_user=false");
|
||||
mutate("/groups");
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{(table) => {
|
||||
if (
|
||||
pendingApprovalCount == 0 &&
|
||||
table.getColumn("approval_required")?.getFilterValue() === true
|
||||
) {
|
||||
table.setColumnFilters([]);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{pendingApprovalCount > 0 && (
|
||||
<Button
|
||||
disabled={users?.length == 0}
|
||||
onClick={() => {
|
||||
table.setPageIndex(0);
|
||||
let current =
|
||||
table.getColumn("approval_required")?.getFilterValue() ===
|
||||
undefined
|
||||
? true
|
||||
: undefined;
|
||||
|
||||
table.setColumnFilters([
|
||||
{
|
||||
id: "approval_required",
|
||||
value: current,
|
||||
},
|
||||
]);
|
||||
}}
|
||||
variant={
|
||||
table.getColumn("approval_required")?.getFilterValue() ===
|
||||
true
|
||||
? "tertiary"
|
||||
: "secondary"
|
||||
}
|
||||
>
|
||||
Pending Approvals
|
||||
<NotificationCountBadge count={pendingApprovalCount} />
|
||||
</Button>
|
||||
)}
|
||||
<DataTableRowsPerPage table={table} disabled={users?.length == 0} />
|
||||
<DataTableRefreshButton
|
||||
isDisabled={users?.length == 0}
|
||||
onClick={() => {
|
||||
mutate("/users?service_user=false");
|
||||
mutate("/groups");
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</DataTable>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import Button from "@components/Button";
|
||||
import { notify } from "@components/Notification";
|
||||
import { useApiCall } from "@utils/api";
|
||||
import { isNetBirdHosted } from "@utils/netbird";
|
||||
import { Trash2 } from "lucide-react";
|
||||
import { Trash2, XCircle } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useMemo } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
@@ -36,6 +36,42 @@ export default function UserActionCell({
|
||||
});
|
||||
};
|
||||
|
||||
const approveUser = async () => {
|
||||
const name = user.name || "User";
|
||||
notify({
|
||||
title: `'${name}' approved`,
|
||||
description: "User was successfully approved.",
|
||||
promise: userRequest.post({}, `/${user.id}/approve`).then(() => {
|
||||
mutate(`/users?service_user=${serviceUser}`);
|
||||
}),
|
||||
loadingMessage: "Approving the user...",
|
||||
});
|
||||
};
|
||||
|
||||
const rejectUser = async () => {
|
||||
const name = user.name || "User";
|
||||
const choice = await confirm({
|
||||
title: `Reject '${name}'?`,
|
||||
description:
|
||||
"Rejecting this user will remove them from the account permanently. This action cannot be undone.",
|
||||
confirmText: "Reject",
|
||||
cancelText: "Cancel",
|
||||
type: "danger",
|
||||
maxWidthClass: "max-w-md",
|
||||
});
|
||||
if (!choice) return;
|
||||
|
||||
notify({
|
||||
title: `'${name}' rejected`,
|
||||
description: "User was successfully rejected and removed.",
|
||||
promise: userRequest.del("", `/${user.id}/reject`).then(() => {
|
||||
mutate(`/users?service_user=${serviceUser}`);
|
||||
}),
|
||||
|
||||
loadingMessage: "Rejecting the user...",
|
||||
});
|
||||
};
|
||||
|
||||
const openConfirm = async () => {
|
||||
const name = user.name || "User";
|
||||
const choice = await confirm({
|
||||
@@ -44,6 +80,7 @@ export default function UserActionCell({
|
||||
"Deleting this user will remove their devices and remove dashboard access. This action cannot be undone.",
|
||||
confirmText: "Delete",
|
||||
cancelText: "Cancel",
|
||||
maxWidthClass: "max-w-md",
|
||||
type: "danger",
|
||||
});
|
||||
if (!choice) return;
|
||||
@@ -55,21 +92,50 @@ export default function UserActionCell({
|
||||
return user.is_current;
|
||||
}, [permission.users.delete, user.is_current]);
|
||||
|
||||
const isPendingApproval = user.pending_approval;
|
||||
const canManageUsers = permission.users.update;
|
||||
|
||||
return (
|
||||
<div className={"flex justify-end pr-4 items-center gap-4"}>
|
||||
{!serviceUser && isNetBirdHosted() && (
|
||||
<div className={"flex justify-end pr-4 items-center gap-2"}>
|
||||
{!serviceUser && isNetBirdHosted() && !isPendingApproval && (
|
||||
<UserResendInviteButton user={user} />
|
||||
)}
|
||||
<Button
|
||||
variant={"danger-outline"}
|
||||
size={"sm"}
|
||||
onClick={openConfirm}
|
||||
data-cy={"delete-user"}
|
||||
disabled={disabled}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
Delete
|
||||
</Button>
|
||||
|
||||
{isPendingApproval && canManageUsers && (
|
||||
<>
|
||||
<Button
|
||||
variant={"secondary"}
|
||||
size={"xs"}
|
||||
onClick={approveUser}
|
||||
data-cy={"approve-user"}
|
||||
>
|
||||
Approve
|
||||
</Button>
|
||||
<Button
|
||||
variant={"danger-outline"}
|
||||
size={"xs"}
|
||||
className={"!px-3"}
|
||||
onClick={rejectUser}
|
||||
data-cy={"reject-user"}
|
||||
>
|
||||
<XCircle size={14} />
|
||||
Reject
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{!isPendingApproval && (
|
||||
<Button
|
||||
variant={"danger-outline"}
|
||||
size={"sm"}
|
||||
onClick={openConfirm}
|
||||
data-cy={"delete-user"}
|
||||
disabled={disabled}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
Delete
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ export default function UserBlockCell({ user, isUserPage = false }: Props) {
|
||||
});
|
||||
};
|
||||
|
||||
if (user?.pending_approval) return;
|
||||
|
||||
return !disabled ? (
|
||||
<div className={"flex"}>
|
||||
<ToggleSwitch
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
import MultipleGroups from "@components/ui/MultipleGroups";
|
||||
import { notify } from "@components/Notification";
|
||||
import { useApiCall } from "@utils/api";
|
||||
import { uniq } from "lodash";
|
||||
import React, { useMemo } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { useGroups } from "@/contexts/GroupsProvider";
|
||||
import { usePermissions } from "@/contexts/PermissionsProvider";
|
||||
import { Group } from "@/interfaces/Group";
|
||||
import { User } from "@/interfaces/User";
|
||||
import EmptyRow from "@/modules/common-table-rows/EmptyRow";
|
||||
import GroupsRow from "@/modules/common-table-rows/GroupsRow";
|
||||
|
||||
type Props = {
|
||||
user: User;
|
||||
};
|
||||
export default function UserGroupCell({ user }: Readonly<Props>) {
|
||||
const { groups, isLoading } = useGroups();
|
||||
const [modal, setModal] = useState(false);
|
||||
const { mutate } = useSWRConfig();
|
||||
const { permission } = usePermissions();
|
||||
const userRequest = useApiCall<User>("/users");
|
||||
|
||||
const allGroups = useMemo(() => {
|
||||
if (isLoading) return [];
|
||||
@@ -20,6 +27,10 @@ export default function UserGroupCell({ user }: Readonly<Props>) {
|
||||
.filter((g): g is Group => g !== undefined);
|
||||
}, [user.auto_groups, groups, isLoading]);
|
||||
|
||||
const userGroupIds = useMemo(() => {
|
||||
return (allGroups.map((group) => group.id) as string[]) || [];
|
||||
}, [allGroups]);
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className={"flex gap-2"}>
|
||||
@@ -28,9 +39,45 @@ export default function UserGroupCell({ user }: Readonly<Props>) {
|
||||
</div>
|
||||
);
|
||||
|
||||
return allGroups.length == 0 ? (
|
||||
<EmptyRow />
|
||||
) : (
|
||||
<MultipleGroups groups={allGroups} />
|
||||
const handleSave = async (promises: Promise<Group>[]) => {
|
||||
if (!user) return;
|
||||
|
||||
const groups = await Promise.all(promises);
|
||||
const groupIds =
|
||||
groups?.map((group) => group?.id).filter((id) => id !== undefined) || [];
|
||||
|
||||
notify({
|
||||
title: user?.name || user?.email || "User",
|
||||
description: "Groups of the user were successfully saved",
|
||||
promise: userRequest
|
||||
.put(
|
||||
{
|
||||
...user,
|
||||
auto_groups: groupIds,
|
||||
},
|
||||
`/${user.id}`,
|
||||
)
|
||||
.then(() => {
|
||||
setModal(false);
|
||||
mutate(`/users?service_user=false`);
|
||||
mutate(`/integrations/msp/switcher`);
|
||||
mutate("/groups");
|
||||
}),
|
||||
loadingMessage: "Updating groups...",
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<GroupsRow
|
||||
label={"Auto-assigned Groups"}
|
||||
description={"Groups will be assigned to peers added by this user."}
|
||||
groups={userGroupIds}
|
||||
onSave={handleSave}
|
||||
hideAllGroup={true}
|
||||
disabled={!permission.users.update}
|
||||
showAddGroupButton={permission.users.update}
|
||||
modal={modal}
|
||||
setModal={setModal}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,27 @@ export default function UserNameCell({ user }: Readonly<Props>) {
|
||||
const status = user.status;
|
||||
const isCurrent = user.is_current;
|
||||
|
||||
const getStatusIcon = () => {
|
||||
if (user?.pending_approval) {
|
||||
return {
|
||||
color: "bg-netbird text-netbird-950",
|
||||
icon: <Clock size={12} />,
|
||||
};
|
||||
}
|
||||
if (status === "blocked") {
|
||||
return { color: "bg-red-500 text-red-100", icon: <Ban size={12} /> };
|
||||
}
|
||||
if (status === "invited") {
|
||||
return {
|
||||
color: "bg-yellow-400 text-yellow-900",
|
||||
icon: <Clock size={12} />,
|
||||
};
|
||||
}
|
||||
return { color: "bg-gray-400", icon: <Clock size={12} /> };
|
||||
};
|
||||
|
||||
const { color, icon } = getStatusIcon();
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn("flex gap-4 px-2 py-1 items-center")}
|
||||
@@ -29,12 +50,10 @@ export default function UserNameCell({ user }: Readonly<Props>) {
|
||||
<div
|
||||
className={cn(
|
||||
"w-5 h-5 absolute -right-1 -bottom-1 bg-nb-gray-930 rounded-full flex items-center justify-center border-2 border-nb-gray-950",
|
||||
status == "invited" && "bg-yellow-400 text-yellow-900",
|
||||
status == "blocked" && "bg-red-500 text-red-100",
|
||||
color,
|
||||
)}
|
||||
>
|
||||
{status == "invited" && <Clock size={12} />}
|
||||
{status == "blocked" && <Ban size={12} />}
|
||||
{icon}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import FullTooltip from "@components/FullTooltip";
|
||||
import InlineLink from "@components/InlineLink";
|
||||
import { cn } from "@utils/helpers";
|
||||
import { ExternalLinkIcon, HelpCircle } from "lucide-react";
|
||||
import React from "react";
|
||||
import { User } from "@/interfaces/User";
|
||||
|
||||
@@ -8,23 +11,73 @@ type Props = {
|
||||
|
||||
export default function UserStatusCell({ user }: Readonly<Props>) {
|
||||
const status = user.status;
|
||||
const isPendingApproval = user.pending_approval;
|
||||
|
||||
const getStatusDisplay = () => {
|
||||
if (isPendingApproval) {
|
||||
return { text: "Pending Approval", color: "bg-netbird" };
|
||||
}
|
||||
if (status === "blocked") {
|
||||
return { text: "Blocked", color: "bg-red-500" };
|
||||
}
|
||||
if (status === "invited") {
|
||||
return { text: "Pending", color: "bg-yellow-400" };
|
||||
}
|
||||
if (status === "active") {
|
||||
return { text: "Active", color: "bg-green-500" };
|
||||
}
|
||||
return { text: status || "Unknown", color: "bg-gray-400" };
|
||||
};
|
||||
|
||||
const { text, color } = getStatusDisplay();
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn("flex gap-2.5 items-center text-nb-gray-300 text-sm")}
|
||||
data-cy={"user-status-cell"}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"h-2 w-2 rounded-full",
|
||||
status == "invited" && "bg-yellow-400",
|
||||
status == "blocked" && "bg-red-500",
|
||||
status == "active" && "bg-green-500",
|
||||
)}
|
||||
></span>
|
||||
{status == "invited" && "Pending"}
|
||||
{status == "blocked" && "Blocked"}
|
||||
{status == "active" && "Active"}
|
||||
<div onClick={(e) => e.stopPropagation()}>
|
||||
<FullTooltip
|
||||
content={
|
||||
<div className={"max-w-xs text-xs flex flex-col gap-2"}>
|
||||
<div>
|
||||
This user needs to be approved by an administrator before it can
|
||||
join your organization.
|
||||
</div>
|
||||
|
||||
<div>
|
||||
If you want to disable approval for new users, go to{" "}
|
||||
<InlineLink href={"/settings?tab=authentication"}>
|
||||
Settings
|
||||
</InlineLink>{" "}
|
||||
and disable{" "}
|
||||
<span className={"font-medium text-white"}>
|
||||
{"'User Approval Required'"}
|
||||
</span>
|
||||
.
|
||||
</div>
|
||||
<div>
|
||||
Learn more about{" "}
|
||||
<InlineLink
|
||||
href={"https://docs.netbird.io/how-to/approve-users"}
|
||||
target={"_blank"}
|
||||
>
|
||||
User Approval <ExternalLinkIcon size={12} />
|
||||
</InlineLink>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
interactive={true}
|
||||
side="right"
|
||||
disabled={!isPendingApproval}
|
||||
>
|
||||
<div
|
||||
className={cn("flex gap-2.5 items-center text-nb-gray-300 text-sm")}
|
||||
data-cy={"user-status-cell"}
|
||||
>
|
||||
<span className={cn("h-2 w-2 rounded-full", color)}></span>
|
||||
{text}
|
||||
{isPendingApproval && (
|
||||
<HelpCircle size={14} className="text-netbird cursor-help" />
|
||||
)}
|
||||
</div>
|
||||
</FullTooltip>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -215,6 +215,7 @@ export function useApiErrorHandling(ignoreError = false) {
|
||||
const { login } = useOidc();
|
||||
const currentPath = usePathname();
|
||||
const { setError } = useErrorBoundary();
|
||||
|
||||
if (ignoreError)
|
||||
return (err: ErrorResponse) => {
|
||||
console.log(err);
|
||||
@@ -231,6 +232,21 @@ export function useApiErrorHandling(ignoreError = false) {
|
||||
if (err.code == 401 && err.message == "token invalid") {
|
||||
setError(err);
|
||||
}
|
||||
|
||||
// Handle user blocked/pending approval responses
|
||||
if (err.code == 403 && (
|
||||
err.message?.toLowerCase().includes("blocked") ||
|
||||
err.message?.toLowerCase().includes("pending")
|
||||
)) {
|
||||
const params = new URLSearchParams({
|
||||
code: err.code.toString(),
|
||||
message: encodeURIComponent(err.message),
|
||||
type: "user-status"
|
||||
});
|
||||
window.location.href = `/error?${params.toString()}`;
|
||||
return Promise.reject(err);
|
||||
}
|
||||
|
||||
if (err.code == 500 && err.message == "internal server error") {
|
||||
setError(err);
|
||||
}
|
||||
|
||||
@@ -20,11 +20,13 @@ export function randomBoolean() {
|
||||
return Math.random() >= 0.5;
|
||||
}
|
||||
|
||||
export function removeAllSpaces(str: string) {
|
||||
export function removeAllSpaces(str?: string) {
|
||||
if (!str) return "";
|
||||
return str.replace(/\s/g, "");
|
||||
}
|
||||
|
||||
export const generateColorFromString = (str: string) => {
|
||||
export const generateColorFromString = (str?: string) => {
|
||||
if (!str) return "#f68330";
|
||||
if (str.includes("System")) return "#808080";
|
||||
if (str.toLowerCase().startsWith("netbird")) return "#f68330";
|
||||
let hash = 0;
|
||||
|
||||
@@ -8,16 +8,13 @@ export const getNetBirdUpCommand = () => {
|
||||
if (GRPC_API_ORIGIN) {
|
||||
cmd += " --management-url " + GRPC_API_ORIGIN;
|
||||
}
|
||||
if (!isNetBirdHosted()) {
|
||||
let admin_url = window.location.protocol + "//" + window.location.hostname;
|
||||
if (window.location.port != "") {
|
||||
admin_url += ":" + window.location.port;
|
||||
}
|
||||
cmd += " --admin-url " + admin_url;
|
||||
}
|
||||
return cmd;
|
||||
};
|
||||
|
||||
export const getInstallUrl = () => {
|
||||
return window.location.origin + "/install";
|
||||
};
|
||||
|
||||
export const isNetBirdHosted = () => {
|
||||
return (
|
||||
window.location.hostname.endsWith(".netbird.io") ||
|
||||
|
||||
@@ -14,7 +14,8 @@ const config: Config = {
|
||||
"50": "#f4f6f7",
|
||||
"100": "#e4e7e9",
|
||||
"200": "#cbd2d6",
|
||||
"300": "#a7b1b9",
|
||||
"250": "#b7c0c6",
|
||||
"300": "#aab4bd",
|
||||
"350": "#8f9ca8",
|
||||
"400": "#7c8994",
|
||||
"500": "#616e79",
|
||||
@@ -27,14 +28,15 @@ const config: Config = {
|
||||
"920": "#25282d",
|
||||
"925": "#1e2123",
|
||||
"930": "#25282c",
|
||||
"940": "#1b1f22",
|
||||
"940": "#1c1d21",
|
||||
"950": "#181a1d",
|
||||
},
|
||||
netbird: {
|
||||
DEFAULT: "#f68330",
|
||||
"50": "#fff6ed",
|
||||
"100": "#feecd6",
|
||||
"200": "#fcd5ac",
|
||||
"150": "#ffdfb8",
|
||||
"200": "#ffd4a6",
|
||||
"300": "#fab677",
|
||||
"400": "#f68330",
|
||||
"500": "#f46d1b",
|
||||
|
||||
Reference in New Issue
Block a user