show site type

This commit is contained in:
Milo Schwartz 2024-11-24 22:48:17 -05:00
parent ce2bfcddd5
commit 8c02367507
No known key found for this signature in database
6 changed files with 54 additions and 25 deletions

View file

@ -38,14 +38,15 @@ function querySites(orgId: string, accessibleSiteIds: number[]) {
megabytesIn: sites.megabytesIn,
megabytesOut: sites.megabytesOut,
orgName: orgs.name,
type: sites.type,
})
.from(sites)
.leftJoin(orgs, eq(sites.orgId, orgs.orgId))
.where(
and(
inArray(sites.siteId, accessibleSiteIds),
eq(sites.orgId, orgId)
)
eq(sites.orgId, orgId),
),
);
}
@ -57,7 +58,7 @@ export type ListSitesResponse = {
export async function listSites(
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
): Promise<any> {
try {
const parsedQuery = listSitesSchema.safeParse(req.query);
@ -65,8 +66,8 @@ export async function listSites(
return next(
createHttpError(
HttpCode.BAD_REQUEST,
fromError(parsedQuery.error)
)
fromError(parsedQuery.error),
),
);
}
const { limit, offset } = parsedQuery.data;
@ -76,8 +77,8 @@ export async function listSites(
return next(
createHttpError(
HttpCode.BAD_REQUEST,
fromError(parsedParams.error)
)
fromError(parsedParams.error),
),
);
}
const { orgId } = parsedParams.data;
@ -86,8 +87,8 @@ export async function listSites(
return next(
createHttpError(
HttpCode.FORBIDDEN,
"User does not have access to this organization"
)
"User does not have access to this organization",
),
);
}
@ -100,8 +101,8 @@ export async function listSites(
.where(
or(
eq(userSites.userId, req.user!.userId),
eq(roleSites.roleId, req.userOrgRoleId!)
)
eq(roleSites.roleId, req.userOrgRoleId!),
),
);
const accessibleSiteIds = accessibleSites.map((site) => site.siteId);
@ -113,8 +114,8 @@ export async function listSites(
.where(
and(
inArray(sites.siteId, accessibleSiteIds),
eq(sites.orgId, orgId)
)
eq(sites.orgId, orgId),
),
);
const sitesList = await baseQuery.limit(limit).offset(offset);
@ -137,7 +138,10 @@ export async function listSites(
});
} catch (error) {
return next(
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"An error occurred",
),
);
}
}

View file

@ -81,7 +81,7 @@ export default function UsersTable({ roles: r }: RolesTableProps) {
<DropdownMenuContent align="end">
<DropdownMenuItem>
<button
className="text-red-600 hover:text-red-800"
className="text-red-500"
onClick={() => {
setIsDeleteModalOpen(true);
setUserToRemove(roleRow);

View file

@ -99,7 +99,7 @@ export default function UsersTable({ users: u }: UsersTableProps) {
return (
<div className="flex flex-row items-center gap-1">
{userRow.isOwner && <Crown className="w-4 h-4" />}
{userRow.isOwner && <Crown className="w-4 h-4 text-yellow-600" />}
<span>{userRow.role}</span>
</div>
);
@ -138,13 +138,13 @@ export default function UsersTable({ users: u }: UsersTableProps) {
{userRow.email !== user?.email && (
<DropdownMenuItem>
<button
className="text-red-600 hover:text-red-800"
className="text-red-500"
onClick={() => {
setIsDeleteModalOpen(
true
true,
);
setSelectedUser(
userRow
userRow,
);
}}
>
@ -159,7 +159,7 @@ export default function UsersTable({ users: u }: UsersTableProps) {
className="ml-2"
onClick={() =>
router.push(
`/${org?.org.orgId}/settings/access/users/${userRow.id}`
`/${org?.org.orgId}/settings/access/users/${userRow.id}`,
)
}
>
@ -185,7 +185,7 @@ export default function UsersTable({ users: u }: UsersTableProps) {
title: "Failed to remove user",
description: formatAxiosError(
e,
"An error occurred while removing the user."
"An error occurred while removing the user.",
),
});
});
@ -198,7 +198,7 @@ export default function UsersTable({ users: u }: UsersTableProps) {
});
setUsers((prev) =>
prev.filter((u) => u.id !== selectedUser?.id)
prev.filter((u) => u.id !== selectedUser?.id),
);
}
}

View file

@ -117,7 +117,7 @@ export default function SitesTable({ resources, orgId }: ResourcesTableProps) {
},
{
accessorKey: "domain",
header: "Domain",
header: "Full URL",
cell: ({ row }) => {
const resourceRow = row.original;
return (

View file

@ -27,6 +27,7 @@ export type SiteRow = {
mbIn: string;
mbOut: string;
orgId: string;
type: "newt" | "wireguard";
};
type SitesTableProps = {
@ -105,6 +106,29 @@ export default function SitesTable({ sites, orgId }: SitesTableProps) {
accessorKey: "mbOut",
header: "MB Out",
},
{
accessorKey: "type",
header: "Connection Type",
cell: ({ row }) => {
const originalRow = row.original;
if (originalRow.type === "newt") {
return (
<div className="flex items-center space-x-2">
<span>Newt</span>
</div>
);
}
if (originalRow.type === "wireguard") {
return (
<div className="flex items-center space-x-2">
<span>WireGuard</span>
</div>
);
}
},
},
{
id: "actions",
cell: ({ row }) => {
@ -135,7 +159,7 @@ export default function SitesTable({ sites, orgId }: SitesTableProps) {
setSelectedSite(siteRow);
setIsDeleteModalOpen(true);
}}
className="text-red-600 hover:text-red-800"
className="text-red-500"
>
Delete
</button>
@ -147,7 +171,7 @@ export default function SitesTable({ sites, orgId }: SitesTableProps) {
className="ml-2"
onClick={() =>
router.push(
`/${siteRow.orgId}/settings/sites/${siteRow.nice}`
`/${siteRow.orgId}/settings/sites/${siteRow.nice}`,
)
}
>

View file

@ -40,6 +40,7 @@ export default async function SitesPage(props: SitesPageProps) {
mbIn: formatSize(site.megabytesIn || 0),
mbOut: formatSize(site.megabytesOut || 0),
orgId: params.orgId,
type: site.type as any,
};
});