perf: Slim down logged in round 2 (#20535)
* perf: Slim down loggedInViewer some more * Move locationOptions to apps router * Moved calVideo related handlers to separate router * Moved calendar related handlers to separate router * Rename * Moved deleteCredential to new router * Moved updateProfile to me router * fix unit test * fix e2e test * tweak * missing --------- Co-authored-by: Anik Dhabal Babu <[email protected]> Co-authored-by: unknown <[email protected]>
This commit is contained in:
66 files changed
+240
-205
No files matched your search
@@ -84,16 +84,16 @@ export function CalendarListContainer(props: { heading?: boolean; fromOnboarding
|
||||
exact: true,
|
||||
}
|
||||
),
|
||||
utils.viewer.connectedCalendars.invalidate(),
|
||||
utils.viewer.calendars.connectedCalendars.invalidate(),
|
||||
]);
|
||||
const query = trpc.viewer.connectedCalendars.useQuery();
|
||||
const query = trpc.viewer.calendars.connectedCalendars.useQuery();
|
||||
const installedCalendars = trpc.viewer.apps.integrations.useQuery({
|
||||
variant: "calendar",
|
||||
onlyInstalled: true,
|
||||
});
|
||||
const mutation = trpc.viewer.setDestinationCalendar.useMutation({
|
||||
const mutation = trpc.viewer.calendars.setDestinationCalendar.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.viewer.connectedCalendars.invalidate();
|
||||
utils.viewer.calendars.connectedCalendars.invalidate();
|
||||
},
|
||||
});
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useState } from "react";
|
||||
import { Dialog } from "@calcom/features/components/controlled-dialog";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { AppRouter } from "@calcom/trpc/types/server/routers/_app";
|
||||
import type { AppRouter } from "@calcom/trpc/server/routers/_app";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { ConfirmationDialogContent } from "@calcom/ui/components/dialog";
|
||||
import {
|
||||
@@ -36,7 +36,7 @@ export function MultiDisconnectIntegration({ credentials, onSuccess }: Props) {
|
||||
} | null>(null);
|
||||
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
|
||||
|
||||
const mutation = trpc.viewer.deleteCredential.useMutation({
|
||||
const mutation = trpc.viewer.credentials.delete.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast(t("app_removed_successfully"), "success");
|
||||
onSuccess && onSuccess();
|
||||
@@ -47,7 +47,7 @@ export function MultiDisconnectIntegration({ credentials, onSuccess }: Props) {
|
||||
setConfirmationDialogOpen(false);
|
||||
},
|
||||
async onSettled() {
|
||||
await utils.viewer.connectedCalendars.invalidate();
|
||||
await utils.viewer.calendars.connectedCalendars.invalidate();
|
||||
await utils.viewer.apps.integrations.invalidate();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ const LocationsWrapper = ({
|
||||
};
|
||||
|
||||
const EventTypeConferencingAppSettings = ({ eventType, slug }: { eventType: TEventType; slug: string }) => {
|
||||
const locationsQuery = trpc.viewer.locationOptions.useQuery({});
|
||||
const locationsQuery = trpc.viewer.apps.locationOptions.useQuery({});
|
||||
const { t } = useLocale();
|
||||
|
||||
const SkeletonLoader = () => {
|
||||
|
||||
@@ -92,7 +92,7 @@ export const EditLocationDialog = (props: ISetLocationDialog) => {
|
||||
teamId,
|
||||
} = props;
|
||||
const { t } = useLocale();
|
||||
const locationsQuery = trpc.viewer.locationOptions.useQuery({ teamId });
|
||||
const locationsQuery = trpc.viewer.apps.locationOptions.useQuery({ teamId });
|
||||
|
||||
useEffect(() => {
|
||||
if (selection) {
|
||||
|
||||
@@ -11,8 +11,10 @@ import { EditLocationDialog } from "../EditLocationDialog";
|
||||
vi.mock("@calcom/trpc/react", () => ({
|
||||
trpc: {
|
||||
viewer: {
|
||||
locationOptions: {
|
||||
useQuery: vi.fn(),
|
||||
apps: {
|
||||
locationOptions: {
|
||||
useQuery: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,14 +4,14 @@ import type { RouterInputs } from "@calcom/trpc/react";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
interface ICreateEventsOnCalendarSelectProps {
|
||||
calendar?: RouterInputs["viewer"]["setDestinationCalendar"] | null;
|
||||
calendar?: RouterInputs["viewer"]["calendars"]["setDestinationCalendar"] | null;
|
||||
}
|
||||
|
||||
const CreateEventsOnCalendarSelect = (props: ICreateEventsOnCalendarSelectProps) => {
|
||||
const { calendar } = props;
|
||||
const { t } = useLocale();
|
||||
const mutation = trpc.viewer.setDestinationCalendar.useMutation();
|
||||
const connectedCalendarsQuery = trpc.viewer.connectedCalendars.useQuery();
|
||||
const mutation = trpc.viewer.calendars.setDestinationCalendar.useMutation();
|
||||
const connectedCalendarsQuery = trpc.viewer.calendars.connectedCalendars.useQuery();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -16,7 +16,7 @@ interface IConnectCalendarsProps {
|
||||
|
||||
const ConnectedCalendars = (props: IConnectCalendarsProps) => {
|
||||
const { nextStep, isPageLoading } = props;
|
||||
const queryConnectedCalendars = trpc.viewer.connectedCalendars.useQuery({
|
||||
const queryConnectedCalendars = trpc.viewer.calendars.connectedCalendars.useQuery({
|
||||
onboarding: true,
|
||||
eventTypeId: null,
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ const UserProfile = () => {
|
||||
const [firstRender, setFirstRender] = useState(true);
|
||||
|
||||
// Create a separate mutation for avatar updates
|
||||
const avatarMutation = trpc.viewer.updateProfile.useMutation({
|
||||
const avatarMutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async (data) => {
|
||||
showToast(t("your_user_profile_updated_successfully"), "success");
|
||||
setImageSrc(data.avatarUrl ?? "");
|
||||
@@ -49,7 +49,7 @@ const UserProfile = () => {
|
||||
});
|
||||
|
||||
// Original mutation remains for onboarding completion
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
const mutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async () => {
|
||||
try {
|
||||
if (eventTypes?.length === 0) {
|
||||
|
||||
@@ -58,7 +58,7 @@ const UserSettings = (props: IUserSettingsProps) => {
|
||||
await utils.viewer.me.invalidate();
|
||||
nextStep();
|
||||
};
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
const mutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: onSuccess,
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const DisableUserImpersonation = ({ disableImpersonation }: { disableImpersonati
|
||||
|
||||
const { t } = useLocale();
|
||||
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
const mutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async () => {
|
||||
showToast(t("your_user_profile_updated_successfully"), "success");
|
||||
await utils.viewer.me.invalidate();
|
||||
|
||||
@@ -102,7 +102,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => {
|
||||
checkUsername(debouncedUsername);
|
||||
}, [debouncedUsername, currentUsername]);
|
||||
|
||||
const updateUsername = trpc.viewer.updateProfile.useMutation({
|
||||
const updateUsername = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async () => {
|
||||
onSuccessMutation && (await onSuccessMutation());
|
||||
await update({ username: inputUsernameValue });
|
||||
|
||||
@@ -70,7 +70,7 @@ const UsernameTextfield = (props: ICustomUsernameProps & Partial<React.Component
|
||||
checkUsername(debouncedUsername);
|
||||
}, [debouncedUsername, currentUsername]);
|
||||
|
||||
const updateUsernameMutation = trpc.viewer.updateProfile.useMutation({
|
||||
const updateUsernameMutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async () => {
|
||||
onSuccessMutation && (await onSuccessMutation());
|
||||
setOpenDialogSaveUsername(false);
|
||||
|
||||
@@ -207,7 +207,7 @@ export default function InstalledApps({ category }: PageProps) {
|
||||
updateData({ isOpen: true, credentialId, teamId });
|
||||
};
|
||||
|
||||
const deleteCredentialMutation = trpc.viewer.deleteCredential.useMutation();
|
||||
const deleteCredentialMutation = trpc.viewer.credentials.delete.useMutation();
|
||||
|
||||
const handleRemoveApp = ({ credentialId, teamId, callback }: RemoveAppParams) => {
|
||||
deleteCredentialMutation.mutate(
|
||||
@@ -217,7 +217,7 @@ export default function InstalledApps({ category }: PageProps) {
|
||||
showToast(t("app_removed_successfully"), "success");
|
||||
callback();
|
||||
utils.viewer.apps.integrations.invalidate();
|
||||
utils.viewer.connectedCalendars.invalidate();
|
||||
utils.viewer.calendars.connectedCalendars.invalidate();
|
||||
},
|
||||
onError: () => {
|
||||
showToast(t("error_removing_app"), "error");
|
||||
|
||||
@@ -155,7 +155,7 @@ const AppearanceView = ({
|
||||
typeof document !== "undefined" &&
|
||||
document.documentElement.classList.contains("dark"));
|
||||
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
const mutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async (data) => {
|
||||
await utils.viewer.me.invalidate();
|
||||
showToast(t("settings_updated_successfully"), "success");
|
||||
|
||||
@@ -103,7 +103,7 @@ const GeneralView = ({ localeProp, user, travelSchedules, revalidatePage }: Gene
|
||||
const [isUpdateBtnLoading, setIsUpdateBtnLoading] = useState<boolean>(false);
|
||||
const [isTZScheduleOpen, setIsTZScheduleOpen] = useState<boolean>(false);
|
||||
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
const mutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async (res) => {
|
||||
await utils.viewer.me.invalidate();
|
||||
reset(getValues());
|
||||
|
||||
@@ -94,7 +94,7 @@ const ProfileView = () => {
|
||||
const { update } = useSession();
|
||||
const { data: user, isPending } = trpc.viewer.me.get.useQuery({ includePasswordAdded: true });
|
||||
|
||||
const updateProfileMutation = trpc.viewer.updateProfile.useMutation({
|
||||
const updateProfileMutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: async (res) => {
|
||||
await update(res);
|
||||
utils.viewer.me.invalidate();
|
||||
|
||||
@@ -26,7 +26,7 @@ const ProfileImpersonationView = ({ user }: { user: RouterOutputs["viewer"]["me"
|
||||
user?.disableImpersonation
|
||||
);
|
||||
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
const mutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast(t("profile_updated_successfully"), "success");
|
||||
},
|
||||
|
||||
@@ -11,19 +11,14 @@ import { IdentityProvider } from "@calcom/prisma/enums";
|
||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Alert } from "@calcom/ui/components/alert";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Form } from "@calcom/ui/components/form";
|
||||
import { PasswordField } from "@calcom/ui/components/form";
|
||||
import { Select } from "@calcom/ui/components/form";
|
||||
import { SettingsToggle } from "@calcom/ui/components/form";
|
||||
import { Alert } from "@calcom/ui/components/alert";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import {
|
||||
SkeletonButton,
|
||||
SkeletonContainer,
|
||||
SkeletonText,
|
||||
SkeletonAvatar,
|
||||
} from "@calcom/ui/components/skeleton";
|
||||
import { SkeletonButton, SkeletonContainer, SkeletonText } from "@calcom/ui/components/skeleton";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
type ChangePasswordSessionFormValues = {
|
||||
@@ -63,7 +58,7 @@ const PasswordView = ({ user }: PasswordViewProps) => {
|
||||
|
||||
const [sessionTimeout, setSessionTimeout] = useState<number | undefined>(initialSessionTimeout);
|
||||
|
||||
const sessionMutation = trpc.viewer.updateProfile.useMutation({
|
||||
const sessionMutation = trpc.viewer.me.updateProfile.useMutation({
|
||||
onSuccess: (data) => {
|
||||
showToast(t("session_timeout_changed"), "success");
|
||||
formMethods.reset(formMethods.getValues());
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler";
|
||||
import { calVideoRouter } from "@calcom/trpc/server/routers/viewer/calVideo/_router";
|
||||
|
||||
export default createNextApiHandler(calVideoRouter);
|
||||
@@ -0,0 +1,4 @@
|
||||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler";
|
||||
import { calendarsRouter } from "@calcom/trpc/server/routers/viewer/calendars/_router";
|
||||
|
||||
export default createNextApiHandler(calendarsRouter);
|
||||
@@ -0,0 +1,4 @@
|
||||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler";
|
||||
import { credentialsRouter } from "@calcom/trpc/server/routers/viewer/credentials/_router";
|
||||
|
||||
export default createNextApiHandler(credentialsRouter);
|
||||
@@ -41,7 +41,7 @@ test.describe("Change username on settings", () => {
|
||||
|
||||
await usernameInput.fill(item.username);
|
||||
await page.click("[data-testid=update-username-btn]");
|
||||
await submitAndWaitForResponse(page, "/api/trpc/viewer/updateProfile?batch=1", {
|
||||
await submitAndWaitForResponse(page, "/api/trpc/me/updateProfile?batch=1", {
|
||||
action: () => page.click("[data-testid=save-username]"),
|
||||
});
|
||||
|
||||
|
||||
@@ -448,7 +448,7 @@ test.describe("authorized user sees changed translations (de->ar)", async () =>
|
||||
await page.locator(".bg-default > div > div:nth-child(2)").first().click();
|
||||
await page.getByTestId("select-option-ar").click();
|
||||
|
||||
await submitAndWaitForResponse(page, "/api/trpc/viewer/updateProfile?batch=1", {
|
||||
await submitAndWaitForResponse(page, "/api/trpc/me/updateProfile?batch=1", {
|
||||
action: () => page.click("[data-testid=general-submit-button]"),
|
||||
});
|
||||
|
||||
@@ -508,7 +508,7 @@ test.describe("authorized user sees changed translations (de->pt-BR) [locale1]",
|
||||
await page.locator(".bg-default > div > div:nth-child(2)").first().click();
|
||||
await page.locator("text=Português (Brasil)").click();
|
||||
|
||||
await submitAndWaitForResponse(page, "/api/trpc/viewer/updateProfile?batch=1", {
|
||||
await submitAndWaitForResponse(page, "/api/trpc/me/updateProfile?batch=1", {
|
||||
action: () => page.click("[data-testid=general-submit-button]"),
|
||||
});
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ test.describe("Update Profile", () => {
|
||||
|
||||
await page.getByTestId("password").fill(user?.username ?? "Nameless User");
|
||||
|
||||
await submitAndWaitForResponse(page, "/api/trpc/viewer/updateProfile?batch=1", {
|
||||
await submitAndWaitForResponse(page, "/api/trpc/me/updateProfile?batch=1", {
|
||||
action: () => page.getByTestId("profile-update-email-submit-button").click(),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user