Skip to content

Commit a8f43da

Browse files
authored
refactor: Move Users Admin TRPC router from features package to trpc layer (calcom#25816)
* move users admin router to trpc package * users admin router * update import path * fix
1 parent 43b6c63 commit a8f43da

5 files changed

Lines changed: 47 additions & 32 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { userAdminRouter } from "@calcom/features/ee/users/server/trpc-router";
21
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler";
2+
import { userAdminRouter } from "@calcom/trpc/server/routers/viewer/users/_router";
33

44
export default createNextApiHandler(userAdminRouter);

packages/features/ee/users/components/UserForm.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line no-restricted-imports
21
import { noop } from "lodash";
32
import { Controller, useForm } from "react-hook-form";
43

@@ -13,9 +12,24 @@ import { Button } from "@calcom/ui/components/button";
1312
import { Form, EmailField, Select, Label, TextField } from "@calcom/ui/components/form";
1413
import { ImageUploader } from "@calcom/ui/components/image-uploader";
1514

16-
import type { UserAdminRouterOutputs } from "../server/trpc-router";
17-
18-
type User = UserAdminRouterOutputs["get"]["user"];
15+
interface User {
16+
id: number;
17+
name: string | null;
18+
email: string;
19+
username: string | null;
20+
bio: string | null;
21+
timeZone: string;
22+
weekStart: string;
23+
theme: string | null;
24+
defaultScheduleId: number | null;
25+
locale: string;
26+
timeFormat: number;
27+
allowDynamicBooking: boolean;
28+
identityProvider: string;
29+
role: string;
30+
avatarUrl: string | null;
31+
createdDate?: string | Date;
32+
}
1933

2034
type Option<T extends string | number = string> = {
2135
value: T;
@@ -33,7 +47,15 @@ type OptionValues = {
3347

3448
type FormValues = Pick<
3549
User,
36-
"avatarUrl" | "name" | "username" | "email" | "bio" | "createdDate" | "theme" | "defaultScheduleId" | "allowDynamicBooking"
50+
| "avatarUrl"
51+
| "name"
52+
| "username"
53+
| "email"
54+
| "bio"
55+
| "createdDate"
56+
| "theme"
57+
| "defaultScheduleId"
58+
| "allowDynamicBooking"
3759
> &
3860
OptionValues;
3961

packages/features/ee/users/pages/users-edit-view.tsx

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
11
"use client";
22

33
import { usePathname, useRouter } from "next/navigation";
4-
import { z } from "zod";
54

6-
import NoSSR from "@calcom/lib/components/NoSSR";
7-
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
85
import { getParserWithGeneric } from "@calcom/prisma/zod-utils";
96
import { trpc } from "@calcom/trpc/react";
107
import { showToast } from "@calcom/ui/components/toast";
118

12-
import LicenseRequired from "../../common/components/LicenseRequired";
139
import { UserForm } from "../components/UserForm";
1410
import { userBodySchema } from "../schemas/userBodySchema";
15-
import type { UserAdminRouterOutputs } from "../server/trpc-router";
1611

17-
type User = UserAdminRouterOutputs["get"]["user"];
18-
const userIdSchema = z.object({ id: z.coerce.number() });
19-
20-
const UsersEditPage = () => {
21-
const params = useParamsWithFallback();
22-
const input = userIdSchema.safeParse(params);
23-
24-
if (!input.success) return <div>Invalid input</div>;
25-
26-
const [data] = trpc.viewer.users.get.useSuspenseQuery({ userId: input.data.id });
27-
const { user } = data;
28-
29-
return (
30-
<LicenseRequired>
31-
<NoSSR>
32-
<UsersEditView user={user} />
33-
</NoSSR>
34-
</LicenseRequired>
35-
);
36-
};
12+
interface User {
13+
id: number;
14+
name: string | null;
15+
email: string;
16+
username: string | null;
17+
bio: string | null;
18+
timeZone: string;
19+
weekStart: string;
20+
theme: string | null;
21+
defaultScheduleId: number | null;
22+
locale: string;
23+
timeFormat: number;
24+
allowDynamicBooking: boolean;
25+
identityProvider: string;
26+
role: string;
27+
avatarUrl: string | null;
28+
createdDate?: string | Date;
29+
}
3730

3831
export const UsersEditView = ({ user }: { user: User }) => {
3932
const pathname = usePathname();

packages/trpc/server/routers/viewer/_router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { userAdminRouter } from "@calcom/features/ee/users/server/trpc-router";
21
import { featureFlagRouter } from "@calcom/features/flags/server/router";
32

43
import { router } from "../../trpc";
@@ -39,6 +38,7 @@ import { slotsRouter } from "./slots/_router";
3938
import { ssoRouter } from "./sso/_router";
4039
import { viewerTeamsRouter } from "./teams/_router";
4140
import { travelSchedulesRouter } from "./travelSchedules/_router";
41+
import { userAdminRouter } from "./users/_router";
4242
import { webhookRouter } from "./webhook/_router";
4343
import { workflowsRouter } from "./workflows/_router";
4444

File renamed without changes.

0 commit comments

Comments
 (0)