-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
233 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,75 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { clearConfigCache } from "prettier"; | ||
import { type ReactElement } from "react"; | ||
import { LayoutAuthenticated } from "~/components/layouts/layout"; | ||
import { api } from "~/utils/api"; | ||
|
||
const Controller = () => { | ||
const { data: controllerStats } = api.admin.getControllerStats.useQuery({}); | ||
const { data: controllerData, isLoading } = | ||
api.admin.getControllerStats.useQuery(); | ||
|
||
if (isLoading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
const { networkCount, totalMembers, controllerStatus } = controllerData; | ||
|
||
const { allowManagementFrom, allowTcpFallbackRelay, listeningOn } = | ||
controllerStatus?.config?.settings; | ||
|
||
const { online, tcpFallbackActive, version } = controllerStatus; | ||
|
||
return ( | ||
<div> | ||
Controller | ||
<pre>{JSON.stringify(controllerStats, null, 2)}</pre> | ||
<div className="flex items-center justify-center "> | ||
<div className="grid grid-cols-1 gap-5 space-y-4 pt-10 md:space-y-0 lg:grid-cols-2 xl:grid-cols-3"> | ||
<div className="card card-normal w-60 bg-base-300 sm:w-96"> | ||
<div className="card-body flex-grow-0"> | ||
<h2 className="card-title flex justify-center">Networks</h2> | ||
<p className="">Network Count: {networkCount}</p> | ||
<p className="">Total Members: {totalMembers}</p> | ||
</div> | ||
</div> | ||
<div className="card card-normal w-60 bg-base-300 sm:w-96"> | ||
<div className="card-body"> | ||
<h2 className="card-title flex justify-center">Controller TCP</h2> | ||
<p className="">Allow Management From:</p> | ||
<ul className="list-inside list-disc"> | ||
{allowManagementFrom.map((address, index) => ( | ||
<li key={index}>{address}</li> | ||
))} | ||
</ul> | ||
<p className=""> | ||
Allow TCP Fallback Relay: {allowTcpFallbackRelay ? "Yes" : "No"} | ||
</p> | ||
<p className="">Listening On:</p> | ||
<ul className="list-inside list-disc"> | ||
{listeningOn.map((address, index) => ( | ||
<li key={index}>{address}</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<div className="card card-normal w-60 bg-base-300 sm:w-96"> | ||
<div className="card-body flex-grow-0"> | ||
<h2 className="card-title flex justify-center"> | ||
Controller Stats | ||
</h2> | ||
<p className="">Online: {online ? "Yes" : "No"}</p> | ||
<p className=""> | ||
TCP Fallback Active: {tcpFallbackActive ? "Yes" : "No"} | ||
</p> | ||
<p className="">Version: {version}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
Controller.getLayout = function getLayout(page: ReactElement) { | ||
return <LayoutAuthenticated>{page}</LayoutAuthenticated>; | ||
}; | ||
|
||
export default Controller; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { clearConfigCache } from "prettier"; | ||
import { type ReactElement } from "react"; | ||
import { LayoutAuthenticated } from "~/components/layouts/layout"; | ||
import { api } from "~/utils/api"; | ||
|
||
const Settings = () => { | ||
const { mutate: setOptions } = api.options.update.useMutation(); | ||
|
||
const { data: options, refetch: refetchOptions } = | ||
api.options.getAll.useQuery(); | ||
|
||
return ( | ||
<div> | ||
<div className="flex items-center justify-center pt-10"> | ||
<div className="flex space-x-4"> | ||
<div className="card card-normal w-96 bg-base-300"> | ||
<div className="card-body"> | ||
<h2 className="card-title flex justify-center">Site Settings</h2> | ||
<div className="flex items-center"> | ||
<p>Enable user registration?</p> | ||
<input | ||
type="checkbox" | ||
checked={options?.enableRegistration} | ||
className="checkbox-primary checkbox" | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
setOptions( | ||
{ enableRegistration: e.target.checked }, | ||
{ onSuccess: () => void refetchOptions() } | ||
); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
Settings.getLayout = function getLayout(page: ReactElement) { | ||
return <LayoutAuthenticated>{page}</LayoutAuthenticated>; | ||
}; | ||
|
||
export default Settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { z } from "zod"; | ||
import { createTRPCRouter, adminRoleProtectedRoute } from "~/server/api/trpc"; | ||
|
||
export const globalOptionsRouter = createTRPCRouter({ | ||
update: adminRoleProtectedRoute | ||
.input( | ||
z.object({ | ||
enableRegistration: z.boolean().optional(), | ||
firstUserRegistration: z.boolean().optional(), | ||
}) | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
return await ctx.prisma.globalOptions.update({ | ||
where: { | ||
id: 1, | ||
}, | ||
data: { | ||
...input, | ||
}, | ||
}); | ||
}), | ||
getAll: adminRoleProtectedRoute.query(async ({ ctx }) => { | ||
return await ctx.prisma.globalOptions.findFirst({ | ||
where: { | ||
id: 1, | ||
}, | ||
}); | ||
}), | ||
}); |
Oops, something went wrong.