From a8f43da47282977e377a212b14e4136808376693 Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Sun, 14 Dec 2025 20:45:20 +0900 Subject: [PATCH] refactor: Move Users Admin TRPC router from features package to trpc layer (#25816) * move users admin router to trpc package * users admin router * update import path * fix --- apps/web/pages/api/trpc/users/[trpc].ts | 2 +- .../features/ee/users/components/UserForm.tsx | 32 +++++++++++--- .../ee/users/pages/users-edit-view.tsx | 43 ++++++++----------- .../trpc/server/routers/viewer/_router.tsx | 2 +- .../server/routers/viewer/users/_router.ts} | 0 5 files changed, 47 insertions(+), 32 deletions(-) rename packages/{features/ee/users/server/trpc-router.ts => trpc/server/routers/viewer/users/_router.ts} (100%) diff --git a/apps/web/pages/api/trpc/users/[trpc].ts b/apps/web/pages/api/trpc/users/[trpc].ts index 9829c4a3bb..a01762cf99 100644 --- a/apps/web/pages/api/trpc/users/[trpc].ts +++ b/apps/web/pages/api/trpc/users/[trpc].ts @@ -1,4 +1,4 @@ -import { userAdminRouter } from "@calcom/features/ee/users/server/trpc-router"; import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; +import { userAdminRouter } from "@calcom/trpc/server/routers/viewer/users/_router"; export default createNextApiHandler(userAdminRouter); diff --git a/packages/features/ee/users/components/UserForm.tsx b/packages/features/ee/users/components/UserForm.tsx index 5451941639..5ccd9706d6 100644 --- a/packages/features/ee/users/components/UserForm.tsx +++ b/packages/features/ee/users/components/UserForm.tsx @@ -1,4 +1,3 @@ -// eslint-disable-next-line no-restricted-imports import { noop } from "lodash"; import { Controller, useForm } from "react-hook-form"; @@ -13,9 +12,24 @@ import { Button } from "@calcom/ui/components/button"; import { Form, EmailField, Select, Label, TextField } from "@calcom/ui/components/form"; import { ImageUploader } from "@calcom/ui/components/image-uploader"; -import type { UserAdminRouterOutputs } from "../server/trpc-router"; - -type User = UserAdminRouterOutputs["get"]["user"]; +interface User { + id: number; + name: string | null; + email: string; + username: string | null; + bio: string | null; + timeZone: string; + weekStart: string; + theme: string | null; + defaultScheduleId: number | null; + locale: string; + timeFormat: number; + allowDynamicBooking: boolean; + identityProvider: string; + role: string; + avatarUrl: string | null; + createdDate?: string | Date; +} type Option = { value: T; @@ -33,7 +47,15 @@ type OptionValues = { type FormValues = Pick< User, - "avatarUrl" | "name" | "username" | "email" | "bio" | "createdDate" | "theme" | "defaultScheduleId" | "allowDynamicBooking" + | "avatarUrl" + | "name" + | "username" + | "email" + | "bio" + | "createdDate" + | "theme" + | "defaultScheduleId" + | "allowDynamicBooking" > & OptionValues; diff --git a/packages/features/ee/users/pages/users-edit-view.tsx b/packages/features/ee/users/pages/users-edit-view.tsx index 405ecf0ffb..795e0697f5 100644 --- a/packages/features/ee/users/pages/users-edit-view.tsx +++ b/packages/features/ee/users/pages/users-edit-view.tsx @@ -1,39 +1,32 @@ "use client"; import { usePathname, useRouter } from "next/navigation"; -import { z } from "zod"; -import NoSSR from "@calcom/lib/components/NoSSR"; -import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback"; import { getParserWithGeneric } from "@calcom/prisma/zod-utils"; import { trpc } from "@calcom/trpc/react"; import { showToast } from "@calcom/ui/components/toast"; -import LicenseRequired from "../../common/components/LicenseRequired"; import { UserForm } from "../components/UserForm"; import { userBodySchema } from "../schemas/userBodySchema"; -import type { UserAdminRouterOutputs } from "../server/trpc-router"; -type User = UserAdminRouterOutputs["get"]["user"]; -const userIdSchema = z.object({ id: z.coerce.number() }); - -const UsersEditPage = () => { - const params = useParamsWithFallback(); - const input = userIdSchema.safeParse(params); - - if (!input.success) return
Invalid input
; - - const [data] = trpc.viewer.users.get.useSuspenseQuery({ userId: input.data.id }); - const { user } = data; - - return ( - - - - - - ); -}; +interface User { + id: number; + name: string | null; + email: string; + username: string | null; + bio: string | null; + timeZone: string; + weekStart: string; + theme: string | null; + defaultScheduleId: number | null; + locale: string; + timeFormat: number; + allowDynamicBooking: boolean; + identityProvider: string; + role: string; + avatarUrl: string | null; + createdDate?: string | Date; +} export const UsersEditView = ({ user }: { user: User }) => { const pathname = usePathname(); diff --git a/packages/trpc/server/routers/viewer/_router.tsx b/packages/trpc/server/routers/viewer/_router.tsx index 28832bf5df..1c2942ef63 100644 --- a/packages/trpc/server/routers/viewer/_router.tsx +++ b/packages/trpc/server/routers/viewer/_router.tsx @@ -1,4 +1,3 @@ -import { userAdminRouter } from "@calcom/features/ee/users/server/trpc-router"; import { featureFlagRouter } from "@calcom/features/flags/server/router"; import { router } from "../../trpc"; @@ -39,6 +38,7 @@ import { slotsRouter } from "./slots/_router"; import { ssoRouter } from "./sso/_router"; import { viewerTeamsRouter } from "./teams/_router"; import { travelSchedulesRouter } from "./travelSchedules/_router"; +import { userAdminRouter } from "./users/_router"; import { webhookRouter } from "./webhook/_router"; import { workflowsRouter } from "./workflows/_router"; diff --git a/packages/features/ee/users/server/trpc-router.ts b/packages/trpc/server/routers/viewer/users/_router.ts similarity index 100% rename from packages/features/ee/users/server/trpc-router.ts rename to packages/trpc/server/routers/viewer/users/_router.ts