Settings Improvements - tRPC, Skeletons & Screen Width Issues (#4484)

* Add skeleton and trpc to profile page

* Refactor general page

* Calendars add skeleton loader

* Add translations to calendar empty screen

* Improve conferencing pages

* Add skeleton loader and TRPC to appearance page

* Fixes children being cut off at screen types

* PR feedback fixes

Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/4450/head
Joe Au-Yeung 2022-09-15 05:05:26 -04:00 committed by GitHub
parent d3b9ebbd34
commit 0d9d182b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 312 additions and 360 deletions

View File

@ -1,8 +1,6 @@
import { GetServerSidePropsContext } from "next";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
import prisma from "@calcom/prisma";
import { trpc } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react";
import Badge from "@calcom/ui/v2/core/Badge"; import Badge from "@calcom/ui/v2/core/Badge";
import { Button } from "@calcom/ui/v2/core/Button"; import { Button } from "@calcom/ui/v2/core/Button";
@ -12,14 +10,34 @@ import ColorPicker from "@calcom/ui/v2/core/colorpicker";
import { Form } from "@calcom/ui/v2/core/form/fields"; import { Form } from "@calcom/ui/v2/core/form/fields";
import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout"; import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
import showToast from "@calcom/ui/v2/core/notifications"; import showToast from "@calcom/ui/v2/core/notifications";
import { SkeletonContainer, SkeletonText, SkeletonButton } from "@calcom/ui/v2/core/skeleton";
import { getSession } from "@lib/auth"; const SkeletonLoader = () => {
import { inferSSRProps } from "@lib/types/inferSSRProps"; return (
<SkeletonContainer>
<div className="mt-6 mb-8 space-y-6 divide-y">
<div className="flex items-center">
<SkeletonButton className="mr-6 h-32 w-48 rounded-md p-5" />
<SkeletonButton className="mr-6 h-32 w-48 rounded-md p-5" />
<SkeletonButton className="mr-6 h-32 w-48 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>
const AppearanceView = (props: inferSSRProps<typeof getServerSideProps>) => { <SkeletonText className="h-8 w-full" />
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
</div>
</SkeletonContainer>
);
};
const AppearanceView = () => {
const { t } = useLocale(); const { t } = useLocale();
const { user } = props;
const { data: user, isLoading } = trpc.useQuery(["viewer.me"]);
const mutation = trpc.useMutation("viewer.updateProfile", { const mutation = trpc.useMutation("viewer.updateProfile", {
onSuccess: () => { onSuccess: () => {
showToast(t("settings_updated_successfully"), "success"); showToast(t("settings_updated_successfully"), "success");
@ -31,169 +49,132 @@ const AppearanceView = (props: inferSSRProps<typeof getServerSideProps>) => {
const formMethods = useForm(); const formMethods = useForm();
return ( if (isLoading) return <SkeletonLoader />;
<Form
form={formMethods}
handleSubmit={(values) => {
mutation.mutate({
...values,
// Radio values don't support null as values, therefore we convert an empty string
// back to null here.
theme: values.theme || null,
});
}}>
<Meta title="Appearance" description="Manage settings for your booking appearance" />
<div className="mb-6 flex items-center text-sm">
<div>
<p className="font-semibold">{t("theme")}</p>
<p className="text-gray-600">{t("theme_applies_note")}</p>
</div>
</div>
<div className="flex flex-col justify-between sm:flex-row">
<ThemeLabel
variant="system"
value={null}
label={t("theme_system")}
defaultChecked={user.theme === null}
register={formMethods.register}
/>
<ThemeLabel
variant="light"
value="light"
label={t("theme_light")}
defaultChecked={user.theme === "light"}
register={formMethods.register}
/>
<ThemeLabel
variant="dark"
value="dark"
label={t("theme_dark")}
defaultChecked={user.theme === "dark"}
register={formMethods.register}
/>
</div>
<hr className="border-1 my-8 border-neutral-200" /> if (user)
<div className="mb-6 flex items-center text-sm"> return (
<div> <Form
<p className="font-semibold">{t("custom_brand_colors")}</p> form={formMethods}
<p className="mt-0.5 leading-5 text-gray-600">{t("customize_your_brand_colors")}</p> handleSubmit={(values) => {
mutation.mutate({
...values,
// Radio values don't support null as values, therefore we convert an empty string
// back to null here.
theme: values.theme || null,
});
}}>
<Meta title="Appearance" description="Manage settings for your booking appearance" />
<div className="mb-6 flex items-center text-sm">
<div>
<p className="font-semibold">{t("theme")}</p>
<p className="text-gray-600">{t("theme_applies_note")}</p>
</div>
</div>
<div className="flex flex-col justify-between sm:flex-row">
<ThemeLabel
variant="system"
value={null}
label={t("theme_system")}
defaultChecked={user.theme === null}
register={formMethods.register}
/>
<ThemeLabel
variant="light"
value="light"
label={t("theme_light")}
defaultChecked={user.theme === "light"}
register={formMethods.register}
/>
<ThemeLabel
variant="dark"
value="dark"
label={t("theme_dark")}
defaultChecked={user.theme === "dark"}
register={formMethods.register}
/>
</div> </div>
</div>
<div className="block justify-between sm:flex"> <hr className="border-1 my-8 border-neutral-200" />
<Controller <div className="mb-6 flex items-center text-sm">
name="brandColor" <div>
control={formMethods.control} <p className="font-semibold">{t("custom_brand_colors")}</p>
defaultValue={user.brandColor} <p className="mt-0.5 leading-5 text-gray-600">{t("customize_your_brand_colors")}</p>
render={({ field: { value } }) => ( </div>
<div> </div>
<p className="mb-2 block text-sm font-medium text-gray-900">{t("light_brand_color")}</p>
<ColorPicker <div className="block justify-between sm:flex">
defaultValue={user.brandColor} <Controller
onChange={(value) => formMethods.setValue("brandColor", value)} name="brandColor"
/> control={formMethods.control}
</div> defaultValue={user.brandColor}
)} render={() => (
/> <div>
<Controller <p className="mb-2 block text-sm font-medium text-gray-900">{t("light_brand_color")}</p>
name="darkBrandColor" <ColorPicker
control={formMethods.control} defaultValue={user.brandColor}
defaultValue={user.darkBrandColor} onChange={(value) => formMethods.setValue("brandColor", value)}
render={({ field: { value } }) => ( />
<div className="mt-6 sm:mt-0"> </div>
<p className="mb-2 block text-sm font-medium text-gray-900">{t("dark_brand_color")}</p> )}
<ColorPicker />
defaultValue={user.darkBrandColor} <Controller
onChange={(value) => formMethods.setValue("darkBrandColor", value)} name="darkBrandColor"
/> control={formMethods.control}
</div> defaultValue={user.darkBrandColor}
)} render={() => (
/> <div className="mt-6 sm:mt-0">
</div> <p className="mb-2 block text-sm font-medium text-gray-900">{t("dark_brand_color")}</p>
{/* TODO future PR to preview brandColors */} <ColorPicker
{/* <Button defaultValue={user.darkBrandColor}
onChange={(value) => formMethods.setValue("darkBrandColor", value)}
/>
</div>
)}
/>
</div>
{/* TODO future PR to preview brandColors */}
{/* <Button
color="secondary" color="secondary"
EndIcon={Icon.FiExternalLink} EndIcon={Icon.FiExternalLink}
className="mt-6" className="mt-6"
onClick={() => window.open(`${WEBAPP_URL}/${user.username}/${user.eventTypes[0].title}`, "_blank")}> onClick={() => window.open(`${WEBAPP_URL}/${user.username}/${user.eventTypes[0].title}`, "_blank")}>
Preview Preview
</Button> */} </Button> */}
<hr className="border-1 my-8 border-neutral-200" /> <hr className="border-1 my-8 border-neutral-200" />
<Controller <Controller
name="hideBranding" name="hideBranding"
control={formMethods.control} control={formMethods.control}
defaultValue={user.hideBranding} defaultValue={user.hideBranding}
render={({ field: { value } }) => ( render={({ field: { value } }) => (
<> <>
<div className="flex w-full text-sm"> <div className="flex w-full text-sm">
<div className="mr-1 flex-grow"> <div className="mr-1 flex-grow">
<div className="flex items-center"> <div className="flex items-center">
<p className="mr-2 font-semibold">{t("disable_cal_branding")}</p>{" "} <p className="mr-2 font-semibold">{t("disable_cal_branding")}</p>{" "}
<Badge variant="gray">{t("pro")}</Badge> <Badge variant="gray">{t("pro")}</Badge>
</div>
<p className="mt-0.5 text-gray-600">{t("removes_cal_branding")}</p>
</div>
<div className="flex-none">
<Switch
onCheckedChange={(checked) => formMethods.setValue("hideBranding", checked)}
checked={value}
/>
</div> </div>
<p className="mt-0.5 text-gray-600">{t("removes_cal_branding")}</p>
</div> </div>
<div className="flex-none"> </>
<Switch )}
onCheckedChange={(checked) => formMethods.setValue("hideBranding", checked)} />
checked={value} <Button color="primary" className="mt-8">
/> {t("update")}
</div> </Button>
</div> </Form>
</> );
)}
/>
<Button color="primary" className="mt-8">
{t("update")}
</Button>
</Form>
);
}; };
AppearanceView.getLayout = getLayout; AppearanceView.getLayout = getLayout;
export default AppearanceView; export default AppearanceView;
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const session = await getSession(context);
if (!session?.user?.id) {
return { redirect: { permanent: false, destination: "/auth/login" } };
}
const user = await prisma.user.findUnique({
where: {
id: session.user.id,
},
select: {
username: true,
timeZone: true,
timeFormat: true,
weekStart: true,
brandColor: true,
darkBrandColor: true,
hideBranding: true,
theme: true,
eventTypes: {
select: {
title: true,
},
},
},
});
if (!user) {
throw new Error("User seems logged in but cannot be found in the db");
}
return {
props: {
user,
},
};
};
interface ThemeLabelProps { interface ThemeLabelProps {
variant: "light" | "dark" | "system"; variant: "light" | "dark" | "system";
value?: "light" | "dark" | null; value?: "light" | "dark" | null;

View File

@ -11,6 +11,7 @@ import Badge from "@calcom/ui/v2/core/Badge";
import EmptyScreen from "@calcom/ui/v2/core/EmptyScreen"; import EmptyScreen from "@calcom/ui/v2/core/EmptyScreen";
import Meta from "@calcom/ui/v2/core/Meta"; import Meta from "@calcom/ui/v2/core/Meta";
import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout"; import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
import { SkeletonContainer, SkeletonText, SkeletonButton } from "@calcom/ui/v2/core/skeleton";
import { List, ListItem, ListItemText, ListItemTitle } from "@calcom/ui/v2/modules/List"; import { List, ListItem, ListItemText, ListItemTitle } from "@calcom/ui/v2/modules/List";
import DestinationCalendarSelector from "@calcom/ui/v2/modules/event-types/DestinationCalendarSelector"; import DestinationCalendarSelector from "@calcom/ui/v2/modules/event-types/DestinationCalendarSelector";
import DisconnectIntegration from "@calcom/ui/v2/modules/integrations/DisconnectIntegration"; import DisconnectIntegration from "@calcom/ui/v2/modules/integrations/DisconnectIntegration";
@ -19,6 +20,21 @@ import { QueryCell } from "@lib/QueryCell";
import { CalendarSwitch } from "@components/v2/settings/CalendarSwitch"; import { CalendarSwitch } from "@components/v2/settings/CalendarSwitch";
const SkeletonLoader = () => {
return (
<SkeletonContainer>
<div className="mt-6 mb-8 space-y-6 divide-y">
<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="mr-6 h-8 w-20 rounded-md p-5" />
</div>
</SkeletonContainer>
);
};
const CalendarsView = () => { const CalendarsView = () => {
const { t } = useLocale(); const { t } = useLocale();
const router = useRouter(); const router = useRouter();
@ -37,6 +53,7 @@ const CalendarsView = () => {
<Meta title="Calendars" description="Configure how your event types interact with your calendars" /> <Meta title="Calendars" description="Configure how your event types interact with your calendars" />
<QueryCell <QueryCell
query={query} query={query}
customLoader={<SkeletonLoader />}
success={({ data }) => { success={({ data }) => {
return data.connectedCalendars.length ? ( return data.connectedCalendars.length ? (
<div> <div>
@ -65,7 +82,6 @@ const CalendarsView = () => {
/> />
</div> </div>
</div> </div>
<h4 className="mt-12 text-base font-semibold leading-5 text-black"> <h4 className="mt-12 text-base font-semibold leading-5 text-black">
{t("check_for_conflicts")} {t("check_for_conflicts")}
</h4> </h4>
@ -130,9 +146,9 @@ const CalendarsView = () => {
) : ( ) : (
<EmptyScreen <EmptyScreen
Icon={Icon.FiCalendar} Icon={Icon.FiCalendar}
headline="No calendar installed" headline={t("no_calendar_installed")}
description="You have not yet connected any of your calendars" description={t("no_calendar_installed_description")}
buttonText="Add a calendar" buttonText={t("add_a_calendar")}
buttonOnClick={() => router.push(`${WEBAPP_URL}/apps/categories/calendar`)} buttonOnClick={() => router.push(`${WEBAPP_URL}/apps/categories/calendar`)}
/> />
); );

View File

@ -1,92 +1,110 @@
import { GetServerSidePropsContext } from "next"; import { useState } from "react";
import getApps from "@calcom/app-store/utils";
import { getSession } from "@calcom/lib/auth";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
import prisma from "@calcom/prisma"; import { trpc } from "@calcom/trpc/react";
import { Icon } from "@calcom/ui"; import { Icon } from "@calcom/ui";
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Button } from "@calcom/ui/v2"; import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Button } from "@calcom/ui/v2";
import { Dialog, DialogContent } from "@calcom/ui/v2/core/Dialog";
import Meta from "@calcom/ui/v2/core/Meta"; import Meta from "@calcom/ui/v2/core/Meta";
import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout"; import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
import showToast from "@calcom/ui/v2/core/notifications";
import { SkeletonContainer, SkeletonText } from "@calcom/ui/v2/core/skeleton";
import { List, ListItem, ListItemText, ListItemTitle } from "@calcom/ui/v2/modules/List"; import { List, ListItem, ListItemText, ListItemTitle } from "@calcom/ui/v2/modules/List";
import DisconnectIntegration from "@calcom/ui/v2/modules/integrations/DisconnectIntegration";
import { inferSSRProps } from "@lib/types/inferSSRProps"; const SkeletonLoader = () => {
return (
<SkeletonContainer>
<div className="mt-6 mb-8 space-y-6 divide-y">
<SkeletonText className="h-8 w-full" />
<SkeletonText className="h-8 w-full" />
</div>
</SkeletonContainer>
);
};
const ConferencingLayout = (props: inferSSRProps<typeof getServerSideProps>) => { const ConferencingLayout = () => {
const { t } = useLocale(); const { t } = useLocale();
const utils = trpc.useContext();
const { apps } = props; const { data: apps, isLoading } = trpc.useQuery(
["viewer.integrations", { variant: "conferencing", onlyInstalled: true }],
{
suspense: true,
}
);
const deleteAppMutation = trpc.useMutation("viewer.deleteCredential", {
onSuccess: () => {
showToast("Integration deleted successfully", "success");
utils.invalidateQueries(["viewer.integrations", { variant: "conferencing", onlyInstalled: true }]);
setDeleteAppModal(false);
},
onError: () => {
showToast("Error deleting app", "error");
setDeleteAppModal(false);
},
});
// Error reason: getaddrinfo EAI_AGAIN http const [deleteAppModal, setDeleteAppModal] = useState(false);
// const query = trpc.useQuery(["viewer.integrations", { variant: "conferencing", onlyInstalled: true }], { const [deleteCredentialId, setDeleteCredentialId] = useState<number>(0);
// suspense: true,
// }); if (isLoading) return <SkeletonLoader />;
return ( return (
<div className="w-full bg-white sm:mx-0 xl:mt-0"> <div className="w-full bg-white sm:mx-0 xl:mt-0">
<Meta title="conferencing" description="conferencing_description" /> <Meta title="conferencing" description="conferencing_description" />
<List roundContainer={true}> <List roundContainer={true}>
{apps.map((app) => ( {apps?.items &&
<ListItem rounded={false} className="flex-col border-0" key={app.title}> apps.items
<div className="flex w-full flex-1 items-center space-x-3 pl-1 pt-1 rtl:space-x-reverse"> .map((app) => ({ ...app, title: app.title || app.name }))
{ .map((app) => (
// eslint-disable-next-line @next/next/no-img-element <ListItem rounded={false} className="flex-col border-0" key={app.title}>
app.logo && <img className="h-10 w-10" src={app.logo} alt={app.title} /> <div className="flex w-full flex-1 items-center space-x-3 pl-1 pt-1 rtl:space-x-reverse">
} {
<div className="flex-grow truncate pl-2"> // eslint-disable-next-line @next/next/no-img-element
<ListItemTitle component="h3" className="mb-1 space-x-2"> app.logo && <img className="h-10 w-10" src={app.logo} alt={app.title} />
<h3 className="truncate text-sm font-medium text-neutral-900">{app.title}</h3> }
</ListItemTitle> <div className="flex-grow truncate pl-2">
<ListItemText component="p">{app.description}</ListItemText> <ListItemTitle component="h3" className="mb-1 space-x-2">
</div> <h3 className="truncate text-sm font-medium text-neutral-900">{app.title}</h3>
<div> </ListItemTitle>
<Dropdown> <ListItemText component="p">{app.description}</ListItemText>
<DropdownMenuTrigger asChild> </div>
<Button StartIcon={Icon.FiMoreHorizontal} size="icon" color="secondary" /> <div>
</DropdownMenuTrigger> <Dropdown>
<DropdownMenuContent> <DropdownMenuTrigger asChild>
<DropdownMenuItem> <Button StartIcon={Icon.FiMoreHorizontal} size="icon" color="secondary" />
<DisconnectIntegration </DropdownMenuTrigger>
credentialId={app.credentialId} <DropdownMenuContent>
label={t("remove_app")} <DropdownMenuItem>
trashIcon <Button
isGlobal={app.isGlobal} color="destructive"
/> StartIcon={Icon.FiTrash}
</DropdownMenuItem> disabled={app.isGlobal}
</DropdownMenuContent> onClick={() => {
</Dropdown> setDeleteCredentialId(app.credentialIds[0]);
</div> setDeleteAppModal(true);
{/* <div className="flex w-1/2 space-x-6"> }}>
<img className="h-10 w-10" src={app.logo} alt={app.title} /> {t("remove_app")}
</Button>
<div className=" truncate pl-2"> </DropdownMenuItem>
<h3 className="truncate text-sm font-medium text-neutral-900">{app.title}</h3> </DropdownMenuContent>
<p className="truncate text-sm text-gray-500">{app.description}</p> </Dropdown>
</div>
</div> </div>
</div> </ListItem>
))}
<div>
<Dropdown>
<DropdownMenuTrigger className="focus:ring-brand-900 block h-[36px] w-auto justify-center rounded-md border border-gray-200 bg-transparent text-gray-700 focus:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-1">
<Icon.FiMoreHorizontal className="group-hover:text-gray-800" />
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<DisconnectIntegration
credentialId={app.credentialId}
label={t("remove_app")}
trashIcon
isGlobal={app.isGlobal}
/>
</DropdownMenuItem>
</DropdownMenuContent>
</Dropdown>
</div> */}
</div>
</ListItem>
))}
</List> </List>
<Dialog open={deleteAppModal} onOpenChange={setDeleteAppModal}>
<DialogContent
title={t("Remove app")}
description={t("are_you_sure_you_want_to_remove_this_app")}
type="confirmation"
actionText={t("yes_remove_app")}
Icon={Icon.FiAlertCircle}
actionOnClick={() => deleteAppMutation.mutate({ id: deleteCredentialId })}
/>
</Dialog>
</div> </div>
); );
}; };
@ -94,39 +112,3 @@ const ConferencingLayout = (props: inferSSRProps<typeof getServerSideProps>) =>
ConferencingLayout.getLayout = getLayout; ConferencingLayout.getLayout = getLayout;
export default ConferencingLayout; export default ConferencingLayout;
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const session = await getSession(context);
if (!session?.user?.id) {
return { redirect: { permanent: false, destination: "/auth/login" } };
}
const videoCredentials = await prisma.credential.findMany({
where: {
userId: session.user.id,
app: {
categories: {
has: "video",
},
},
},
});
const apps = getApps(videoCredentials)
.filter((app) => {
return app.variant === "conferencing" && app.credentials.length;
})
.map((app) => {
return {
slug: app.slug,
title: app.title || app.name,
logo: app.logo,
description: app.description,
credentialId: app.credentials[0].id,
isGlobal: app.isGlobal || false,
};
});
return { props: { apps } };
};

View File

@ -1,11 +1,8 @@
import { GetServerSidePropsContext } from "next";
import { TFunction } from "next-i18next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useMemo } from "react"; import { useMemo } from "react";
import { useForm, Controller } from "react-hook-form"; import { useForm, Controller } from "react-hook-form";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
import prisma from "@calcom/prisma";
import { trpc } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react";
import { Button } from "@calcom/ui/v2/core/Button"; import { Button } from "@calcom/ui/v2/core/Button";
import Meta from "@calcom/ui/v2/core/Meta"; import Meta from "@calcom/ui/v2/core/Meta";
@ -14,35 +11,47 @@ import Select from "@calcom/ui/v2/core/form/Select";
import { Form, Label } from "@calcom/ui/v2/core/form/fields"; import { Form, Label } from "@calcom/ui/v2/core/form/fields";
import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout"; import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
import showToast from "@calcom/ui/v2/core/notifications"; import showToast from "@calcom/ui/v2/core/notifications";
import { SkeletonContainer, SkeletonText, SkeletonButton } from "@calcom/ui/v2/core/skeleton";
import { withQuery } from "@lib/QueryCell"; import { withQuery } from "@lib/QueryCell";
import { getSession } from "@lib/auth";
import { nameOfDay } from "@lib/core/i18n/weekday"; import { nameOfDay } from "@lib/core/i18n/weekday";
import { inferSSRProps } from "@lib/types/inferSSRProps";
const SkeletonLoader = () => {
return (
<SkeletonContainer>
<div className="mt-6 mb-8 space-y-6 divide-y">
<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="mr-6 h-8 w-20 rounded-md p-5" />
</div>
</SkeletonContainer>
);
};
interface GeneralViewProps { interface GeneralViewProps {
localeProp: string; localeProp: string;
t: TFunction;
user: {
timeZone: string;
timeFormat: number | null;
weekStart: string;
};
} }
const WithQuery = withQuery(["viewer.public.i18n"], { context: { skipBatch: true } }); const WithQuery = withQuery(["viewer.public.i18n"], { context: { skipBatch: true } });
const GeneralQueryView = (props: inferSSRProps<typeof getServerSideProps>) => { const GeneralQueryView = () => {
const { t } = useLocale(); return (
<WithQuery
return <WithQuery success={({ data }) => <GeneralView localeProp={data.locale} t={t} {...props} />} />; success={({ data }) => <GeneralView localeProp={data.locale} />}
customLoader={<SkeletonLoader />}
/>
);
}; };
const GeneralView = ({ localeProp, t, user }: GeneralViewProps) => { const GeneralView = ({ localeProp }: GeneralViewProps) => {
const router = useRouter(); const router = useRouter();
const utils = trpc.useContext(); const utils = trpc.useContext();
const { t } = useLocale();
// const { data: user, isLoading } = trpc.useQuery(["viewer.me"]); const { data: user, isLoading } = trpc.useQuery(["viewer.me"]);
const mutation = trpc.useMutation("viewer.updateProfile", { const mutation = trpc.useMutation("viewer.updateProfile", {
onSuccess: () => { onSuccess: () => {
showToast(t("settings_updated_successfully"), "success"); showToast(t("settings_updated_successfully"), "success");
@ -95,6 +104,8 @@ const GeneralView = ({ localeProp, t, user }: GeneralViewProps) => {
}, },
}); });
if (isLoading) return <SkeletonLoader />;
return ( return (
<Form <Form
form={formMethods} form={formMethods}
@ -187,32 +198,3 @@ const GeneralView = ({ localeProp, t, user }: GeneralViewProps) => {
GeneralQueryView.getLayout = getLayout; GeneralQueryView.getLayout = getLayout;
export default GeneralQueryView; export default GeneralQueryView;
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const session = await getSession(context);
if (!session?.user?.id) {
return { redirect: { permanent: false, destination: "/auth/login" } };
}
const user = await prisma.user.findUnique({
where: {
id: session.user.id,
},
select: {
timeZone: true,
timeFormat: true,
weekStart: true,
},
});
if (!user) {
throw new Error("User seems logged in but cannot be found in the db");
}
return {
props: {
user,
},
};
};

View File

@ -1,12 +1,10 @@
import crypto from "crypto"; import crypto from "crypto";
import { GetServerSidePropsContext } from "next";
import { signOut } from "next-auth/react"; import { signOut } from "next-auth/react";
import { useRef, useState, BaseSyntheticEvent } from "react"; import { useRef, useState, BaseSyntheticEvent } from "react";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { ErrorCode, getSession } from "@calcom/lib/auth"; import { ErrorCode } from "@calcom/lib/auth";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
import prisma from "@calcom/prisma";
import { TRPCClientErrorLike } from "@calcom/trpc/client"; import { TRPCClientErrorLike } from "@calcom/trpc/client";
import { trpc } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react";
import { AppRouter } from "@calcom/trpc/server/routers/_app"; import { AppRouter } from "@calcom/trpc/server/routers/_app";
@ -20,21 +18,37 @@ import Meta from "@calcom/ui/v2/core/Meta";
import { Form, Label, TextField, PasswordField } from "@calcom/ui/v2/core/form/fields"; import { Form, Label, TextField, PasswordField } from "@calcom/ui/v2/core/form/fields";
import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout"; import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
import showToast from "@calcom/ui/v2/core/notifications"; import showToast from "@calcom/ui/v2/core/notifications";
import { SkeletonContainer, SkeletonText, SkeletonButton, SkeletonAvatar } from "@calcom/ui/v2/core/skeleton";
import { inferSSRProps } from "@lib/types/inferSSRProps";
import TwoFactor from "@components/auth/TwoFactor"; import TwoFactor from "@components/auth/TwoFactor";
const SkeletonLoader = () => {
return (
<SkeletonContainer>
<div className="mt-6 mb-8 space-y-6 divide-y">
<div className="flex items-center">
<SkeletonAvatar className=" h-12 w-12 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 { interface DeleteAccountValues {
totpCode: string; totpCode: string;
} }
const ProfileView = (props: inferSSRProps<typeof getServerSideProps>) => { const ProfileView = () => {
const { t } = useLocale(); const { t } = useLocale();
const utils = trpc.useContext(); const utils = trpc.useContext();
const { user } = props; const { data: user, isLoading } = trpc.useQuery(["viewer.me"]);
// const { data: user, isLoading } = trpc.useQuery(["viewer.me"]);
const mutation = trpc.useMutation("viewer.updateProfile", { const mutation = trpc.useMutation("viewer.updateProfile", {
onSuccess: () => { onSuccess: () => {
showToast(t("settings_updated_successfully"), "success"); showToast(t("settings_updated_successfully"), "success");
@ -50,6 +64,11 @@ const ProfileView = (props: inferSSRProps<typeof getServerSideProps>) => {
const form = useForm<DeleteAccountValues>(); const form = useForm<DeleteAccountValues>();
const emailMd5 = crypto
.createHash("md5")
.update(user?.email || "example@example.com")
.digest("hex");
const onDeleteMeSuccessMutation = async () => { const onDeleteMeSuccessMutation = async () => {
await utils.invalidateQueries(["viewer.me"]); await utils.invalidateQueries(["viewer.me"]);
showToast(t("Your account was deleted"), "success"); showToast(t("Your account was deleted"), "success");
@ -88,7 +107,7 @@ const ProfileView = (props: inferSSRProps<typeof getServerSideProps>) => {
const formMethods = useForm({ const formMethods = useForm({
defaultValues: { defaultValues: {
avatar: user.avatar || "", avatar: user?.avatar || "",
username: user?.username || "", username: user?.username || "",
name: user?.name || "", name: user?.name || "",
bio: user?.bio || "", bio: user?.bio || "",
@ -107,6 +126,8 @@ const ProfileView = (props: inferSSRProps<typeof getServerSideProps>) => {
[ErrorCode.ThirdPartyIdentityProviderEnabled]: t("account_created_with_identity_provider"), [ErrorCode.ThirdPartyIdentityProviderEnabled]: t("account_created_with_identity_provider"),
}; };
if (isLoading) return <SkeletonLoader />;
return ( return (
<> <>
<Form <Form
@ -116,13 +137,12 @@ const ProfileView = (props: inferSSRProps<typeof getServerSideProps>) => {
}}> }}>
<Meta title="Profile" description="Manage settings for your cal profile" /> <Meta title="Profile" description="Manage settings for your cal profile" />
<div className="flex items-center"> <div className="flex items-center">
{/* TODO upload new avatar */}
<Controller <Controller
control={formMethods.control} control={formMethods.control}
name="avatar" name="avatar"
render={({ field: { value } }) => ( render={({ field: { value } }) => (
<> <>
<Avatar alt="" imageSrc={value} gravatarFallbackMd5={user.emailMd5} size="lg" /> <Avatar alt="" imageSrc={value} gravatarFallbackMd5={emailMd5} size="lg" />
<div className="ml-4"> <div className="ml-4">
<ImageUploader <ImageUploader
target="avatar" target="avatar"
@ -222,7 +242,7 @@ const ProfileView = (props: inferSSRProps<typeof getServerSideProps>) => {
ref={passwordRef} ref={passwordRef}
/> />
{user.twoFactorEnabled && ( {user?.twoFactorEnabled && (
<Form handleSubmit={onConfirm} className="pb-4" form={form}> <Form handleSubmit={onConfirm} className="pb-4" form={form}>
<TwoFactor center={false} /> <TwoFactor center={false} />
</Form> </Form>
@ -240,39 +260,3 @@ const ProfileView = (props: inferSSRProps<typeof getServerSideProps>) => {
ProfileView.getLayout = getLayout; ProfileView.getLayout = getLayout;
export default ProfileView; export default ProfileView;
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const session = await getSession(context);
if (!session?.user?.id) {
return { redirect: { permanent: false, destination: "/auth/login" } };
}
const user = await prisma.user.findUnique({
where: {
id: session.user.id,
},
select: {
id: true,
username: true,
email: true,
name: true,
bio: true,
avatar: true,
twoFactorEnabled: true,
},
});
if (!user) {
throw new Error("User seems logged in but cannot be found in the db");
}
return {
props: {
user: {
...user,
emailMd5: crypto.createHash("md5").update(user.email).digest("hex"),
},
},
};
};

View File

@ -1239,5 +1239,8 @@
"password_reset_leading":"If you did not receive the email soon, check that the email address you entered is correct, check your spam folder or reach out to support if the issue persists.", "password_reset_leading":"If you did not receive the email soon, check that the email address you entered is correct, check your spam folder or reach out to support if the issue persists.",
"password_updated":"Password updated!", "password_updated":"Password updated!",
"pending_payment": "Pending payment", "pending_payment": "Pending payment",
"confirmation_page_rainbow": "Token gate your event with tokens or NFTs on Ethereum, Polygon, and more." "confirmation_page_rainbow": "Token gate your event with tokens or NFTs on Ethereum, Polygon, and more.",
"no_calendar_installed": "No calendar installed",
"no_calendar_installed_description": "You have not yet connected any of your calendars",
"add_a_calendar": "Add a calendar"
} }

View File

@ -176,6 +176,10 @@ const loggedInViewerRouter = createProtectedRouter()
darkBrandColor: user.darkBrandColor, darkBrandColor: user.darkBrandColor,
plan: user.plan, plan: user.plan,
away: user.away, away: user.away,
bio: user.bio,
weekStart: user.weekStart,
theme: user.theme,
hideBranding: user.hideBranding,
}; };
}, },
}) })

View File

@ -310,7 +310,7 @@ export default function SettingsLayout({
<MobileSettingsContainer onSideContainerOpen={() => setSideContainerOpen(!sideContainerOpen)} /> <MobileSettingsContainer onSideContainerOpen={() => setSideContainerOpen(!sideContainerOpen)} />
}> }>
<div className="flex flex-1 [&>*]:flex-1"> <div className="flex flex-1 [&>*]:flex-1">
<div className="mx-auto max-w-4xl justify-center"> <div className="mx-auto max-w-xs justify-center md:max-w-3xl">
<ShellHeader /> <ShellHeader />
<ErrorBoundary>{children}</ErrorBoundary> <ErrorBoundary>{children}</ErrorBoundary>
</div> </div>
@ -325,7 +325,7 @@ function ShellHeader() {
const { meta } = useMeta(); const { meta } = useMeta();
const { t, isLocaleReady } = useLocale(); const { t, isLocaleReady } = useLocale();
return ( return (
<header className="mx-auto block max-w-4xl justify-between pt-12 sm:flex sm:pt-8"> <header className="mx-auto block max-w-xs justify-between pt-12 sm:flex sm:pt-8 md:max-w-3xl">
<div className="mb-8 flex w-full items-center border-b border-gray-200 pb-8"> <div className="mb-8 flex w-full items-center border-b border-gray-200 pb-8">
{meta.backButton && ( {meta.backButton && (
<a href="javascript:history.back()"> <a href="javascript:history.back()">