perf: server-fetch data for all pages in /settings/my-account (#20712)

* wip

* fix type check

* refactor "/settings/my-account/profile"

* refactor "settings/my-account/general"

* refactor "/settings/my-accouunt/calendars"

* refactor "/settings/my-account/appearance"

* fix: type-check

---------

Co-authored-by: Amit Sharma <[email protected]>
Co-authored-by: Amit Sharma <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-07-24 22:36:40 +01:00
1 parent 6259b0b3cb
commit 6b9115dfde
32 files changed
+721 -524

No files matched your search

@@ -12,6 +12,7 @@ import type { BulkUpdatParams } from "@calcom/features/eventtypes/components/Bul
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { AppCategories } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc/react";
import type { RouterOutputs } from "@calcom/trpc/react";
import { Button } from "@calcom/ui/components/button";
import { EmptyScreen } from "@calcom/ui/components/empty-screen";
import type { Icon } from "@calcom/ui/components/icon";
@@ -181,9 +182,11 @@ type ModalState = {
type PageProps = {
category: AppCategories;
connectedCalendars: RouterOutputs["viewer"]["calendars"]["connectedCalendars"];
installedCalendars: RouterOutputs["viewer"]["apps"]["integrations"];
};
export default function InstalledApps({ category }: PageProps) {
export default function InstalledApps({ category, connectedCalendars, installedCalendars }: PageProps) {
const { t } = useLocale();
const utils = trpc.useUtils();
const categoryList: AppCategories[] = Object.values(AppCategories).filter((category) => {
@@ -233,7 +236,12 @@ export default function InstalledApps({ category }: PageProps) {
{categoryList.includes(category) && (
<IntegrationsContainer handleDisconnect={handleDisconnect} variant={category} />
)}
{category === "calendar" && <CalendarListContainer />}
{category === "calendar" && (
<CalendarListContainer
connectedCalendars={connectedCalendars}
installedCalendars={installedCalendars}
/>
)}
{category === "other" && (
<IntegrationsContainer
handleDisconnect={handleDisconnect}
@@ -0,0 +1,37 @@
"use client";
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { SkeletonButton, SkeletonContainer, SkeletonText } from "@calcom/ui/components/skeleton";
export const SkeletonLoader = () => {
const { t } = useLocale();
return (
<SettingsHeader title={t("appearance")} description={t("appearance_description")}>
<SkeletonContainer>
<div className="border-subtle mt-6 flex items-center rounded-t-xl border p-6 text-sm">
<SkeletonText className="h-8 w-1/3" />
</div>
<div className="border-subtle space-y-6 border-x px-4 py-6 sm:px-6">
<div className="[&>*]:bg-emphasis flex w-full items-center justify-center gap-x-2 [&>*]:animate-pulse">
<div className="h-32 flex-1 rounded-md p-5" />
<div className="h-32 flex-1 rounded-md p-5" />
<div className="h-32 flex-1 rounded-md p-5" />
</div>
<div className="flex justify-between">
<SkeletonText className="h-8 w-1/3" />
<SkeletonText className="h-8 w-1/3" />
</div>
<SkeletonText className="h-8 w-full" />
</div>
<div className="rounded-b-lg">
<SectionBottomActions align="end">
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
</SectionBottomActions>
</div>
</SkeletonContainer>
</SettingsHeader>
);
};
@@ -1,5 +1,7 @@
"use client";
import { revalidateSettingsAppearance } from "app/(use-page-wrapper)/settings/(settings-layout)/my-account/appearance/actions";
import { revalidateHasTeamPlan } from "app/cache/membership";
import { useSession } from "next-auth/react";
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
@@ -8,11 +10,11 @@ import type { z } from "zod";
import { BookerLayoutSelector } from "@calcom/features/settings/BookerLayoutSelector";
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
import ThemeLabel from "@calcom/features/settings/ThemeLabel";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { APP_NAME } from "@calcom/lib/constants";
import { DEFAULT_LIGHT_BRAND_COLOR, DEFAULT_DARK_BRAND_COLOR } from "@calcom/lib/constants";
import { checkWCAGContrastColor } from "@calcom/lib/getBrandColours";
import useGetBrandingColours from "@calcom/lib/getBrandColours";
import { useHasPaidPlan } from "@calcom/lib/hooks/useHasPaidPlan";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useTheme from "@calcom/lib/hooks/useTheme";
import { validateBookerLayouts } from "@calcom/lib/validateBookerLayouts";
@@ -23,38 +25,9 @@ import { Alert } from "@calcom/ui/components/alert";
import { UpgradeTeamsBadge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import { SettingsToggle, ColorPicker, Form } from "@calcom/ui/components/form";
import { SkeletonButton, SkeletonContainer, SkeletonText } from "@calcom/ui/components/skeleton";
import { showToast } from "@calcom/ui/components/toast";
import { useCalcomTheme } from "@calcom/ui/styles";
const SkeletonLoader = () => {
return (
<SkeletonContainer>
<div className="border-subtle mt-6 flex items-center rounded-t-xl border p-6 text-sm">
<SkeletonText className="h-8 w-1/3" />
</div>
<div className="border-subtle space-y-6 border-x px-4 py-6 sm:px-6">
<div className="[&>*]:bg-emphasis flex w-full items-center justify-center gap-x-2 [&>*]:animate-pulse">
<div className="h-32 flex-1 rounded-md p-5" />
<div className="h-32 flex-1 rounded-md p-5" />
<div className="h-32 flex-1 rounded-md p-5" />
</div>
<div className="flex justify-between">
<SkeletonText className="h-8 w-1/3" />
<SkeletonText className="h-8 w-1/3" />
</div>
<SkeletonText className="h-8 w-full" />
</div>
<div className="rounded-b-lg">
<SectionBottomActions align="end">
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
</SectionBottomActions>
</div>
</SkeletonContainer>
);
};
const useBrandColors = (
currentTheme: string | null,
{
@@ -158,6 +131,8 @@ const AppearanceView = ({
const mutation = trpc.viewer.me.updateProfile.useMutation({
onSuccess: async (data) => {
await utils.viewer.me.invalidate();
revalidateSettingsAppearance();
revalidateHasTeamPlan();
showToast(t("settings_updated_successfully"), "success");
resetBrandColorsThemeReset({ brandColor: data.brandColor, darkBrandColor: data.darkBrandColor });
resetBookerLayoutThemeReset({ metadata: data.metadata });
@@ -173,11 +148,13 @@ const AppearanceView = ({
},
onSettled: async () => {
await utils.viewer.me.invalidate();
revalidateSettingsAppearance();
revalidateHasTeamPlan();
},
});
return (
<div>
<SettingsHeader title={t("appearance")} description={t("appearance_description")}>
<div className="border-subtle mt-6 flex items-center rounded-t-lg border p-6 text-sm">
<div>
<p className="text-default text-base font-semibold">{t("app_theme")}</p>
@@ -425,17 +402,8 @@ const AppearanceView = ({
/>
</>
)}
</div>
</SettingsHeader>
);
};
const AppearancePage = () => {
const { data: user, isPending } = trpc.viewer.me.get.useQuery();
const { isPending: isTeamPlanStatusLoading, hasPaidPlan } = useHasPaidPlan();
if (isPending || isTeamPlanStatusLoading || !user) return <SkeletonLoader />;
return <AppearanceView user={user} hasPaidPlan={hasPaidPlan} />;
};
export default AppearancePage;
export default AppearanceView;
@@ -0,0 +1,23 @@
"use client";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { SkeletonButton, SkeletonContainer, SkeletonText } from "@calcom/ui/components/skeleton";
export const SkeletonLoader = () => {
const { t } = useLocale();
return (
<SettingsHeader title={t("general")} description={t("general_description")} borderInShellHeader={true}>
<SkeletonContainer>
<div className="border-subtle space-y-6 rounded-b-xl border border-t-0 px-4 py-8 sm:px-6">
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonButton className="ml-auto h-8 w-20 rounded-md p-5" />
</div>
</SkeletonContainer>
</SettingsHeader>
);
};
@@ -1,11 +1,13 @@
"use client";
import { revalidateSettingsGeneral } from "app/(use-page-wrapper)/settings/(settings-layout)/my-account/general/actions";
import { useSession } from "next-auth/react";
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { TimezoneSelect } from "@calcom/features/components/timezone-select";
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { formatLocalizedDateTime } from "@calcom/lib/dayjs";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { localeOptions } from "@calcom/lib/i18n";
@@ -18,8 +20,8 @@ import { Form } from "@calcom/ui/components/form";
import { Label } from "@calcom/ui/components/form";
import { Select } from "@calcom/ui/components/form";
import { SettingsToggle } from "@calcom/ui/components/form";
import { SkeletonButton, SkeletonContainer, SkeletonText } from "@calcom/ui/components/skeleton";
import { showToast } from "@calcom/ui/components/toast";
import { revalidateTravelSchedules } from "@calcom/web/app/cache/travelSchedule";
import TravelScheduleModal from "@components/settings/TravelScheduleModal";
@@ -45,55 +47,13 @@ export type FormValues = {
}[];
};
const SkeletonLoader = () => {
return (
<SkeletonContainer>
<div className="border-subtle space-y-6 rounded-b-xl border border-t-0 px-4 py-8 sm:px-6">
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonButton className="ml-auto h-8 w-20 rounded-md p-5" />
</div>
</SkeletonContainer>
);
};
interface GeneralViewProps {
localeProp: string;
user: RouterOutputs["viewer"]["me"]["get"];
travelSchedules: RouterOutputs["viewer"]["travelSchedules"]["get"];
revalidatePage: GeneralQueryViewProps["revalidatePage"];
}
type GeneralQueryViewProps = {
revalidatePage: () => Promise<void>;
};
const GeneralQueryView = ({ revalidatePage }: GeneralQueryViewProps) => {
const { t } = useLocale();
const { data: user, isPending } = trpc.viewer.me.get.useQuery();
const { data: travelSchedules, isPending: isPendingTravelSchedules } =
trpc.viewer.travelSchedules.get.useQuery();
if (isPending || isPendingTravelSchedules) return <SkeletonLoader />;
if (!user) {
throw new Error(t("something_went_wrong"));
}
return (
<GeneralView
user={user}
travelSchedules={travelSchedules || []}
localeProp={user.locale}
revalidatePage={revalidatePage}
/>
);
};
const GeneralView = ({ localeProp, user, travelSchedules, revalidatePage }: GeneralViewProps) => {
const GeneralView = ({ user, travelSchedules }: GeneralViewProps) => {
const localeProp = user.locale ?? "en";
const utils = trpc.useContext();
const {
t,
@@ -106,6 +66,8 @@ const GeneralView = ({ localeProp, user, travelSchedules, revalidatePage }: Gene
const mutation = trpc.viewer.me.updateProfile.useMutation({
onSuccess: async (res) => {
await utils.viewer.me.invalidate();
revalidateSettingsGeneral();
revalidateTravelSchedules();
reset(getValues());
showToast(t("settings_updated_successfully"), "success");
await update(res);
@@ -114,13 +76,14 @@ const GeneralView = ({ localeProp, user, travelSchedules, revalidatePage }: Gene
window.calNewLocale = res.locale;
document.cookie = `calNewLocale=${res.locale}; path=/`;
}
await revalidatePage();
},
onError: () => {
showToast(t("error_updating_settings"), "error");
},
onSettled: async () => {
await utils.viewer.me.invalidate();
revalidateSettingsGeneral();
revalidateTravelSchedules();
setIsUpdateBtnLoading(false);
},
});
@@ -188,215 +151,217 @@ const GeneralView = ({ localeProp, user, travelSchedules, revalidatePage }: Gene
const watchedTzSchedules = formMethods.watch("travelSchedules");
return (
<div>
<Form
form={formMethods}
handleSubmit={async (values) => {
setIsUpdateBtnLoading(true);
mutation.mutate({
...values,
locale: values.locale.value,
timeFormat: values.timeFormat.value,
weekStart: values.weekStart.value,
});
}}>
<div className="border-subtle border-x border-y-0 px-4 py-8 sm:px-6">
<Controller
name="locale"
render={({ field: { value, onChange } }) => (
<>
<Label className="text-emphasis">
<>{t("language")}</>
</Label>
<Select<{ label: string; value: string }>
className="capitalize"
options={localeOptions}
value={value}
onChange={onChange}
/>
</>
)}
/>
<Controller
name="timeZone"
control={formMethods.control}
render={({ field: { value } }) => (
<>
<Label className="text-emphasis mt-6">
<>{t("timezone")}</>
</Label>
<TimezoneSelect
id="timezone"
value={value}
onChange={(event) => {
if (event) formMethods.setValue("timeZone", event.value, { shouldDirty: true });
}}
/>
</>
)}
/>
{!watchedTzSchedules.length ? (
<Button
color="secondary"
className="mt-2"
StartIcon="calendar"
onClick={() => setIsTZScheduleOpen(true)}>
{t("schedule_timezone_change")}
</Button>
) : (
<div className="bg-muted border-subtle mt-2 rounded-md border p-4">
<Label>{t("travel_schedule")}</Label>
<div className="border-subtle bg-default mt-4 rounded-md border text-sm">
{watchedTzSchedules.map((schedule, index) => {
return (
<div
className={classNames(
"flex items-center p-4",
index !== 0 ? "border-subtle border-t" : ""
)}
key={index}>
<div>
<div className="text-emphasis font-semibold">{`${formatLocalizedDateTime(
schedule.startDate,
{ day: "numeric", month: "long" },
language
)} ${
schedule.endDate
? `- ${formatLocalizedDateTime(
schedule.endDate,
{ day: "numeric", month: "long" },
language
)}`
: ``
}`}</div>
<div className="text-subtle">{schedule.timeZone.replace(/_/g, " ")}</div>
</div>
<Button
color="secondary"
className="ml-auto"
variant="icon"
StartIcon="trash-2"
onClick={() => {
const updatedSchedules = watchedTzSchedules.filter(
(s, filterIndex) => filterIndex !== index
);
formMethods.setValue("travelSchedules", updatedSchedules, { shouldDirty: true });
}}
/>
</div>
);
})}
</div>
<SettingsHeader title={t("general")} description={t("general_description")} borderInShellHeader={true}>
<div>
<Form
form={formMethods}
handleSubmit={async (values) => {
setIsUpdateBtnLoading(true);
mutation.mutate({
...values,
locale: values.locale.value,
timeFormat: values.timeFormat.value,
weekStart: values.weekStart.value,
});
}}>
<div className="border-subtle border-x border-y-0 px-4 py-8 sm:px-6">
<Controller
name="locale"
render={({ field: { value, onChange } }) => (
<>
<Label className="text-emphasis">
<>{t("language")}</>
</Label>
<Select<{ label: string; value: string }>
className="capitalize"
options={localeOptions}
value={value}
onChange={onChange}
/>
</>
)}
/>
<Controller
name="timeZone"
control={formMethods.control}
render={({ field: { value } }) => (
<>
<Label className="text-emphasis mt-6">
<>{t("timezone")}</>
</Label>
<TimezoneSelect
id="timezone"
value={value}
onChange={(event) => {
if (event) formMethods.setValue("timeZone", event.value, { shouldDirty: true });
}}
/>
</>
)}
/>
{!watchedTzSchedules.length ? (
<Button
StartIcon="plus"
color="secondary"
className="mt-4"
className="mt-2"
StartIcon="calendar"
onClick={() => setIsTZScheduleOpen(true)}>
{t("add")}
{t("schedule_timezone_change")}
</Button>
) : (
<div className="bg-muted border-subtle mt-2 rounded-md border p-4">
<Label>{t("travel_schedule")}</Label>
<div className="border-subtle bg-default mt-4 rounded-md border text-sm">
{watchedTzSchedules.map((schedule, index) => {
return (
<div
className={classNames(
"flex items-center p-4",
index !== 0 ? "border-subtle border-t" : ""
)}
key={index}>
<div>
<div className="text-emphasis font-semibold">{`${formatLocalizedDateTime(
schedule.startDate,
{ day: "numeric", month: "long" },
language
)} ${
schedule.endDate
? `- ${formatLocalizedDateTime(
schedule.endDate,
{ day: "numeric", month: "long" },
language
)}`
: ``
}`}</div>
<div className="text-subtle">{schedule.timeZone.replace(/_/g, " ")}</div>
</div>
<Button
color="secondary"
className="ml-auto"
variant="icon"
StartIcon="trash-2"
onClick={() => {
const updatedSchedules = watchedTzSchedules.filter(
(s, filterIndex) => filterIndex !== index
);
formMethods.setValue("travelSchedules", updatedSchedules, { shouldDirty: true });
}}
/>
</div>
);
})}
</div>
<Button
StartIcon="plus"
color="secondary"
className="mt-4"
onClick={() => setIsTZScheduleOpen(true)}>
{t("add")}
</Button>
</div>
)}
<Controller
name="timeFormat"
control={formMethods.control}
render={({ field: { value } }) => (
<>
<Label className="text-emphasis mt-6">
<>{t("time_format")}</>
</Label>
<Select
value={value}
options={timeFormatOptions}
onChange={(event) => {
if (event) formMethods.setValue("timeFormat", { ...event }, { shouldDirty: true });
}}
/>
</>
)}
/>
<div className="text-gray text-subtle mt-2 flex items-center text-xs">
{t("timeformat_profile_hint")}
</div>
)}
<Controller
name="timeFormat"
control={formMethods.control}
render={({ field: { value } }) => (
<>
<Label className="text-emphasis mt-6">
<>{t("time_format")}</>
</Label>
<Select
value={value}
options={timeFormatOptions}
onChange={(event) => {
if (event) formMethods.setValue("timeFormat", { ...event }, { shouldDirty: true });
}}
/>
</>
)}
/>
<div className="text-gray text-subtle mt-2 flex items-center text-xs">
{t("timeformat_profile_hint")}
<Controller
name="weekStart"
control={formMethods.control}
render={({ field: { value } }) => (
<>
<Label className="text-emphasis mt-6">
<>{t("start_of_week")}</>
</Label>
<Select
value={value}
options={weekStartOptions}
onChange={(event) => {
if (event) formMethods.setValue("weekStart", { ...event }, { shouldDirty: true });
}}
/>
</>
)}
/>
</div>
<Controller
name="weekStart"
control={formMethods.control}
render={({ field: { value } }) => (
<>
<Label className="text-emphasis mt-6">
<>{t("start_of_week")}</>
</Label>
<Select
value={value}
options={weekStartOptions}
onChange={(event) => {
if (event) formMethods.setValue("weekStart", { ...event }, { shouldDirty: true });
}}
/>
</>
)}
/>
</div>
<SectionBottomActions align="end">
<Button
loading={isUpdateBtnLoading}
disabled={isDisabled}
color="primary"
type="submit"
data-testid="general-submit-button">
<>{t("update")}</>
</Button>
</SectionBottomActions>
</Form>
<SectionBottomActions align="end">
<Button
loading={isUpdateBtnLoading}
disabled={isDisabled}
color="primary"
type="submit"
data-testid="general-submit-button">
<>{t("update")}</>
</Button>
</SectionBottomActions>
</Form>
<SettingsToggle
toggleSwitchAtTheEnd={true}
title={t("dynamic_booking")}
description={t("allow_dynamic_booking")}
disabled={mutation.isPending}
checked={isAllowDynamicBookingChecked}
onCheckedChange={(checked) => {
setIsAllowDynamicBookingChecked(checked);
mutation.mutate({ allowDynamicBooking: checked });
}}
switchContainerClassName="mt-6"
/>
<SettingsToggle
toggleSwitchAtTheEnd={true}
title={t("dynamic_booking")}
description={t("allow_dynamic_booking")}
disabled={mutation.isPending}
checked={isAllowDynamicBookingChecked}
onCheckedChange={(checked) => {
setIsAllowDynamicBookingChecked(checked);
mutation.mutate({ allowDynamicBooking: checked });
}}
switchContainerClassName="mt-6"
/>
<SettingsToggle
data-testid="my-seo-indexing-switch"
toggleSwitchAtTheEnd={true}
title={t("seo_indexing")}
description={t("allow_seo_indexing")}
disabled={mutation.isPending || user.organizationSettings?.allowSEOIndexing === false}
checked={isAllowSEOIndexingChecked}
onCheckedChange={(checked) => {
setIsAllowSEOIndexingChecked(checked);
mutation.mutate({ allowSEOIndexing: checked });
}}
switchContainerClassName="mt-6"
/>
<SettingsToggle
data-testid="my-seo-indexing-switch"
toggleSwitchAtTheEnd={true}
title={t("seo_indexing")}
description={t("allow_seo_indexing")}
disabled={mutation.isPending || user.organizationSettings?.allowSEOIndexing === false}
checked={isAllowSEOIndexingChecked}
onCheckedChange={(checked) => {
setIsAllowSEOIndexingChecked(checked);
mutation.mutate({ allowSEOIndexing: checked });
}}
switchContainerClassName="mt-6"
/>
<SettingsToggle
toggleSwitchAtTheEnd={true}
title={t("monthly_digest_email")}
description={t("monthly_digest_email_for_teams")}
disabled={mutation.isPending}
checked={isReceiveMonthlyDigestEmailChecked}
onCheckedChange={(checked) => {
setIsReceiveMonthlyDigestEmailChecked(checked);
mutation.mutate({ receiveMonthlyDigestEmail: checked });
}}
switchContainerClassName="mt-6"
/>
<TravelScheduleModal
open={isTZScheduleOpen}
onOpenChange={() => setIsTZScheduleOpen(false)}
setValue={formMethods.setValue}
existingSchedules={formMethods.getValues("travelSchedules") ?? []}
/>
</div>
<SettingsToggle
toggleSwitchAtTheEnd={true}
title={t("monthly_digest_email")}
description={t("monthly_digest_email_for_teams")}
disabled={mutation.isPending}
checked={isReceiveMonthlyDigestEmailChecked}
onCheckedChange={(checked) => {
setIsReceiveMonthlyDigestEmailChecked(checked);
mutation.mutate({ receiveMonthlyDigestEmail: checked });
}}
switchContainerClassName="mt-6"
/>
<TravelScheduleModal
open={isTZScheduleOpen}
onOpenChange={() => setIsTZScheduleOpen(false)}
setValue={formMethods.setValue}
existingSchedules={formMethods.getValues("travelSchedules") ?? []}
/>
</div>
</SettingsHeader>
);
};
export default GeneralQueryView;
export default GeneralView;
@@ -0,0 +1,35 @@
"use client";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { APP_NAME } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import {
SkeletonButton,
SkeletonAvatar,
SkeletonContainer,
SkeletonText,
} from "@calcom/ui/components/skeleton";
export const SkeletonLoader = () => {
const { t } = useLocale();
return (
<SettingsHeader
title={t("profile")}
description={t("profile_description", { appName: APP_NAME })}
borderInShellHeader={true}>
<SkeletonContainer>
<div className="border-subtle space-y-6 rounded-b-lg border border-t-0 px-4 py-8">
<div className="flex items-center">
<SkeletonAvatar className="me-4 mt-0 h-16 w-16 px-4" />
<SkeletonButton className="h-6 w-32 rounded-md p-5" />
</div>
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
</div>
</SkeletonContainer>
</SettingsHeader>
);
};
@@ -1,6 +1,7 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { revalidateSettingsProfile } from "app/cache/path/settings/my-account";
// eslint-disable-next-line no-restricted-imports
import { get, pick } from "lodash";
import { signOut, useSession } from "next-auth/react";
@@ -12,6 +13,7 @@ import { z } from "zod";
import { ErrorCode } from "@calcom/features/auth/lib/ErrorCode";
import { Dialog } from "@calcom/features/components/controlled-dialog";
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { DisplayInfo } from "@calcom/features/users/components/UserTable/EditSheet/DisplayInfo";
import { APP_NAME, FULL_NAME_LENGTH_MAX_LIMIT } from "@calcom/lib/constants";
import { emailSchema } from "@calcom/lib/emailSchema";
@@ -34,12 +36,6 @@ import { Label } from "@calcom/ui/components/form";
import { TextField } from "@calcom/ui/components/form";
import { Icon } from "@calcom/ui/components/icon";
import { ImageUploader } from "@calcom/ui/components/image-uploader";
import {
SkeletonButton,
SkeletonContainer,
SkeletonText,
SkeletonAvatar,
} from "@calcom/ui/components/skeleton";
import { showToast } from "@calcom/ui/components/toast";
import TwoFactor from "@components/auth/TwoFactor";
@@ -50,24 +46,6 @@ import { UsernameAvailabilityField } from "@components/ui/UsernameAvailability";
import type { TRPCClientErrorLike } from "@trpc/client";
const SkeletonLoader = () => {
return (
<SkeletonContainer>
<div className="border-subtle space-y-6 rounded-b-lg border border-t-0 px-4 py-8">
<div className="flex items-center">
<SkeletonAvatar className="me-4 mt-0 h-16 w-16 px-4" />
<SkeletonButton className="h-6 w-32 rounded-md p-5" />
</div>
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
</div>
</SkeletonContainer>
);
};
interface DeleteAccountValues {
totpCode: string;
}
@@ -87,18 +65,20 @@ export type FormValues = {
bio: string;
secondaryEmails: Email[];
};
type Props = {
user: RouterOutputs["viewer"]["me"]["get"];
};
const ProfileView = () => {
const ProfileView = ({ user }: Props) => {
const { t } = useLocale();
const utils = trpc.useUtils();
const { update } = useSession();
const { data: user, isPending } = trpc.viewer.me.get.useQuery({ includePasswordAdded: true });
const updateProfileMutation = trpc.viewer.me.updateProfile.useMutation({
onSuccess: async (res) => {
await update(res);
utils.viewer.me.invalidate();
utils.viewer.me.shouldVerifyEmail.invalidate();
revalidateSettingsProfile();
if (res.hasEmailBeenChanged && res.sendEmailVerification) {
showToast(t("change_of_email_toast", { email: tempFormValues?.email }), "success");
@@ -125,6 +105,7 @@ const ProfileView = () => {
onSuccess: async (res) => {
showToast(t(res.message), "success");
utils.viewer.me.invalidate();
revalidateSettingsProfile();
},
onError: (e) => {
showToast(t(e.message), "error");
@@ -136,6 +117,7 @@ const ProfileView = () => {
setShowSecondaryEmailModalOpen(false);
setNewlyAddedSecondaryEmail(res?.data?.email);
utils.viewer.me.invalidate();
revalidateSettingsProfile();
},
onError: (error) => {
setSecondaryEmailAddErrorMessage(error?.message || "");
@@ -160,6 +142,8 @@ const ProfileView = () => {
const onDeleteMeSuccessMutation = async () => {
await utils.viewer.me.invalidate();
revalidateSettingsProfile();
showToast(t("Your account was deleted"), "success");
setHasDeleteErrors(false); // dismiss any open errors
@@ -189,6 +173,7 @@ const ProfileView = () => {
onError: onDeleteMeErrorMutation,
async onSettled() {
await utils.viewer.me.invalidate();
revalidateSettingsProfile();
},
});
const deleteMeWithoutPasswordMutation = trpc.viewer.me.deleteMeWithoutPassword.useMutation({
@@ -196,6 +181,7 @@ const ProfileView = () => {
onError: onDeleteMeErrorMutation,
async onSettled() {
await utils.viewer.me.invalidate();
revalidateSettingsProfile();
},
});
@@ -241,10 +227,6 @@ const ProfileView = () => {
[ErrorCode.ThirdPartyIdentityProviderEnabled]: t("account_created_with_identity_provider"),
};
if (isPending || !user) {
return <SkeletonLoader />;
}
const userEmail = user.email || "";
const defaultValues = {
username: user.username || "",
@@ -269,7 +251,10 @@ const ProfileView = () => {
};
return (
<>
<SettingsHeader
title={t("profile")}
description={t("profile_description", { appName: APP_NAME })}
borderInShellHeader={true}>
<ProfileForm
key={JSON.stringify(defaultValues)}
defaultValues={defaultValues}
@@ -305,6 +290,7 @@ const ProfileView = () => {
onSuccessMutation={async () => {
showToast(t("settings_updated_successfully"), "success");
await utils.viewer.me.invalidate();
revalidateSettingsProfile();
}}
onErrorMutation={() => {
showToast(t("error_updating_settings"), "error");
@@ -473,7 +459,7 @@ const ProfileView = () => {
onCancel={() => setNewlyAddedSecondaryEmail(undefined)}
/>
)}
</>
</SettingsHeader>
);
};
@@ -1,6 +1,7 @@
"use client";
import { useWebPush } from "@calcom/features/notifications/WebPushContext";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button } from "@calcom/ui/components/button";
@@ -9,11 +10,16 @@ const PushNotificationsView = () => {
const { subscribe, unsubscribe, isSubscribed, isLoading } = useWebPush();
return (
<div className="border-subtle rounded-b-xl border-x border-b px-4 pb-10 pt-8 sm:px-6">
<Button color="primary" onClick={isSubscribed ? unsubscribe : subscribe} disabled={isLoading}>
{isSubscribed ? t("disable_browser_notifications") : t("allow_browser_notifications")}
</Button>
</div>
<SettingsHeader
title={t("push_notifications")}
description={t("push_notifications_description")}
borderInShellHeader={true}>
<div className="border-subtle rounded-b-xl border-x border-b px-4 pb-10 pt-8 sm:px-6">
<Button color="primary" onClick={isSubscribed ? unsubscribe : subscribe} disabled={isLoading}>
{isSubscribed ? t("disable_browser_notifications") : t("allow_browser_notifications")}
</Button>
</div>
</SettingsHeader>
);
};