chore: App router migration - general settings (#16312)
* added lockedSMS to future routes * add orgMigrations routes to future * correct metadata * small fix * add orgMigrations to future * Move components to client components * Remove tRPC element from edit user RSC * Get username for meta * Remove suspense query * Remove orgMigrations from app router * Type fix * Revert "Remove suspense query" This reverts commit eadd814f6e4a5d6856d9218342b7909c22fe62c6. * Handle suspenseQuery in app router * User edit page, fetch data server side * Update yarn.lock * Export getFixedT * Set PageWrapper as root layout for settings * Settings Layout accepts strings for shell heading * Add OOO to app router settings * Refactor layout for my-account pages * Remove instances of pages router from my-account * Refactor security pages * Add billing to app router * Add admin API link to layout * Add api keys page * Webhooks WIP * Refactor SettingsHeader to client component * Add webhook pages * Refactor API keys page * Add admin app page * Type fix * fix types * fix developer/webhooks/[id] param value type error * remove unnecessary code * do not pass t prop to CreateNewWebhookButton * fix type errors in webhook-edit-view * fix the remaining type errors * do not use prisma directly in generateMetadata * remove use client if unnecessary * Remove unused shell heading from SettingsLayoutAppDir * improve metadata * fix billing page * fix import in settings/teams * Use next `notFound()` * fix type check * fix type check * remove unused code * Fix calendar setting page * Separate settings pages into route groups * Refactor admin settings pages * Remove meta instance from billing page route * Update settings layoutAppDir * Refactor developer settings pages * Refactor out of office * Refactor my account settings * Refactor admin api page * Refactor security pages * Type fix * fix styling in settings layout --------- Co-authored-by: Somay Chauhan <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
187 files changed
+4628
-3586
No files matched your search
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { noop } from "lodash";
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useSession } from "next-auth/react";
|
||||
import type { AriaRole, ComponentType } from "react";
|
||||
import React, { Fragment, useEffect } from "react";
|
||||
@@ -70,9 +72,11 @@ export const withLicenseRequired =
|
||||
// eslint-disable-next-line react/display-name
|
||||
(hocProps: T) =>
|
||||
(
|
||||
<LicenseRequired>
|
||||
<Component {...hocProps} />
|
||||
</LicenseRequired>
|
||||
<div>
|
||||
<LicenseRequired>
|
||||
<Component {...hocProps} />
|
||||
</LicenseRequired>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default LicenseRequired;
|
||||
@@ -1,12 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
|
||||
import { getLayout } from "@calcom/features/settings/layouts/SettingsLayout";
|
||||
import { UpgradeTip } from "@calcom/features/tips";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Button, Icon, Meta, ButtonGroup } from "@calcom/ui";
|
||||
import { Button, Icon, ButtonGroup } from "@calcom/ui";
|
||||
|
||||
const AdminAPIViewWrapper = () => {
|
||||
export const AdminAPIView = () => {
|
||||
const { t } = useLocale();
|
||||
|
||||
const features = [
|
||||
@@ -28,11 +27,6 @@ const AdminAPIViewWrapper = () => {
|
||||
];
|
||||
return (
|
||||
<LicenseRequired>
|
||||
<Meta
|
||||
title={`${t("admin")} ${t("api_reference")}`}
|
||||
description={t("leverage_our_api")}
|
||||
borderInShellHeader={false}
|
||||
/>
|
||||
<div className="mt-8">
|
||||
<UpgradeTip
|
||||
plan="enterprise"
|
||||
@@ -59,6 +53,4 @@ const AdminAPIViewWrapper = () => {
|
||||
);
|
||||
};
|
||||
|
||||
AdminAPIViewWrapper.getLayout = getLayout;
|
||||
|
||||
export default AdminAPIViewWrapper;
|
||||
export default AdminAPIView;
|
||||
@@ -1,44 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import type { Team } from "@prisma/client";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import type { z } from "zod";
|
||||
|
||||
import NoSSR from "@calcom/core/components/NoSSR";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
|
||||
import type { orgSettingsSchema } from "@calcom/prisma/zod-utils";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button, Form, Meta, TextField, showToast } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../../../../settings/layouts/SettingsLayout";
|
||||
import LicenseRequired from "../../../../common/components/LicenseRequired";
|
||||
|
||||
const paramsSchema = z.object({ id: z.coerce.number() });
|
||||
|
||||
const OrgEditPage = () => {
|
||||
const params = useParamsWithFallback();
|
||||
const parsedParams = paramsSchema.safeParse(params);
|
||||
|
||||
if (!parsedParams.success) return <div>Invalid id</div>;
|
||||
|
||||
return <OrgEditView orgId={parsedParams.data.id} />;
|
||||
};
|
||||
|
||||
const OrgEditView = ({ orgId }: { orgId: number }) => {
|
||||
const [org] = trpc.viewer.organizations.adminGet.useSuspenseQuery({ id: orgId });
|
||||
|
||||
return (
|
||||
<LicenseRequired>
|
||||
<Meta
|
||||
title={`Editing organization: ${org.name}`}
|
||||
description="Here you can edit a current organization."
|
||||
/>
|
||||
<NoSSR>
|
||||
<OrgForm org={org} />
|
||||
</NoSSR>
|
||||
</LicenseRequired>
|
||||
);
|
||||
};
|
||||
import { Button, Form, TextField, showToast } from "@calcom/ui";
|
||||
|
||||
type FormValues = {
|
||||
name: Team["name"];
|
||||
@@ -46,7 +16,7 @@ type FormValues = {
|
||||
organizationSettings: z.infer<typeof orgSettingsSchema>;
|
||||
};
|
||||
|
||||
const OrgForm = ({
|
||||
export const OrgForm = ({
|
||||
org,
|
||||
}: {
|
||||
org: FormValues & {
|
||||
@@ -108,6 +78,4 @@ const OrgForm = ({
|
||||
);
|
||||
};
|
||||
|
||||
OrgEditPage.getLayout = getLayout;
|
||||
|
||||
export default OrgEditPage;
|
||||
export default OrgForm;
|
||||
@@ -3,39 +3,18 @@
|
||||
import { Trans } from "next-i18next";
|
||||
import { useState } from "react";
|
||||
|
||||
import NoSSR from "@calcom/core/components/NoSSR";
|
||||
import LicenseRequired from "@calcom/ee/common/components/LicenseRequired";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import {
|
||||
Badge,
|
||||
ConfirmationDialogContent,
|
||||
Dialog,
|
||||
DropdownActions,
|
||||
Meta,
|
||||
showToast,
|
||||
Table,
|
||||
} from "@calcom/ui";
|
||||
import { Badge, ConfirmationDialogContent, Dialog, DropdownActions, showToast, Table } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../../../../settings/layouts/SettingsLayout";
|
||||
import { subdomainSuffix } from "../../../../organizations/lib/orgDomains";
|
||||
|
||||
const { Body, Cell, ColumnTitle, Header, Row } = Table;
|
||||
|
||||
function AdminOrgTable() {
|
||||
export function AdminOrgTable() {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
const [data] = trpc.viewer.organizations.adminGetAll.useSuspenseQuery();
|
||||
const verifyMutation = trpc.viewer.organizations.adminVerify.useMutation({
|
||||
onSuccess: async (_data, variables) => {
|
||||
showToast(t("org_has_been_processed"), "success");
|
||||
await invalidateQueries(utils, variables);
|
||||
},
|
||||
onError: (err) => {
|
||||
console.error(err.message);
|
||||
showToast(t("org_error_processing"), "error");
|
||||
},
|
||||
});
|
||||
const updateMutation = trpc.viewer.organizations.adminUpdate.useMutation({
|
||||
onSuccess: async (_data, variables) => {
|
||||
showToast(t("org_has_been_processed"), "success");
|
||||
@@ -240,21 +219,7 @@ function AdminOrgTable() {
|
||||
);
|
||||
}
|
||||
|
||||
const AdminOrgList = () => {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<LicenseRequired>
|
||||
<Meta title={t("organizations")} description={t("orgs_page_description")} />
|
||||
<NoSSR>
|
||||
<AdminOrgTable />
|
||||
</NoSSR>
|
||||
</LicenseRequired>
|
||||
);
|
||||
};
|
||||
|
||||
AdminOrgList.getLayout = getLayout;
|
||||
|
||||
export default AdminOrgList;
|
||||
export default AdminOrgTable;
|
||||
|
||||
const DeleteOrgDialog = ({
|
||||
org,
|
||||
|
||||
@@ -5,9 +5,7 @@ import { useEffect } from "react";
|
||||
|
||||
import { HOSTED_CAL_FEATURES } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Meta } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
||||
import SSOConfiguration from "../components/SSOConfiguration";
|
||||
|
||||
const SAMLSSO = () => {
|
||||
@@ -22,16 +20,9 @@ const SAMLSSO = () => {
|
||||
|
||||
return (
|
||||
<div className="bg-default w-full sm:mx-0">
|
||||
<Meta
|
||||
title={t("sso_configuration")}
|
||||
description={t("sso_configuration_description")}
|
||||
borderInShellHeader={true}
|
||||
/>
|
||||
<SSOConfiguration teamId={null} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
SAMLSSO.getLayout = getLayout;
|
||||
|
||||
export default SAMLSSO;
|
||||
@@ -150,7 +150,7 @@ function UsersTableBare() {
|
||||
const [userToDelete, setUserToDelete] = useState<number | null>(null);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<TextField
|
||||
placeholder="username or email"
|
||||
label="Search"
|
||||
@@ -293,7 +293,7 @@ function UsersTableBare() {
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,8 @@ import { usePathname, useRouter } from "next/navigation";
|
||||
|
||||
import { getParserWithGeneric } from "@calcom/prisma/zod-utils";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Meta, showToast } from "@calcom/ui";
|
||||
import { showToast } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
||||
import LicenseRequired from "../../common/components/LicenseRequired";
|
||||
import { UserForm } from "../components/UserForm";
|
||||
import { userBodySchema } from "../schemas/userBodySchema";
|
||||
@@ -30,20 +29,19 @@ const UsersAddView = () => {
|
||||
},
|
||||
});
|
||||
return (
|
||||
<LicenseRequired>
|
||||
<Meta title="Add new user" description="Here you can add a new user." />
|
||||
<UserForm
|
||||
submitLabel="Add user"
|
||||
onSubmit={async (values) => {
|
||||
const parser = getParserWithGeneric(userBodySchema);
|
||||
const parsedValues = parser(values);
|
||||
mutation.mutate(parsedValues);
|
||||
}}
|
||||
/>
|
||||
</LicenseRequired>
|
||||
<div>
|
||||
<LicenseRequired>
|
||||
<UserForm
|
||||
submitLabel="Add user"
|
||||
onSubmit={async (values) => {
|
||||
const parser = getParserWithGeneric(userBodySchema);
|
||||
const parsedValues = parser(values);
|
||||
mutation.mutate(parsedValues);
|
||||
}}
|
||||
/>
|
||||
</LicenseRequired>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
UsersAddView.getLayout = getLayout;
|
||||
|
||||
export default UsersAddView;
|
||||
@@ -7,13 +7,14 @@ import NoSSR from "@calcom/core/components/NoSSR";
|
||||
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
|
||||
import { getParserWithGeneric } from "@calcom/prisma/zod-utils";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Meta, showToast } from "@calcom/ui";
|
||||
import { showToast } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
||||
import LicenseRequired from "../../common/components/LicenseRequired";
|
||||
import { UserForm } from "../components/UserForm";
|
||||
import { userBodySchema } from "../schemas/userBodySchema";
|
||||
import type { UserAdminRouterOutputs } from "../server/trpc-router";
|
||||
|
||||
type User = UserAdminRouterOutputs["get"]["user"];
|
||||
const userIdSchema = z.object({ id: z.coerce.number() });
|
||||
|
||||
const UsersEditPage = () => {
|
||||
@@ -22,14 +23,22 @@ const UsersEditPage = () => {
|
||||
|
||||
if (!input.success) return <div>Invalid input</div>;
|
||||
|
||||
return <UsersEditView userId={input.data.id} />;
|
||||
const [data] = trpc.viewer.users.get.useSuspenseQuery({ userId: input.data.id });
|
||||
const { user } = data;
|
||||
|
||||
return (
|
||||
<LicenseRequired>
|
||||
<NoSSR>
|
||||
<UsersEditView user={user} />
|
||||
</NoSSR>
|
||||
</LicenseRequired>
|
||||
);
|
||||
};
|
||||
|
||||
const UsersEditView = ({ userId }: { userId: number }) => {
|
||||
export const UsersEditView = ({ user }: { user: User }) => {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const [data] = trpc.viewer.users.get.useSuspenseQuery({ userId });
|
||||
const { user } = data;
|
||||
|
||||
const utils = trpc.useUtils();
|
||||
const mutation = trpc.viewer.users.update.useMutation({
|
||||
onSuccess: async () => {
|
||||
@@ -43,29 +52,22 @@ const UsersEditView = ({ userId }: { userId: number }) => {
|
||||
},
|
||||
});
|
||||
return (
|
||||
<LicenseRequired>
|
||||
<Meta title={`Editing user: ${user.username}`} description="Here you can edit a current user." />
|
||||
<NoSSR>
|
||||
<UserForm
|
||||
key={JSON.stringify(user)}
|
||||
onSubmit={(values) => {
|
||||
const parser = getParserWithGeneric(userBodySchema);
|
||||
const parsedValues = parser(values);
|
||||
const data: Partial<typeof parsedValues & { userId: number }> = {
|
||||
...parsedValues,
|
||||
userId: user.id,
|
||||
};
|
||||
// Don't send username if it's the same as the current one
|
||||
if (user.username === data.username) delete data.username;
|
||||
mutation.mutate(data);
|
||||
}}
|
||||
defaultValues={user}
|
||||
/>
|
||||
</NoSSR>
|
||||
</LicenseRequired>
|
||||
<UserForm
|
||||
key={JSON.stringify(user)}
|
||||
onSubmit={(values) => {
|
||||
const parser = getParserWithGeneric(userBodySchema);
|
||||
const parsedValues = parser(values);
|
||||
const data: Partial<typeof parsedValues & { userId: number }> = {
|
||||
...parsedValues,
|
||||
userId: user.id,
|
||||
};
|
||||
// Don't send username if it's the same as the current one
|
||||
if (user.username === data.username) delete data.username;
|
||||
mutation.mutate(data);
|
||||
}}
|
||||
defaultValues={user}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
UsersEditPage.getLayout = getLayout;
|
||||
|
||||
export default UsersEditPage;
|
||||
export default UsersEditView;
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import NoSSR from "@calcom/core/components/NoSSR";
|
||||
import { Button, Meta } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
||||
import { UsersTable } from "../components/UsersTable";
|
||||
@@ -9,17 +8,6 @@ import { UsersTable } from "../components/UsersTable";
|
||||
const DeploymentUsersListPage = () => {
|
||||
return (
|
||||
<>
|
||||
<Meta
|
||||
title="Users"
|
||||
description="A list of all the users in your account including their name, title, email and role."
|
||||
CTA={
|
||||
<div className="mt-4 space-x-5 sm:ml-16 sm:mt-0 sm:flex-none">
|
||||
{/* TODO: Add import users functionality */}
|
||||
{/* <Button disabled>Import users</Button> */}
|
||||
<Button href="/settings/admin/users/add">Add user</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<NoSSR>
|
||||
<UsersTable />
|
||||
</NoSSR>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { Suspense } from "react";
|
||||
|
||||
import NoSSR from "@calcom/core/components/NoSSR";
|
||||
import { Meta, SkeletonText, SkeletonContainer } from "@calcom/ui";
|
||||
import { SkeletonText, SkeletonContainer } from "@calcom/ui";
|
||||
|
||||
import { FlagAdminList } from "../components/FlagAdminList";
|
||||
|
||||
@@ -18,13 +20,10 @@ const SkeletonLoader = () => {
|
||||
|
||||
export const FlagListingView = () => {
|
||||
return (
|
||||
<>
|
||||
<Meta title="Feature Flags" description="Here you can toggle your Cal.com instance features." />
|
||||
<NoSSR>
|
||||
<Suspense fallback={<SkeletonLoader />}>
|
||||
<FlagAdminList />
|
||||
</Suspense>
|
||||
</NoSSR>
|
||||
</>
|
||||
<NoSSR>
|
||||
<Suspense fallback={<SkeletonLoader />}>
|
||||
<FlagAdminList />
|
||||
</Suspense>
|
||||
</NoSSR>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
import React, { Suspense } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { Icon } from "@calcom/ui";
|
||||
|
||||
interface HeaderProps {
|
||||
children: React.ReactNode;
|
||||
title?: string;
|
||||
description?: string;
|
||||
CTA?: React.ReactNode;
|
||||
borderInShellHeader?: boolean;
|
||||
backButton?: boolean;
|
||||
}
|
||||
|
||||
export default function Header({
|
||||
children,
|
||||
title,
|
||||
description,
|
||||
CTA,
|
||||
borderInShellHeader,
|
||||
backButton,
|
||||
}: HeaderProps) {
|
||||
return (
|
||||
<div>
|
||||
<header
|
||||
className={classNames(
|
||||
"border-subtle mx-auto block justify-between sm:flex",
|
||||
borderInShellHeader && "rounded-t-lg border px-4 py-6 sm:px-6",
|
||||
borderInShellHeader === undefined && "mb-8 border-b pb-8"
|
||||
)}>
|
||||
<div className="flex w-full items-center">
|
||||
{backButton && (
|
||||
<a href="javascript:history.back()">
|
||||
<Icon name="arrow-left" className="mr-7" />
|
||||
</a>
|
||||
)}
|
||||
<div>
|
||||
{title ? (
|
||||
<h1 className="font-cal text-emphasis mb-1 text-xl font-semibold leading-5 tracking-wide">
|
||||
{title}
|
||||
</h1>
|
||||
) : (
|
||||
<div className="bg-emphasis mb-1 h-5 w-24 animate-pulse rounded-lg" />
|
||||
)}
|
||||
{description ? (
|
||||
<p className="text-default text-sm ltr:mr-4 rtl:ml-4">{description}</p>
|
||||
) : (
|
||||
<div className="bg-emphasis h-5 w-32 animate-pulse rounded-lg" />
|
||||
)}
|
||||
</div>
|
||||
<div className="ms-auto flex-shrink-0">{CTA}</div>
|
||||
</div>
|
||||
</header>
|
||||
<Suspense fallback={<Icon name="loader" />}>{children}</Suspense>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+255
-246
@@ -5,7 +5,7 @@ import { useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import type { ComponentProps } from "react";
|
||||
import React, { Suspense, useEffect, useState } from "react";
|
||||
import React, { useEffect, useState, useMemo } from "react";
|
||||
|
||||
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
|
||||
import Shell from "@calcom/features/shell/Shell";
|
||||
@@ -18,7 +18,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { IdentityProvider, MembershipRole, UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { VerticalTabItemProps } from "@calcom/ui";
|
||||
import { Badge, Button, ErrorBoundary, Icon, Skeleton, useMeta, VerticalTabItem } from "@calcom/ui";
|
||||
import { Badge, Button, ErrorBoundary, Icon, Skeleton, VerticalTabItem } from "@calcom/ui";
|
||||
|
||||
const tabs: VerticalTabItemProps[] = [
|
||||
{
|
||||
@@ -31,6 +31,7 @@ const tabs: VerticalTabItemProps[] = [
|
||||
{ name: "calendars", href: "/settings/my-account/calendars" },
|
||||
{ name: "conferencing", href: "/settings/my-account/conferencing" },
|
||||
{ name: "appearance", href: "/settings/my-account/appearance" },
|
||||
{ name: "out_of_office", href: "/settings/my-account/out-of-office" },
|
||||
// TODO
|
||||
// { name: "referrals", href: "/settings/my-account/referrals" },
|
||||
],
|
||||
@@ -59,6 +60,7 @@ const tabs: VerticalTabItemProps[] = [
|
||||
//
|
||||
{ name: "webhooks", href: "/settings/developer/webhooks" },
|
||||
{ name: "api_keys", href: "/settings/developer/api-keys" },
|
||||
{ name: "admin_api", href: "/settings/organizations/admin-api" },
|
||||
// TODO: Add profile level for embeds
|
||||
// { name: "embeds", href: "/v2/settings/developer/embeds" },
|
||||
],
|
||||
@@ -80,13 +82,26 @@ const tabs: VerticalTabItemProps[] = [
|
||||
href: "/settings/organizations/members",
|
||||
},
|
||||
{
|
||||
name: "appearance",
|
||||
href: "/settings/organizations/appearance",
|
||||
name: "privacy",
|
||||
href: "/settings/organizations/privacy",
|
||||
},
|
||||
{
|
||||
name: "billing",
|
||||
href: "/settings/organizations/billing",
|
||||
},
|
||||
{ name: "OAuth Clients", href: "/settings/organizations/platform/oauth-clients" },
|
||||
{
|
||||
name: "SSO",
|
||||
href: "/settings/organizations/sso",
|
||||
},
|
||||
{
|
||||
name: "directory_sync",
|
||||
href: "/settings/organizations/dsync",
|
||||
},
|
||||
{
|
||||
name: "admin_api",
|
||||
href: "https://cal.com/docs/enterprise-features/api/api-reference/bookings#admin-access",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -95,6 +110,12 @@ const tabs: VerticalTabItemProps[] = [
|
||||
icon: "users",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
name: "other_teams",
|
||||
href: "/settings/organizations/teams/other",
|
||||
icon: "users",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
name: "admin",
|
||||
href: "/settings/admin",
|
||||
@@ -114,57 +135,92 @@ const tabs: VerticalTabItemProps[] = [
|
||||
];
|
||||
|
||||
tabs.find((tab) => {
|
||||
// Add "SAML SSO" to the tab
|
||||
if (tab.name === "security" && !HOSTED_CAL_FEATURES) {
|
||||
tab.children?.push({ name: "sso_configuration", href: "/settings/security/sso" });
|
||||
// TODO: Enable dsync for self hosters
|
||||
// tab.children?.push({ name: "directory_sync", href: "/settings/security/dsync" });
|
||||
}
|
||||
});
|
||||
|
||||
// The following keys are assigned to admin only
|
||||
const adminRequiredKeys = ["admin"];
|
||||
const organizationRequiredKeys = ["organization"];
|
||||
const organizationAdminKeys = ["privacy", "billing", "OAuth Clients", "SSO", "directory_sync"];
|
||||
|
||||
const useTabs = () => {
|
||||
const session = useSession();
|
||||
const { data: user } = trpc.viewer.me.useQuery();
|
||||
const { data: user } = trpc.viewer.me.useQuery({ includePasswordAdded: true });
|
||||
const orgBranding = useOrgBranding();
|
||||
|
||||
const isAdmin = session.data?.user.role === UserPermissionRole.ADMIN;
|
||||
const isOrgAdminOrOwner =
|
||||
orgBranding?.role === MembershipRole.ADMIN || orgBranding?.role === MembershipRole.OWNER;
|
||||
|
||||
tabs.map((tab) => {
|
||||
if (tab.href === "/settings/my-account") {
|
||||
tab.name = user?.name || "my_account";
|
||||
tab.icon = undefined;
|
||||
tab.avatar = getUserAvatarUrl(user);
|
||||
} else if (tab.href === "/settings/organizations") {
|
||||
tab.name = orgBranding?.name || "organization";
|
||||
tab.avatar = `${orgBranding?.fullDomain}/org/${orgBranding?.slug}/avatar.png`;
|
||||
} else if (
|
||||
tab.href === "/settings/security" &&
|
||||
user?.identityProvider === IdentityProvider.GOOGLE &&
|
||||
!user?.twoFactorEnabled
|
||||
) {
|
||||
tab.children = tab?.children?.filter(
|
||||
(childTab) => childTab.href !== "/settings/security/two-factor-auth"
|
||||
);
|
||||
}
|
||||
return tab;
|
||||
});
|
||||
const processTabsMemod = useMemo(() => {
|
||||
const processedTabs = tabs.map((tab) => {
|
||||
if (tab.href === "/settings/my-account") {
|
||||
return {
|
||||
...tab,
|
||||
name: user?.name || "my_account",
|
||||
icon: undefined,
|
||||
avatar: getUserAvatarUrl(user),
|
||||
};
|
||||
} else if (tab.href === "/settings/organizations") {
|
||||
const newArray = (tab?.children ?? []).filter(
|
||||
(child) => isOrgAdminOrOwner || !organizationAdminKeys.includes(child.name)
|
||||
);
|
||||
|
||||
// check if name is in adminRequiredKeys
|
||||
return tabs.filter((tab) => {
|
||||
if (organizationRequiredKeys.includes(tab.name)) return !!session.data?.user?.org;
|
||||
// TODO: figure out feature flag as it doesnt cause a re-render of the component when loaded.
|
||||
// You have to refresh the page to see the changes.
|
||||
if (true) {
|
||||
newArray.splice(4, 0, {
|
||||
name: "attributes",
|
||||
href: "/settings/organizations/attributes",
|
||||
});
|
||||
}
|
||||
|
||||
if (isAdmin) return true;
|
||||
return !adminRequiredKeys.includes(tab.name);
|
||||
});
|
||||
return {
|
||||
...tab,
|
||||
children: newArray,
|
||||
name: orgBranding?.name || "organization",
|
||||
avatar: getPlaceholderAvatar(orgBranding?.logoUrl, orgBranding?.name),
|
||||
};
|
||||
} else if (
|
||||
tab.href === "/settings/security" &&
|
||||
user?.identityProvider === IdentityProvider.GOOGLE &&
|
||||
!user?.twoFactorEnabled &&
|
||||
!user?.passwordAdded
|
||||
) {
|
||||
const filtered = tab?.children?.filter(
|
||||
(childTab) => childTab.href !== "/settings/security/two-factor-auth"
|
||||
);
|
||||
return { ...tab, children: filtered };
|
||||
} else if (tab.href === "/settings/developer") {
|
||||
const filtered = tab?.children?.filter(
|
||||
(childTab) => isOrgAdminOrOwner || childTab.name !== "admin_api"
|
||||
);
|
||||
return { ...tab, children: filtered };
|
||||
}
|
||||
return tab;
|
||||
});
|
||||
|
||||
// check if name is in adminRequiredKeys
|
||||
return processedTabs.filter((tab) => {
|
||||
if (organizationRequiredKeys.includes(tab.name)) return !!orgBranding;
|
||||
if (tab.name === "other_teams" && !isOrgAdminOrOwner) return false;
|
||||
|
||||
if (isAdmin) return true;
|
||||
return !adminRequiredKeys.includes(tab.name);
|
||||
});
|
||||
}, [isAdmin, orgBranding, isOrgAdminOrOwner, user]);
|
||||
|
||||
return processTabsMemod;
|
||||
};
|
||||
|
||||
const BackButtonInSidebar = ({ name }: { name: string }) => {
|
||||
return (
|
||||
<Link
|
||||
href="/"
|
||||
className="hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis group-hover:text-default text-emphasis group my-6 flex h-6 max-h-6 w-full flex-row items-center rounded-md px-3 py-2 text-sm font-medium leading-4 transition"
|
||||
className="hover:bg-subtle todesktop:mt-10 [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis group-hover:text-default text-emphasis group my-6 flex h-6 max-h-6 w-full flex-row items-center rounded-md px-3 py-2 text-sm font-medium leading-4 transition"
|
||||
data-testid={`vertical-tab-${name}`}>
|
||||
<Icon
|
||||
name="arrow-left"
|
||||
@@ -183,30 +239,12 @@ interface SettingsSidebarContainerProps {
|
||||
bannersHeight?: number;
|
||||
}
|
||||
|
||||
const SettingsSidebarContainer = ({
|
||||
className = "",
|
||||
navigationIsOpenedOnMobile,
|
||||
bannersHeight,
|
||||
}: SettingsSidebarContainerProps) => {
|
||||
const searchParams = useCompatSearchParams();
|
||||
const TeamListCollapsible = () => {
|
||||
const { data: teams } = trpc.viewer.teams.list.useQuery();
|
||||
const { t } = useLocale();
|
||||
const tabsWithPermissions = useTabs();
|
||||
const [teamMenuState, setTeamMenuState] =
|
||||
useState<{ teamId: number | undefined; teamMenuOpen: boolean }[]>();
|
||||
const [otherTeamMenuState, setOtherTeamMenuState] = useState<
|
||||
{
|
||||
teamId: number | undefined;
|
||||
teamMenuOpen: boolean;
|
||||
}[]
|
||||
>();
|
||||
const { data: teams } = trpc.viewer.teams.list.useQuery();
|
||||
const session = useSession();
|
||||
const { data: currentOrg } = trpc.viewer.organizations.listCurrent.useQuery(undefined, {
|
||||
enabled: !!session.data?.user?.org,
|
||||
});
|
||||
|
||||
const { data: otherTeams } = trpc.viewer.organizations.listOtherTeams.useQuery();
|
||||
|
||||
const searchParams = useCompatSearchParams();
|
||||
useEffect(() => {
|
||||
if (teams) {
|
||||
const teamStates = teams?.map((team) => ({
|
||||
@@ -223,6 +261,147 @@ const SettingsSidebarContainer = ({
|
||||
}
|
||||
}, [searchParams?.get("id"), teams]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{teams &&
|
||||
teamMenuState &&
|
||||
teams.map((team, index: number) => {
|
||||
if (!teamMenuState[index]) {
|
||||
return null;
|
||||
}
|
||||
if (teamMenuState.some((teamState) => teamState.teamId === team.id))
|
||||
return (
|
||||
<Collapsible
|
||||
className="cursor-pointer"
|
||||
key={team.id}
|
||||
open={teamMenuState[index].teamMenuOpen}
|
||||
onOpenChange={() =>
|
||||
setTeamMenuState([
|
||||
...teamMenuState,
|
||||
(teamMenuState[index] = {
|
||||
...teamMenuState[index],
|
||||
teamMenuOpen: !teamMenuState[index].teamMenuOpen,
|
||||
}),
|
||||
])
|
||||
}>
|
||||
<CollapsibleTrigger asChild>
|
||||
<div
|
||||
className="hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis text-default flex h-9 w-full flex-row items-center rounded-md px-2 py-[10px] text-left text-sm font-medium leading-none transition"
|
||||
onClick={() =>
|
||||
setTeamMenuState([
|
||||
...teamMenuState,
|
||||
(teamMenuState[index] = {
|
||||
...teamMenuState[index],
|
||||
teamMenuOpen: !teamMenuState[index].teamMenuOpen,
|
||||
}),
|
||||
])
|
||||
}>
|
||||
<div className="me-3">
|
||||
{teamMenuState[index].teamMenuOpen ? (
|
||||
<Icon name="chevron-down" className="h-4 w-4" />
|
||||
) : (
|
||||
<Icon name="chevron-right" className="h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
{!team.parentId && (
|
||||
<img
|
||||
src={getPlaceholderAvatar(team.logoUrl, team.name)}
|
||||
className="h-[16px] w-[16px] self-start rounded-full stroke-[2px] ltr:mr-2 rtl:ml-2 md:mt-0"
|
||||
alt={team.name || "Team logo"}
|
||||
/>
|
||||
)}
|
||||
<p className="w-1/2 truncate leading-normal">{team.name}</p>
|
||||
{!team.accepted && (
|
||||
<Badge className="ms-3" variant="orange">
|
||||
Inv.
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="space-y-0.5">
|
||||
{team.accepted && (
|
||||
<VerticalTabItem
|
||||
name={t("profile")}
|
||||
href={`/settings/teams/${team.id}/profile`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
)}
|
||||
<VerticalTabItem
|
||||
name={t("members")}
|
||||
href={`/settings/teams/${team.id}/members`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
<VerticalTabItem
|
||||
name={t("event_types_page_title")}
|
||||
href={`/event-types?teamIds=${team.id}`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
{(team.role === MembershipRole.OWNER ||
|
||||
team.role === MembershipRole.ADMIN ||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore this exists wtf?
|
||||
(team.isOrgAdmin && team.isOrgAdmin)) && (
|
||||
<>
|
||||
{/* TODO */}
|
||||
{/* <VerticalTabItem
|
||||
name={t("general")}
|
||||
href={`${WEBAPP_URL}/settings/my-account/appearance`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/> */}
|
||||
<VerticalTabItem
|
||||
name={t("appearance")}
|
||||
href={`/settings/teams/${team.id}/appearance`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
{/* Hide if there is a parent ID */}
|
||||
{!team.parentId ? (
|
||||
<>
|
||||
<VerticalTabItem
|
||||
name={t("billing")}
|
||||
href={`/settings/teams/${team.id}/billing`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const SettingsSidebarContainer = ({
|
||||
className = "",
|
||||
navigationIsOpenedOnMobile,
|
||||
bannersHeight,
|
||||
}: SettingsSidebarContainerProps) => {
|
||||
const searchParams = useCompatSearchParams();
|
||||
const { t } = useLocale();
|
||||
const tabsWithPermissions = useTabs();
|
||||
const [otherTeamMenuState, setOtherTeamMenuState] = useState<
|
||||
{
|
||||
teamId: number | undefined;
|
||||
teamMenuOpen: boolean;
|
||||
}[]
|
||||
>();
|
||||
const session = useSession();
|
||||
const { data: currentOrg } = trpc.viewer.organizations.listCurrent.useQuery(undefined, {
|
||||
enabled: !!session.data?.user?.org,
|
||||
});
|
||||
|
||||
const { data: otherTeams } = trpc.viewer.organizations.listOtherTeams.useQuery(undefined, {
|
||||
enabled: !!session.data?.user?.org,
|
||||
});
|
||||
|
||||
// Same as above but for otherTeams
|
||||
useEffect(() => {
|
||||
if (otherTeams) {
|
||||
@@ -244,17 +423,6 @@ const SettingsSidebarContainer = ({
|
||||
const isOrgAdminOrOwner =
|
||||
currentOrg && currentOrg?.user?.role && ["OWNER", "ADMIN"].includes(currentOrg?.user?.role);
|
||||
|
||||
if (isOrgAdminOrOwner) {
|
||||
const teamsIndex = tabsWithPermissions.findIndex((tab) => tab.name === "teams");
|
||||
|
||||
tabsWithPermissions.splice(teamsIndex + 1, 0, {
|
||||
name: "other_teams",
|
||||
href: "/settings/organizations/teams/other",
|
||||
icon: "users",
|
||||
children: [],
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<nav
|
||||
style={{ maxHeight: `calc(100vh - ${bannersHeight}px)`, top: `${bannersHeight}px` }}
|
||||
@@ -274,38 +442,38 @@ const SettingsSidebarContainer = ({
|
||||
{!["teams", "other_teams"].includes(tab.name) && (
|
||||
<React.Fragment key={tab.href}>
|
||||
<div className={`${!tab.children?.length ? "!mb-3" : ""}`}>
|
||||
<div className="[&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis text-default group flex h-9 w-full flex-row items-center rounded-md px-2 text-sm font-medium leading-none">
|
||||
<div className="[&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis text-default group flex h-7 w-full flex-row items-center rounded-md px-2 text-sm font-medium leading-none">
|
||||
{tab && tab.icon && (
|
||||
<Icon
|
||||
name={tab.icon}
|
||||
className="h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0"
|
||||
className="text-subtle h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0"
|
||||
/>
|
||||
)}
|
||||
{!tab.icon && tab?.avatar && (
|
||||
<img
|
||||
className="h-4 w-4 rounded-full ltr:mr-3 rtl:ml-3"
|
||||
src={tab?.avatar}
|
||||
alt="User Avatar"
|
||||
alt="Organization Logo"
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
title={tab.name}
|
||||
as="p"
|
||||
className="truncate text-sm font-medium leading-5"
|
||||
className="text-subtle truncate text-sm font-medium leading-5"
|
||||
loadingClassName="ms-3">
|
||||
{t(tab.name)}
|
||||
</Skeleton>
|
||||
</div>
|
||||
</div>
|
||||
<div className="my-3 space-y-0.5">
|
||||
<div className="my-3 space-y-px">
|
||||
{tab.children?.map((child, index) => (
|
||||
<VerticalTabItem
|
||||
key={child.href}
|
||||
name={t(child.name)}
|
||||
isExternalLink={child.isExternalLink}
|
||||
href={child.href || "/"}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
className={`my-0.5 me-5 h-7 ${
|
||||
textClassNames="text-emphasis font-medium text-sm"
|
||||
className={`me-5 h-7 !px-2 ${
|
||||
tab.children && index === tab.children?.length - 1 && "!mb-3"
|
||||
}`}
|
||||
disableChevron
|
||||
@@ -317,144 +485,25 @@ const SettingsSidebarContainer = ({
|
||||
|
||||
{tab.name === "teams" && (
|
||||
<React.Fragment key={tab.href}>
|
||||
<div className={`${!tab.children?.length ? "mb-3" : ""}`}>
|
||||
<div data-testid="tab-teams" className={`${!tab.children?.length ? "mb-3" : ""}`}>
|
||||
<Link href={tab.href}>
|
||||
<div className="hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis group-hover:text-default text-default group flex h-9 w-full flex-row items-center rounded-md px-2 py-[10px] text-sm font-medium leading-none transition">
|
||||
<div className="hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis group-hover:text-default text-default group flex h-9 w-full flex-row items-center rounded-md px-2 py-[10px] text-sm font-medium leading-none transition">
|
||||
{tab && tab.icon && (
|
||||
<Icon
|
||||
name={tab.icon}
|
||||
className="h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0"
|
||||
className="text-subtle h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0"
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
title={tab.name}
|
||||
as="p"
|
||||
className="truncate text-sm font-medium leading-5"
|
||||
className="text-subtle truncate text-sm font-medium leading-5"
|
||||
loadingClassName="ms-3">
|
||||
{t(isOrgAdminOrOwner ? "my_teams" : tab.name)}
|
||||
</Skeleton>
|
||||
</div>
|
||||
</Link>
|
||||
{teams &&
|
||||
teamMenuState &&
|
||||
teams.map((team, index: number) => {
|
||||
if (!teamMenuState[index]) {
|
||||
return null;
|
||||
}
|
||||
if (teamMenuState.some((teamState) => teamState.teamId === team.id))
|
||||
return (
|
||||
<Collapsible
|
||||
className="cursor-pointer"
|
||||
key={team.id}
|
||||
open={teamMenuState[index].teamMenuOpen}
|
||||
onOpenChange={() =>
|
||||
setTeamMenuState([
|
||||
...teamMenuState,
|
||||
(teamMenuState[index] = {
|
||||
...teamMenuState[index],
|
||||
teamMenuOpen: !teamMenuState[index].teamMenuOpen,
|
||||
}),
|
||||
])
|
||||
}>
|
||||
<CollapsibleTrigger asChild>
|
||||
<div
|
||||
className="hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis text-default flex h-9 w-full flex-row items-center rounded-md px-3 py-[10px] text-left text-sm font-medium leading-none transition"
|
||||
onClick={() =>
|
||||
setTeamMenuState([
|
||||
...teamMenuState,
|
||||
(teamMenuState[index] = {
|
||||
...teamMenuState[index],
|
||||
teamMenuOpen: !teamMenuState[index].teamMenuOpen,
|
||||
}),
|
||||
])
|
||||
}>
|
||||
<div className="me-3">
|
||||
{teamMenuState[index].teamMenuOpen ? (
|
||||
<Icon name="chevron-down" className="h-4 w-4" />
|
||||
) : (
|
||||
<Icon name="chevron-right" className="h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
{!team.parentId && (
|
||||
<img
|
||||
src={getPlaceholderAvatar(team.logoUrl, team.name)}
|
||||
className="h-[16px] w-[16px] self-start rounded-full stroke-[2px] ltr:mr-2 rtl:ml-2 md:mt-0"
|
||||
alt={team.name || "Team logo"}
|
||||
/>
|
||||
)}
|
||||
<p className="w-1/2 truncate leading-normal">{team.name}</p>
|
||||
{!team.accepted && (
|
||||
<Badge className="ms-3" variant="orange">
|
||||
Inv.
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="space-y-0.5">
|
||||
{team.accepted && (
|
||||
<VerticalTabItem
|
||||
name={t("profile")}
|
||||
href={`/settings/teams/${team.id}/profile`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
)}
|
||||
<VerticalTabItem
|
||||
name={t("members")}
|
||||
href={`/settings/teams/${team.id}/members`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
<VerticalTabItem
|
||||
name={t("event_types_page_title")}
|
||||
href={`/event-types?teamIds=${team.id}`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
{(team.role === MembershipRole.OWNER ||
|
||||
team.role === MembershipRole.ADMIN ||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore this exists wtf?
|
||||
(team.isOrgAdmin && team.isOrgAdmin)) && (
|
||||
<>
|
||||
{/* TODO */}
|
||||
{/* <VerticalTabItem
|
||||
name={t("general")}
|
||||
href={`${WEBAPP_URL}/settings/my-account/appearance`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/> */}
|
||||
<VerticalTabItem
|
||||
name={t("appearance")}
|
||||
href={`/settings/teams/${team.id}/appearance`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
{/* Hide if there is a parent ID */}
|
||||
{!team.parentId ? (
|
||||
<>
|
||||
<VerticalTabItem
|
||||
name={t("billing")}
|
||||
href={`/settings/teams/${team.id}/billing`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
{HOSTED_CAL_FEATURES && (
|
||||
<VerticalTabItem
|
||||
name={t("saml_config")}
|
||||
href={`/settings/teams/${team.id}/sso`}
|
||||
textClassNames="px-3 text-emphasis font-medium text-sm"
|
||||
disableChevron
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
);
|
||||
})}
|
||||
<TeamListCollapsible />
|
||||
{(!currentOrg || (currentOrg && currentOrg?.user?.role !== "MEMBER")) && (
|
||||
<VerticalTabItem
|
||||
name={t("add_a_team")}
|
||||
@@ -476,13 +525,13 @@ const SettingsSidebarContainer = ({
|
||||
{tab && tab.icon && (
|
||||
<Icon
|
||||
name={tab.icon}
|
||||
className="h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0"
|
||||
className="text-subtle h-[16px] w-[16px] stroke-[2px] ltr:mr-3 rtl:ml-3 md:mt-0"
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
title={t("org_admin_other_teams")}
|
||||
as="p"
|
||||
className="truncate text-sm font-medium leading-5"
|
||||
className="text-subtle truncate text-sm font-medium leading-5"
|
||||
loadingClassName="ms-3">
|
||||
{t("org_admin_other_teams")}
|
||||
</Skeleton>
|
||||
@@ -511,7 +560,7 @@ const SettingsSidebarContainer = ({
|
||||
}>
|
||||
<CollapsibleTrigger asChild>
|
||||
<div
|
||||
className="hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis text-default flex h-9 w-full flex-row items-center rounded-md px-3 py-[10px] text-left text-sm font-medium leading-none transition"
|
||||
className="hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis text-default flex h-9 w-full flex-row items-center rounded-md px-2 py-[10px] text-left text-sm font-medium leading-none transition"
|
||||
onClick={() =>
|
||||
setOtherTeamMenuState([
|
||||
...otherTeamMenuState,
|
||||
@@ -582,8 +631,8 @@ const MobileSettingsContainer = (props: { onSideContainerOpen?: () => void }) =>
|
||||
|
||||
return (
|
||||
<>
|
||||
<nav className="bg-muted border-muted sticky top-0 z-20 flex w-full items-center justify-between border-b py-2 sm:relative lg:hidden">
|
||||
<div className="flex items-center space-x-3 ">
|
||||
<nav className="bg-muted border-muted sticky top-0 z-20 flex w-full items-center justify-between border-b px-2 py-2 sm:relative lg:hidden">
|
||||
<div className="flex items-center space-x-3">
|
||||
<Button StartIcon="menu" color="minimal" variant="icon" onClick={props.onSideContainerOpen}>
|
||||
<span className="sr-only">{t("show_navigation")}</span>
|
||||
</Button>
|
||||
@@ -603,10 +652,11 @@ const MobileSettingsContainer = (props: { onSideContainerOpen?: () => void }) =>
|
||||
export default function SettingsLayout({
|
||||
children,
|
||||
...rest
|
||||
}: { children: React.ReactNode } & ComponentProps<typeof Shell>) {
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
} & ComponentProps<typeof Shell>) {
|
||||
const pathname = usePathname();
|
||||
const state = useState(false);
|
||||
const { t } = useLocale();
|
||||
const [sideContainerOpen, setSideContainerOpen] = state;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -646,11 +696,8 @@ export default function SettingsLayout({
|
||||
<MobileSettingsContainer onSideContainerOpen={() => setSideContainerOpen(!sideContainerOpen)} />
|
||||
}>
|
||||
<div className="flex flex-1 [&>*]:flex-1">
|
||||
<div className="mx-auto max-w-full justify-center lg:max-w-4xl">
|
||||
<ShellHeader />
|
||||
<ErrorBoundary>
|
||||
<Suspense fallback={<Icon name="loader" />}>{children}</Suspense>
|
||||
</ErrorBoundary>
|
||||
<div className="mx-auto max-w-full justify-center lg:max-w-3xl">
|
||||
<ErrorBoundary>{children}</ErrorBoundary>
|
||||
</div>
|
||||
</div>
|
||||
</Shell>
|
||||
@@ -688,41 +735,3 @@ type SidebarContainerElementProps = {
|
||||
};
|
||||
|
||||
export const getLayout = (page: React.ReactElement) => <SettingsLayout>{page}</SettingsLayout>;
|
||||
|
||||
export function ShellHeader() {
|
||||
const { meta } = useMeta();
|
||||
const { t, isLocaleReady } = useLocale();
|
||||
return (
|
||||
<>
|
||||
<header
|
||||
className={classNames(
|
||||
"border-subtle mx-auto block justify-between sm:flex",
|
||||
meta.borderInShellHeader && "rounded-t-lg border px-4 py-6 sm:px-6",
|
||||
meta.borderInShellHeader === undefined && "mb-8 border-b pb-8"
|
||||
)}>
|
||||
<div className="flex w-full items-center">
|
||||
{meta.backButton && (
|
||||
<a href="javascript:history.back()">
|
||||
<Icon name="arrow-left" className="mr-7" />
|
||||
</a>
|
||||
)}
|
||||
<div>
|
||||
{meta.title && isLocaleReady ? (
|
||||
<h1 className="font-cal text-emphasis mb-1 text-xl font-semibold leading-5 tracking-wide">
|
||||
{t(meta.title)}
|
||||
</h1>
|
||||
) : (
|
||||
<div className="bg-emphasis mb-1 h-5 w-24 animate-pulse rounded-lg" />
|
||||
)}
|
||||
{meta.description && isLocaleReady ? (
|
||||
<p className="text-default text-sm ltr:mr-4 rtl:ml-4">{t(meta.description)}</p>
|
||||
) : (
|
||||
<div className="bg-emphasis h-5 w-32 animate-pulse rounded-lg" />
|
||||
)}
|
||||
</div>
|
||||
<div className="ms-auto flex-shrink-0">{meta.CTA}</div>
|
||||
</div>
|
||||
</header>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@radix-ui/react-collapsible";
|
||||
import { useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Button, Icon } from "@calcom/ui";
|
||||
|
||||
import { CreateOrEditOutOfOfficeEntryModal } from "./CreateOrEditOutOfOfficeModal";
|
||||
|
||||
const CreateNewOutOfOfficeEntry = () => {
|
||||
const { t } = useLocale();
|
||||
|
||||
const params = useSearchParams();
|
||||
const openModalOnStart = !!params?.get("om");
|
||||
useEffect(() => {
|
||||
if (openModalOnStart) {
|
||||
setOpenModal(true);
|
||||
}
|
||||
}, [openModalOnStart]);
|
||||
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
color="primary"
|
||||
className="flex w-20 items-center justify-between px-4"
|
||||
onClick={() => setOpenModal(true)}
|
||||
data-testid="add_entry_ooo">
|
||||
<Icon name="plus" size={16} /> {t("add")}
|
||||
</Button>
|
||||
{openModal && (
|
||||
<CreateOrEditOutOfOfficeEntryModal
|
||||
openModal={openModal}
|
||||
closeModal={() => {
|
||||
setOpenModal(false);
|
||||
}}
|
||||
currentlyEditingOutOfOfficeEntry={null}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateNewOutOfOfficeEntry;
|
||||
+9
-1
@@ -19,7 +19,15 @@ import {
|
||||
TextArea,
|
||||
UpgradeTeamsBadge,
|
||||
} from "@calcom/ui";
|
||||
import type { BookingRedirectForm } from "@calcom/web/pages/settings/my-account/out-of-office";
|
||||
|
||||
export type BookingRedirectForm = {
|
||||
dateRange: { startDate: Date; endDate: Date };
|
||||
offset: number;
|
||||
toTeamUserId: number | null;
|
||||
reasonId: number;
|
||||
notes?: string;
|
||||
uuid?: string | null;
|
||||
};
|
||||
|
||||
export const CreateOrEditOutOfOfficeEntryModal = ({
|
||||
openModal,
|
||||
+27
-6
@@ -1,4 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { Trans } from "next-i18next";
|
||||
import { useState } from "react";
|
||||
import { useFormState } from "react-hook-form";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -16,13 +19,11 @@ import {
|
||||
TableRow,
|
||||
Tooltip,
|
||||
} from "@calcom/ui";
|
||||
import type { BookingRedirectForm } from "@calcom/web/pages/settings/my-account/out-of-office";
|
||||
|
||||
export const OutOfOfficeEntriesList = ({
|
||||
editOutOfOfficeEntry,
|
||||
}: {
|
||||
editOutOfOfficeEntry: (entry: BookingRedirectForm) => void;
|
||||
}) => {
|
||||
import { CreateOrEditOutOfOfficeEntryModal } from "./CreateOrEditOutOfOfficeModal";
|
||||
import type { BookingRedirectForm } from "./CreateOrEditOutOfOfficeModal";
|
||||
|
||||
export const OutOfOfficeEntriesList = () => {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
const { data, isPending } = trpc.viewer.outOfOfficeEntriesList.useQuery();
|
||||
@@ -36,6 +37,16 @@ export const OutOfOfficeEntriesList = ({
|
||||
showToast(`An error ocurred`, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const [currentlyEditingOutOfOfficeEntry, setCurrentlyEditingOutOfOfficeEntry] =
|
||||
useState<BookingRedirectForm | null>(null);
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
|
||||
const editOutOfOfficeEntry = (entry: BookingRedirectForm) => {
|
||||
setCurrentlyEditingOutOfOfficeEntry(entry);
|
||||
setOpenModal(true);
|
||||
};
|
||||
|
||||
if (data === null || data?.length === 0 || (data === undefined && !isPending))
|
||||
return (
|
||||
<EmptyScreen
|
||||
@@ -168,6 +179,16 @@ export const OutOfOfficeEntriesList = ({
|
||||
)}
|
||||
</TableBody>
|
||||
</TableNew>
|
||||
{openModal && (
|
||||
<CreateOrEditOutOfOfficeEntryModal
|
||||
openModal={openModal}
|
||||
closeModal={() => {
|
||||
setOpenModal(false);
|
||||
setCurrentlyEditingOutOfOfficeEntry(null);
|
||||
}}
|
||||
currentlyEditingOutOfOfficeEntry={currentlyEditingOutOfOfficeEntry}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { CreateButtonWithTeamsList } from "@calcom/ui";
|
||||
|
||||
export const CreateNewWebhookButton = ({ isAdmin }: { isAdmin: boolean }) => {
|
||||
const router = useRouter();
|
||||
const { t } = useLocale();
|
||||
const createFunction = (teamId?: number, platform?: boolean) => {
|
||||
if (platform) {
|
||||
router.push(`webhooks/new${platform ? `?platform=${platform}` : ""}`);
|
||||
} else {
|
||||
router.push(`webhooks/new${teamId ? `?teamId=${teamId}` : ""}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<CreateButtonWithTeamsList
|
||||
color="secondary"
|
||||
subtitle={t("create_for").toUpperCase()}
|
||||
isAdmin={isAdmin}
|
||||
createFunction={createFunction}
|
||||
data-testid="new_webhook"
|
||||
includeOrg={true}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateNewWebhookButton;
|
||||
@@ -3,3 +3,4 @@ export { default as WebhookListItem } from "./WebhookListItem";
|
||||
export { default as WebhookListItemSkeleton } from "./WebhookListItemSkeleton";
|
||||
export { default as WebhookListSkeleton } from "./WebhookListSkeleton";
|
||||
export { default as WebhookTestDisclosure } from "./WebhookTestDisclosure";
|
||||
export { default as CreateNewWebhookButton } from "./CreateNewWebhookButton";
|
||||
@@ -0,0 +1,9 @@
|
||||
const getNewWebhookUrl = (teamId?: number, platform?: boolean) => {
|
||||
if (platform) {
|
||||
return `webhooks/new${platform ? `?platform=${platform}` : ""}`;
|
||||
} else {
|
||||
return `webhooks/new${teamId ? `?teamId=${teamId}` : ""}`;
|
||||
}
|
||||
};
|
||||
|
||||
export default getNewWebhookUrl;
|
||||
@@ -1,27 +1,29 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Meta, showToast, SkeletonContainer } from "@calcom/ui";
|
||||
import { showToast, SkeletonContainer } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../settings/layouts/SettingsLayout";
|
||||
import type { WebhookFormSubmitData } from "../components/WebhookForm";
|
||||
import WebhookForm from "../components/WebhookForm";
|
||||
import { subscriberUrlReserved } from "../lib/subscriberUrlReserved";
|
||||
|
||||
const EditWebhook = () => {
|
||||
const searchParams = useCompatSearchParams();
|
||||
const id = searchParams?.get("id");
|
||||
|
||||
if (!id) return <SkeletonContainer />;
|
||||
|
||||
// I think we should do SSR for this page
|
||||
return <Component webhookId={id} />;
|
||||
type WebhookProps = {
|
||||
id: string;
|
||||
userId: number | null;
|
||||
teamId: number | null;
|
||||
subscriberUrl: string;
|
||||
payloadTemplate: string | null;
|
||||
active: boolean;
|
||||
eventTriggers: WebhookTriggerEvents[];
|
||||
secret: string | null;
|
||||
platform: boolean;
|
||||
};
|
||||
|
||||
function Component({ webhookId }: { webhookId: string }) {
|
||||
export function EditWebhookView({ webhook }: { webhook?: WebhookProps }) {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
const router = useRouter();
|
||||
@@ -29,24 +31,18 @@ function Component({ webhookId }: { webhookId: string }) {
|
||||
{ variant: "other", onlyInstalled: true },
|
||||
{
|
||||
suspense: true,
|
||||
enabled: !!webhookId,
|
||||
}
|
||||
);
|
||||
const { data: webhook } = trpc.viewer.webhook.get.useQuery(
|
||||
{ webhookId },
|
||||
{
|
||||
suspense: true,
|
||||
enabled: !!webhookId,
|
||||
enabled: !!webhook,
|
||||
}
|
||||
);
|
||||
|
||||
const { data: webhooks } = trpc.viewer.webhook.list.useQuery(undefined, {
|
||||
suspense: true,
|
||||
enabled: !!webhookId,
|
||||
enabled: !!webhook,
|
||||
});
|
||||
const editWebhookMutation = trpc.viewer.webhook.edit.useMutation({
|
||||
async onSuccess() {
|
||||
await utils.viewer.webhook.list.invalidate();
|
||||
await utils.viewer.webhook.get.invalidate({ webhookId });
|
||||
await utils.viewer.webhook.get.invalidate({ webhookId: webhook?.id });
|
||||
showToast(t("webhook_updated_successfully"), "success");
|
||||
router.back();
|
||||
},
|
||||
@@ -59,12 +55,6 @@ function Component({ webhookId }: { webhookId: string }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Meta
|
||||
title={t("edit_webhook")}
|
||||
description={t("add_webhook_description", { appName: APP_NAME })}
|
||||
borderInShellHeader={true}
|
||||
backButton
|
||||
/>
|
||||
<WebhookForm
|
||||
noRoutingFormTriggers={false}
|
||||
webhook={webhook}
|
||||
@@ -106,6 +96,4 @@ function Component({ webhookId }: { webhookId: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
EditWebhook.getLayout = getLayout;
|
||||
|
||||
export default EditWebhook;
|
||||
export default EditWebhookView;
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
@@ -7,7 +9,6 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Meta, showToast, SkeletonContainer, SkeletonText } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../settings/layouts/SettingsLayout";
|
||||
import type { WebhookFormSubmitData } from "../components/WebhookForm";
|
||||
import WebhookForm from "../components/WebhookForm";
|
||||
import { subscriberUrlReserved } from "../lib/subscriberUrlReserved";
|
||||
@@ -23,7 +24,7 @@ const SkeletonLoader = ({ title, description }: { title: string; description: st
|
||||
</SkeletonContainer>
|
||||
);
|
||||
};
|
||||
const NewWebhookView = () => {
|
||||
export const NewWebhookView = () => {
|
||||
const searchParams = useCompatSearchParams();
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
@@ -95,22 +96,12 @@ const NewWebhookView = () => {
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Meta
|
||||
title={t("add_webhook")}
|
||||
description={t("add_webhook_description", { appName: APP_NAME })}
|
||||
backButton
|
||||
borderInShellHeader={true}
|
||||
/>
|
||||
<WebhookForm
|
||||
noRoutingFormTriggers={false}
|
||||
onSubmit={onCreateWebhook}
|
||||
apps={installedApps?.items.map((app) => app.slug)}
|
||||
/>
|
||||
</>
|
||||
<WebhookForm
|
||||
noRoutingFormTriggers={false}
|
||||
onSubmit={onCreateWebhook}
|
||||
apps={installedApps?.items.map((app) => app.slug)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
NewWebhookView.getLayout = getLayout;
|
||||
|
||||
export default NewWebhookView;
|
||||
@@ -1,6 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl";
|
||||
@@ -8,17 +11,9 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { WebhooksByViewer } from "@calcom/trpc/server/routers/viewer/webhook/getByViewer.handler";
|
||||
import {
|
||||
Avatar,
|
||||
CreateButtonWithTeamsList,
|
||||
EmptyScreen,
|
||||
Meta,
|
||||
SkeletonContainer,
|
||||
SkeletonText,
|
||||
} from "@calcom/ui";
|
||||
import { Avatar, EmptyScreen, Meta, SkeletonContainer, SkeletonText } from "@calcom/ui";
|
||||
|
||||
import { getLayout } from "../../settings/layouts/SettingsLayout";
|
||||
import { WebhookListItem } from "../components";
|
||||
import { WebhookListItem, CreateNewWebhookButton } from "../components";
|
||||
|
||||
const SkeletonLoader = ({
|
||||
title,
|
||||
@@ -42,7 +37,6 @@ const SkeletonLoader = ({
|
||||
|
||||
const WebhooksView = () => {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const session = useSession();
|
||||
const isAdmin = session.data?.user.role === UserPermissionRole.ADMIN;
|
||||
|
||||
@@ -50,13 +44,6 @@ const WebhooksView = () => {
|
||||
enabled: session.status === "authenticated",
|
||||
});
|
||||
|
||||
const createFunction = (teamId?: number, platform?: boolean) => {
|
||||
if (platform) {
|
||||
router.push(`webhooks/new${platform ? `?platform=${platform}` : ""}`);
|
||||
} else {
|
||||
router.push(`webhooks/new${teamId ? `?teamId=${teamId}` : ""}`);
|
||||
}
|
||||
};
|
||||
if (isPending || !data) {
|
||||
return (
|
||||
<SkeletonLoader
|
||||
@@ -69,28 +56,43 @@ const WebhooksView = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Meta
|
||||
<div>
|
||||
<WebhooksList webhooksByViewer={data} isAdmin={isAdmin} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const WebhooksViewAppDir = () => {
|
||||
const { t } = useLocale();
|
||||
const session = useSession();
|
||||
const isAdmin = session.data?.user.role === UserPermissionRole.ADMIN;
|
||||
|
||||
const { data, isPending } = trpc.viewer.webhook.getByViewer.useQuery(undefined, {
|
||||
enabled: session.status === "authenticated",
|
||||
});
|
||||
|
||||
if (isPending || !data) {
|
||||
return (
|
||||
<SkeletonLoader
|
||||
title={t("webhooks")}
|
||||
description={t("add_webhook_description", { appName: APP_NAME })}
|
||||
CTA={
|
||||
data && data.webhookGroups.length > 0 ? (
|
||||
<CreateButtonWithTeamsList
|
||||
color="secondary"
|
||||
subtitle={t("create_for").toUpperCase()}
|
||||
isAdmin={isAdmin}
|
||||
createFunction={createFunction}
|
||||
data-testid="new_webhook"
|
||||
includeOrg={true}
|
||||
/>
|
||||
) : (
|
||||
<></>
|
||||
)
|
||||
}
|
||||
borderInShellHeader={(data && data.profiles.length === 1) || !data?.webhookGroups?.length}
|
||||
borderInShellHeader={true}
|
||||
/>
|
||||
<div>
|
||||
<WebhooksList webhooksByViewer={data} isAdmin={isAdmin} createFunction={createFunction} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsHeader
|
||||
title={t("webhooks")}
|
||||
description={t("add_webhook_description", { appName: APP_NAME })}
|
||||
CTA={data && data.webhookGroups.length > 0 ? <CreateNewWebhookButton isAdmin={isAdmin} /> : <></>}
|
||||
borderInShellHeader={(data && data.profiles.length === 1) || !data?.webhookGroups?.length}>
|
||||
<div>
|
||||
<WebhooksList webhooksByViewer={data} isAdmin={isAdmin} />
|
||||
</div>
|
||||
</SettingsHeader>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -98,15 +100,12 @@ const WebhooksView = () => {
|
||||
const WebhooksList = ({
|
||||
webhooksByViewer,
|
||||
isAdmin,
|
||||
createFunction,
|
||||
}: {
|
||||
webhooksByViewer: WebhooksByViewer;
|
||||
isAdmin: boolean;
|
||||
createFunction: (teamId?: number, platform?: boolean) => void;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
|
||||
const { profiles, webhookGroups } = webhooksByViewer;
|
||||
const bookerUrl = useBookerUrl();
|
||||
|
||||
@@ -146,7 +145,7 @@ const WebhooksList = ({
|
||||
readOnly={group.metadata?.readOnly ?? false}
|
||||
lastItem={group.webhooks.length === index + 1}
|
||||
onEditWebhook={() =>
|
||||
router.push(`${WEBAPP_URL}/settings/developer/webhooks/${webhook.id} `)
|
||||
router.push(`${WEBAPP_URL}/settings/developer/webhooks/${webhook.id}`)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
@@ -162,15 +161,8 @@ const WebhooksList = ({
|
||||
headline={t("create_your_first_webhook")}
|
||||
description={t("create_your_first_webhook_description", { appName: APP_NAME })}
|
||||
className="rounded-b-lg rounded-t-none border-t-0"
|
||||
buttonRaw={
|
||||
<CreateButtonWithTeamsList
|
||||
subtitle={t("create_for").toUpperCase()}
|
||||
isAdmin={isAdmin}
|
||||
createFunction={createFunction}
|
||||
data-testid="new_webhook"
|
||||
includeOrg={true}
|
||||
/>
|
||||
}
|
||||
buttonRaw={<CreateNewWebhookButton isAdmin={isAdmin} />}
|
||||
border={true}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
@@ -179,6 +171,4 @@ const WebhooksList = ({
|
||||
);
|
||||
};
|
||||
|
||||
WebhooksView.getLayout = getLayout;
|
||||
|
||||
export default WebhooksView;
|
||||
@@ -4,6 +4,7 @@ import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { createAProfileForAnExistingUser } from "../../createAProfileForAnExistingUser";
|
||||
import { getParsedTeam } from "./teamUtils";
|
||||
@@ -192,4 +193,50 @@ export class OrganizationRepository {
|
||||
}
|
||||
return getParsedTeam(org);
|
||||
}
|
||||
|
||||
static async adminFindById({ id }: { id: number }) {
|
||||
const org = await prisma.team.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
metadata: true,
|
||||
isOrganization: true,
|
||||
members: {
|
||||
where: {
|
||||
role: "OWNER",
|
||||
},
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
organizationSettings: {
|
||||
select: {
|
||||
isOrganizationConfigured: true,
|
||||
isOrganizationVerified: true,
|
||||
orgAutoAcceptEmail: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!org) {
|
||||
throw new Error("Organization not found");
|
||||
}
|
||||
|
||||
const parsedMetadata = teamMetadataSchema.parse(org.metadata);
|
||||
if (!org?.isOrganization) {
|
||||
throw new Error("Organization not found");
|
||||
}
|
||||
return { ...org, metadata: parsedMetadata };
|
||||
}
|
||||
}
|
||||
@@ -553,4 +553,12 @@ export class UserRepository {
|
||||
}
|
||||
return teamIds;
|
||||
}
|
||||
|
||||
static async adminFindById(userId: number) {
|
||||
return await prisma.user.findUniqueOrThrow({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import { compareMembership } from "@calcom/lib/event-types/getEventTypesByViewer";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Webhook } from "@calcom/prisma/client";
|
||||
import type { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
type WebhookGroup = {
|
||||
teamId?: number | null;
|
||||
profile: {
|
||||
slug: string | null;
|
||||
name: string | null;
|
||||
image?: string;
|
||||
};
|
||||
metadata?: {
|
||||
readOnly: boolean;
|
||||
};
|
||||
webhooks: Webhook[];
|
||||
};
|
||||
|
||||
const filterWebhooks = (webhook: Webhook) => {
|
||||
const appIds = [
|
||||
"zapier",
|
||||
// Add more if needed
|
||||
];
|
||||
|
||||
return !appIds.some((appId: string) => webhook.appId == appId);
|
||||
};
|
||||
|
||||
export class WebhookRepository {
|
||||
static async getAllWebhooksByUserId({
|
||||
userId,
|
||||
organizationId,
|
||||
userRole,
|
||||
}: {
|
||||
userId: number;
|
||||
organizationId?: number | null;
|
||||
userRole?: UserPermissionRole;
|
||||
}) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
select: {
|
||||
username: true,
|
||||
avatarUrl: true,
|
||||
name: true,
|
||||
webhooks: true,
|
||||
teams: {
|
||||
where: {
|
||||
accepted: true,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
isOrganization: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
parentId: true,
|
||||
metadata: true,
|
||||
members: {
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
},
|
||||
webhooks: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
let userWebhooks = user.webhooks;
|
||||
userWebhooks = userWebhooks.filter(filterWebhooks);
|
||||
let webhookGroups: WebhookGroup[] = [];
|
||||
const bookerUrl = await getBookerBaseUrl(organizationId ?? null);
|
||||
|
||||
const image = user?.username ? `${bookerUrl}/${user.username}/avatar.png` : undefined;
|
||||
webhookGroups.push({
|
||||
teamId: null,
|
||||
profile: {
|
||||
slug: user.username,
|
||||
name: user.name,
|
||||
image,
|
||||
},
|
||||
webhooks: userWebhooks,
|
||||
metadata: {
|
||||
readOnly: false,
|
||||
},
|
||||
});
|
||||
|
||||
const teamMemberships = user.teams.map((membership) => ({
|
||||
teamId: membership.team.id,
|
||||
membershipRole: membership.role,
|
||||
}));
|
||||
|
||||
const teamWebhookGroups: WebhookGroup[] = user.teams.map((membership) => {
|
||||
const orgMembership = teamMemberships.find(
|
||||
(teamM) => teamM.teamId === membership.team.parentId
|
||||
)?.membershipRole;
|
||||
return {
|
||||
teamId: membership.team.id,
|
||||
profile: {
|
||||
name: membership.team.name,
|
||||
slug: membership.team.slug
|
||||
? !membership.team.parentId
|
||||
? `/team`
|
||||
: `${membership.team.slug}`
|
||||
: null,
|
||||
image: `${bookerUrl}/team/${membership.team.slug}/avatar.png`,
|
||||
},
|
||||
metadata: {
|
||||
readOnly:
|
||||
membership.role ===
|
||||
(membership.team.parentId
|
||||
? orgMembership && compareMembership(orgMembership, membership.role)
|
||||
? orgMembership
|
||||
: MembershipRole.MEMBER
|
||||
: MembershipRole.MEMBER),
|
||||
},
|
||||
webhooks: membership.team.webhooks.filter(filterWebhooks),
|
||||
};
|
||||
});
|
||||
|
||||
webhookGroups = webhookGroups.concat(teamWebhookGroups);
|
||||
|
||||
if (userRole === "ADMIN") {
|
||||
const platformWebhooks = await prisma.webhook.findMany({
|
||||
where: { platform: true },
|
||||
});
|
||||
webhookGroups.push({
|
||||
teamId: null,
|
||||
profile: {
|
||||
slug: "Platform",
|
||||
name: "Platform",
|
||||
image,
|
||||
},
|
||||
webhooks: platformWebhooks,
|
||||
metadata: {
|
||||
readOnly: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
webhookGroups: webhookGroups.filter((groupBy) => !!groupBy.webhooks?.length),
|
||||
profiles: webhookGroups.map((group) => ({
|
||||
teamId: group.teamId,
|
||||
...group.profile,
|
||||
...group.metadata,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
static async findByWebhookId(webhookId?: string) {
|
||||
return await prisma.webhook.findUniqueOrThrow({
|
||||
where: {
|
||||
id: webhookId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
subscriberUrl: true,
|
||||
payloadTemplate: true,
|
||||
active: true,
|
||||
eventTriggers: true,
|
||||
secret: true,
|
||||
teamId: true,
|
||||
userId: true,
|
||||
platform: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
|
||||
import { SingleValueComponent } from "@calcom/features/calendars/DestinationCalendarSelector";
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
import type { TAdminGet } from "./adminGet.schema";
|
||||
@@ -14,54 +11,7 @@ type AdminGetOptions = {
|
||||
};
|
||||
|
||||
export const adminGetHandler = async ({ input }: AdminGetOptions) => {
|
||||
const org = await prisma.team.findUnique({
|
||||
where: {
|
||||
id: input.id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
metadata: true,
|
||||
isOrganization: true,
|
||||
members: {
|
||||
where: {
|
||||
role: "OWNER",
|
||||
},
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
organizationSettings: {
|
||||
select: {
|
||||
isOrganizationConfigured: true,
|
||||
isOrganizationVerified: true,
|
||||
orgAutoAcceptEmail: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!org) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Organization not found",
|
||||
});
|
||||
}
|
||||
const parsedMetadata = teamMetadataSchema.parse(org.metadata);
|
||||
if (!org?.isOrganization) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Organization not found",
|
||||
});
|
||||
}
|
||||
return { ...org, metadata: parsedMetadata };
|
||||
return await OrganizationRepository.adminFindById({ id: input.id });
|
||||
};
|
||||
|
||||
export default adminGetHandler;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { WebhookRepository } from "@calcom/lib/server/repository/webhook";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import type { TGetInputSchema } from "./get.schema";
|
||||
@@ -11,20 +11,5 @@ type GetOptions = {
|
||||
};
|
||||
|
||||
export const getHandler = async ({ ctx: _ctx, input }: GetOptions) => {
|
||||
return await prisma.webhook.findUniqueOrThrow({
|
||||
where: {
|
||||
id: input.webhookId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
subscriberUrl: true,
|
||||
payloadTemplate: true,
|
||||
active: true,
|
||||
eventTriggers: true,
|
||||
secret: true,
|
||||
teamId: true,
|
||||
userId: true,
|
||||
platform: true,
|
||||
},
|
||||
});
|
||||
return await WebhookRepository.findByWebhookId(input.webhookId);
|
||||
};
|
||||
@@ -1,12 +1,7 @@
|
||||
import { compareMembership } from "@calcom/lib/event-types/getEventTypesByViewer";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { WebhookRepository } from "@calcom/lib/server/repository/webhook";
|
||||
import type { Webhook } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
type GetByViewerOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
@@ -37,130 +32,10 @@ export type WebhooksByViewer = {
|
||||
}[];
|
||||
};
|
||||
|
||||
const filterWebhooks = (webhook: Webhook) => {
|
||||
const appIds = [
|
||||
"zapier",
|
||||
// Add more if needed
|
||||
];
|
||||
|
||||
return !appIds.some((appId: string) => webhook.appId == appId);
|
||||
};
|
||||
|
||||
export const getByViewerHandler = async ({ ctx }: GetByViewerOptions) => {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: ctx.user.id,
|
||||
},
|
||||
select: {
|
||||
username: true,
|
||||
avatarUrl: true,
|
||||
name: true,
|
||||
webhooks: true,
|
||||
teams: {
|
||||
where: {
|
||||
accepted: true,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
isOrganization: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
parentId: true,
|
||||
metadata: true,
|
||||
members: {
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
},
|
||||
webhooks: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
return await WebhookRepository.getAllWebhooksByUserId({
|
||||
userId: ctx.user.id,
|
||||
organizationId: ctx.user.profile?.organizationId,
|
||||
userRole: ctx.user.role,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR" });
|
||||
}
|
||||
|
||||
let userWebhooks = user.webhooks;
|
||||
userWebhooks = userWebhooks.filter(filterWebhooks);
|
||||
let webhookGroups: WebhookGroup[] = [];
|
||||
const bookerUrl = await getBookerBaseUrl(ctx.user.profile?.organizationId ?? null);
|
||||
|
||||
const image = user?.username ? `${bookerUrl}/${user.username}/avatar.png` : undefined;
|
||||
webhookGroups.push({
|
||||
teamId: null,
|
||||
profile: {
|
||||
slug: user.username,
|
||||
name: user.name,
|
||||
image,
|
||||
},
|
||||
webhooks: userWebhooks,
|
||||
metadata: {
|
||||
readOnly: false,
|
||||
},
|
||||
});
|
||||
|
||||
const teamMemberships = user.teams.map((membership) => ({
|
||||
teamId: membership.team.id,
|
||||
membershipRole: membership.role,
|
||||
}));
|
||||
|
||||
const teamWebhookGroups: WebhookGroup[] = user.teams.map((membership) => {
|
||||
const orgMembership = teamMemberships.find(
|
||||
(teamM) => teamM.teamId === membership.team.parentId
|
||||
)?.membershipRole;
|
||||
return {
|
||||
teamId: membership.team.id,
|
||||
profile: {
|
||||
name: membership.team.name,
|
||||
slug: membership.team.slug ? (!membership.team.parentId ? `/team` : `${membership.team.slug}`) : null,
|
||||
image: `${bookerUrl}/team/${membership.team.slug}/avatar.png`,
|
||||
},
|
||||
metadata: {
|
||||
readOnly:
|
||||
membership.role ===
|
||||
(membership.team.parentId
|
||||
? orgMembership && compareMembership(orgMembership, membership.role)
|
||||
? orgMembership
|
||||
: MembershipRole.MEMBER
|
||||
: MembershipRole.MEMBER),
|
||||
},
|
||||
webhooks: membership.team.webhooks.filter(filterWebhooks),
|
||||
};
|
||||
});
|
||||
|
||||
webhookGroups = webhookGroups.concat(teamWebhookGroups);
|
||||
|
||||
if (ctx.user.role === "ADMIN") {
|
||||
const platformWebhooks = await prisma.webhook.findMany({
|
||||
where: { platform: true },
|
||||
});
|
||||
webhookGroups.push({
|
||||
teamId: null,
|
||||
profile: {
|
||||
slug: "Platform",
|
||||
name: "Platform",
|
||||
image,
|
||||
},
|
||||
webhooks: platformWebhooks,
|
||||
metadata: {
|
||||
readOnly: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
webhookGroups: webhookGroups.filter((groupBy) => !!groupBy.webhooks?.length),
|
||||
profiles: webhookGroups.map((group) => ({
|
||||
teamId: group.teamId,
|
||||
...group.profile,
|
||||
...group.metadata,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
import type { CreateBtnProps, Option } from "./CreateButton";
|
||||
|
||||
@@ -139,7 +139,7 @@ export function ListItemText<TComponent extends keyof JSX.IntrinsicElements = "s
|
||||
component,
|
||||
{
|
||||
...passThroughProps,
|
||||
className: classNames("text-sm text-subtle truncate", props.className),
|
||||
className: classNames("text-sm text-subtle truncate prose", props.className),
|
||||
"data-testid": "list-item-text",
|
||||
},
|
||||
props.children
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
import React from "react";
|
||||
|
||||
|
||||
Reference in new issue
Block a user