Files
cal.diy/packages/trpc/server/routers/viewer/admin/_router.ts
T
sean-brydon 0969d5960a feat: temp admin user management
## What does this PR do?
Loom: https://www.loom.com/share/361ca6ca9b5748079cba59ed2f348d90

Not all items on edit from update the user. This is very temp page to help Milos

How to test:
Login as admin user
settings > admin > users
search - see filtered users
scroll to bottom of list - notice we refetch before you hit the bottom so you dont notice items loading
delete user -> user is deleted and removed from list (radix bug in main causes dialog to freeze refresh to make this go away)
edit user -> Edit users email/username/identityprovider. Not all items on this update work just yet. These will be picked up when we come to implement the proper user table.
2023-07-07 18:25:21 +05:30

51 lines
1.7 KiB
TypeScript

import { authedAdminProcedure } from "../../../procedures/authedProcedure";
import { router } from "../../../trpc";
import { ZListMembersSchema } from "./listPaginated.schema";
import { ZAdminPasswordResetSchema } from "./sendPasswordReset.schema";
type AdminRouterHandlerCache = {
listPaginated?: typeof import("./listPaginated.handler").listPaginatedHandler;
sendPasswordReset?: typeof import("./sendPasswordReset.handler").sendPasswordResetHandler;
};
const UNSTABLE_HANDLER_CACHE: AdminRouterHandlerCache = {};
export const adminRouter = router({
listPaginated: authedAdminProcedure.input(ZListMembersSchema).query(async ({ ctx, input }) => {
if (!UNSTABLE_HANDLER_CACHE.listPaginated) {
UNSTABLE_HANDLER_CACHE.listPaginated = await import("./listPaginated.handler").then(
(mod) => mod.listPaginatedHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.listPaginated) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.listPaginated({
ctx,
input,
});
}),
sendPasswordReset: authedAdminProcedure
.input(ZAdminPasswordResetSchema)
.mutation(async ({ ctx, input }) => {
if (!UNSTABLE_HANDLER_CACHE.sendPasswordReset) {
UNSTABLE_HANDLER_CACHE.sendPasswordReset = await import("./sendPasswordReset.handler").then(
(mod) => mod.sendPasswordResetHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.sendPasswordReset) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.sendPasswordReset({
ctx,
input,
});
}),
});