2022-09-15 09:47:59 +00:00
|
|
|
import { MembershipRole, UserPermissionRole } from "@prisma/client";
|
2022-09-12 20:26:42 +00:00
|
|
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@radix-ui/react-collapsible";
|
2022-09-08 15:35:31 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
2022-11-10 20:23:56 +00:00
|
|
|
import Link from "next/link";
|
2022-10-13 15:50:08 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-09-12 20:26:42 +00:00
|
|
|
import React, { ComponentProps, useEffect, useState } from "react";
|
2022-08-09 09:21:15 +00:00
|
|
|
|
2023-01-10 15:39:29 +00:00
|
|
|
import Shell from "@calcom/features/shell/Shell";
|
2022-09-07 01:33:50 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { HOSTED_CAL_FEATURES, WEBAPP_URL } from "@calcom/lib/constants";
|
2022-09-21 04:53:31 +00:00
|
|
|
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
|
2022-08-30 19:46:52 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-09-12 20:26:42 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-01-05 17:00:16 +00:00
|
|
|
import {
|
|
|
|
Badge,
|
|
|
|
Button,
|
|
|
|
ErrorBoundary,
|
|
|
|
Icon,
|
|
|
|
VerticalTabItemProps,
|
|
|
|
VerticalTabItem,
|
|
|
|
Skeleton,
|
|
|
|
useMeta,
|
|
|
|
} from "@calcom/ui";
|
2022-09-06 19:34:58 +00:00
|
|
|
|
2022-09-08 15:35:31 +00:00
|
|
|
const tabs: VerticalTabItemProps[] = [
|
2022-09-06 19:34:58 +00:00
|
|
|
{
|
|
|
|
name: "my_account",
|
2022-09-07 01:33:50 +00:00
|
|
|
href: "/settings/my-account",
|
2022-09-06 19:34:58 +00:00
|
|
|
icon: Icon.FiUser,
|
|
|
|
children: [
|
|
|
|
{ name: "profile", href: "/settings/my-account/profile" },
|
|
|
|
{ name: "general", href: "/settings/my-account/general" },
|
|
|
|
{ name: "calendars", href: "/settings/my-account/calendars" },
|
|
|
|
{ name: "conferencing", href: "/settings/my-account/conferencing" },
|
|
|
|
{ name: "appearance", href: "/settings/my-account/appearance" },
|
|
|
|
// TODO
|
2022-09-07 01:33:50 +00:00
|
|
|
// { name: "referrals", href: "/settings/my-account/referrals" },
|
2022-09-06 19:34:58 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "security",
|
|
|
|
href: "/settings/security",
|
|
|
|
icon: Icon.FiKey,
|
|
|
|
children: [
|
|
|
|
{ name: "password", href: "/settings/security/password" },
|
|
|
|
{ name: "2fa_auth", href: "/settings/security/two-factor-auth" },
|
2022-10-19 09:33:40 +00:00
|
|
|
{ name: "impersonation", href: "/settings/security/impersonation" },
|
2022-09-06 19:34:58 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "billing",
|
|
|
|
href: "/settings/billing",
|
|
|
|
icon: Icon.FiCreditCard,
|
2022-10-04 22:54:15 +00:00
|
|
|
children: [{ name: "manage_billing", href: "/settings/billing" }],
|
2022-09-06 19:34:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "developer",
|
|
|
|
href: "/settings/developer",
|
|
|
|
icon: Icon.FiTerminal,
|
|
|
|
children: [
|
|
|
|
//
|
2022-09-07 01:33:50 +00:00
|
|
|
{ name: "webhooks", href: "/settings/developer/webhooks" },
|
2022-09-12 19:07:52 +00:00
|
|
|
{ name: "api_keys", href: "/settings/developer/api-keys" },
|
|
|
|
// TODO: Add profile level for embeds
|
|
|
|
// { name: "embeds", href: "/v2/settings/developer/embeds" },
|
2022-09-06 19:34:58 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "teams",
|
|
|
|
href: "/settings/teams",
|
|
|
|
icon: Icon.FiUsers,
|
2022-09-07 01:33:50 +00:00
|
|
|
children: [],
|
2022-09-06 19:34:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "admin",
|
|
|
|
href: "/settings/admin",
|
|
|
|
icon: Icon.FiLock,
|
|
|
|
children: [
|
|
|
|
//
|
|
|
|
{ name: "impersonation", href: "/settings/admin/impersonation" },
|
2022-12-07 21:47:02 +00:00
|
|
|
{ name: "apps", href: "/settings/admin/apps/calendar" },
|
2022-09-06 19:34:58 +00:00
|
|
|
{ name: "users", href: "/settings/admin/users" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2022-08-09 09:21:15 +00:00
|
|
|
|
2022-10-18 20:34:32 +00:00
|
|
|
tabs.find((tab) => {
|
|
|
|
// Add "SAML SSO" to the tab
|
|
|
|
if (tab.name === "security" && !HOSTED_CAL_FEATURES) {
|
|
|
|
tab.children?.push({ name: "saml_config", href: "/settings/security/sso" });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-09-08 15:35:31 +00:00
|
|
|
// The following keys are assigned to admin only
|
|
|
|
const adminRequiredKeys = ["admin"];
|
|
|
|
|
|
|
|
const useTabs = () => {
|
|
|
|
const session = useSession();
|
2022-09-13 16:11:37 +00:00
|
|
|
|
|
|
|
const isAdmin = session.data?.user.role === UserPermissionRole.ADMIN;
|
2022-12-26 10:23:03 +00:00
|
|
|
|
|
|
|
tabs.map((tab) => {
|
|
|
|
if (tab.name === "my_account") {
|
|
|
|
tab.name = session.data?.user?.name || "my_account";
|
|
|
|
tab.icon = undefined;
|
|
|
|
tab.avatar = WEBAPP_URL + "/" + session.data?.user?.username + "/avatar.png";
|
|
|
|
}
|
|
|
|
return tab;
|
|
|
|
});
|
|
|
|
|
2022-09-08 15:35:31 +00:00
|
|
|
// check if name is in adminRequiredKeys
|
|
|
|
return tabs.filter((tab) => {
|
|
|
|
if (isAdmin) return true;
|
|
|
|
return !adminRequiredKeys.includes(tab.name);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-12-26 10:23:03 +00:00
|
|
|
const BackButtonInSidebar = ({ name }: { name: string }) => {
|
|
|
|
return (
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
2023-01-09 12:15:10 +00:00
|
|
|
href="/event-types"
|
2023-01-06 12:13:56 +00:00
|
|
|
className="group my-6 flex h-6 max-h-6 w-64 flex-row items-center rounded-md py-2 px-3 text-sm font-medium leading-4 text-black hover:bg-gray-100 group-hover:text-gray-700 [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:text-gray-900"
|
|
|
|
data-testid={`vertical-tab-${name}`}>
|
|
|
|
<Icon.FiArrowLeft className="h-4 w-4 stroke-[2px] ltr:mr-[10px] rtl:ml-[10px] md:mt-0" />
|
|
|
|
<Skeleton title={name} as="p" className="max-w-36 min-h-4 truncate">
|
|
|
|
{name}
|
|
|
|
</Skeleton>
|
2022-12-26 10:23:03 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-12-19 17:37:20 +00:00
|
|
|
interface SettingsSidebarContainerProps {
|
|
|
|
className?: string;
|
|
|
|
navigationIsOpenedOnMobile?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingsSidebarContainer = ({
|
|
|
|
className = "",
|
|
|
|
navigationIsOpenedOnMobile,
|
|
|
|
}: SettingsSidebarContainerProps) => {
|
2022-09-12 20:26:42 +00:00
|
|
|
const { t } = useLocale();
|
2022-12-07 21:35:41 +00:00
|
|
|
const router = useRouter();
|
2022-09-08 15:35:31 +00:00
|
|
|
const tabsWithPermissions = useTabs();
|
2022-09-12 20:26:42 +00:00
|
|
|
const [teamMenuState, setTeamMenuState] =
|
|
|
|
useState<{ teamId: number | undefined; teamMenuOpen: boolean }[]>();
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: teams } = trpc.viewer.teams.list.useQuery();
|
2022-09-12 20:26:42 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (teams) {
|
2022-12-07 21:35:41 +00:00
|
|
|
const teamStates = teams?.map((team) => ({
|
|
|
|
teamId: team.id,
|
|
|
|
teamMenuOpen: String(team.id) === router.query.id,
|
|
|
|
}));
|
2022-09-12 20:26:42 +00:00
|
|
|
setTeamMenuState(teamStates);
|
2022-12-07 21:35:41 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
const tabMembers = Array.from(document.getElementsByTagName("a")).filter(
|
|
|
|
(bottom) => bottom.dataset.testid === "vertical-tab-Members"
|
|
|
|
)[1];
|
|
|
|
tabMembers?.scrollIntoView({ behavior: "smooth" });
|
|
|
|
}, 100);
|
2022-09-12 20:26:42 +00:00
|
|
|
}
|
2022-12-07 21:35:41 +00:00
|
|
|
}, [router.query.id, teams]);
|
2022-09-12 20:26:42 +00:00
|
|
|
|
2022-09-07 01:33:50 +00:00
|
|
|
return (
|
2022-09-12 20:26:42 +00:00
|
|
|
<nav
|
2022-12-19 17:37:20 +00:00
|
|
|
className={classNames(
|
2023-01-07 10:10:35 +00:00
|
|
|
"no-scrollbar fixed bottom-0 left-0 top-0 z-10 flex max-h-screen w-56 flex-col space-y-1 overflow-x-hidden overflow-y-scroll bg-gray-50 px-2 pb-3 transition-transform lg:sticky lg:flex",
|
2022-12-19 17:37:20 +00:00
|
|
|
className,
|
|
|
|
navigationIsOpenedOnMobile
|
2023-01-07 10:10:35 +00:00
|
|
|
? "translate-x-0 opacity-100"
|
2023-01-04 15:46:42 +00:00
|
|
|
: "-translate-x-full opacity-0 lg:translate-x-0 lg:opacity-100"
|
2022-12-19 17:37:20 +00:00
|
|
|
)}
|
2022-09-12 20:26:42 +00:00
|
|
|
aria-label="Tabs">
|
|
|
|
<>
|
2022-12-26 10:23:03 +00:00
|
|
|
<BackButtonInSidebar name={t("back")} />
|
2022-09-12 20:26:42 +00:00
|
|
|
{tabsWithPermissions.map((tab) => {
|
|
|
|
return tab.name !== "teams" ? (
|
2022-09-13 16:11:37 +00:00
|
|
|
<React.Fragment key={tab.href}>
|
2022-09-27 09:24:09 +00:00
|
|
|
<div className={`${!tab.children?.length ? "!mb-3" : ""}`}>
|
2022-12-07 21:47:02 +00:00
|
|
|
<div className="group flex h-9 w-64 flex-row items-center rounded-md px-3 text-sm font-medium leading-none text-gray-600 [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:text-gray-900">
|
2022-09-12 20:26:42 +00:00
|
|
|
{tab && tab.icon && (
|
2023-01-04 07:38:45 +00:00
|
|
|
<tab.icon className="h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0" />
|
2022-09-12 20:26:42 +00:00
|
|
|
)}
|
2022-12-26 10:23:03 +00:00
|
|
|
{!tab.icon && tab?.avatar && (
|
2023-01-04 07:38:45 +00:00
|
|
|
<img
|
|
|
|
className="h-4 w-4 rounded-full ltr:mr-3 rtl:ml-3"
|
|
|
|
src={tab?.avatar}
|
|
|
|
alt="User Avatar"
|
|
|
|
/>
|
2022-12-26 10:23:03 +00:00
|
|
|
)}
|
2022-09-27 09:24:09 +00:00
|
|
|
<p className="text-sm font-medium leading-5">{t(tab.name)}</p>
|
2022-09-12 20:26:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-27 09:24:09 +00:00
|
|
|
<div className="my-3">
|
|
|
|
{tab.children?.map((child, index) => (
|
2022-09-12 20:26:42 +00:00
|
|
|
<VerticalTabItem
|
2022-09-13 16:11:37 +00:00
|
|
|
key={child.href}
|
|
|
|
name={t(child.name)}
|
2022-09-22 15:33:59 +00:00
|
|
|
isExternalLink={child.isExternalLink}
|
2022-09-13 16:11:37 +00:00
|
|
|
href={child.href || "/"}
|
2022-09-12 20:26:42 +00:00
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
2022-09-27 09:24:09 +00:00
|
|
|
className={`my-0.5 h-7 ${tab.children && index === tab.children?.length - 1 && "!mb-3"}`}
|
2022-09-12 20:26:42 +00:00
|
|
|
disableChevron
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
2022-09-13 16:11:37 +00:00
|
|
|
</React.Fragment>
|
2022-09-12 20:26:42 +00:00
|
|
|
) : (
|
2022-09-13 16:11:37 +00:00
|
|
|
<React.Fragment key={tab.href}>
|
2022-09-27 09:24:09 +00:00
|
|
|
<div className={`${!tab.children?.length ? "mb-3" : ""}`}>
|
2022-11-10 20:23:56 +00:00
|
|
|
<Link href={tab.href}>
|
2023-01-06 12:13:56 +00:00
|
|
|
<div className="group flex h-9 w-64 flex-row items-center rounded-md px-3 py-[10px] text-sm font-medium leading-none text-gray-600 hover:bg-gray-100 group-hover:text-gray-700 [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:text-gray-900">
|
|
|
|
{tab && tab.icon && (
|
|
|
|
<tab.icon className="h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0" />
|
|
|
|
)}
|
|
|
|
<p className="text-sm font-medium leading-5">{t(tab.name)}</p>
|
|
|
|
</div>
|
2022-11-10 20:23:56 +00:00
|
|
|
</Link>
|
2022-09-12 20:26:42 +00:00
|
|
|
{teams &&
|
|
|
|
teamMenuState &&
|
2022-09-15 09:47:59 +00:00
|
|
|
teams.map((team, index: number) => {
|
|
|
|
if (teamMenuState.some((teamState) => teamState.teamId === team.id))
|
|
|
|
return (
|
|
|
|
<Collapsible
|
|
|
|
key={team.id}
|
|
|
|
open={teamMenuState[index].teamMenuOpen}
|
|
|
|
onOpenChange={() =>
|
2022-09-12 20:26:42 +00:00
|
|
|
setTeamMenuState([
|
|
|
|
...teamMenuState,
|
|
|
|
(teamMenuState[index] = {
|
|
|
|
...teamMenuState[index],
|
|
|
|
teamMenuOpen: !teamMenuState[index].teamMenuOpen,
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
}>
|
2022-09-15 09:47:59 +00:00
|
|
|
<CollapsibleTrigger>
|
|
|
|
<div
|
|
|
|
className="flex h-9 w-64 flex-row items-center rounded-md px-3 py-[10px] text-sm font-medium leading-none hover:bg-gray-100 group-hover:text-gray-700 [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:text-gray-900"
|
|
|
|
onClick={() =>
|
|
|
|
setTeamMenuState([
|
|
|
|
...teamMenuState,
|
|
|
|
(teamMenuState[index] = {
|
|
|
|
...teamMenuState[index],
|
|
|
|
teamMenuOpen: !teamMenuState[index].teamMenuOpen,
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
}>
|
2023-01-04 07:38:45 +00:00
|
|
|
<div className="ltr:mr-3 rtl:ml-3">
|
2022-09-15 09:47:59 +00:00
|
|
|
{teamMenuState[index].teamMenuOpen ? (
|
|
|
|
<Icon.FiChevronDown />
|
|
|
|
) : (
|
|
|
|
<Icon.FiChevronRight />
|
|
|
|
)}
|
|
|
|
</div>
|
2022-09-21 04:53:31 +00:00
|
|
|
<img
|
|
|
|
src={getPlaceholderAvatar(team.logo, team?.name as string)}
|
2023-01-04 07:38:45 +00:00
|
|
|
className="h-[16px] w-[16px] self-start rounded-full stroke-[2px] ltr:mr-2 rtl:ml-2 md:mt-0"
|
2022-09-21 04:53:31 +00:00
|
|
|
alt={team.name || "Team logo"}
|
|
|
|
/>
|
2022-09-15 09:47:59 +00:00
|
|
|
<p>{team.name}</p>
|
|
|
|
{!team.accepted && (
|
2023-01-04 07:38:45 +00:00
|
|
|
<Badge className="ltr:ml-3 rtl:mr-3" variant="orange">
|
2022-09-15 09:47:59 +00:00
|
|
|
Inv.
|
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</CollapsibleTrigger>
|
|
|
|
<CollapsibleContent>
|
|
|
|
{team.accepted && (
|
|
|
|
<VerticalTabItem
|
|
|
|
name={t("profile")}
|
2022-09-16 12:03:58 +00:00
|
|
|
href={`/settings/teams/${team.id}/profile`}
|
2022-09-15 09:47:59 +00:00
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
|
|
|
disableChevron
|
|
|
|
/>
|
2022-09-12 20:26:42 +00:00
|
|
|
)}
|
2022-09-15 09:47:59 +00:00
|
|
|
<VerticalTabItem
|
|
|
|
name={t("members")}
|
2022-09-16 12:03:58 +00:00
|
|
|
href={`/settings/teams/${team.id}/members`}
|
2022-09-15 09:47:59 +00:00
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
|
|
|
disableChevron
|
2022-09-12 20:26:42 +00:00
|
|
|
/>
|
2022-09-15 09:47:59 +00:00
|
|
|
{(team.role === MembershipRole.OWNER || team.role === MembershipRole.ADMIN) && (
|
|
|
|
<>
|
|
|
|
{/* TODO */}
|
|
|
|
{/* <VerticalTabItem
|
2022-09-12 20:26:42 +00:00
|
|
|
name={t("general")}
|
|
|
|
href={`${WEBAPP_URL}/settings/my-account/appearance`}
|
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
|
|
|
disableChevron
|
2022-09-13 17:55:39 +00:00
|
|
|
/> */}
|
2022-09-15 09:47:59 +00:00
|
|
|
<VerticalTabItem
|
|
|
|
name={t("appearance")}
|
2022-09-16 12:03:58 +00:00
|
|
|
href={`/settings/teams/${team.id}/appearance`}
|
2022-09-15 09:47:59 +00:00
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
|
|
|
disableChevron
|
|
|
|
/>
|
2022-11-10 20:23:56 +00:00
|
|
|
<VerticalTabItem
|
|
|
|
name={t("billing")}
|
|
|
|
href={`/settings/teams/${team.id}/billing`}
|
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
|
|
|
disableChevron
|
|
|
|
/>
|
2022-10-18 20:34:32 +00:00
|
|
|
{HOSTED_CAL_FEATURES && (
|
|
|
|
<VerticalTabItem
|
|
|
|
name={t("saml_config")}
|
|
|
|
href={`/settings/teams/${team.id}/sso`}
|
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
|
|
|
disableChevron
|
|
|
|
/>
|
|
|
|
)}
|
2022-09-15 09:47:59 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</CollapsibleContent>
|
|
|
|
</Collapsible>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
<VerticalTabItem
|
|
|
|
name={t("add_a_team")}
|
|
|
|
href={`${WEBAPP_URL}/settings/teams/new`}
|
|
|
|
textClassNames="px-3 text-gray-900 font-medium text-sm"
|
|
|
|
icon={Icon.FiPlus}
|
|
|
|
disableChevron
|
|
|
|
/>
|
2022-09-12 20:26:42 +00:00
|
|
|
</div>
|
2022-09-13 16:11:37 +00:00
|
|
|
</React.Fragment>
|
2022-09-12 20:26:42 +00:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
</nav>
|
2022-09-07 01:33:50 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const MobileSettingsContainer = (props: { onSideContainerOpen?: () => void }) => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-12-19 17:37:20 +00:00
|
|
|
<nav className="sticky top-0 z-20 flex w-full items-center justify-between border-b border-gray-100 bg-gray-50 p-4 sm:relative lg:hidden">
|
2022-09-08 17:34:13 +00:00
|
|
|
<div className="flex items-center space-x-3 ">
|
2023-01-19 14:55:32 +00:00
|
|
|
<Button StartIcon={Icon.FiMenu} color="minimal" variant="icon" onClick={props.onSideContainerOpen}>
|
2022-12-19 17:37:20 +00:00
|
|
|
<span className="sr-only">{t("show_navigation")}</span>
|
|
|
|
</Button>
|
|
|
|
|
2023-01-04 07:38:45 +00:00
|
|
|
<a
|
|
|
|
href="/"
|
|
|
|
className="flex items-center space-x-2 rounded-md px-3 py-1 hover:bg-gray-200 rtl:space-x-reverse">
|
2022-09-07 01:33:50 +00:00
|
|
|
<Icon.FiArrowLeft className="text-gray-700" />
|
|
|
|
<p className="font-semibold text-black">{t("settings")}</p>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-08-09 09:21:15 +00:00
|
|
|
export default function SettingsLayout({
|
|
|
|
children,
|
|
|
|
...rest
|
|
|
|
}: { children: React.ReactNode } & ComponentProps<typeof Shell>) {
|
2022-10-13 15:50:08 +00:00
|
|
|
const router = useRouter();
|
2022-09-07 01:33:50 +00:00
|
|
|
const state = useState(false);
|
2022-12-19 17:37:20 +00:00
|
|
|
const { t } = useLocale();
|
2022-09-07 01:33:50 +00:00
|
|
|
const [sideContainerOpen, setSideContainerOpen] = state;
|
2022-09-26 19:09:51 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const closeSideContainer = () => {
|
|
|
|
if (window.innerWidth >= 1024) {
|
|
|
|
setSideContainerOpen(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("resize", closeSideContainer);
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener("resize", closeSideContainer);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
2022-10-13 15:50:08 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (sideContainerOpen) {
|
|
|
|
setSideContainerOpen(!sideContainerOpen);
|
|
|
|
}
|
|
|
|
}, [router.asPath]);
|
|
|
|
|
2022-08-09 09:21:15 +00:00
|
|
|
return (
|
2022-09-06 19:34:58 +00:00
|
|
|
<Shell
|
2022-12-07 20:53:44 +00:00
|
|
|
withoutSeo={true}
|
2022-09-06 19:34:58 +00:00
|
|
|
flexChildrenContainer
|
|
|
|
{...rest}
|
2022-12-19 17:37:20 +00:00
|
|
|
SidebarContainer={
|
|
|
|
<>
|
|
|
|
{/* Mobile backdrop */}
|
|
|
|
{sideContainerOpen && (
|
|
|
|
<button
|
|
|
|
onClick={() => setSideContainerOpen(false)}
|
|
|
|
className="fixed top-0 left-0 z-10 h-full w-full bg-black/50">
|
|
|
|
<span className="sr-only">{t("hide_navigation")}</span>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<SettingsSidebarContainer navigationIsOpenedOnMobile={sideContainerOpen} />
|
|
|
|
</>
|
|
|
|
}
|
2022-09-07 01:33:50 +00:00
|
|
|
drawerState={state}
|
|
|
|
MobileNavigationContainer={null}
|
|
|
|
TopNavContainer={
|
|
|
|
<MobileSettingsContainer onSideContainerOpen={() => setSideContainerOpen(!sideContainerOpen)} />
|
2022-09-06 19:34:58 +00:00
|
|
|
}>
|
2022-09-07 01:33:50 +00:00
|
|
|
<div className="flex flex-1 [&>*]:flex-1">
|
2022-10-04 20:24:08 +00:00
|
|
|
<div className="mx-auto max-w-full justify-center md:max-w-3xl">
|
2022-09-07 01:33:50 +00:00
|
|
|
<ShellHeader />
|
2022-09-12 19:07:52 +00:00
|
|
|
<ErrorBoundary>{children}</ErrorBoundary>
|
2022-09-07 01:33:50 +00:00
|
|
|
</div>
|
2022-08-30 19:46:52 +00:00
|
|
|
</div>
|
2022-08-09 09:21:15 +00:00
|
|
|
</Shell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getLayout = (page: React.ReactElement) => <SettingsLayout>{page}</SettingsLayout>;
|
2022-08-30 19:46:52 +00:00
|
|
|
|
|
|
|
function ShellHeader() {
|
|
|
|
const { meta } = useMeta();
|
|
|
|
const { t, isLocaleReady } = useLocale();
|
|
|
|
return (
|
2022-12-19 17:37:20 +00:00
|
|
|
<header className="mx-auto block justify-between pt-8 sm:flex">
|
2022-09-12 19:07:52 +00:00
|
|
|
<div className="mb-8 flex w-full items-center border-b border-gray-200 pb-8">
|
|
|
|
{meta.backButton && (
|
|
|
|
<a href="javascript:history.back()">
|
|
|
|
<Icon.FiArrowLeft className="mr-7" />
|
|
|
|
</a>
|
2022-08-30 19:46:52 +00:00
|
|
|
)}
|
2022-09-12 19:07:52 +00:00
|
|
|
<div>
|
|
|
|
{meta.title && isLocaleReady ? (
|
2022-10-01 10:50:27 +00:00
|
|
|
<h1 className="font-cal mb-1 text-xl font-bold tracking-wide text-black">{t(meta.title)}</h1>
|
2022-09-12 19:07:52 +00:00
|
|
|
) : (
|
|
|
|
<div className="mb-1 h-6 w-24 animate-pulse rounded-md bg-gray-200" />
|
|
|
|
)}
|
|
|
|
{meta.description && isLocaleReady ? (
|
|
|
|
<p className="text-sm text-gray-600 ltr:mr-4 rtl:ml-4">{t(meta.description)}</p>
|
|
|
|
) : (
|
|
|
|
<div className="mb-1 h-6 w-32 animate-pulse rounded-md bg-gray-200" />
|
|
|
|
)}
|
|
|
|
</div>
|
2022-10-20 10:03:39 +00:00
|
|
|
<div className="ml-auto">{meta.CTA}</div>
|
2022-08-30 19:46:52 +00:00
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|