diff --git a/src/api/index.ts b/src/api/index.ts index b59445d..d9ac4bd 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -8,8 +8,9 @@ export function createApiClient({ env }: { env: env }): AxiosInstance { return apiInstance; } - if (apiInstance) { - return apiInstance + if (typeof window === "undefined") { + // @ts-ignore + return; } let baseURL; @@ -45,7 +46,8 @@ export const internal = axios.create({ baseURL: `http://localhost:${process.env.SERVER_EXTERNAL_PORT}/api/v1`, timeout: 10000, headers: { - "Content-Type": "application/json" + "Content-Type": "application/json", + "X-CSRF-Token": "x-csrf-protection" } }); diff --git a/src/app/[orgId]/settings/access/roles/components/RolesTable.tsx b/src/app/[orgId]/settings/access/roles/components/RolesTable.tsx index e70a989..7b67c08 100644 --- a/src/app/[orgId]/settings/access/roles/components/RolesTable.tsx +++ b/src/app/[orgId]/settings/access/roles/components/RolesTable.tsx @@ -40,26 +40,6 @@ export default function UsersTable({ roles: r }: RolesTableProps) { const { toast } = useToast(); const columns: ColumnDef[] = [ - { - accessorKey: "name", - header: ({ column }) => { - return ( - - ); - } - }, - { - accessorKey: "description", - header: "Description" - }, { id: "actions", cell: ({ row }) => { @@ -67,14 +47,9 @@ export default function UsersTable({ roles: r }: RolesTableProps) { return ( <> -
+
{roleRow.isAdmin && ( - + )} {!roleRow.isAdmin && ( @@ -107,6 +82,26 @@ export default function UsersTable({ roles: r }: RolesTableProps) { ); } + }, + { + accessorKey: "name", + header: ({ column }) => { + return ( + + ); + } + }, + { + accessorKey: "description", + header: "Description" } ]; diff --git a/src/app/[orgId]/settings/access/users/components/UsersTable.tsx b/src/app/[orgId]/settings/access/users/components/UsersTable.tsx index 143bf91..6b45fd4 100644 --- a/src/app/[orgId]/settings/access/users/components/UsersTable.tsx +++ b/src/app/[orgId]/settings/access/users/components/UsersTable.tsx @@ -50,6 +50,64 @@ export default function UsersTable({ users: u }: UsersTableProps) { const { toast } = useToast(); const columns: ColumnDef[] = [ + { + id: "dots", + cell: ({ row }) => { + const userRow = row.original; + return ( + <> +
+ {userRow.isOwner && ( + + )} + {!userRow.isOwner && ( + <> + + + + + + + + Manage User + + + {userRow.email !== user?.email && ( + { + setIsDeleteModalOpen( + true + ); + setSelectedUser( + userRow + ); + }} + > + + Remove User + + + )} + + + + )} +
+ + ); + } + }, { accessorKey: "email", header: ({ column }) => { @@ -114,73 +172,27 @@ export default function UsersTable({ users: u }: UsersTableProps) { id: "actions", cell: ({ row }) => { const userRow = row.original; - return ( - <> -
- {userRow.isOwner && ( - + )} + {!userRow.isOwner && ( + + - )} - {!userRow.isOwner && ( - <> - - - - - - - - Manage User - - - {userRow.email !== user?.email && ( - { - setIsDeleteModalOpen( - true - ); - setSelectedUser( - userRow - ); - }} - > - - Remove User - - - )} - - - - - - - )} -
- + + )} +
); } } diff --git a/src/app/[orgId]/settings/resources/[resourceId]/components/ResourceInfoBox.tsx b/src/app/[orgId]/settings/resources/[resourceId]/components/ResourceInfoBox.tsx index abcf9f9..6eacfc2 100644 --- a/src/app/[orgId]/settings/resources/[resourceId]/components/ResourceInfoBox.tsx +++ b/src/app/[orgId]/settings/resources/[resourceId]/components/ResourceInfoBox.tsx @@ -69,7 +69,7 @@ export default function ResourceInfoBox({}: ResourceInfoBoxType) { )}
-
+
!isNaN(Number(val)), { - message: "Port must be a number", + message: "Port must be a number" }) - .transform((val) => Number(val)), + .transform((val) => Number(val)) // protocol: z.string(), }); @@ -99,16 +99,16 @@ export default function ReverseProxyTargets(props: { defaultValues: { ip: "", method: "http", - port: "80", + port: "80" // protocol: "TCP", - }, + } }); useEffect(() => { const fetchTargets = async () => { try { const res = await api.get>( - `/resource/${params.resourceId}/targets`, + `/resource/${params.resourceId}/targets` ); if (res.status === 200) { @@ -121,8 +121,8 @@ export default function ReverseProxyTargets(props: { title: "Failed to fetch targets", description: formatAxiosError( err, - "An error occurred while fetching targets", - ), + "An error occurred while fetching targets" + ) }); } finally { setPageLoading(false); @@ -133,7 +133,7 @@ export default function ReverseProxyTargets(props: { const fetchSite = async () => { try { const res = await api.get>( - `/site/${resource.siteId}`, + `/site/${resource.siteId}` ); if (res.status === 200) { @@ -146,27 +146,28 @@ export default function ReverseProxyTargets(props: { title: "Failed to fetch resource", description: formatAxiosError( err, - "An error occurred while fetching resource", - ), + "An error occurred while fetching resource" + ) }); } - } + }; fetchSite(); }, []); async function addTarget(data: AddTargetFormValues) { // Check if target with same IP, port and method already exists const isDuplicate = targets.some( - target => target.ip === data.ip && - target.port === data.port && - target.method === data.method + (target) => + target.ip === data.ip && + target.port === data.port && + target.method === data.method ); if (isDuplicate) { toast({ variant: "destructive", title: "Duplicate target", - description: "A target with these settings already exists", + description: "A target with these settings already exists" }); return; } @@ -179,7 +180,7 @@ export default function ReverseProxyTargets(props: { toast({ variant: "destructive", title: "Invalid target IP", - description: "Target IP must be within the site subnet", + description: "Target IP must be within the site subnet" }); return; } @@ -190,7 +191,7 @@ export default function ReverseProxyTargets(props: { enabled: true, targetId: new Date().getTime(), new: true, - resourceId: resource.resourceId, + resourceId: resource.resourceId }; setTargets([...targets, newTarget]); @@ -199,7 +200,7 @@ export default function ReverseProxyTargets(props: { const removeTarget = (targetId: number) => { setTargets([ - ...targets.filter((target) => target.targetId !== targetId), + ...targets.filter((target) => target.targetId !== targetId) ]); if (!targets.find((target) => target.targetId === targetId)?.new) { @@ -212,8 +213,8 @@ export default function ReverseProxyTargets(props: { targets.map((target) => target.targetId === targetId ? { ...target, ...data, updated: true } - : target, - ), + : target + ) ); } @@ -222,7 +223,7 @@ export default function ReverseProxyTargets(props: { setLoading(true); const res = await api.post(`/resource/${params.resourceId}`, { - ssl: sslEnabled, + ssl: sslEnabled }); updateResource({ ssl: sslEnabled }); @@ -233,7 +234,7 @@ export default function ReverseProxyTargets(props: { port: target.port, // protocol: target.protocol, method: target.method, - enabled: target.enabled, + enabled: target.enabled }; if (target.new) { @@ -244,7 +245,7 @@ export default function ReverseProxyTargets(props: { } else if (target.updated) { const res = await api.post( `/target/${target.targetId}`, - data, + data ); } @@ -253,23 +254,23 @@ export default function ReverseProxyTargets(props: { let res = { ...t, new: false, - updated: false, + updated: false }; return res; - }), + }) ]); } for (const targetId of targetsToRemove) { await api.delete(`/target/${targetId}`); setTargets( - targets.filter((target) => target.targetId !== targetId), + targets.filter((target) => target.targetId !== targetId) ); } toast({ title: "Resource updated", - description: "Resource and targets updated successfully", + description: "Resource and targets updated successfully" }); setTargetsToRemove([]); @@ -280,8 +281,8 @@ export default function ReverseProxyTargets(props: { title: "Operation failed", description: formatAxiosError( err, - "An error occurred during the save operation", - ), + "An error occurred during the save operation" + ) }); } @@ -299,13 +300,15 @@ export default function ReverseProxyTargets(props: { updateTarget(row.original.targetId, { method: value }) } > - {row.original.method} + + {row.original.method} + http https - ), + ) }, { accessorKey: "ip", @@ -313,13 +316,14 @@ export default function ReverseProxyTargets(props: { cell: ({ row }) => ( updateTarget(row.original.targetId, { - ip: e.target.value, + ip: e.target.value }) } /> - ), + ) }, { accessorKey: "port", @@ -328,13 +332,14 @@ export default function ReverseProxyTargets(props: { updateTarget(row.original.targetId, { - port: parseInt(e.target.value, 10), + port: parseInt(e.target.value, 10) }) } /> - ), + ) }, // { // accessorKey: "protocol", @@ -364,7 +369,7 @@ export default function ReverseProxyTargets(props: { updateTarget(row.original.targetId, { enabled: val }) } /> - ), + ) }, { id: "actions", @@ -387,8 +392,8 @@ export default function ReverseProxyTargets(props: {
- ), - }, + ) + } ]; const table = useReactTable({ @@ -397,7 +402,7 @@ export default function ReverseProxyTargets(props: { getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), - getFilteredRowModel: getFilteredRowModel(), + getFilteredRowModel: getFilteredRowModel() }); if (pageLoading) { @@ -437,7 +442,7 @@ export default function ReverseProxyTargets(props: {
@@ -452,11 +457,11 @@ export default function ReverseProxyTargets(props: { diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsx index 1a37e67..190f291 100644 --- a/src/components/ui/command.tsx +++ b/src/components/ui/command.tsx @@ -46,7 +46,7 @@ const CommandInput = React.forwardRef< ( ( span]:line-clamp-1", + "flex h-9 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-base md:text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", className )} {...props}