V2.0 - Routing Forms and Shell 2.0 everywhere (#3902)
* Add duplicate form support * Fix duplication logic * Change to feathericons everywhere and other fixes * Dont allow routes for fallback route * Fix banner * Fix Empty Screen * Text area + embded window fixes * Semi fix avatar * Fix all TS issues * Fix tests * Troubleshoot container + Active on count * Support routing using query params * Improve mobile * NITS * Fix padding on input * Support multiselect in router endpoint * Fix the issue where app goes in embed mode after viewing embed once * Fix icons * Add router url tests * Add Responses download and form toggling tests * Add required validation test * Change Icons everywhere * App typeform app * Improvements in cli * Starting to move event types settings to tabs * Begin migration to single page form * Single page tabs * Limits Page * Advanced tab * Add RHF to dependancies * Add typeform how-to-use page * Add typeform how-to-use page and screenshots * Most of advanced tab * Solved RHF mismtach * Build fixes * RHF conditionals fixes * Improved legibility * Fix TS error * Add missing image * Update CliApp.tsx * Major refactor/organisation into optional V2 UI * Portal EditLocationModal * Fix dialoug form * Update imports * Auto Animate + custom inputs WIP * Custom Inputs * WIP Apps * Fixing stories imports * Stripe app * Remove duplicate dialog * Remove duplicate dialog * Major locations cleanup, 10s of bug fixes and app-store improvements * Fix missing pieces * More fixes * Fix embed URL * Fix app toggles + number of active apps * Fix container padding on disabledBorder prop * Removes strict * more fixes * EventType Team page WIP * Fix embed * Use new Shell * NIT * Add Darkmode gray color * V2 Shell WIP * Fix headings on shell V2 * Fix mobile layout with V2 shell * V2 create event type button * Checked Team Select * Hidden to happen on save - not on toggle * Team Attendee Select animation * Get form-edit page working * Get route-builder page working * Fix scheduling type and remove multi select label * Fix overflow on teams url * Get UI as per designs for form-edit * Make route-builder upto date with design * Add no responses banner * Update forms list as per designs * Button shouldnt decide where it would be positioned, users of it might have different requirements * A single select box in a row(when no other select boxes are present) wasnt taking the correct width in comparison to when it had other select boxes * Small missing pieces * Revert console * Revert api * Fixes * Fix Embed TS errors * Fix TS errors * Fix Eslint errors * Fix TS errors for UI * Fix ESLINT error * Fix TS errors * Add missing import * Fix CLI * Add a default placeholder * Remove hardcoded daily:integrations * Fix message for payment page * Revert api and console to main * Update README * Fix TS errors * Fix Lint warnings * Fix Tests * Streamline actions and make them easy to manage * A much more simplified approach to implementing actions * Fix embed * Fix most TS errors * Fix more TS errors * Reduce TS errors to zero * Fix tests * Fix UI * Fix UI * Self review fixes * TS failures caught merge issues * Security hardening * Use V2 Shell everywhere * Add missing file * Problems created by new shell fixed * Fix Shell * Fix Routing Form Card up and down positons * Fix Embed and other design fixes * Fix dropdown old event-types * Fix type errors * Fix allowed chek * Fix dropdown not closing on clicking EMbed button * Fix dropdown not closing on embed button * Fix event-type button group layout * Add label for switch * Fix dropdown in mobile mode * Remove useless comments * Login with pro for tests * Remove bg gray till App-Store pages are revamped Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]>
This commit is contained in:
44 files changed
+1912
-1723
No files matched your search
@@ -95,5 +95,6 @@ jobs:
|
||||
if: ${{ always() }}
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: test-results-core
|
||||
path: packages/app-store/**/playwright/results
|
||||
name: test-results
|
||||
path: test-results
|
||||
|
||||
@@ -80,7 +80,7 @@ const Component = ({
|
||||
|
||||
return (
|
||||
<div className="-mx-4 md:-mx-8">
|
||||
<div className="bg-gray-50 px-8">
|
||||
<div className="px-8">
|
||||
<Link href="/apps">
|
||||
<a className="mt-2 inline-flex px-1 py-2 text-sm text-gray-500 hover:bg-gray-100 hover:text-gray-800">
|
||||
<Icon.FiChevronLeft className="h-5 w-5" /> {t("browse_apps")}
|
||||
|
||||
@@ -6,10 +6,10 @@ import { components, ControlProps } from "react-select";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import showToast from "@calcom/lib/notification";
|
||||
import { Button, Switch } from "@calcom/ui";
|
||||
import { Dialog, DialogClose, DialogContent } from "@calcom/ui/Dialog";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { InputLeading, Label, TextArea, TextField } from "@calcom/ui/form/fields";
|
||||
import { Button, Switch } from "@calcom/ui/v2";
|
||||
|
||||
import { EMBED_LIB_URL, WEBAPP_URL } from "@lib/config/constants";
|
||||
|
||||
@@ -1128,7 +1128,7 @@ export const EmbedDialog = () => {
|
||||
type EmbedButtonProps<T> = {
|
||||
embedUrl: string;
|
||||
children?: React.ReactNode;
|
||||
className: string;
|
||||
className?: string;
|
||||
as?: T;
|
||||
};
|
||||
|
||||
@@ -1140,7 +1140,7 @@ export const EmbedButton = <T extends React.ElementType>({
|
||||
...props
|
||||
}: EmbedButtonProps<T> & React.ComponentPropsWithoutRef<T>) => {
|
||||
const router = useRouter();
|
||||
className = classNames(className, "hidden lg:flex");
|
||||
className = classNames(className, "hidden lg:inline-flex");
|
||||
const openEmbedModal = () => {
|
||||
const query = {
|
||||
...router.query,
|
||||
@@ -1164,7 +1164,10 @@ export const EmbedButton = <T extends React.ElementType>({
|
||||
className={className}
|
||||
data-test-embed-url={embedUrl}
|
||||
data-testid="embed"
|
||||
onClick={() => openEmbedModal()}>
|
||||
type="button"
|
||||
onClick={() => {
|
||||
openEmbedModal();
|
||||
}}>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
|
||||
@@ -167,7 +167,7 @@ function EventTypeSingleLayout({
|
||||
/>
|
||||
</div>
|
||||
{/* TODO: Figure out why combined isnt working - works in storybook */}
|
||||
<ButtonGroup combined containerProps={{ className: "px-4 border-gray-300 hidden lg:block" }}>
|
||||
<ButtonGroup combined containerProps={{ className: "px-4 border-gray-300 hidden lg:flex" }}>
|
||||
{/* We have to warp this in tooltip as it has a href which disabels the tooltip on buttons */}
|
||||
<Tooltip content={t("preview")}>
|
||||
<Button
|
||||
|
||||
@@ -24,7 +24,7 @@ export type AppProps = Omit<NextAppProps, "Component"> & {
|
||||
Component: NextAppProps["Component"] & {
|
||||
requiresLicense?: boolean;
|
||||
isThemeSupported?: boolean | ((arg: { router: NextRouter }) => boolean);
|
||||
getLayout?: (page: React.ReactElement) => ReactNode;
|
||||
getLayout?: (page: React.ReactElement, router: NextRouter) => ReactNode;
|
||||
};
|
||||
/** Will be defined only is there was an error */
|
||||
err?: Error;
|
||||
|
||||
@@ -18,6 +18,7 @@ const V2_WHITELIST = [
|
||||
"/apps/",
|
||||
"/success",
|
||||
];
|
||||
const V2_BLACKLIST = ["/apps/routing_forms"];
|
||||
|
||||
const middleware: NextMiddleware = async (req) => {
|
||||
const url = req.nextUrl;
|
||||
@@ -37,7 +38,11 @@ const middleware: NextMiddleware = async (req) => {
|
||||
}
|
||||
}
|
||||
/** Display available V2 pages to users who opted-in to early access */
|
||||
if (req.cookies.has("calcom-v2-early-access") && V2_WHITELIST.some((p) => url.pathname.startsWith(p))) {
|
||||
if (
|
||||
req.cookies.has("calcom-v2-early-access") &&
|
||||
!V2_BLACKLIST.some((p) => url.pathname.startsWith(p)) &&
|
||||
V2_WHITELIST.some((p) => url.pathname.startsWith(p))
|
||||
) {
|
||||
// rewrite to the current subdomain under the pages/sites folder
|
||||
url.pathname = `/v2${url.pathname}`;
|
||||
return NextResponse.rewrite(url);
|
||||
|
||||
@@ -47,7 +47,8 @@ function MyApp(props: AppProps) {
|
||||
</LicenseRequired>
|
||||
) : (
|
||||
<Component {...pageProps} err={err} />
|
||||
)
|
||||
),
|
||||
router
|
||||
)}
|
||||
</AppProviders>
|
||||
);
|
||||
|
||||
@@ -77,7 +77,7 @@ class MyDocument extends Document<Props> {
|
||||
</Head>
|
||||
|
||||
{/* Keep the embed hidden till parent initializes and gives it the appropriate styles */}
|
||||
<body className="dark:bg-darkgray-50 bg-gray-100">
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
{/* In case of Embed we want background to be transparent so that it merges into the website seamlessly. Also, we keep the body hidden here and embed logic would take care of showing the body when it's ready */}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import { GetServerSidePropsContext } from "next";
|
||||
import { NextRouter, useRouter } from "next/router";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import RoutingFormsRoutingConfig from "@calcom/app-store/ee/routing_forms/pages/app-routing.config";
|
||||
import TypeformRoutingConfig from "@calcom/app-store/typeform/pages/app-routing.config";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { AppGetServerSideProps } from "@calcom/types/AppGetServerSideProps";
|
||||
import { inferSSRProps } from "@calcom/types/inferSSRProps";
|
||||
|
||||
import { AppProps } from "@lib/app-providers";
|
||||
import { getSession } from "@lib/auth";
|
||||
|
||||
type AppPage = {
|
||||
type AppPageType = {
|
||||
getServerSideProps: AppGetServerSideProps;
|
||||
// A component than can accept any properties
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
default: ((props: any) => JSX.Element) & { isThemeSupported?: boolean };
|
||||
default: ((props: any) => JSX.Element) & Pick<AppProps["Component"], "isThemeSupported" | "getLayout">;
|
||||
};
|
||||
|
||||
type Found = {
|
||||
notFound: false;
|
||||
Component: AppPage["default"];
|
||||
getServerSideProps: AppPage["getServerSideProps"];
|
||||
Component: AppPageType["default"];
|
||||
getServerSideProps: AppPageType["getServerSideProps"];
|
||||
};
|
||||
|
||||
type NotFound = {
|
||||
@@ -33,7 +33,7 @@ const AppsRouting = {
|
||||
};
|
||||
|
||||
function getRoute(appName: string, pages: string[]) {
|
||||
const routingConfig = AppsRouting[appName as keyof typeof AppsRouting] as Record<string, AppPage>;
|
||||
const routingConfig = AppsRouting[appName as keyof typeof AppsRouting] as Record<string, AppPageType>;
|
||||
|
||||
if (!routingConfig) {
|
||||
return {
|
||||
@@ -41,7 +41,7 @@ function getRoute(appName: string, pages: string[]) {
|
||||
} as NotFound;
|
||||
}
|
||||
const mainPage = pages[0];
|
||||
const appPage = routingConfig[mainPage] as AppPage;
|
||||
const appPage = routingConfig[mainPage] as AppPageType;
|
||||
|
||||
if (!appPage) {
|
||||
return {
|
||||
@@ -51,7 +51,7 @@ function getRoute(appName: string, pages: string[]) {
|
||||
return { notFound: false, Component: appPage.default, ...appPage } as Found;
|
||||
}
|
||||
|
||||
export default function AppPage(props: inferSSRProps<typeof getServerSideProps>) {
|
||||
const AppPage: AppPageType["default"] = function AppPage(props) {
|
||||
const appName = props.appName;
|
||||
const router = useRouter();
|
||||
const pages = router.query.pages as string[];
|
||||
@@ -66,16 +66,34 @@ export default function AppPage(props: inferSSRProps<typeof getServerSideProps>)
|
||||
throw new Error("Route can't be undefined");
|
||||
}
|
||||
return <route.Component {...componentProps} />;
|
||||
}
|
||||
};
|
||||
|
||||
AppPage.isThemeSupported = ({ router }: { router: NextRouter }) => {
|
||||
AppPage.isThemeSupported = ({ router }) => {
|
||||
const route = getRoute(router.query.slug as string, router.query.pages as string[]);
|
||||
if (route.notFound) {
|
||||
return false;
|
||||
}
|
||||
return route.Component.isThemeSupported;
|
||||
const isThemeSupported = route.Component.isThemeSupported;
|
||||
if (typeof isThemeSupported === "function") {
|
||||
return isThemeSupported({ router });
|
||||
}
|
||||
|
||||
return !!isThemeSupported;
|
||||
};
|
||||
|
||||
AppPage.getLayout = (page, router) => {
|
||||
const route = getRoute(router.query.slug as string, router.query.pages as string[]);
|
||||
if (route.notFound) {
|
||||
return null;
|
||||
}
|
||||
if (!route.Component.getLayout) {
|
||||
return page;
|
||||
}
|
||||
return route.Component.getLayout(page, router);
|
||||
};
|
||||
|
||||
export default AppPage;
|
||||
|
||||
export async function getServerSideProps(
|
||||
context: GetServerSidePropsContext<{
|
||||
slug: string;
|
||||
|
||||
@@ -204,7 +204,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="-mx-4 mb-16 overflow-hidden rounded-sm border border-gray-200 bg-white sm:mx-0">
|
||||
<div className="mb-16 overflow-hidden rounded-sm border border-gray-200 bg-white sm:mx-0">
|
||||
<ul className="divide-y divide-neutral-200" data-testid="event-types">
|
||||
{types.map((type, index) => {
|
||||
const embedLink = `${group.profile.slug}/${type.slug}`;
|
||||
@@ -221,19 +221,19 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
||||
)}>
|
||||
<div
|
||||
className={classNames(
|
||||
"group flex w-full items-center justify-between px-4 py-4 hover:bg-neutral-50 sm:px-6",
|
||||
"group flex w-full items-center justify-between px-4 py-4 pr-0 hover:bg-neutral-50 sm:px-6",
|
||||
type.$disabled && "hover:bg-white"
|
||||
)}>
|
||||
{types.length > 1 && !type.$disabled && (
|
||||
<>
|
||||
<button
|
||||
className="invisible absolute left-1/2 -mt-4 mb-4 -ml-4 hidden h-7 w-7 scale-0 items-center justify-center rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[19px] sm:ml-0 sm:flex"
|
||||
className="invisible absolute left-[3px] -mt-4 mb-4 -ml-4 hidden h-7 w-7 scale-0 items-center justify-center rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex lg:left-[34px]"
|
||||
onClick={() => moveEventType(index, -1)}>
|
||||
<Icon.FiArrowUp className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="invisible absolute left-1/2 mt-8 -ml-4 hidden h-7 w-7 scale-0 items-center justify-center rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[19px] sm:ml-0 sm:flex"
|
||||
className="invisible absolute left-[3px] mt-8 -ml-4 hidden h-7 w-7 scale-0 items-center justify-center rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex lg:left-[34px]"
|
||||
onClick={() => moveEventType(index, 1)}>
|
||||
<Icon.FiArrowDown className="h-5 w-5" />
|
||||
</button>
|
||||
@@ -328,6 +328,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
||||
color="minimal"
|
||||
size="sm"
|
||||
type="button"
|
||||
as={Button}
|
||||
StartIcon={Icon.FiCode}
|
||||
className={classNames(
|
||||
"w-full rounded-none",
|
||||
|
||||
@@ -249,19 +249,19 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
||||
)}>
|
||||
<div
|
||||
className={classNames(
|
||||
"group flex w-full items-center justify-between px-4 py-4 hover:bg-neutral-50 sm:px-6",
|
||||
"group flex w-full items-center justify-between px-4 py-4 pr-0 hover:bg-neutral-50 sm:px-6",
|
||||
type.$disabled && "hover:bg-white"
|
||||
)}>
|
||||
{types.length > 1 && !type.$disabled && (
|
||||
<>
|
||||
<button
|
||||
className="invisible absolute left-1/2 -mt-4 mb-4 -ml-4 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[36px] sm:ml-0 sm:flex"
|
||||
className="invisible absolute left-[5px] -mt-4 mb-4 -ml-4 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex lg:left-[36px]"
|
||||
onClick={() => moveEventType(index, -1)}>
|
||||
<Icon.FiArrowUp className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="invisible absolute left-1/2 mt-8 -ml-4 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[36px] sm:ml-0 sm:flex"
|
||||
className="invisible absolute left-[5px] mt-8 -ml-4 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex lg:left-[36px]"
|
||||
onClick={() => moveEventType(index, 1)}>
|
||||
<Icon.FiArrowDown className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
@@ -19,19 +19,30 @@ type UserFixture = ReturnType<typeof createUserFixture>;
|
||||
const userIncludes = PrismaType.validator<PrismaType.UserInclude>()({
|
||||
eventTypes: true,
|
||||
credentials: true,
|
||||
routingForms: true,
|
||||
});
|
||||
|
||||
const userWithEventTypes = PrismaType.validator<PrismaType.UserArgs>()({
|
||||
include: userIncludes,
|
||||
});
|
||||
|
||||
const seededForm = {
|
||||
id: "948ae412-d995-4865-875a-48302588de03",
|
||||
name: "Seeded Form - Pro",
|
||||
};
|
||||
|
||||
type UserWithIncludes = PrismaType.UserGetPayload<typeof userWithEventTypes>;
|
||||
|
||||
// creates a user fixture instance and stores the collection
|
||||
export const createUsersFixture = (page: Page, workerInfo: WorkerInfo) => {
|
||||
const store = { users: [], page } as { users: UserFixture[]; page: typeof page };
|
||||
return {
|
||||
create: async (opts?: CustomUserOpts) => {
|
||||
create: async (
|
||||
opts?: CustomUserOpts | null,
|
||||
scenario: {
|
||||
seedRoutingForms?: boolean;
|
||||
} = {}
|
||||
) => {
|
||||
const _user = await prisma.user.create({
|
||||
data: await createUser(workerInfo, opts),
|
||||
});
|
||||
@@ -61,6 +72,122 @@ export const createUsersFixture = (page: Page, workerInfo: WorkerInfo) => {
|
||||
length: 30,
|
||||
},
|
||||
});
|
||||
if (scenario.seedRoutingForms) {
|
||||
await prisma.app_RoutingForms_Form.create({
|
||||
data: {
|
||||
routes: [
|
||||
{
|
||||
id: "8a898988-89ab-4cde-b012-31823f708642",
|
||||
action: { type: "eventTypeRedirectUrl", value: "pro/30min" },
|
||||
queryValue: {
|
||||
id: "8a898988-89ab-4cde-b012-31823f708642",
|
||||
type: "group",
|
||||
children1: {
|
||||
"8988bbb8-0123-4456-b89a-b1823f70c5ff": {
|
||||
type: "rule",
|
||||
properties: {
|
||||
field: "c4296635-9f12-47b1-8153-c3a854649182",
|
||||
value: ["event-routing"],
|
||||
operator: "equal",
|
||||
valueSrc: ["value"],
|
||||
valueType: ["text"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "aa8aaba9-cdef-4012-b456-71823f70f7ef",
|
||||
action: { type: "customPageMessage", value: "Custom Page Result" },
|
||||
queryValue: {
|
||||
id: "aa8aaba9-cdef-4012-b456-71823f70f7ef",
|
||||
type: "group",
|
||||
children1: {
|
||||
"b99b8a89-89ab-4cde-b012-31823f718ff5": {
|
||||
type: "rule",
|
||||
properties: {
|
||||
field: "c4296635-9f12-47b1-8153-c3a854649182",
|
||||
value: ["custom-page"],
|
||||
operator: "equal",
|
||||
valueSrc: ["value"],
|
||||
valueType: ["text"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "a8ba9aab-4567-489a-bcde-f1823f71b4ad",
|
||||
action: { type: "externalRedirectUrl", value: "https://google.com" },
|
||||
queryValue: {
|
||||
id: "a8ba9aab-4567-489a-bcde-f1823f71b4ad",
|
||||
type: "group",
|
||||
children1: {
|
||||
"998b9b9a-0123-4456-b89a-b1823f7232b9": {
|
||||
type: "rule",
|
||||
properties: {
|
||||
field: "c4296635-9f12-47b1-8153-c3a854649182",
|
||||
value: ["external-redirect"],
|
||||
operator: "equal",
|
||||
valueSrc: ["value"],
|
||||
valueType: ["text"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "aa8ba8b9-0123-4456-b89a-b182623406d8",
|
||||
action: { type: "customPageMessage", value: "Multiselect chosen" },
|
||||
queryValue: {
|
||||
id: "aa8ba8b9-0123-4456-b89a-b182623406d8",
|
||||
type: "group",
|
||||
children1: {
|
||||
"b98a8abb-cdef-4012-b456-718262343d27": {
|
||||
type: "rule",
|
||||
properties: {
|
||||
field: "d4292635-9f12-17b1-9153-c3a854649182",
|
||||
value: [["Option-2"]],
|
||||
operator: "multiselect_equals",
|
||||
valueSrc: ["value"],
|
||||
valueType: ["multiselect"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "898899aa-4567-489a-bcde-f1823f708646",
|
||||
action: { type: "customPageMessage", value: "Fallback Message" },
|
||||
isFallback: true,
|
||||
queryValue: { id: "898899aa-4567-489a-bcde-f1823f708646", type: "group" },
|
||||
},
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
id: "c4296635-9f12-47b1-8153-c3a854649182",
|
||||
type: "text",
|
||||
label: "Test field",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: "d4292635-9f12-17b1-9153-c3a854649182",
|
||||
type: "multiselect",
|
||||
label: "Multi Select",
|
||||
identifier: "multi",
|
||||
selectText: "Option-1\nOption-2",
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
user: {
|
||||
connect: {
|
||||
id: _user.id,
|
||||
},
|
||||
},
|
||||
name: seededForm.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
const user = await prisma.user.findUniqueOrThrow({
|
||||
where: { id: _user.id },
|
||||
include: userIncludes,
|
||||
@@ -97,7 +224,8 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
|
||||
return {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
eventTypes: user.eventTypes!,
|
||||
eventTypes: user.eventTypes,
|
||||
routingForms: user.routingForms,
|
||||
self,
|
||||
login: async () => login({ ...(await self()), password: user.username }, store.page),
|
||||
getPaymentCredential: async () => getPaymentCredential(store.page),
|
||||
@@ -115,7 +243,7 @@ type CustomUserOpts = Partial<Pick<Prisma.User, CustomUserOptsKeys>> & { timeZon
|
||||
// creates the actual user in the db.
|
||||
const createUser = async (
|
||||
workerInfo: WorkerInfo,
|
||||
opts?: CustomUserOpts
|
||||
opts?: CustomUserOpts | null
|
||||
): Promise<PrismaType.UserCreateInput> => {
|
||||
// build a unique name for our user
|
||||
const uname = `${opts?.username ?? opts?.plan?.toLocaleLowerCase() ?? UserPlan.PRO.toLowerCase()}-${
|
||||
|
||||
@@ -8,7 +8,7 @@ import { createPaymentsFixture } from "../fixtures/payments";
|
||||
import { createServersFixture } from "../fixtures/servers";
|
||||
import { createUsersFixture } from "../fixtures/users";
|
||||
|
||||
interface Fixtures {
|
||||
export interface Fixtures {
|
||||
users: ReturnType<typeof createUsersFixture>;
|
||||
bookings: ReturnType<typeof createBookingsFixture>;
|
||||
payments: ReturnType<typeof createPaymentsFixture>;
|
||||
|
||||
@@ -356,10 +356,6 @@ nav#nav--settings > a.active svg {
|
||||
@apply text-neutral-500;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #f3f4f6;
|
||||
}
|
||||
|
||||
hr {
|
||||
@apply border-gray-200;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
if (!formId) {
|
||||
throw new Error("formId must be provided");
|
||||
}
|
||||
|
||||
const form = await prisma.app_RoutingForms_Form.findFirst({
|
||||
where: {
|
||||
id: formId,
|
||||
},
|
||||
});
|
||||
if (!form) {
|
||||
throw new Error("Form not found");
|
||||
}
|
||||
res.setHeader("Content-Type", "text/csv; charset=UTF-8");
|
||||
res.setHeader("Content-Disposition", `attachment; filename="${form.name}-${form.id}.csv"`);
|
||||
res.setHeader("Transfer-Encoding", "chunked");
|
||||
const csvIterator = getResponses(formId);
|
||||
for await (const partialCsv of csvIterator) {
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
import { useRouter } from "next/router";
|
||||
import type { NextRouter } from "next/router";
|
||||
import { useState, createContext, useContext, forwardRef } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { z } from "zod";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
||||
import { Dialog, DialogClose, DialogContent } from "@calcom/ui/Dialog";
|
||||
import {
|
||||
Button,
|
||||
ButtonProps,
|
||||
Dropdown,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger,
|
||||
Form,
|
||||
showToast,
|
||||
Switch,
|
||||
TextField,
|
||||
} from "@calcom/ui/v2";
|
||||
|
||||
import { EmbedButton, EmbedDialog } from "@components/Embed";
|
||||
|
||||
import { SerializableForm } from "../types/types";
|
||||
import { App_RoutingForms_Form } from ".prisma/client";
|
||||
|
||||
type RoutingForm = SerializableForm<App_RoutingForms_Form>;
|
||||
|
||||
const newFormModalQuerySchema = z.object({
|
||||
action: z.string(),
|
||||
target: z.string().optional(),
|
||||
});
|
||||
|
||||
const openModal = (router: NextRouter, option: { target?: string; action: string }) => {
|
||||
const query = {
|
||||
...router.query,
|
||||
dialog: "new-form",
|
||||
...option,
|
||||
};
|
||||
router.push(
|
||||
{
|
||||
pathname: router.pathname,
|
||||
query,
|
||||
},
|
||||
undefined,
|
||||
{ shallow: true }
|
||||
);
|
||||
};
|
||||
|
||||
function NewFormDialog({ appUrl }: { appUrl: string }) {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const utils = trpc.useContext();
|
||||
|
||||
const mutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
onSuccess: (_data, variables) => {
|
||||
utils.invalidateQueries("viewer.app_routing_forms.forms");
|
||||
router.push(`${appUrl}/form-edit/${variables.id}`);
|
||||
},
|
||||
onError: () => {
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const hookForm = useForm<{
|
||||
name: string;
|
||||
description: string;
|
||||
}>();
|
||||
|
||||
const { action, target } = router.query as z.infer<typeof newFormModalQuerySchema>;
|
||||
|
||||
const { register } = hookForm;
|
||||
return (
|
||||
<Dialog name="new-form" clearQueryParamsOnClose={["target", "action"]}>
|
||||
<DialogContent className="overflow-y-auto">
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-bold leading-6 text-gray-900" id="modal-title">
|
||||
Add New Form
|
||||
</h3>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500">Create your form to route a booker</p>
|
||||
</div>
|
||||
</div>
|
||||
<Form
|
||||
form={hookForm}
|
||||
handleSubmit={(values) => {
|
||||
const formId = uuidv4();
|
||||
mutation.mutate({
|
||||
id: formId,
|
||||
...values,
|
||||
addFallback: true,
|
||||
duplicateFrom: action === "duplicate" ? target : null,
|
||||
});
|
||||
}}>
|
||||
<div className="mt-3 space-y-4">
|
||||
<TextField label={t("title")} required placeholder="A Routing Form" {...register("name")} />
|
||||
<div className="mb-5">
|
||||
<h3 className="mb-2 text-base font-medium leading-6 text-gray-900">Description</h3>
|
||||
<div className="w-full">
|
||||
<textarea
|
||||
id="description"
|
||||
data-testid="description"
|
||||
className="block w-full rounded-sm border-gray-300 text-sm "
|
||||
placeholder="Form Description"
|
||||
{...register("description")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-8 flex flex-row-reverse gap-x-2">
|
||||
<Button loading={mutation.isLoading} data-testid="add-form" type="submit">
|
||||
{t("continue")}
|
||||
</Button>
|
||||
<DialogClose asChild>
|
||||
<Button color="secondary">{t("cancel")}</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
const dropdownCtx = createContext<{ dropdown: boolean }>({ dropdown: false });
|
||||
|
||||
export const FormActionsDropdown = ({ form, children }: { form: RoutingForm; children: React.ReactNode }) => {
|
||||
const { disabled } = form;
|
||||
return (
|
||||
<dropdownCtx.Provider value={{ dropdown: true }}>
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(disabled && " opacity-30")}
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>{children}</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</dropdownCtx.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
function Dialogs({
|
||||
appUrl,
|
||||
deleteDialogOpen,
|
||||
setDeleteDialogOpen,
|
||||
deleteDialogFormId,
|
||||
}: {
|
||||
appUrl: string;
|
||||
deleteDialogOpen: boolean;
|
||||
setDeleteDialogOpen: (open: boolean) => void;
|
||||
deleteDialogFormId: string | null;
|
||||
}) {
|
||||
const utils = trpc.useContext();
|
||||
const router = useRouter();
|
||||
const deleteMutation = trpc.useMutation("viewer.app_routing_forms.deleteForm", {
|
||||
onSuccess: () => {
|
||||
showToast("Form deleted", "success");
|
||||
setDeleteDialogOpen(false);
|
||||
router.replace(`${appUrl}/forms`);
|
||||
},
|
||||
onSettled: () => {
|
||||
utils.invalidateQueries(["viewer.app_routing_forms.forms"]);
|
||||
setDeleteDialogOpen(false);
|
||||
},
|
||||
onError: () => {
|
||||
showToast("Something went wrong", "error");
|
||||
},
|
||||
});
|
||||
return (
|
||||
<div id="form-dialogs">
|
||||
<EmbedDialog />
|
||||
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
|
||||
<ConfirmationDialogContent
|
||||
isLoading={deleteMutation.isLoading}
|
||||
variety="danger"
|
||||
title="Delete Form"
|
||||
confirmBtnText="Yes, delete Form"
|
||||
loadingText="Yes, delete Form"
|
||||
onConfirm={(e) => {
|
||||
if (!deleteDialogFormId) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
deleteMutation.mutate({
|
||||
id: deleteDialogFormId,
|
||||
});
|
||||
}}>
|
||||
Are you sure you want to delete this form? Anyone who you've shared the link with will no
|
||||
longer be able to book using it. Also, all associated responses would be deleted.
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
<NewFormDialog appUrl={appUrl} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const actionsCtx = createContext({
|
||||
appUrl: "",
|
||||
_delete: {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
||||
onAction: (_arg: { routingForm: RoutingForm | null }) => {},
|
||||
isLoading: false,
|
||||
},
|
||||
toggle: {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
||||
onAction: (_arg: { routingForm: RoutingForm | null; checked: boolean }) => {},
|
||||
isLoading: false,
|
||||
},
|
||||
});
|
||||
|
||||
export function FormActionsProvider({ appUrl, children }: { appUrl: string; children: React.ReactNode }) {
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [deleteDialogFormId, setDeleteDialogFormId] = useState<string | null>(null);
|
||||
const router = useRouter();
|
||||
|
||||
const toggleMutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
onError: () => {
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
onSuccess: () => {
|
||||
router.replace(router.asPath);
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<actionsCtx.Provider
|
||||
value={{
|
||||
appUrl,
|
||||
_delete: {
|
||||
onAction: ({ routingForm }) => {
|
||||
if (!routingForm) {
|
||||
return;
|
||||
}
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogFormId(routingForm.id);
|
||||
},
|
||||
isLoading: false,
|
||||
},
|
||||
toggle: {
|
||||
onAction: ({ routingForm, checked }) => {
|
||||
if (!routingForm) {
|
||||
return;
|
||||
}
|
||||
toggleMutation.mutate({
|
||||
...routingForm,
|
||||
disabled: !checked,
|
||||
});
|
||||
},
|
||||
isLoading: toggleMutation.isLoading,
|
||||
},
|
||||
}}>
|
||||
{children}
|
||||
</actionsCtx.Provider>
|
||||
<Dialogs
|
||||
appUrl={appUrl}
|
||||
deleteDialogFormId={deleteDialogFormId}
|
||||
deleteDialogOpen={deleteDialogOpen}
|
||||
setDeleteDialogOpen={setDeleteDialogOpen}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
type FormActionType =
|
||||
| "preview"
|
||||
| "edit"
|
||||
| "copyLink"
|
||||
| "toggle"
|
||||
| "_delete"
|
||||
| "embed"
|
||||
| "duplicate"
|
||||
| "download"
|
||||
| "create";
|
||||
|
||||
type FormActionProps<T> = {
|
||||
routingForm: RoutingForm | null;
|
||||
as?: T;
|
||||
label?: string;
|
||||
//TODO: Provide types here
|
||||
action: FormActionType;
|
||||
children?: React.ReactNode;
|
||||
render?: (props: { routingForm: RoutingForm | null; className?: string; label?: string }) => JSX.Element;
|
||||
} & ButtonProps;
|
||||
|
||||
export const FormAction = forwardRef(function FormAction<T extends typeof Button>(
|
||||
props: FormActionProps<T>,
|
||||
forwardedRef: React.ForwardedRef<HTMLAnchorElement | HTMLButtonElement>
|
||||
) {
|
||||
const { action: actionName, routingForm, children, as: asFromElement, ...additionalProps } = props;
|
||||
const { appUrl, _delete, toggle } = useContext(actionsCtx);
|
||||
const dropdownCtxValue = useContext(dropdownCtx);
|
||||
const dropdown = dropdownCtxValue?.dropdown;
|
||||
const embedLink = `forms/${routingForm?.id}`;
|
||||
const formLink = `${CAL_URL}/${embedLink}`;
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const actionData: Record<
|
||||
FormActionType,
|
||||
ButtonProps & { as?: React.ElementType; render?: FormActionProps<unknown>["render"] }
|
||||
> = {
|
||||
preview: {
|
||||
href: formLink,
|
||||
},
|
||||
copyLink: {
|
||||
onClick: () => {
|
||||
showToast(t("link_copied"), "success");
|
||||
navigator.clipboard.writeText(formLink);
|
||||
},
|
||||
},
|
||||
duplicate: {
|
||||
onClick: () => openModal(router, { action: "duplicate", target: routingForm?.id }),
|
||||
},
|
||||
embed: {
|
||||
as: EmbedButton,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
embedUrl: embedLink,
|
||||
},
|
||||
edit: {
|
||||
href: `${appUrl}/form-edit/${routingForm?.id}`,
|
||||
},
|
||||
download: {
|
||||
href: `/api/integrations/routing_forms/responses/${routingForm?.id}`,
|
||||
},
|
||||
_delete: {
|
||||
onClick: () => _delete.onAction({ routingForm }),
|
||||
loading: _delete.isLoading,
|
||||
},
|
||||
create: {
|
||||
onClick: () => openModal(router, { action: "new" }),
|
||||
},
|
||||
toggle: {
|
||||
render: ({ routingForm, label = "", ...restProps }) => {
|
||||
if (!routingForm) {
|
||||
return <></>;
|
||||
}
|
||||
return (
|
||||
<div {...restProps}>
|
||||
<Switch
|
||||
checked={!routingForm.disabled}
|
||||
label={label}
|
||||
onCheckedChange={(checked) => toggle.onAction({ routingForm, checked })}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
loading: toggle.isLoading,
|
||||
},
|
||||
};
|
||||
|
||||
const { as: asFromAction, ...action } = actionData[actionName];
|
||||
const as = asFromElement || asFromAction;
|
||||
const actionProps = {
|
||||
...action,
|
||||
...(additionalProps as ButtonProps),
|
||||
} as ButtonProps & { render?: FormActionProps<unknown>["render"] };
|
||||
|
||||
if (actionProps.render) {
|
||||
return actionProps.render({
|
||||
routingForm,
|
||||
...additionalProps,
|
||||
});
|
||||
}
|
||||
|
||||
const Component = as || Button;
|
||||
if (!dropdown) {
|
||||
return (
|
||||
<Component ref={forwardedRef} {...actionProps}>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<DropdownMenuItem>
|
||||
<Component ref={forwardedRef} {...actionProps}>
|
||||
{children}
|
||||
</Component>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import NavTabs from "@components/NavTabs";
|
||||
import { HorizontalTabs } from "@calcom/ui/v2";
|
||||
|
||||
import { getSerializableForm } from "../lib/getSerializableForm";
|
||||
|
||||
@@ -17,12 +17,12 @@ export default function RoutingNavBar({
|
||||
{
|
||||
name: "Routing",
|
||||
href: `${appUrl}/route-builder/${form?.id}`,
|
||||
className: "hidden lg:block",
|
||||
className: "pointer-events-none opacity-30 lg:pointer-events-auto lg:opacity-100",
|
||||
},
|
||||
];
|
||||
return (
|
||||
<div className="mb-4">
|
||||
<NavTabs tabs={tabs} />
|
||||
<HorizontalTabs tabs={tabs} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
import Shell from "@calcom/ui/Shell";
|
||||
|
||||
import RoutingNavBar from "../components/RoutingNavBar";
|
||||
import { getSerializableForm } from "../lib/getSerializableForm";
|
||||
|
||||
const RoutingShell: React.FC<{
|
||||
form: ReturnType<typeof getSerializableForm>;
|
||||
heading: ReactNode;
|
||||
appUrl: string;
|
||||
children: ReactNode;
|
||||
}> = function RoutingShell({ children, form, heading, appUrl }) {
|
||||
return (
|
||||
<Shell heading={heading} subtitle={form.description || ""}>
|
||||
<div className="-mx-4 px-4 sm:px-6 md:-mx-8 md:px-8">
|
||||
<div className="bg-gray-50">
|
||||
<RoutingNavBar appUrl={appUrl} form={form} />
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</Shell>
|
||||
);
|
||||
};
|
||||
export default RoutingShell;
|
||||
@@ -1,122 +0,0 @@
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import { CopyRedirectUrlButton } from "@calcom/app-store/typeform/components";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import showToast from "@calcom/lib/notification";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Switch } from "@calcom/ui";
|
||||
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
||||
import { DialogTrigger, Dialog } from "@calcom/ui/Dialog";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import { EmbedButton, EmbedDialog } from "@components/Embed";
|
||||
|
||||
import { getSerializableForm } from "../lib/getSerializableForm";
|
||||
|
||||
export default function SideBar({
|
||||
form,
|
||||
appUrl,
|
||||
}: {
|
||||
form: ReturnType<typeof getSerializableForm>;
|
||||
appUrl: string;
|
||||
}) {
|
||||
const { t } = useLocale();
|
||||
|
||||
const utils = trpc.useContext();
|
||||
const router = useRouter();
|
||||
const mutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
onSuccess() {
|
||||
router.replace(router.asPath);
|
||||
},
|
||||
onError() {
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
onSettled() {
|
||||
utils.invalidateQueries(["viewer.app_routing_forms.form"]);
|
||||
},
|
||||
});
|
||||
|
||||
const deleteMutation = trpc.useMutation("viewer.app_routing_forms.deleteForm", {
|
||||
onError() {
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
onSuccess() {
|
||||
router.push(`/${appUrl}/forms`);
|
||||
},
|
||||
});
|
||||
|
||||
const embedLink = `forms/${form.id}`;
|
||||
const formLink = `${CAL_URL}/${embedLink}`;
|
||||
|
||||
return (
|
||||
<div className="m-0 mt-1 mb-4 w-full lg:w-3/12 lg:px-2 lg:ltr:ml-2 lg:rtl:mr-2">
|
||||
<div className="px-2" data-testid="toggle-form">
|
||||
<Switch
|
||||
checked={!form.disabled}
|
||||
onCheckedChange={(isChecked) => {
|
||||
mutation.mutate({ ...form, disabled: !isChecked });
|
||||
}}
|
||||
label={t("Enable Form")}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-4 space-y-1.5">
|
||||
<a
|
||||
href={formLink}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-md inline-flex items-center rounded-sm px-2 py-1 text-sm font-medium text-neutral-700 hover:bg-gray-200 hover:text-gray-900">
|
||||
<Icon.FiExternalLink className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" aria-hidden="true" />
|
||||
{t("preview")}
|
||||
</a>
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(formLink);
|
||||
showToast("Link copied!", "success");
|
||||
}}
|
||||
type="button"
|
||||
className="text-md flex items-center rounded-sm px-2 py-1 text-sm font-medium text-gray-700 hover:bg-gray-200 hover:text-gray-900">
|
||||
<Icon.FiLink className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" />
|
||||
{t("Copy link to form")}
|
||||
</button>
|
||||
<CopyRedirectUrlButton form={form} />
|
||||
<EmbedButton
|
||||
as="button"
|
||||
embedUrl={encodeURIComponent(embedLink)}
|
||||
type="button"
|
||||
className="text-md flex items-center rounded-sm px-2 py-1 text-sm font-medium text-gray-700 hover:bg-gray-200 hover:text-gray-900">
|
||||
<Icon.FiCode className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" aria-hidden="true" />
|
||||
{t("embed")}
|
||||
</EmbedButton>
|
||||
|
||||
<a
|
||||
data-testid="download-responses"
|
||||
href={"/api/integrations/routing_forms/responses/" + form.id}
|
||||
download={`${form.name}-${form.id}.csv`}
|
||||
className="text-md flex items-center rounded-sm px-2 py-1 text-sm font-medium text-gray-700 hover:bg-gray-200 hover:text-gray-900">
|
||||
<Icon.FiDownload className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" />
|
||||
{t("Download responses (CSV)")}
|
||||
</a>
|
||||
<Dialog>
|
||||
<DialogTrigger className="text-md flex items-center rounded-sm px-2 py-1 text-sm font-medium text-red-500 hover:bg-gray-200">
|
||||
<Icon.FiTrash className="h-4 w-4 text-red-500 ltr:mr-2 rtl:ml-2" />
|
||||
{t("delete")}
|
||||
</DialogTrigger>
|
||||
<ConfirmationDialogContent
|
||||
isLoading={deleteMutation.isLoading}
|
||||
variety="danger"
|
||||
title="Delete Form"
|
||||
confirmBtnText="Yes, delete form"
|
||||
onConfirm={() => {
|
||||
deleteMutation.mutate({ id: form.id });
|
||||
}}>
|
||||
Are you sure you want to delete this form? Anyone who you've shared the link with will no
|
||||
longer be able to book using it.
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
<EmbedDialog />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
import { App_RoutingForms_Form } from "@prisma/client";
|
||||
import { useRouter } from "next/router";
|
||||
import { useForm, UseFormReturn } from "react-hook-form";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { Form } from "@calcom/ui/form/fields";
|
||||
import { showToast } from "@calcom/ui/v2";
|
||||
import { ButtonGroup, TextAreaField, TextField, Tooltip, DropdownMenuSeparator, Button } from "@calcom/ui/v2";
|
||||
import Meta from "@calcom/ui/v2/core/Meta";
|
||||
import { ShellMain } from "@calcom/ui/v2/core/Shell";
|
||||
import Banner from "@calcom/ui/v2/core/banner";
|
||||
|
||||
import { SerializableForm } from "../types/types";
|
||||
import { FormAction, FormActionsDropdown, FormActionsProvider } from "./FormActions";
|
||||
import RoutingNavBar from "./RoutingNavBar";
|
||||
|
||||
type RoutingForm = SerializableForm<App_RoutingForms_Form>;
|
||||
type RoutingFormWithResponseCount = RoutingForm & {
|
||||
_count: {
|
||||
responses: number;
|
||||
};
|
||||
};
|
||||
|
||||
const Actions = ({
|
||||
form,
|
||||
mutation,
|
||||
}: {
|
||||
form: RoutingFormWithResponseCount;
|
||||
mutation: {
|
||||
isLoading: boolean;
|
||||
};
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<div className="flex items-center">
|
||||
<div className="hidden md:inline-flex md:items-center ">
|
||||
<FormAction
|
||||
className="self-center border-r-2 border-gray-300 pr-5 "
|
||||
data-testid="toggle-form"
|
||||
action="toggle"
|
||||
routingForm={form}
|
||||
/>
|
||||
</div>
|
||||
<ButtonGroup
|
||||
combined
|
||||
containerProps={{ className: "px-4 border-gray-300 hidden md:inline-flex items-center" }}>
|
||||
<Tooltip content={t("preview")}>
|
||||
<FormAction
|
||||
routingForm={form}
|
||||
color="secondary"
|
||||
target="_blank"
|
||||
size="icon"
|
||||
type="button"
|
||||
rel="noreferrer"
|
||||
action="preview"
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
combined
|
||||
/>
|
||||
</Tooltip>
|
||||
<FormAction
|
||||
routingForm={form}
|
||||
action="copyLink"
|
||||
color="secondary"
|
||||
size="icon"
|
||||
type="button"
|
||||
StartIcon={Icon.FiLink}
|
||||
tooltip={t("copy_link")}
|
||||
combined
|
||||
/>
|
||||
<Tooltip content="Download Responses">
|
||||
<FormAction
|
||||
data-testid="download-responses"
|
||||
routingForm={form}
|
||||
action="download"
|
||||
color="secondary"
|
||||
size="icon"
|
||||
type="button"
|
||||
StartIcon={Icon.FiDownload}
|
||||
combined
|
||||
/>
|
||||
</Tooltip>
|
||||
<FormAction
|
||||
routingForm={form}
|
||||
action="embed"
|
||||
color="secondary"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiCode}
|
||||
tooltip={t("embed")}
|
||||
combined
|
||||
/>
|
||||
<FormAction
|
||||
routingForm={form}
|
||||
action="_delete"
|
||||
// className="mr-3"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiTrash}
|
||||
color="secondary"
|
||||
type="button"
|
||||
tooltip={t("delete")}
|
||||
combined
|
||||
/>
|
||||
</ButtonGroup>
|
||||
<div className="flex md:hidden">
|
||||
<FormActionsDropdown form={form}>
|
||||
<FormAction
|
||||
routingForm={form}
|
||||
color="minimal"
|
||||
target="_blank"
|
||||
type="button"
|
||||
rel="noreferrer"
|
||||
action="preview"
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
combined>
|
||||
Preview
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="copyLink"
|
||||
className="w-full"
|
||||
routingForm={form}
|
||||
color="minimal"
|
||||
type="button"
|
||||
StartIcon={Icon.FiCopy}>
|
||||
{t("copy")}
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="download"
|
||||
routingForm={form}
|
||||
className="w-full"
|
||||
color="minimal"
|
||||
type="button"
|
||||
StartIcon={Icon.FiDownload}>
|
||||
Download Responses
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="download"
|
||||
routingForm={form}
|
||||
className="w-full"
|
||||
color="minimal"
|
||||
type="button"
|
||||
StartIcon={Icon.FiDownload}>
|
||||
Download Responses
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="embed"
|
||||
routingForm={form}
|
||||
color="minimal"
|
||||
type="button"
|
||||
className="w-full"
|
||||
StartIcon={Icon.FiCode}>
|
||||
{t("embed")}
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="_delete"
|
||||
routingForm={form}
|
||||
className="w-full"
|
||||
type="button"
|
||||
color="destructive"
|
||||
StartIcon={Icon.FiTrash}>
|
||||
{t("delete")}
|
||||
</FormAction>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<div className="inline-flex items-center">
|
||||
<Button color="minimal">
|
||||
<FormAction
|
||||
className="self-center"
|
||||
action="toggle"
|
||||
label={form.disabled ? "Enable Form" : "Disable Form"}
|
||||
routingForm={form}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
</FormActionsDropdown>
|
||||
</div>
|
||||
<div className="mr-4 h-5 border-0 border-gray-300 md:border-l-2" />
|
||||
<Button data-testid="update-form" loading={mutation.isLoading} type="submit" color="primary">
|
||||
{t("save")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default function SingleForm({
|
||||
form,
|
||||
appUrl,
|
||||
Page,
|
||||
}: {
|
||||
form: RoutingFormWithResponseCount;
|
||||
appUrl: string;
|
||||
Page: React.FC<{
|
||||
form: RoutingFormWithResponseCount;
|
||||
appUrl: string;
|
||||
hookForm: UseFormReturn<RoutingFormWithResponseCount>;
|
||||
}>;
|
||||
}) {
|
||||
const hookForm = useForm({
|
||||
defaultValues: form,
|
||||
});
|
||||
const utils = trpc.useContext();
|
||||
const router = useRouter();
|
||||
|
||||
const mutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
onSuccess() {
|
||||
router.replace(router.asPath);
|
||||
showToast("Form updated successfully.", "success");
|
||||
},
|
||||
onError() {
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
onSettled() {
|
||||
utils.invalidateQueries(["viewer.app_routing_forms.form"]);
|
||||
},
|
||||
});
|
||||
return (
|
||||
<Form
|
||||
form={hookForm}
|
||||
handleSubmit={(data) => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
mutation.mutate({
|
||||
...data,
|
||||
});
|
||||
}}>
|
||||
<FormActionsProvider appUrl={appUrl}>
|
||||
<Meta title={form.name} description={form.description || ""} />
|
||||
<ShellMain
|
||||
heading={form.name}
|
||||
subtitle={form.description || ""}
|
||||
backPath={`/${appUrl}/forms`}
|
||||
CTA={<Actions form={form} mutation={mutation} />}>
|
||||
<div className="-mx-4 px-4 sm:px-6 md:-mx-8 md:px-8">
|
||||
<div className="flex flex-col items-center md:flex-row md:items-start">
|
||||
<div className="min-w-72 max-w-72 mb-6 md:mr-6">
|
||||
<TextField
|
||||
type="text"
|
||||
containerClassName="mb-6"
|
||||
placeholder="Title"
|
||||
{...hookForm.register("name")}
|
||||
/>
|
||||
<TextAreaField
|
||||
rows={3}
|
||||
id="description"
|
||||
data-testid="description"
|
||||
placeholder="Form Description"
|
||||
{...hookForm.register("description")}
|
||||
defaultValue={form.description || ""}
|
||||
/>
|
||||
{!form._count?.responses && (
|
||||
<Banner
|
||||
className="mt-6"
|
||||
variant="neutral"
|
||||
title="No Responses yet"
|
||||
description="Wait for some time for responses to be collected. You can go and submit the form yourself as well."
|
||||
Icon={Icon.FiInfo}
|
||||
onDismiss={() => console.log("dismissed")}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full rounded-md border border-gray-200 p-8">
|
||||
<RoutingNavBar appUrl={appUrl} form={form} />
|
||||
<Page hookForm={hookForm} form={form} appUrl={appUrl} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ShellMain>
|
||||
</FormActionsProvider>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
+7
-2
@@ -56,6 +56,7 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
.cal-query-builder .rule--drag-handler,
|
||||
.cal-query-builder .rule--header {
|
||||
display: flex;
|
||||
@@ -65,6 +66,11 @@
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
/* Disable Reordering of rules - It is not required with the current functionality plus it's not working correctly even if someone wants to re-order */
|
||||
.cal-query-builder .rule--drag-handler {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cal-query-builder .rule--func--wrapper,
|
||||
.cal-query-builder .rule--func,
|
||||
.cal-query-builder .rule--func--args,
|
||||
@@ -95,7 +101,7 @@
|
||||
.cal-query-builder .widget--widget,
|
||||
.cal-query-builder .widget--valuesrc,
|
||||
.cal-query-builder .widget--sep {
|
||||
margin-left: 10px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.cal-query-builder .widget--valuesrc {
|
||||
@@ -113,7 +119,6 @@
|
||||
.cal-query-builder .group-or-rule-container {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
.cal-query-builder .rule {
|
||||
|
||||
+8
-9
@@ -1,4 +1,3 @@
|
||||
import { TrashIcon } from "@heroicons/react/solid";
|
||||
import { ChangeEvent } from "react";
|
||||
import {
|
||||
FieldProps,
|
||||
@@ -11,11 +10,10 @@ import {
|
||||
TextWidgetProps,
|
||||
} from "react-awesome-query-builder";
|
||||
|
||||
import { Button as CalButton } from "@calcom/ui";
|
||||
import { Input } from "@calcom/ui/form/fields";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Button as CalButton, TextArea, TextField, SelectWithValidation as Select } from "@calcom/ui/v2";
|
||||
|
||||
// import { mapListValues } from "../../../../utils/stuff";
|
||||
import { SelectWithValidation as Select } from "@components/ui/form/Select";
|
||||
|
||||
const TextAreaWidget = (props: TextWidgetProps) => {
|
||||
const { value, setValue, readonly, placeholder, maxLength, customProps, ...remainingProps } = props;
|
||||
@@ -27,7 +25,7 @@ const TextAreaWidget = (props: TextWidgetProps) => {
|
||||
|
||||
const textValue = value || "";
|
||||
return (
|
||||
<textarea
|
||||
<TextArea
|
||||
value={textValue}
|
||||
placeholder={placeholder}
|
||||
disabled={readonly}
|
||||
@@ -50,7 +48,8 @@ const TextWidget = (props: TextWidgetProps & { type?: string }) => {
|
||||
};
|
||||
const textValue = value || "";
|
||||
return (
|
||||
<input
|
||||
<TextField
|
||||
containerClassName="w-full"
|
||||
type={type}
|
||||
className="flex flex-grow border-gray-300 text-sm dark:border-gray-900 dark:bg-gray-700 dark:text-white dark:selection:bg-green-500 disabled:dark:text-gray-500"
|
||||
value={textValue}
|
||||
@@ -65,7 +64,7 @@ const TextWidget = (props: TextWidgetProps & { type?: string }) => {
|
||||
|
||||
function NumberWidget({ value, setValue, ...remainingProps }: NumberWidgetProps) {
|
||||
return (
|
||||
<Input
|
||||
<TextField
|
||||
name="query-builder"
|
||||
type="number"
|
||||
className="mt-0 border-gray-300 text-sm dark:border-gray-900 dark:bg-gray-700 dark:text-white dark:selection:bg-green-500 disabled:dark:text-gray-500"
|
||||
@@ -156,7 +155,7 @@ function Button({ type, label, onClick, readonly }: ButtonProps) {
|
||||
if (type === "delRule" || type == "delGroup") {
|
||||
return (
|
||||
<button className="ml-5">
|
||||
<TrashIcon className="m-0 h-4 w-4 text-neutral-500" onClick={onClick} />
|
||||
<Icon.FiTrash className="m-0 h-4 w-4 text-neutral-500" onClick={onClick} />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -170,10 +169,10 @@ function Button({ type, label, onClick, readonly }: ButtonProps) {
|
||||
}
|
||||
return (
|
||||
<CalButton
|
||||
StartIcon={Icon.FiPlus}
|
||||
data-testid={dataTestId}
|
||||
type="button"
|
||||
color="secondary"
|
||||
size="sm"
|
||||
disabled={readonly}
|
||||
onClick={onClick}>
|
||||
{label}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { App_RoutingForms_Form, User } from ".prisma/client";
|
||||
|
||||
export async function isAllowed({
|
||||
userId,
|
||||
formId,
|
||||
}: {
|
||||
userId: User["id"];
|
||||
formId: App_RoutingForms_Form["id"];
|
||||
}) {
|
||||
const form = await prisma.app_RoutingForms_Form.findUnique({
|
||||
where: {
|
||||
id: formId,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
if (!form) {
|
||||
// If form doesn't exist at all, then it's a creation and can be allowed.
|
||||
return true;
|
||||
}
|
||||
return form.userId === userId;
|
||||
}
|
||||
@@ -1,25 +1,29 @@
|
||||
import { ArrowDownIcon, ArrowUpIcon, CollectionIcon, PlusIcon, TrashIcon } from "@heroicons/react/solid";
|
||||
import { useRouter } from "next/router";
|
||||
import { App_RoutingForms_Form } from "@prisma/client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Controller, useFieldArray, useForm, UseFormReturn } from "react-hook-form";
|
||||
import { Controller, useFieldArray } from "react-hook-form";
|
||||
import { UseFormReturn } from "react-hook-form";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import showToast from "@calcom/lib/notification";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { AppGetServerSidePropsContext, AppPrisma, AppUser } from "@calcom/types/AppGetServerSideProps";
|
||||
import { BooleanToggleGroup, Button, EmptyScreen, Select } from "@calcom/ui";
|
||||
import { Form, TextArea } from "@calcom/ui/form/fields";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { Button, EmptyScreen, SelectField, TextAreaField, TextField, Shell } from "@calcom/ui/v2";
|
||||
import { BooleanToggleGroupField } from "@calcom/ui/v2/core/form/BooleanToggleGroup";
|
||||
import FormCard from "@calcom/ui/v2/core/form/FormCard";
|
||||
|
||||
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
|
||||
import EditableHeading from "@components/ui/EditableHeading";
|
||||
|
||||
import RoutingShell from "../../components/RoutingShell";
|
||||
import SideBar from "../../components/SideBar";
|
||||
import SingleForm from "../../components/SingleForm";
|
||||
import { getSerializableForm } from "../../lib/getSerializableForm";
|
||||
import { SerializableForm } from "../../types/types";
|
||||
|
||||
type RoutingForm = SerializableForm<App_RoutingForms_Form>;
|
||||
type RoutingFormWithResponseCount = RoutingForm & {
|
||||
_count: {
|
||||
responses: number;
|
||||
};
|
||||
};
|
||||
type HookForm = UseFormReturn<RoutingFormWithResponseCount>;
|
||||
export const FieldTypes = [
|
||||
{
|
||||
label: "Short Text",
|
||||
@@ -55,10 +59,12 @@ function Field({
|
||||
hookForm,
|
||||
hookFieldNamespace,
|
||||
deleteField,
|
||||
fieldIndex,
|
||||
moveUp,
|
||||
moveDown,
|
||||
}: {
|
||||
hookForm: UseFormReturn<inferSSRProps<typeof getServerSideProps>["form"]>;
|
||||
fieldIndex: number;
|
||||
hookForm: HookForm;
|
||||
hookFieldNamespace: `fields.${number}`;
|
||||
deleteField: {
|
||||
check: () => boolean;
|
||||
@@ -92,98 +98,63 @@ function Field({
|
||||
return (
|
||||
<div
|
||||
data-testid="field"
|
||||
className="group mb-4 flex w-full items-center justify-between hover:bg-neutral-50 ltr:mr-2 rtl:ml-2">
|
||||
{moveUp.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-1/2 -mt-4 mb-4 -ml-4 hidden h-7 w-7 scale-0 rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[19px] sm:ml-0 sm:block"
|
||||
onClick={() => moveUp.fn()}>
|
||||
<ArrowUpIcon />
|
||||
</button>
|
||||
) : null}
|
||||
|
||||
{moveDown.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-1/2 mt-8 -ml-4 hidden h-7 w-7 scale-0 rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[19px] sm:ml-0 sm:block"
|
||||
onClick={() => moveDown.fn()}>
|
||||
<ArrowDownIcon />
|
||||
</button>
|
||||
) : null}
|
||||
<div className="-mx-4 flex flex-1 items-center rounded-sm border border-neutral-200 bg-white p-4 sm:mx-0">
|
||||
className="group mb-4 flex w-full items-center justify-between ltr:mr-2 rtl:ml-2">
|
||||
<FormCard
|
||||
label={label || `Field ${fieldIndex + 1}`}
|
||||
moveUp={moveUp}
|
||||
moveDown={moveDown}
|
||||
deleteField={deleteField}>
|
||||
<div className="w-full">
|
||||
<div className="mt-2 block items-center sm:flex">
|
||||
<div className="min-w-48 mb-4 sm:mb-0">
|
||||
<label htmlFor="label" className="mt-0 flex text-sm font-medium text-neutral-700">
|
||||
Label
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="This is what your users would see"
|
||||
required
|
||||
{...hookForm.register(`${hookFieldNamespace}.label`)}
|
||||
className="block w-full rounded-sm border-gray-300 text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-6 w-full">
|
||||
<TextField
|
||||
label="Label"
|
||||
type="text"
|
||||
placeholder="This is what your users would see"
|
||||
required
|
||||
{...hookForm.register(`${hookFieldNamespace}.label`)}
|
||||
className="block w-full rounded-sm border-gray-300 text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2 block items-center sm:flex">
|
||||
<div className="min-w-48 mb-4 sm:mb-0">
|
||||
<label htmlFor="label" className="mt-0 flex text-sm font-medium text-neutral-700">
|
||||
Identifier
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<input
|
||||
type="text"
|
||||
required
|
||||
placeholder="Identifies field by this name."
|
||||
value={identifier}
|
||||
onChange={(e) => setUserChangedIdentifier(e.target.value)}
|
||||
className="block w-full rounded-sm border-gray-300 text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-6 w-full">
|
||||
<TextField
|
||||
label="Identifier"
|
||||
name="identifier"
|
||||
required
|
||||
placeholder="Identifies field by this name."
|
||||
value={identifier}
|
||||
onChange={(e) => setUserChangedIdentifier(e.target.value)}
|
||||
className="block w-full rounded-sm border-gray-300 text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2 block items-center sm:flex">
|
||||
<div className="min-w-48 mb-4 sm:mb-0">
|
||||
<label htmlFor="label" className="mt-0 flex text-sm font-medium text-neutral-700">
|
||||
Type
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<Controller
|
||||
name={`${hookFieldNamespace}.type`}
|
||||
control={hookForm.control}
|
||||
render={({ field: { value, onChange } }) => {
|
||||
const defaultValue = FieldTypes.find((fieldType) => fieldType.value === value);
|
||||
return (
|
||||
<Select
|
||||
className="data-testid-field-type"
|
||||
options={FieldTypes}
|
||||
onChange={(option) => {
|
||||
if (!option) {
|
||||
return;
|
||||
}
|
||||
onChange(option.value);
|
||||
}}
|
||||
defaultValue={defaultValue}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-6 w-full ">
|
||||
<Controller
|
||||
name={`${hookFieldNamespace}.type`}
|
||||
control={hookForm.control}
|
||||
render={({ field: { value, onChange } }) => {
|
||||
const defaultValue = FieldTypes.find((fieldType) => fieldType.value === value);
|
||||
return (
|
||||
<SelectField
|
||||
label="Type"
|
||||
containerClassName="data-testid-field-type"
|
||||
options={FieldTypes}
|
||||
onChange={(option) => {
|
||||
if (!option) {
|
||||
return;
|
||||
}
|
||||
onChange(option.value);
|
||||
}}
|
||||
defaultValue={defaultValue}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{["select", "multiselect"].includes(hookForm.watch(`${hookFieldNamespace}.type`)) ? (
|
||||
<div className="mt-2 block items-center sm:flex">
|
||||
<div className="min-w-48 mb-4 sm:mb-0">
|
||||
<label htmlFor="label" className="mt-0 flex text-sm font-medium text-neutral-700">
|
||||
Options
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="w-full">
|
||||
<TextArea
|
||||
<TextAreaField
|
||||
rows={3}
|
||||
label="Options"
|
||||
placeholder="Add 1 option per line"
|
||||
{...hookForm.register(`${hookFieldNamespace}.selectText`)}
|
||||
/>
|
||||
@@ -191,68 +162,28 @@ function Field({
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="mt-2 block items-center sm:flex">
|
||||
<div className="min-w-48 mb-4 sm:mb-0">
|
||||
<label htmlFor="label" className="mt-0 flex text-sm font-medium text-neutral-700">
|
||||
Required
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<Controller
|
||||
name={`${hookFieldNamespace}.required`}
|
||||
control={hookForm.control}
|
||||
render={({ field: { value, onChange } }) => {
|
||||
return <BooleanToggleGroup value={value} onValueChange={onChange} />;
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<Controller
|
||||
name={`${hookFieldNamespace}.required`}
|
||||
control={hookForm.control}
|
||||
render={({ field: { value, onChange } }) => {
|
||||
return <BooleanToggleGroupField label="Required" value={value} onValueChange={onChange} />;
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{deleteField.check() ? (
|
||||
<button
|
||||
className="float-right ml-5"
|
||||
onClick={() => {
|
||||
deleteField.fn();
|
||||
}}
|
||||
color="secondary">
|
||||
<TrashIcon className="h-4 w-4 text-gray-400" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</FormCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function FormEdit({
|
||||
const FormEdit = ({
|
||||
hookForm,
|
||||
form,
|
||||
appUrl,
|
||||
}: inferSSRProps<typeof getServerSideProps> & { appUrl: string }) {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useContext();
|
||||
const router = useRouter();
|
||||
const mutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
onError() {
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
onSettled() {
|
||||
utils.invalidateQueries([
|
||||
"viewer.app_routing_forms.form",
|
||||
{
|
||||
id: form.id,
|
||||
},
|
||||
]);
|
||||
},
|
||||
onSuccess() {
|
||||
showToast(`Form updated successfully.`, "success");
|
||||
router.replace(router.asPath);
|
||||
},
|
||||
});
|
||||
|
||||
}: {
|
||||
hookForm: HookForm;
|
||||
form: inferSSRProps<typeof getServerSideProps>["form"];
|
||||
}) => {
|
||||
const fieldsNamespace = "fields";
|
||||
const hookForm = useForm({
|
||||
defaultValues: form,
|
||||
});
|
||||
|
||||
const {
|
||||
fields: hookFormFields,
|
||||
append: appendHookFormField,
|
||||
@@ -265,10 +196,6 @@ export default function FormEdit({
|
||||
name: fieldsNamespace,
|
||||
});
|
||||
|
||||
// hookForm.reset(form);
|
||||
if (!form.fields) {
|
||||
form.fields = [];
|
||||
}
|
||||
const addField = () => {
|
||||
appendHookFormField({
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
@@ -280,116 +207,89 @@ export default function FormEdit({
|
||||
});
|
||||
};
|
||||
|
||||
// hookForm.reset(form);
|
||||
if (!form.fields) {
|
||||
form.fields = [];
|
||||
}
|
||||
return hookFormFields.length ? (
|
||||
<div className="flex flex-col-reverse lg:flex-row">
|
||||
<div className="w-full ltr:mr-2 rtl:ml-2">
|
||||
<div className="flex w-full flex-col">
|
||||
{hookFormFields.map((field, key) => {
|
||||
return (
|
||||
<Field
|
||||
fieldIndex={key}
|
||||
hookForm={hookForm}
|
||||
hookFieldNamespace={`${fieldsNamespace}.${key}`}
|
||||
deleteField={{
|
||||
check: () => hookFormFields.length > 1,
|
||||
fn: () => {
|
||||
removeHookFormField(key);
|
||||
},
|
||||
}}
|
||||
moveUp={{
|
||||
check: () => key !== 0,
|
||||
fn: () => {
|
||||
swapHookFormField(key, key - 1);
|
||||
},
|
||||
}}
|
||||
moveDown={{
|
||||
check: () => key !== hookFormFields.length - 1,
|
||||
fn: () => {
|
||||
if (key === hookFormFields.length - 1) {
|
||||
return;
|
||||
}
|
||||
swapHookFormField(key, key + 1);
|
||||
},
|
||||
}}
|
||||
key={key}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{hookFormFields.length ? (
|
||||
<div className={classNames("flex")}>
|
||||
<Button
|
||||
data-testid="add-field"
|
||||
type="button"
|
||||
StartIcon={Icon.FiPlus}
|
||||
color="secondary"
|
||||
onClick={addField}>
|
||||
Add Field
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<button data-testid="add-field" onClick={addField} className="w-full">
|
||||
<EmptyScreen
|
||||
Icon={Icon.FiFileText}
|
||||
headline="Create your first field"
|
||||
description="Fields are the form fields that the booker would see."
|
||||
buttonRaw={<Button>Create Field</Button>}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
export default function FormEditPage({
|
||||
form,
|
||||
appUrl,
|
||||
}: inferSSRProps<typeof getServerSideProps> & { appUrl: string }) {
|
||||
return (
|
||||
<RoutingShell
|
||||
<SingleForm
|
||||
form={form}
|
||||
appUrl={appUrl}
|
||||
heading={
|
||||
<EditableHeading
|
||||
title={hookForm.watch("name")}
|
||||
onChange={(value) => {
|
||||
hookForm.setValue("name", value);
|
||||
}}
|
||||
/>
|
||||
}>
|
||||
{hookFormFields.length ? (
|
||||
<div className="flex flex-col-reverse lg:flex-row">
|
||||
<Form
|
||||
className="w-full max-w-4xl ltr:mr-2 rtl:ml-2 md:w-9/12"
|
||||
form={hookForm}
|
||||
handleSubmit={(data) => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
mutation.mutate({
|
||||
...data,
|
||||
});
|
||||
}}>
|
||||
<div className="mb-5">
|
||||
<h3 className="mb-2 text-base font-medium leading-6 text-gray-900">Description</h3>
|
||||
<div className="w-full">
|
||||
<textarea
|
||||
id="description"
|
||||
data-testid="description"
|
||||
className="block w-full rounded-sm border-gray-300 text-sm "
|
||||
placeholder="Form Description"
|
||||
{...hookForm.register("description")}
|
||||
defaultValue={form.description || ""}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<hr className="mb-5 border-neutral-200" />
|
||||
<h3 className="mb-2 text-base font-medium leading-6 text-gray-900">Fields</h3>
|
||||
<div className="flex flex-col">
|
||||
{hookFormFields.map((field, key) => {
|
||||
return (
|
||||
<Field
|
||||
hookForm={hookForm}
|
||||
hookFieldNamespace={`${fieldsNamespace}.${key}`}
|
||||
deleteField={{
|
||||
check: () => hookFormFields.length > 1,
|
||||
fn: () => {
|
||||
removeHookFormField(key);
|
||||
},
|
||||
}}
|
||||
moveUp={{
|
||||
check: () => key !== 0,
|
||||
fn: () => {
|
||||
swapHookFormField(key, key - 1);
|
||||
},
|
||||
}}
|
||||
moveDown={{
|
||||
check: () => key !== hookFormFields.length - 1,
|
||||
fn: () => {
|
||||
if (key === hookFormFields.length - 1) {
|
||||
return;
|
||||
}
|
||||
swapHookFormField(key, key + 1);
|
||||
},
|
||||
}}
|
||||
key={key}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{hookFormFields.length ? (
|
||||
<div className={classNames("flex")}>
|
||||
<Button
|
||||
data-testid="add-field"
|
||||
type="button"
|
||||
StartIcon={PlusIcon}
|
||||
color="secondary"
|
||||
onClick={addField}>
|
||||
Add Field
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
{hookFormFields.length ? (
|
||||
<div className="mt-4 flex justify-end space-x-2 rtl:space-x-reverse">
|
||||
<Button href="/apps/routing_forms/forms" color="secondary" tabIndex={-1}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
<Button type="submit" data-testid="update-form" disabled={mutation.isLoading}>
|
||||
{t("update")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</Form>
|
||||
<SideBar form={form} appUrl={appUrl} />
|
||||
</div>
|
||||
) : (
|
||||
<button data-testid="add-field" onClick={addField} className="w-full">
|
||||
<EmptyScreen
|
||||
Icon={CollectionIcon}
|
||||
headline="Create your first field"
|
||||
description="Fields are the form fields that the booker would see."
|
||||
button={<Button>Create Field</Button>}
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</RoutingShell>
|
||||
Page={({ hookForm, form }) => <FormEdit hookForm={hookForm} form={form} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
FormEditPage.getLayout = (page: React.ReactElement) => {
|
||||
return <Shell withoutMain={true}>{page}</Shell>;
|
||||
};
|
||||
|
||||
export const getServerSideProps = async function getServerSideProps(
|
||||
context: AppGetServerSidePropsContext,
|
||||
prisma: AppPrisma,
|
||||
@@ -415,10 +315,24 @@ export const getServerSideProps = async function getServerSideProps(
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
const isAllowed = (await import("../../lib/isAllowed")).isAllowed;
|
||||
if (!(await isAllowed({ userId: user.id, formId }))) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const form = await prisma.app_RoutingForms_Form.findUnique({
|
||||
where: {
|
||||
id: formId,
|
||||
},
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
responses: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!form) {
|
||||
|
||||
@@ -1,363 +1,166 @@
|
||||
// TODO: i18n
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { z } from "zod";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import showToast from "@calcom/lib/notification";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { AppGetServerSidePropsContext, AppPrisma, AppUser } from "@calcom/types/AppGetServerSideProps";
|
||||
import { Button, EmptyScreen, Tooltip } from "@calcom/ui";
|
||||
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
||||
import { Dialog, DialogClose, DialogContent } from "@calcom/ui/Dialog";
|
||||
import Dropdown, {
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@calcom/ui/Dropdown";
|
||||
import { CollectionIcon, Icon } from "@calcom/ui/Icon";
|
||||
import Shell from "@calcom/ui/Shell";
|
||||
import { Form, TextField } from "@calcom/ui/form/fields";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { DropdownMenuSeparator, Tooltip } from "@calcom/ui/v2";
|
||||
import { EmptyScreen } from "@calcom/ui/v2";
|
||||
import { Badge } from "@calcom/ui/v2";
|
||||
import { List, ListLinkItem } from "@calcom/ui/v2/core/List";
|
||||
import Shell, { ShellMain } from "@calcom/ui/v2/core/Shell";
|
||||
|
||||
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
|
||||
import { EmbedButton, EmbedDialog } from "@components/Embed";
|
||||
|
||||
import { FormAction, FormActionsDropdown, FormActionsProvider } from "../../components/FormActions";
|
||||
import { getSerializableForm } from "../../lib/getSerializableForm";
|
||||
|
||||
const newFormModalQuerySchema = z.object({
|
||||
action: z.string(),
|
||||
target: z.string().optional(),
|
||||
});
|
||||
|
||||
function NewFormDialog({ appUrl }: { appUrl: string }) {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useContext();
|
||||
const router = useRouter();
|
||||
|
||||
const hookForm = useForm<{
|
||||
name: string;
|
||||
description: string;
|
||||
}>();
|
||||
|
||||
const { action, target } = router.query as z.infer<typeof newFormModalQuerySchema>;
|
||||
const mutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
onSuccess: (_data, variables) => {
|
||||
utils.invalidateQueries("viewer.app_routing_forms.forms");
|
||||
router.push(`${appUrl}/form-edit/${variables.id}`);
|
||||
},
|
||||
onError: () => {
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
});
|
||||
const { register } = hookForm;
|
||||
return (
|
||||
<Dialog name="new-form" clearQueryParamsOnClose={["target", "action"]}>
|
||||
<DialogContent className="overflow-y-auto">
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-bold leading-6 text-gray-900" id="modal-title">
|
||||
Add New Form
|
||||
</h3>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500">Create your form to route a booker</p>
|
||||
</div>
|
||||
</div>
|
||||
<Form
|
||||
form={hookForm}
|
||||
handleSubmit={(values) => {
|
||||
const formId = uuidv4();
|
||||
|
||||
mutation.mutate({
|
||||
id: formId,
|
||||
...values,
|
||||
addFallback: true,
|
||||
duplicateFrom: action === "duplicate" ? target : null,
|
||||
});
|
||||
}}>
|
||||
<div className="mt-3 space-y-4">
|
||||
<TextField label={t("title")} required placeholder="A Routing Form" {...register("name")} />
|
||||
<div className="mb-5">
|
||||
<h3 className="mb-2 text-base font-medium leading-6 text-gray-900">Description</h3>
|
||||
<div className="w-full">
|
||||
<textarea
|
||||
id="description"
|
||||
data-testid="description"
|
||||
className="block w-full rounded-sm border-gray-300 text-sm "
|
||||
placeholder="Form Description"
|
||||
{...register("description")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-8 flex flex-row-reverse gap-x-2">
|
||||
<Button data-testid="add-form" type="submit">
|
||||
{t("continue")}
|
||||
</Button>
|
||||
<DialogClose asChild>
|
||||
<Button color="secondary">{t("cancel")}</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default function RoutingForms({
|
||||
forms,
|
||||
appUrl,
|
||||
}: inferSSRProps<typeof getServerSideProps> & { appUrl: string }) {
|
||||
const router = useRouter();
|
||||
|
||||
const openModal = (option: { target?: string; action: string }) => {
|
||||
const query = {
|
||||
...router.query,
|
||||
dialog: "new-form",
|
||||
...option,
|
||||
};
|
||||
router.push(
|
||||
{
|
||||
pathname: router.pathname,
|
||||
query,
|
||||
},
|
||||
undefined,
|
||||
{ shallow: true }
|
||||
);
|
||||
};
|
||||
const deleteMutation = trpc.useMutation("viewer.app_routing_forms.deleteForm", {
|
||||
onSuccess: () => {
|
||||
showToast("Form deleted", "success");
|
||||
setDeleteDialogOpen(false);
|
||||
router.replace(router.asPath);
|
||||
},
|
||||
onSettled: () => {
|
||||
utils.invalidateQueries(["viewer.app_routing_forms.forms"]);
|
||||
setDeleteDialogOpen(false);
|
||||
},
|
||||
onError: () => {
|
||||
showToast("Something went wrong", "error");
|
||||
},
|
||||
});
|
||||
const utils = trpc.useContext();
|
||||
const { t } = useLocale();
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [deleteDialogFormId, setDeleteDialogFormId] = useState<string | null>(null);
|
||||
|
||||
function NewFormButton() {
|
||||
return (
|
||||
<Button
|
||||
onClick={() => openModal({ action: "new" })}
|
||||
data-testid="new-routing-form"
|
||||
StartIcon={Icon.FiPlus}>
|
||||
<FormAction routingForm={null} data-testid="new-routing-form" StartIcon={Icon.FiPlus} action="create">
|
||||
New Form
|
||||
</Button>
|
||||
</FormAction>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Shell
|
||||
<ShellMain
|
||||
heading="Routing Forms"
|
||||
CTA={<NewFormButton />}
|
||||
subtitle="You can see all routing forms and create one here.">
|
||||
<div className="-mx-4 md:-mx-8">
|
||||
<div className="mb-10 w-full bg-gray-50 px-4 pb-2 sm:px-6 md:px-8">
|
||||
{!forms.length ? (
|
||||
<EmptyScreen
|
||||
Icon={CollectionIcon}
|
||||
headline="Create your first form"
|
||||
description="Forms enable you to allow a booker to connect with the right person or choose the right event, faster. It would work by taking inputs from the booker and using that data to route to the correct booker/event as configured by Cal user"
|
||||
button={<NewFormButton />}
|
||||
/>
|
||||
) : null}
|
||||
{forms.length ? (
|
||||
<div className="-mx-4 mb-16 overflow-hidden rounded-sm border border-gray-200 bg-white sm:mx-0">
|
||||
<ul data-testid="routing-forms-list" className="divide-y divide-neutral-200">
|
||||
{forms.map((form, index) => {
|
||||
if (!form) {
|
||||
return null;
|
||||
}
|
||||
const embedLink = `forms/${form.id}`;
|
||||
const formLink = `${CAL_URL}/${embedLink}`;
|
||||
const description = form.description || "";
|
||||
const disabled = form.disabled;
|
||||
form.routes = form.routes || [];
|
||||
const fields = form.fields || [];
|
||||
return (
|
||||
<li key={index}>
|
||||
<div
|
||||
className={classNames(
|
||||
"flex items-center justify-between hover:bg-neutral-50",
|
||||
disabled ? "hover:bg-white" : ""
|
||||
)}>
|
||||
<div
|
||||
className={classNames(
|
||||
"group flex w-full items-center justify-between px-4 py-4 hover:bg-neutral-50 sm:px-6",
|
||||
disabled ? "hover:bg-white" : ""
|
||||
)}>
|
||||
<Link href={appUrl + "/form-edit/" + form.id}>
|
||||
<a
|
||||
className={classNames(
|
||||
"flex-grow truncate text-sm",
|
||||
disabled ? "pointer-events-none cursor-not-allowed opacity-30" : ""
|
||||
)}>
|
||||
<div className="font-medium text-neutral-900 ltr:mr-1 rtl:ml-1">
|
||||
{form.name}
|
||||
</div>
|
||||
<div className="text-neutral-500 dark:text-white">
|
||||
<h2 className="max-w-[280px] overflow-hidden text-ellipsis pb-2 opacity-60 sm:max-w-[500px]">
|
||||
{description.substring(0, 100)}
|
||||
{description.length > 100 && "..."}
|
||||
</h2>
|
||||
<div className="mt-2 text-neutral-500 dark:text-white">
|
||||
{fields.length} fields, {form.routes.length} routes &{" "}
|
||||
{form._count.responses} Responses
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</Link>
|
||||
<div className="mt-4 hidden flex-shrink-0 sm:mt-0 sm:ml-5 sm:flex">
|
||||
<div
|
||||
className={classNames(
|
||||
"flex justify-between space-x-2 rtl:space-x-reverse ",
|
||||
disabled && "pointer-events-none cursor-not-allowed"
|
||||
)}>
|
||||
<Tooltip content={t("preview") as string}>
|
||||
<Button
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(!disabled && "group-hover:text-black")}
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
href={formLink}
|
||||
/>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content={t("copy_link") as string}>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(disabled && " opacity-30")}
|
||||
StartIcon={Icon.FiLink}
|
||||
onClick={() => {
|
||||
showToast(t("link_copied"), "success");
|
||||
navigator.clipboard.writeText(formLink);
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(disabled && " opacity-30")}
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Link href={appUrl + "/form-edit/" + form.id} passHref={true}>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
disabled={disabled}
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiEdit2}>
|
||||
{t("edit") as string}
|
||||
</Button>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
className="w-full rounded-none"
|
||||
data-testid={"routing-form-duplicate-" + form.id}
|
||||
StartIcon={Icon.FiCopy}
|
||||
onClick={() => openModal({ action: "duplicate", target: form.id })}>
|
||||
{t("duplicate") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<EmbedButton
|
||||
as={Button}
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiCode}
|
||||
className={classNames(
|
||||
"w-full rounded-none",
|
||||
"outline-none",
|
||||
disabled && " pointer-events-none cursor-not-allowed opacity-30"
|
||||
)}
|
||||
embedUrl={encodeURIComponent(embedLink)}>
|
||||
{t("embed")}
|
||||
</EmbedButton>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<DropdownMenuItem>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogFormId(form.id);
|
||||
}}
|
||||
color="warn"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
{t("delete")}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<EmbedDialog />
|
||||
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
|
||||
<ConfirmationDialogContent
|
||||
isLoading={deleteMutation.isLoading}
|
||||
variety="danger"
|
||||
title="Delete Form"
|
||||
confirmBtnText="Yes, delete Form"
|
||||
loadingText="Yes, delete Form"
|
||||
onConfirm={(e) => {
|
||||
if (!deleteDialogFormId) {
|
||||
return;
|
||||
<FormActionsProvider appUrl={appUrl}>
|
||||
<div className="-mx-4 md:-mx-8">
|
||||
<div className="mb-10 w-full px-4 pb-2 sm:px-6 md:px-8">
|
||||
{!forms.length ? (
|
||||
<EmptyScreen
|
||||
Icon={Icon.FiGitMerge}
|
||||
headline="Create your first form"
|
||||
description="Forms enable you to allow a booker to connect with the right person or choose the right event, faster. It would work by taking inputs from the booker and using that data to route to the correct booker/event as configured by Cal user"
|
||||
buttonRaw={<NewFormButton />}
|
||||
/>
|
||||
) : null}
|
||||
{forms.length ? (
|
||||
<div className="-mx-4 mb-16 overflow-hidden bg-white sm:mx-0">
|
||||
<List data-testid="routing-forms-list">
|
||||
{forms.map((form, index) => {
|
||||
if (!form) {
|
||||
return null;
|
||||
}
|
||||
e.preventDefault();
|
||||
deleteMutation.mutate({
|
||||
id: deleteDialogFormId,
|
||||
});
|
||||
}}>
|
||||
Are you sure you want to delete this form? Anyone who you've shared the link with will
|
||||
no longer be able to book using it. Also, all associated responses would be deleted.
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
) : null}
|
||||
<NewFormDialog appUrl={appUrl} />
|
||||
|
||||
const description = form.description || "";
|
||||
const disabled = form.disabled;
|
||||
form.routes = form.routes || [];
|
||||
const fields = form.fields || [];
|
||||
return (
|
||||
<ListLinkItem
|
||||
key={index}
|
||||
href={appUrl + "/form-edit/" + form.id}
|
||||
heading={form.name}
|
||||
disabled={disabled}
|
||||
subHeading={description}
|
||||
actions={
|
||||
<>
|
||||
<FormAction
|
||||
className="self-center border-r-2 border-gray-300 pr-5 "
|
||||
action="toggle"
|
||||
routingForm={form}
|
||||
/>
|
||||
<Tooltip content={t("preview")}>
|
||||
<FormAction
|
||||
action="preview"
|
||||
className="ml-3"
|
||||
routingForm={form}
|
||||
target="_blank"
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
color="minimal"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
/>
|
||||
</Tooltip>
|
||||
<FormAction
|
||||
routingForm={form}
|
||||
action="copyLink"
|
||||
color="minimal"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiLink}
|
||||
disabled={disabled}
|
||||
tooltip={t("copy_link")}
|
||||
/>
|
||||
|
||||
<FormActionsDropdown form={form}>
|
||||
<FormAction
|
||||
action="edit"
|
||||
routingForm={form}
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiEdit}>
|
||||
{t("edit")}
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="download"
|
||||
routingForm={form}
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiDownload}>
|
||||
Download Responses
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="embed"
|
||||
routingForm={form}
|
||||
color="minimal"
|
||||
className="w-full"
|
||||
StartIcon={Icon.FiCode}>
|
||||
{t("embed")}
|
||||
</FormAction>
|
||||
<FormAction
|
||||
action="duplicate"
|
||||
routingForm={form}
|
||||
color="minimal"
|
||||
className="w-full"
|
||||
StartIcon={Icon.FiCopy}>
|
||||
{t("duplicate")}
|
||||
</FormAction>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<FormAction
|
||||
action="_delete"
|
||||
routingForm={form}
|
||||
color="destructive"
|
||||
className="w-full"
|
||||
StartIcon={Icon.FiTrash}>
|
||||
{t("delete")}
|
||||
</FormAction>
|
||||
</FormActionsDropdown>
|
||||
</>
|
||||
}>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<Badge variant="gray" StartIcon={Icon.FiMenu}>
|
||||
{fields.length} {fields.length === 1 ? "field" : "fields"}
|
||||
</Badge>
|
||||
<Badge variant="gray" StartIcon={Icon.FiGitMerge}>
|
||||
{form.routes.length} {form.routes.length === 1 ? "route" : "routes"}
|
||||
</Badge>
|
||||
<Badge variant="gray" StartIcon={Icon.FiMessageCircle}>
|
||||
{form._count.responses} {form._count.responses === 1 ? "response" : "responses"}
|
||||
</Badge>
|
||||
</div>
|
||||
</ListLinkItem>
|
||||
);
|
||||
})}
|
||||
</List>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Shell>
|
||||
</FormActionsProvider>
|
||||
</ShellMain>
|
||||
);
|
||||
}
|
||||
|
||||
RoutingForms.getLayout = (page: React.ReactElement) => {
|
||||
return <Shell withoutMain={true}>{page}</Shell>;
|
||||
};
|
||||
|
||||
export const getServerSideProps = async function getServerSideProps(
|
||||
context: AppGetServerSidePropsContext,
|
||||
prisma: AppPrisma,
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
import { PlusIcon, TrashIcon, ArrowUpIcon, ArrowDownIcon } from "@heroicons/react/solid";
|
||||
import { useRouter } from "next/router";
|
||||
import { App_RoutingForms_Form } from "@prisma/client";
|
||||
import React, { useState, useCallback } from "react";
|
||||
import { Query, Config, Builder, Utils as QbUtils } from "react-awesome-query-builder";
|
||||
// types
|
||||
import { JsonTree, ImmutableTree, BuilderProps } from "react-awesome-query-builder";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import showToast from "@calcom/lib/notification";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { AppGetServerSidePropsContext, AppPrisma, AppUser } from "@calcom/types/AppGetServerSideProps";
|
||||
import { inferSSRProps } from "@calcom/types/inferSSRProps";
|
||||
import { Button } from "@calcom/ui";
|
||||
import { Label } from "@calcom/ui/form/fields";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { Button, TextField, SelectWithValidation as Select, TextArea, Shell } from "@calcom/ui/v2";
|
||||
import FormCard from "@calcom/ui/v2/core/form/FormCard";
|
||||
|
||||
import EditableHeading from "@components/ui/EditableHeading";
|
||||
import { SelectWithValidation as Select } from "@components/ui/form/Select";
|
||||
|
||||
import RoutingShell from "../../components/RoutingShell";
|
||||
import SideBar from "../../components/SideBar";
|
||||
import SingleForm from "../../components/SingleForm";
|
||||
import QueryBuilderInitialConfig from "../../components/react-awesome-query-builder/config/config";
|
||||
import "../../components/react-awesome-query-builder/styles.css";
|
||||
import { getSerializableForm } from "../../lib/getSerializableForm";
|
||||
import { SerializableForm } from "../../types/types";
|
||||
import { FieldTypes } from "../form-edit/[...appPages]";
|
||||
|
||||
type RoutingForm = SerializableForm<App_RoutingForms_Form>;
|
||||
|
||||
const InitialConfig = QueryBuilderInitialConfig;
|
||||
const hasRules = (route: Route) =>
|
||||
route.queryValue.children1 && Object.keys(route.queryValue.children1).length;
|
||||
type QueryBuilderUpdatedConfig = typeof QueryBuilderInitialConfig & { fields: Config["fields"] };
|
||||
export function getQueryBuilderConfig(form: inferSSRProps<typeof getServerSideProps>["form"]) {
|
||||
export function getQueryBuilderConfig(form: RoutingForm) {
|
||||
const fields: Record<
|
||||
string,
|
||||
{
|
||||
@@ -189,34 +186,31 @@ const Route = ({
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="group mb-4 flex w-full flex-row items-center justify-between hover:bg-neutral-50 ltr:mr-2 rtl:ml-2">
|
||||
{!route.isFallback ? (
|
||||
<>
|
||||
{moveUp?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-1/2 -mt-4 mb-4 -ml-4 hidden h-7 w-7 scale-0 rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[19px] sm:ml-0 sm:block"
|
||||
onClick={() => moveUp?.fn()}>
|
||||
<ArrowUpIcon />
|
||||
</button>
|
||||
) : null}
|
||||
{moveDown?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-1/2 mt-8 -ml-4 hidden h-7 w-7 scale-0 rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:left-[19px] sm:ml-0 sm:block"
|
||||
onClick={() => moveDown?.fn()}>
|
||||
<ArrowDownIcon />
|
||||
</button>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
<div className="-mx-4 mb-4 flex w-full items-center rounded-sm border border-neutral-200 bg-white p-4 sm:mx-0">
|
||||
<FormCard
|
||||
className="mb-6"
|
||||
moveUp={moveUp}
|
||||
moveDown={moveDown}
|
||||
label={route.isFallback ? "Fallback Route" : `Route ${index + 1}`}
|
||||
deleteField={{
|
||||
check: () => routes.length !== 1 && !route.isFallback,
|
||||
fn: () => (
|
||||
<button className="ml-5" type="button">
|
||||
<Icon.FiTrash
|
||||
className="m-0 h-4 w-4 text-neutral-500"
|
||||
onClick={() => {
|
||||
const newRoutes = routes.filter((r) => r.id !== route.id);
|
||||
setRoutes(newRoutes);
|
||||
}}
|
||||
/>
|
||||
</button>
|
||||
),
|
||||
}}>
|
||||
<div className="-mx-4 mb-4 flex w-full items-center sm:mx-0">
|
||||
<div className="cal-query-builder w-full ">
|
||||
<div>
|
||||
<div className="flex w-full items-center text-sm text-gray-900">
|
||||
<div className="flex flex-grow-0 whitespace-nowrap">
|
||||
<Label>{route.isFallback ? "Fallback Route" : `Route ${index + 1}`}</Label>
|
||||
<span>: Send Booker to</span>
|
||||
<span>Send Booker to</span>
|
||||
</div>
|
||||
<Select
|
||||
className="block w-full flex-grow px-2"
|
||||
@@ -243,8 +237,9 @@ const Route = ({
|
||||
/>
|
||||
{route.action.type ? (
|
||||
route.action.type === "customPageMessage" ? (
|
||||
<textarea
|
||||
<TextArea
|
||||
required
|
||||
name="customPageMessage"
|
||||
className="flex w-full flex-grow border-gray-300"
|
||||
value={route.action.value}
|
||||
onChange={(e) => {
|
||||
@@ -252,7 +247,8 @@ const Route = ({
|
||||
}}
|
||||
/>
|
||||
) : route.action.type === "externalRedirectUrl" ? (
|
||||
<input
|
||||
<TextField
|
||||
name="externalRedirectUrl"
|
||||
className="flex w-full flex-grow border-gray-300 text-sm"
|
||||
type="text"
|
||||
required
|
||||
@@ -278,17 +274,6 @@ const Route = ({
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
{routes.length !== 1 && !route.isFallback ? (
|
||||
<button className="ml-5" type="button">
|
||||
<TrashIcon
|
||||
className="m-0 h-4 w-4 text-neutral-500"
|
||||
onClick={() => {
|
||||
const newRoutes = routes.filter((r) => r.id !== route.id);
|
||||
setRoutes(newRoutes);
|
||||
}}
|
||||
/>
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{((route.isFallback && hasRules(route)) || !route.isFallback) && (
|
||||
@@ -307,7 +292,7 @@ const Route = ({
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</FormCard>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -323,14 +308,14 @@ const deserializeRoute = (route: SerializableRoute, config: QueryBuilderUpdatedC
|
||||
|
||||
const Routes = ({
|
||||
form,
|
||||
appUrl,
|
||||
hookForm,
|
||||
}: {
|
||||
form: inferSSRProps<typeof getServerSideProps>["form"];
|
||||
appUrl: string;
|
||||
// Figure out the type
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
hookForm: any;
|
||||
}) => {
|
||||
const { routes: serializedRoutes } = form;
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const config = getQueryBuilderConfig(form);
|
||||
const [routes, setRoutes] = useState(() => {
|
||||
const transformRoutes = () => {
|
||||
@@ -346,15 +331,6 @@ const Routes = ({
|
||||
return transformRoutes().map((route) => deserializeRoute(route, config));
|
||||
});
|
||||
|
||||
const mutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
onSuccess: () => {
|
||||
showToast("Form routes saved successfully.", "success");
|
||||
router.replace(router.asPath);
|
||||
},
|
||||
onError: () => {
|
||||
showToast("Something went wrong", "error");
|
||||
},
|
||||
});
|
||||
const mainRoutes = routes.filter((route) => !route.isFallback);
|
||||
let fallbackRoute = routes.find((route) => route.isFallback);
|
||||
if (!fallbackRoute) {
|
||||
@@ -390,25 +366,16 @@ const Routes = ({
|
||||
});
|
||||
};
|
||||
|
||||
const routesToSave: SerializableRoute[] = routes.map((route) => ({
|
||||
id: route.id,
|
||||
action: route.action,
|
||||
isFallback: route.isFallback,
|
||||
queryValue: route.queryValue,
|
||||
}));
|
||||
hookForm.setValue("routes", routesToSave);
|
||||
return (
|
||||
<div className="flex flex-col-reverse md:flex-row">
|
||||
<form
|
||||
className="w-full max-w-4xl ltr:mr-2 rtl:ml-2 md:w-9/12"
|
||||
onSubmit={(e) => {
|
||||
const serializedRoutes: SerializableRoute[] = routes.map((route) => ({
|
||||
id: route.id,
|
||||
action: route.action,
|
||||
isFallback: route.isFallback,
|
||||
queryValue: route.queryValue,
|
||||
}));
|
||||
|
||||
const updatedForm = {
|
||||
...form,
|
||||
routes: serializedRoutes,
|
||||
};
|
||||
mutation.mutate(updatedForm);
|
||||
e.preventDefault();
|
||||
}}>
|
||||
<div className="w-full ltr:mr-2 rtl:ml-2">
|
||||
{mainRoutes.map((route, key) => {
|
||||
return (
|
||||
<Route
|
||||
@@ -436,10 +403,9 @@ const Routes = ({
|
||||
})}
|
||||
<Button
|
||||
type="button"
|
||||
className="mb-8"
|
||||
className="mb-6"
|
||||
color="secondary"
|
||||
StartIcon={PlusIcon}
|
||||
size="sm"
|
||||
StartIcon={Icon.FiPlus}
|
||||
data-testid="add-route"
|
||||
onClick={() => {
|
||||
const newEmptyRoute = getEmptyRoute();
|
||||
@@ -455,7 +421,7 @@ const Routes = ({
|
||||
];
|
||||
setRoutes(newRoutes);
|
||||
}}>
|
||||
Add New Route
|
||||
Add Route
|
||||
</Button>
|
||||
<div>
|
||||
<Route
|
||||
@@ -466,16 +432,7 @@ const Routes = ({
|
||||
setRoutes={setRoutes}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-4 flex justify-end space-x-2 rtl:space-x-reverse">
|
||||
<Button href="/apps/routing_forms/forms" color="secondary" tabIndex={-1}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
<Button type="submit" disabled={mutation.isLoading}>
|
||||
{t("update")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
<SideBar form={form} appUrl={appUrl} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -485,17 +442,22 @@ export default function RouteBuilder({
|
||||
appUrl,
|
||||
}: inferSSRProps<typeof getServerSideProps> & { appUrl: string }) {
|
||||
return (
|
||||
<RoutingShell
|
||||
<SingleForm
|
||||
form={form}
|
||||
appUrl={appUrl}
|
||||
heading={<EditableHeading title={form?.name} readOnly={true} />}
|
||||
form={form}>
|
||||
<div className="route-config">
|
||||
<Routes form={form} appUrl={appUrl} />
|
||||
</div>
|
||||
</RoutingShell>
|
||||
Page={({ hookForm, form }) => (
|
||||
<div className="route-config">
|
||||
<Routes hookForm={hookForm} form={form} />
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
RouteBuilder.getLayout = (page: React.ReactElement) => {
|
||||
return <Shell withoutMain={true}>{page}</Shell>;
|
||||
};
|
||||
|
||||
export const getServerSideProps = async function getServerSideProps(
|
||||
context: AppGetServerSidePropsContext,
|
||||
prisma: AppPrisma,
|
||||
@@ -521,10 +483,25 @@ export const getServerSideProps = async function getServerSideProps(
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const isAllowed = (await import("../../lib/isAllowed")).isAllowed;
|
||||
if (!(await isAllowed({ userId: user.id, formId }))) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const form = await prisma.app_RoutingForms_Form.findUnique({
|
||||
where: {
|
||||
id: formId,
|
||||
},
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
responses: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!form) {
|
||||
return {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { expect, Page } from "@playwright/test";
|
||||
|
||||
import { seededForm } from "@calcom/prisma/seed-app-store";
|
||||
import { test } from "@calcom/web/playwright/lib/fixtures";
|
||||
import { Fixtures, test } from "@calcom/web/playwright/lib/fixtures";
|
||||
|
||||
async function gotoRoutingLink(page: Page, formId: string) {
|
||||
await page.goto(`/forms/${formId}`);
|
||||
@@ -33,6 +32,7 @@ async function verifySelectOptions(
|
||||
.nth(selector.nth)
|
||||
.locator('[id*="react-select-"][aria-disabled]')
|
||||
.allInnerTexts();
|
||||
|
||||
const sortedSelectOptions = [...selectOptions].sort();
|
||||
const sortedExpectedOptions = [...expectedOptions].sort();
|
||||
expect(sortedSelectOptions).toEqual(sortedExpectedOptions);
|
||||
@@ -68,84 +68,110 @@ async function fillForm(
|
||||
}
|
||||
|
||||
test.describe("Routing Forms", () => {
|
||||
test.beforeEach(async ({ page, users }) => {
|
||||
const user = await users.create({ username: "routing_forms" });
|
||||
await user.login();
|
||||
// Install app
|
||||
await page.goto(`/apps/routing_forms`);
|
||||
await page.click('[data-testid="install-app-button"]');
|
||||
await page.waitForNavigation({
|
||||
url: (url) => url.pathname === `/apps/routing_forms/forms`,
|
||||
});
|
||||
});
|
||||
|
||||
test.afterEach(async ({ users }) => {
|
||||
// This also delete forms on cascade
|
||||
await users.deleteAll();
|
||||
});
|
||||
|
||||
test("should be able to add a new form and view it", async ({ page }) => {
|
||||
await page.waitForSelector('[data-testid="empty-screen"]');
|
||||
|
||||
const formId = await addForm(page);
|
||||
|
||||
await page.click('[href="/apps/routing_forms/forms"]');
|
||||
// TODO: Workaround for bug in https://github.com/calcom/cal.com/issues/3410
|
||||
await page.click('[href="/apps/routing_forms/forms"]');
|
||||
|
||||
await page.waitForSelector('[data-testid="routing-forms-list"]');
|
||||
|
||||
// Ensure that it's visible in forms list
|
||||
expect(await page.locator('[data-testid="routing-forms-list"] > li').count()).toBe(1);
|
||||
|
||||
await gotoRoutingLink(page, formId);
|
||||
await page.isVisible("text=Test Form Name");
|
||||
|
||||
await page.goto(`apps/routing_forms/route-builder/${formId}`);
|
||||
await page.click('[data-testid="toggle-form"] [value="on"]');
|
||||
await gotoRoutingLink(page, formId);
|
||||
await page.isVisible("text=ERROR 404");
|
||||
});
|
||||
|
||||
test("should be able to edit the form", async ({ page }) => {
|
||||
await addForm(page);
|
||||
const description = "Test Description";
|
||||
|
||||
const field = {
|
||||
label: "Test Label",
|
||||
typeIndex: 1,
|
||||
};
|
||||
|
||||
const { types } = await fillForm(page, {
|
||||
description,
|
||||
field: field,
|
||||
test.describe("Zero State Routing Forms", () => {
|
||||
test.beforeEach(async ({ page, users }) => {
|
||||
const user = await users.create({ username: "routing_forms" });
|
||||
await user.login();
|
||||
// Install app
|
||||
await page.goto(`/apps/routing_forms`);
|
||||
await page.click('[data-testid="install-app-button"]');
|
||||
await page.waitForNavigation({
|
||||
url: (url) => url.pathname === `/apps/routing_forms/forms`,
|
||||
});
|
||||
});
|
||||
|
||||
await page.reload();
|
||||
test("should be able to add a new form and view it", async ({ page }) => {
|
||||
await page.waitForSelector('[data-testid="empty-screen"]');
|
||||
|
||||
expect(await page.inputValue(`[data-testid="description"]`), description);
|
||||
expect(await page.locator('[data-testid="field"]').count()).toBe(1);
|
||||
expect(await page.inputValue('[name="fields.0.label"]')).toBe(field.label);
|
||||
expect(await page.locator(".data-testid-field-type").first().innerText()).toBe(types[field.typeIndex]);
|
||||
const formId = await addForm(page);
|
||||
|
||||
await page.click('[href*="/apps/routing_forms/route-builder/"]');
|
||||
await page.click('[data-testid="add-route"]');
|
||||
await page.click('[data-testid="add-rule"]');
|
||||
await verifySelectOptions(
|
||||
{
|
||||
selector: ".rule-container .data-testid-field-select",
|
||||
nth: 0,
|
||||
},
|
||||
[field.label],
|
||||
page
|
||||
);
|
||||
await page.click('[href="/apps/routing_forms/forms"]');
|
||||
// TODO: Workaround for bug in https://github.com/calcom/cal.com/issues/3410
|
||||
await page.click('[href="/apps/routing_forms/forms"]');
|
||||
|
||||
await page.waitForSelector('[data-testid="routing-forms-list"]');
|
||||
// Ensure that it's visible in forms list
|
||||
expect(await page.locator('[data-testid="routing-forms-list"] > li').count()).toBe(1);
|
||||
|
||||
await gotoRoutingLink(page, formId);
|
||||
await page.isVisible("text=Test Form Name");
|
||||
|
||||
await page.goto(`apps/routing_forms/route-builder/${formId}`);
|
||||
await page.click('[data-testid="toggle-form"] [value="on"]');
|
||||
await gotoRoutingLink(page, formId);
|
||||
await page.isVisible("text=ERROR 404");
|
||||
});
|
||||
|
||||
test("should be able to edit the form", async ({ page }) => {
|
||||
await addForm(page);
|
||||
const description = "Test Description";
|
||||
|
||||
const field = {
|
||||
label: "Test Label",
|
||||
typeIndex: 1,
|
||||
};
|
||||
|
||||
const { types } = await fillForm(page, {
|
||||
description,
|
||||
field: field,
|
||||
});
|
||||
|
||||
await page.reload();
|
||||
|
||||
expect(await page.inputValue(`[data-testid="description"]`), description);
|
||||
expect(await page.locator('[data-testid="field"]').count()).toBe(1);
|
||||
expect(await page.inputValue('[name="fields.0.label"]')).toBe(field.label);
|
||||
expect(await page.locator(".data-testid-field-type").first().locator("div").nth(1).innerText()).toBe(
|
||||
types[field.typeIndex]
|
||||
);
|
||||
|
||||
await page.click('[href*="/apps/routing_forms/route-builder/"]');
|
||||
await page.click('[data-testid="add-route"]');
|
||||
await page.click('[data-testid="add-rule"]');
|
||||
await verifySelectOptions(
|
||||
{
|
||||
selector: ".rule-container .data-testid-field-select",
|
||||
nth: 0,
|
||||
},
|
||||
[field.label],
|
||||
page
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Seeded Routing Form ", () => {
|
||||
const createUserAndLoginAndInstallApp = async function ({
|
||||
users,
|
||||
page,
|
||||
}: {
|
||||
users: Fixtures["users"];
|
||||
page: Page;
|
||||
}) {
|
||||
const user = await users.create({ username: "routing_forms" }, { seedRoutingForms: true });
|
||||
await user.login();
|
||||
// Install app
|
||||
await page.goto(`/apps/routing_forms`);
|
||||
await page.click('[data-testid="install-app-button"]');
|
||||
await page.waitForNavigation({
|
||||
url: (url) => url.pathname === `/apps/routing_forms/forms`,
|
||||
});
|
||||
return user;
|
||||
};
|
||||
|
||||
test("Routing Link should accept submission while routing works and responses can be downloaded", async ({
|
||||
page,
|
||||
users,
|
||||
}) => {
|
||||
await gotoRoutingLink(page, seededForm.id);
|
||||
const user = await createUserAndLoginAndInstallApp({ users, page });
|
||||
const routingForm = user.routingForms[0];
|
||||
|
||||
// Fill form when you are logged out
|
||||
await users.logout();
|
||||
await gotoRoutingLink(page, routingForm.id);
|
||||
await page.fill('[data-testid="field"]', "event-routing");
|
||||
page.click('button[type="submit"]');
|
||||
await page.waitForNavigation({
|
||||
@@ -154,7 +180,7 @@ test.describe("Routing Forms", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await gotoRoutingLink(page, seededForm.id);
|
||||
await gotoRoutingLink(page, routingForm.id);
|
||||
await page.fill('[data-testid="field"]', "external-redirect");
|
||||
page.click('button[type="submit"]');
|
||||
await page.waitForNavigation({
|
||||
@@ -163,11 +189,15 @@ test.describe("Routing Forms", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await gotoRoutingLink(page, seededForm.id);
|
||||
await gotoRoutingLink(page, routingForm.id);
|
||||
await page.fill('[data-testid="field"]', "custom-page");
|
||||
await page.click('button[type="submit"]');
|
||||
await page.isVisible("text=Custom Page Result");
|
||||
await page.goto(`/apps/routing_forms/route-builder/${seededForm.id}`);
|
||||
|
||||
// Log back in to view form responses.
|
||||
await user.login();
|
||||
|
||||
await page.goto(`/apps/routing_forms/route-builder/${routingForm.id}`);
|
||||
const [download] = await Promise.all([
|
||||
// Start waiting for the download
|
||||
page.waitForEvent("download"),
|
||||
@@ -175,7 +205,7 @@ test.describe("Routing Forms", () => {
|
||||
page.click('[data-testid="download-responses"]'),
|
||||
]);
|
||||
const downloadStream = await download.createReadStream();
|
||||
expect(download.suggestedFilename()).toEqual(`${seededForm.name}-${seededForm.id}.csv`);
|
||||
expect(download.suggestedFilename()).toEqual(`${routingForm.name}-${routingForm.id}.csv`);
|
||||
const csv: string = await new Promise((resolve) => {
|
||||
let body = "";
|
||||
downloadStream?.on("data", (chunk) => {
|
||||
@@ -194,30 +224,37 @@ test.describe("Routing Forms", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("Router URL should work", async ({ page }) => {
|
||||
page.goto(`/router?form=${seededForm.id}&Test field=event-routing`);
|
||||
test("Router URL should work", async ({ page, users }) => {
|
||||
const user = await createUserAndLoginAndInstallApp({ users, page });
|
||||
const routingForm = user.routingForms[0];
|
||||
|
||||
// Router should be publicly accessible
|
||||
await users.logout();
|
||||
page.goto(`/router?form=${routingForm.id}&Test field=event-routing`);
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.pathname.endsWith("/pro/30min");
|
||||
},
|
||||
});
|
||||
|
||||
page.goto(`/router?form=${seededForm.id}&Test field=external-redirect`);
|
||||
page.goto(`/router?form=${routingForm.id}&Test field=external-redirect`);
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.hostname.includes("google.com");
|
||||
},
|
||||
});
|
||||
|
||||
await page.goto(`/router?form=${seededForm.id}&Test field=custom-page`);
|
||||
await page.goto(`/router?form=${routingForm.id}&Test field=custom-page`);
|
||||
await page.isVisible("text=Custom Page Result");
|
||||
|
||||
await page.goto(`/router?form=${seededForm.id}&Test field=doesntmatter&multi=Option-2`);
|
||||
await page.goto(`/router?form=${routingForm.id}&Test field=doesntmatter&multi=Option-2`);
|
||||
await page.isVisible("text=Multiselect chosen");
|
||||
});
|
||||
|
||||
test("Routing Link should validate fields", async ({ page }) => {
|
||||
await gotoRoutingLink(page, seededForm.id);
|
||||
test("Routing Link should validate fields", async ({ page, users }) => {
|
||||
const user = await createUserAndLoginAndInstallApp({ users, page });
|
||||
const routingForm = user.routingForms[0];
|
||||
await gotoRoutingLink(page, routingForm.id);
|
||||
page.click('button[type="submit"]');
|
||||
const firstInputMissingValue = await page.evaluate(() => {
|
||||
return document.querySelectorAll("input")[0].validity.valueMissing;
|
||||
|
||||
@@ -7,6 +7,7 @@ import getWebhooks from "@calcom/lib/webhooks/subscriptions";
|
||||
import { TRPCError } from "@calcom/trpc/server";
|
||||
import { createProtectedRouter, createRouter } from "@calcom/trpc/server/createRouter";
|
||||
|
||||
import { isAllowed } from "./lib/isAllowed";
|
||||
import { zodFields, zodRoutes } from "./zod";
|
||||
|
||||
const app_RoutingForms = createRouter()
|
||||
@@ -181,6 +182,11 @@ const app_RoutingForms = createRouter()
|
||||
}),
|
||||
async resolve({ ctx: { user, prisma }, input }) {
|
||||
const { name, id, description, disabled, addFallback, duplicateFrom } = input;
|
||||
if (!(await isAllowed({ userId: user.id, formId: id }))) {
|
||||
throw new TRPCError({
|
||||
code: "FORBIDDEN",
|
||||
});
|
||||
}
|
||||
let { routes } = input;
|
||||
let { fields } = input;
|
||||
|
||||
@@ -266,11 +272,16 @@ const app_RoutingForms = createRouter()
|
||||
input: z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
return await ctx.prisma.app_RoutingForms_Form.deleteMany({
|
||||
async resolve({ ctx: { user, prisma }, input }) {
|
||||
if (!(await isAllowed({ userId: user.id, formId: input.id }))) {
|
||||
throw new TRPCError({
|
||||
code: "FORBIDDEN",
|
||||
});
|
||||
}
|
||||
return await prisma.app_RoutingForms_Form.deleteMany({
|
||||
where: {
|
||||
id: input.id,
|
||||
userId: ctx.user.id,
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -10,6 +10,12 @@ import { appStoreMetadata } from "./apps.browser.generated";
|
||||
|
||||
const ALL_APPS_MAP = Object.keys(appStoreMetadata).reduce((store, key) => {
|
||||
store[key] = appStoreMetadata[key as keyof typeof appStoreMetadata];
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
delete store[key]["/*"];
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
delete store[key]["__createdUsingCli"];
|
||||
return store;
|
||||
}, {} as Record<string, AppMeta>);
|
||||
|
||||
|
||||
+2
-694
@@ -1,694 +1,2 @@
|
||||
import type { User, UserPlan } from "@prisma/client";
|
||||
import { SessionContextValue, signOut, useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import React, { Fragment, ReactNode, useEffect, useState } from "react";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { useIsEmbed } from "@calcom/embed-core/embed-iframe";
|
||||
import LicenseBanner from "@calcom/features/ee/common/components/LicenseBanner";
|
||||
import TrialBanner from "@calcom/features/ee/common/components/TrialBanner";
|
||||
import ImpersonatingBanner from "@calcom/features/ee/impersonation/components/ImpersonatingBanner";
|
||||
import HelpMenuItem from "@calcom/features/ee/support/components/HelpMenuItem";
|
||||
import CustomBranding from "@calcom/lib/CustomBranding";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { DESKTOP_APP_LINK, JOIN_SLACK, ROADMAP, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import useApp from "@calcom/lib/hooks/useApp";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
import Badge from "@calcom/ui/Badge";
|
||||
import Button from "@calcom/ui/Button";
|
||||
import Dropdown, {
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@calcom/ui/Dropdown";
|
||||
import { CollectionIcon, Icon } from "@calcom/ui/Icon";
|
||||
import Loader from "@calcom/ui/Loader";
|
||||
import { HeadSeo } from "@calcom/ui/v2/core/head-seo";
|
||||
import { useViewerI18n } from "@calcom/web/components/I18nLanguageHandler";
|
||||
|
||||
/* TODO: Get this from endpoint */
|
||||
import pkg from "../../apps/web/package.json";
|
||||
import ErrorBoundary from "./ErrorBoundary";
|
||||
import { KBarContent, KBarRoot, KBarTrigger } from "./Kbar";
|
||||
import Logo from "./Logo";
|
||||
|
||||
export const ONBOARDING_INTRODUCED_AT = dayjs("September 1 2021").toISOString();
|
||||
|
||||
export const ONBOARDING_NEXT_REDIRECT = {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/getting-started",
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const shouldShowOnboarding = (user: Pick<User, "createdDate" | "completedOnboarding">) => {
|
||||
return !user.completedOnboarding && dayjs(user.createdDate).isAfter(ONBOARDING_INTRODUCED_AT);
|
||||
};
|
||||
|
||||
function useRedirectToLoginIfUnauthenticated(isPublic = false) {
|
||||
const { data: session, status } = useSession();
|
||||
const loading = status === "loading";
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (isPublic) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!loading && !session) {
|
||||
router.replace({
|
||||
pathname: "/auth/login",
|
||||
query: {
|
||||
callbackUrl: `${WEBAPP_URL}${location.pathname}${location.search}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [loading, session, isPublic]);
|
||||
|
||||
return {
|
||||
loading: loading && !session,
|
||||
session,
|
||||
};
|
||||
}
|
||||
|
||||
function useRedirectToOnboardingIfNeeded() {
|
||||
const router = useRouter();
|
||||
const query = useMeQuery();
|
||||
const user = query.data;
|
||||
|
||||
const isRedirectingToOnboarding = user && shouldShowOnboarding(user);
|
||||
|
||||
useEffect(() => {
|
||||
if (isRedirectingToOnboarding) {
|
||||
router.replace({
|
||||
pathname: "/getting-started",
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isRedirectingToOnboarding]);
|
||||
return {
|
||||
isRedirectingToOnboarding,
|
||||
};
|
||||
}
|
||||
|
||||
export function ShellSubHeading(props: {
|
||||
title: ReactNode;
|
||||
subtitle?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className={classNames("mb-3 block justify-between sm:flex", props.className)}>
|
||||
<div>
|
||||
<h2 className="text-brand-500 flex content-center items-center space-x-2 text-base font-bold leading-6 rtl:space-x-reverse">
|
||||
{props.title}
|
||||
</h2>
|
||||
{props.subtitle && <p className="text-sm text-neutral-500 ltr:mr-4">{props.subtitle}</p>}
|
||||
</div>
|
||||
{props.actions && <div className="flex-shrink-0">{props.actions}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const Layout = ({
|
||||
status,
|
||||
plan,
|
||||
...props
|
||||
}: LayoutProps & { status: SessionContextValue["status"]; plan?: UserPlan; isLoading: boolean }) => {
|
||||
const isEmbed = useIsEmbed();
|
||||
const router = useRouter();
|
||||
const { data: routingForms } = useApp("routing_forms");
|
||||
|
||||
const { t } = useLocale();
|
||||
const navigation = [
|
||||
{
|
||||
name: t("event_types_page_title"),
|
||||
href: "/event-types",
|
||||
icon: Icon.FiLink,
|
||||
current: router.asPath.startsWith("/event-types"),
|
||||
},
|
||||
{
|
||||
name: t("bookings"),
|
||||
href: "/bookings/upcoming",
|
||||
icon: Icon.FiCalendar,
|
||||
current: router.asPath.startsWith("/bookings"),
|
||||
},
|
||||
{
|
||||
name: t("availability"),
|
||||
href: "/availability",
|
||||
icon: Icon.FiClock,
|
||||
current: router.asPath.startsWith("/availability"),
|
||||
},
|
||||
routingForms
|
||||
? {
|
||||
name: "Routing Forms",
|
||||
href: "/apps/routing_forms/forms",
|
||||
icon: CollectionIcon,
|
||||
current: router.asPath.startsWith("/apps/routing_forms/"),
|
||||
}
|
||||
: null,
|
||||
{
|
||||
name: t("workflows"),
|
||||
href: "/workflows",
|
||||
icon: Icon.FiZap,
|
||||
current: router.asPath.startsWith("/workflows"),
|
||||
pro: true,
|
||||
},
|
||||
{
|
||||
name: t("apps"),
|
||||
href: "/apps",
|
||||
icon: Icon.FiGrid,
|
||||
current: router.asPath.startsWith("/apps") && !router.asPath.startsWith("/apps/routing_forms/"),
|
||||
child: [
|
||||
{
|
||||
name: t("app_store"),
|
||||
href: "/apps",
|
||||
current: router.asPath === "/apps",
|
||||
},
|
||||
{
|
||||
name: t("installed_apps"),
|
||||
href: "/apps/installed",
|
||||
current: router.asPath === "/apps/installed",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t("settings"),
|
||||
href: "/settings/profile",
|
||||
icon: Icon.FiSettings,
|
||||
current: router.asPath.startsWith("/settings"),
|
||||
},
|
||||
];
|
||||
const pageTitle = typeof props.heading === "string" ? props.heading : props.title;
|
||||
|
||||
return (
|
||||
<>
|
||||
<HeadSeo
|
||||
title={pageTitle ?? "Cal.com"}
|
||||
description={props.subtitle ? props.subtitle?.toString() : ""}
|
||||
nextSeoProps={{
|
||||
nofollow: true,
|
||||
noindex: true,
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<Toaster position="bottom-right" />
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={classNames("flex h-screen overflow-hidden", props.large ? "bg-white" : "bg-gray-100")}
|
||||
data-testid="dashboard-shell">
|
||||
{status === "authenticated" && (
|
||||
<div style={isEmbed ? { display: "none" } : {}} className="hidden md:flex lg:flex-shrink-0">
|
||||
<div className="flex w-14 flex-col lg:w-56">
|
||||
<header className="flex h-0 flex-1 flex-col border-r border-gray-200 bg-white">
|
||||
<div className="flex flex-1 flex-col overflow-y-auto pt-3 pb-4 lg:pt-5">
|
||||
<div className="items-center justify-between md:hidden lg:flex">
|
||||
<Link href="/event-types">
|
||||
<a className="px-4">
|
||||
<Logo small />
|
||||
</a>
|
||||
</Link>
|
||||
<div className="flex space-x-2 px-4">
|
||||
<button
|
||||
color="minimal"
|
||||
onClick={() => window.history.back()}
|
||||
className="desktop-only group flex text-sm font-medium text-neutral-500 hover:text-neutral-900">
|
||||
<Icon.FiArrowLeft className="h-4 w-4 flex-shrink-0 text-neutral-400 group-hover:text-neutral-500" />
|
||||
</button>
|
||||
<button
|
||||
color="minimal"
|
||||
onClick={() => window.history.forward()}
|
||||
className="desktop-only group flex text-sm font-medium text-neutral-500 hover:text-neutral-900">
|
||||
<Icon.FiArrowRight className="h-4 w-4 flex-shrink-0 text-neutral-400 group-hover:text-neutral-500" />
|
||||
</button>
|
||||
<KBarTrigger />
|
||||
</div>
|
||||
</div>
|
||||
{/* logo icon for tablet */}
|
||||
<Link href="/event-types">
|
||||
<a className="text-center md:inline lg:hidden">
|
||||
<Logo small icon />
|
||||
</a>
|
||||
</Link>
|
||||
<hr className="desktop-only mt-2.5" />
|
||||
<nav className="mt-2 flex-1 space-y-0.5 bg-white px-2 lg:mt-5">
|
||||
{navigation.map((item) =>
|
||||
!item ? null : (
|
||||
<Fragment key={item.name}>
|
||||
<Link href={item.href}>
|
||||
<a
|
||||
aria-label={item.name}
|
||||
className={classNames(
|
||||
item.current
|
||||
? "bg-neutral-100 text-neutral-900"
|
||||
: "text-neutral-500 hover:bg-gray-50 hover:text-neutral-900",
|
||||
"group flex items-center justify-center rounded py-2.5 px-3 text-sm font-medium sm:justify-start"
|
||||
)}>
|
||||
<item.icon
|
||||
className={classNames(
|
||||
item.current
|
||||
? "text-neutral-900"
|
||||
: "text-neutral-400 group-hover:text-neutral-900",
|
||||
"h-4 w-4 flex-shrink-0 md:ltr:mr-2 md:rtl:ml-3"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="hidden leading-none lg:inline">{item.name}</span>
|
||||
{item.pro && (
|
||||
<span className="ml-1">
|
||||
{plan === "FREE" && <Badge variant="default">PRO</Badge>}
|
||||
</span>
|
||||
)}
|
||||
</a>
|
||||
</Link>
|
||||
{item.child &&
|
||||
router.asPath.startsWith(item.href) &&
|
||||
item.child.map((item) => {
|
||||
return (
|
||||
<Link key={item.name} href={item.href}>
|
||||
<a
|
||||
className={classNames(
|
||||
item.current
|
||||
? "text-neutral-900"
|
||||
: "text-neutral-500 hover:text-neutral-900",
|
||||
"group hidden items-center rounded-sm px-2 py-2 pl-10 text-sm font-medium lg:flex"
|
||||
)}>
|
||||
<span className="hidden leading-none lg:inline">{item.name}</span>
|
||||
</a>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</Fragment>
|
||||
)
|
||||
)}
|
||||
<span className="group flex items-center rounded-sm px-3 py-2.5 text-sm font-medium text-neutral-500 hover:bg-gray-50 hover:text-neutral-900 lg:hidden">
|
||||
<KBarTrigger />
|
||||
</span>
|
||||
</nav>
|
||||
</div>
|
||||
<TrialBanner />
|
||||
<div data-testid="user-dropdown-trigger">
|
||||
<span className="hidden lg:inline">
|
||||
<UserDropdown />
|
||||
</span>
|
||||
<span className="hidden md:inline lg:hidden">
|
||||
<UserDropdown small />
|
||||
</span>
|
||||
</div>
|
||||
<DeploymentInfo />
|
||||
</header>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex w-0 flex-1 flex-col overflow-hidden">
|
||||
<ImpersonatingBanner />
|
||||
<main
|
||||
className={classNames(
|
||||
"relative z-0 flex-1 overflow-y-auto focus:outline-none",
|
||||
status === "authenticated" && "max-w-[1700px]",
|
||||
props.flexChildrenContainer && "flex flex-col"
|
||||
)}>
|
||||
{/* show top navigation for md and smaller (tablet and phones) */}
|
||||
{status === "authenticated" && (
|
||||
<nav
|
||||
style={isEmbed ? { display: "none" } : {}}
|
||||
className="flex items-center justify-between border-b border-gray-200 bg-white p-4 md:hidden">
|
||||
<Link href="/event-types">
|
||||
<a>
|
||||
<Logo />
|
||||
</a>
|
||||
</Link>
|
||||
<div className="flex items-center gap-2 self-center">
|
||||
<span className="group flex items-center rounded-full p-2.5 text-sm font-medium text-neutral-500 hover:bg-gray-50 hover:text-neutral-900 lg:hidden">
|
||||
<KBarTrigger />
|
||||
</span>
|
||||
<button className="rounded-full bg-white p-2 text-gray-400 hover:bg-gray-50 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2">
|
||||
<span className="sr-only">{t("settings")}</span>
|
||||
<Link href="/settings/profile">
|
||||
<a>
|
||||
<Icon.FiSettings className="h-4 w-4" aria-hidden="true" />
|
||||
</a>
|
||||
</Link>
|
||||
</button>
|
||||
<UserDropdown small />
|
||||
</div>
|
||||
</nav>
|
||||
)}
|
||||
<div
|
||||
className={classNames(
|
||||
props.centered && "mx-auto md:max-w-5xl",
|
||||
props.flexChildrenContainer && "flex flex-1 flex-col"
|
||||
)}>
|
||||
{!!props.backPath && (
|
||||
<div className="mx-3 mb-8 sm:mx-8">
|
||||
<Button
|
||||
onClick={() => router.push(props.backPath as string)}
|
||||
StartIcon={Icon.FiArrowLeft}
|
||||
color="secondary">
|
||||
Back
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{props.heading && (
|
||||
<header
|
||||
className={classNames(
|
||||
props.large && "bg-gray-100 py-8 lg:mb-8 lg:pt-16 lg:pb-7",
|
||||
"block justify-between px-4 pt-8 sm:flex sm:px-6 md:px-8"
|
||||
)}>
|
||||
{props.HeadingLeftIcon && <div className="ltr:mr-4">{props.HeadingLeftIcon}</div>}
|
||||
<div className="mb-8 w-full">
|
||||
{props.isLoading ? (
|
||||
<>
|
||||
<div className="mb-1 h-6 w-24 animate-pulse rounded-md bg-gray-200" />
|
||||
<div className="mb-1 h-6 w-32 animate-pulse rounded-md bg-gray-200" />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<h1 className="font-cal mb-1 text-xl font-bold capitalize tracking-wide text-gray-900">
|
||||
{props.heading}
|
||||
</h1>
|
||||
<p className="text-sm text-neutral-500 ltr:mr-4 rtl:ml-4">{props.subtitle}</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{props.CTA && <div className="mb-4 flex-shrink-0">{props.CTA}</div>}
|
||||
</header>
|
||||
)}
|
||||
<div
|
||||
className={classNames(
|
||||
"px-4 sm:px-6 md:px-8",
|
||||
props.flexChildrenContainer && "flex flex-1 flex-col"
|
||||
)}>
|
||||
<ErrorBoundary>{!props.isLoading ? props.children : props.customLoader}</ErrorBoundary>
|
||||
</div>
|
||||
{/* show bottom navigation for md and smaller (tablet and phones) */}
|
||||
{status === "authenticated" && (
|
||||
<nav
|
||||
style={isEmbed ? { display: "none" } : {}}
|
||||
className="bottom-nav fixed bottom-0 z-30 flex w-full bg-white shadow md:hidden">
|
||||
{/* note(PeerRich): using flatMap instead of map to remove settings from bottom nav */}
|
||||
{navigation.flatMap((item, itemIdx) => {
|
||||
if (!item) {
|
||||
return null;
|
||||
}
|
||||
return item.href === "/settings/profile" ? (
|
||||
[]
|
||||
) : (
|
||||
<Link key={item.name} href={item.href}>
|
||||
<a
|
||||
className={classNames(
|
||||
item.current ? "text-gray-900" : "text-neutral-400 hover:text-gray-700",
|
||||
itemIdx === 0 ? "rounded-l-lg" : "",
|
||||
itemIdx === navigation.length - 1 ? "rounded-r-lg" : "",
|
||||
"group relative min-w-0 flex-1 overflow-hidden bg-white py-2 px-2 text-center text-xs text-sm font-medium hover:bg-gray-50 focus:z-10"
|
||||
)}
|
||||
aria-current={item.current ? "page" : undefined}>
|
||||
<item.icon
|
||||
className={classNames(
|
||||
item.current ? "text-gray-900" : "text-gray-400 group-hover:text-gray-500",
|
||||
"mx-auto mb-1 block h-4 w-4 flex-shrink-0 text-center"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="block truncate">{item.name}</span>
|
||||
</a>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
)}
|
||||
{/* add padding to content for mobile navigation*/}
|
||||
<div className="block pt-12 md:hidden" />
|
||||
</div>
|
||||
<LicenseBanner />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const MemoizedLayout = React.memo(Layout);
|
||||
|
||||
type LayoutProps = {
|
||||
centered?: boolean;
|
||||
title?: string;
|
||||
heading?: ReactNode;
|
||||
subtitle?: ReactNode;
|
||||
children: ReactNode;
|
||||
CTA?: ReactNode;
|
||||
large?: boolean;
|
||||
HeadingLeftIcon?: ReactNode;
|
||||
backPath?: string; // renders back button to specified path
|
||||
// use when content needs to expand with flex
|
||||
flexChildrenContainer?: boolean;
|
||||
isPublic?: boolean;
|
||||
customLoader?: ReactNode;
|
||||
};
|
||||
|
||||
export default function Shell(props: LayoutProps) {
|
||||
const { loading, session } = useRedirectToLoginIfUnauthenticated(props.isPublic);
|
||||
const { isRedirectingToOnboarding } = useRedirectToOnboardingIfNeeded();
|
||||
|
||||
const query = useMeQuery();
|
||||
const user = query.data;
|
||||
|
||||
const i18n = useViewerI18n();
|
||||
const { status } = useSession();
|
||||
|
||||
const isLoading = isRedirectingToOnboarding || loading;
|
||||
|
||||
// Don't show any content till translations are loaded.
|
||||
// As they are cached infintely, this status would be loading just once for the app's lifetime until refresh
|
||||
if (i18n.status === "loading") {
|
||||
return (
|
||||
<div className="absolute z-50 flex h-screen w-full items-center bg-gray-50">
|
||||
<Loader />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!session && !props.isPublic) return null;
|
||||
|
||||
return (
|
||||
<KBarRoot>
|
||||
<CustomBranding lightVal={user?.brandColor} darkVal={user?.darkBrandColor} />
|
||||
<MemoizedLayout plan={user?.plan} status={status} {...props} isLoading={isLoading} />
|
||||
<KBarContent />
|
||||
</KBarRoot>
|
||||
);
|
||||
}
|
||||
|
||||
function UserDropdown({ small }: { small?: boolean }) {
|
||||
const { t } = useLocale();
|
||||
const query = useMeQuery();
|
||||
const user = query.data;
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
const Beacon = window.Beacon;
|
||||
// window.Beacon is defined when user actually opens up HelpScout and username is available here. On every re-render update session info, so that it is always latest.
|
||||
Beacon &&
|
||||
Beacon("session-data", {
|
||||
username: user?.username || "Unknown",
|
||||
screenResolution: `${screen.width}x${screen.height}`,
|
||||
});
|
||||
});
|
||||
const mutation = trpc.useMutation("viewer.away", {
|
||||
onSettled() {
|
||||
utils.invalidateQueries("viewer.me");
|
||||
},
|
||||
});
|
||||
const utils = trpc.useContext();
|
||||
const [helpOpen, setHelpOpen] = useState(false);
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
const onHelpItemSelect = () => {
|
||||
setHelpOpen(false);
|
||||
setMenuOpen(false);
|
||||
};
|
||||
|
||||
// Prevent rendering dropdown if user isn't available.
|
||||
// We don't want to show nameless user.
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Dropdown open={menuOpen} onOpenChange={() => setHelpOpen(false)}>
|
||||
<DropdownMenuTrigger asChild onClick={() => setMenuOpen(true)}>
|
||||
<button className="group flex w-full cursor-pointer appearance-none items-center rounded-full p-2 text-left hover:bg-gray-100 sm:pl-3 md:rounded-none lg:pl-2">
|
||||
<span
|
||||
className={classNames(
|
||||
small ? "h-8 w-8" : "h-9 w-9 ltr:mr-2 rtl:ml-3",
|
||||
"relative flex-shrink-0 rounded-full bg-gray-300 "
|
||||
)}>
|
||||
{
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
className="rounded-full"
|
||||
src={WEBAPP_URL + "/" + user.username + "/avatar.png"}
|
||||
alt={user.username || "Nameless User"}
|
||||
/>
|
||||
}
|
||||
{!user.away && (
|
||||
<div className="absolute bottom-0 right-0 h-3 w-3 rounded-full border-2 border-white bg-green-500" />
|
||||
)}
|
||||
{user.away && (
|
||||
<div className="absolute bottom-0 right-0 h-3 w-3 rounded-full border-2 border-white bg-yellow-500" />
|
||||
)}
|
||||
</span>
|
||||
{!small && (
|
||||
<span className="flex flex-grow items-center truncate">
|
||||
<span className="flex-grow truncate text-sm">
|
||||
<span className="block truncate font-medium text-gray-900">
|
||||
{user.name || "Nameless User"}
|
||||
</span>
|
||||
<span className="block truncate font-normal text-neutral-500">
|
||||
{user.username
|
||||
? process.env.NEXT_PUBLIC_WEBSITE_URL === "https://cal.com"
|
||||
? `cal.com/${user.username}`
|
||||
: `/${user.username}`
|
||||
: "No public page"}
|
||||
</span>
|
||||
</span>
|
||||
<Icon.FiMoreVertical
|
||||
className="h-4 w-4 flex-shrink-0 text-gray-400 group-hover:text-gray-500"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent portalled={true} onInteractOutside={() => setMenuOpen(false)}>
|
||||
{helpOpen ? (
|
||||
<HelpMenuItem onHelpItemSelect={() => onHelpItemSelect()} />
|
||||
) : (
|
||||
<>
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
onClick={() => {
|
||||
mutation.mutate({ away: !user?.away });
|
||||
utils.invalidateQueries("viewer.me");
|
||||
}}
|
||||
className="flex min-w-max cursor-pointer items-center px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900">
|
||||
<Icon.FiMoon
|
||||
className={classNames(
|
||||
user.away
|
||||
? "text-purple-500 group-hover:text-purple-700"
|
||||
: "text-gray-500 group-hover:text-gray-700",
|
||||
"h-4 w-4 flex-shrink-0 ltr:mr-2 rtl:ml-3"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{user.away ? t("set_as_free") : t("set_as_away")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
{user.username && (
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user.username}`}
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700">
|
||||
<Icon.FiExternalLink className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-3" />{" "}
|
||||
{t("view_public_page")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
href={JOIN_SLACK}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900">
|
||||
<Icon.FiSlack strokeWidth={1.5} className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-3" />{" "}
|
||||
{t("join_our_slack")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={ROADMAP}
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700">
|
||||
<Icon.FiMap className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-3" /> {t("visit_roadmap")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
|
||||
<button
|
||||
className="flex w-full items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900"
|
||||
onClick={() => setHelpOpen(true)}>
|
||||
<Icon.FiHelpCircle
|
||||
className={classNames(
|
||||
"text-gray-500 group-hover:text-neutral-500",
|
||||
"h-4 w-4 flex-shrink-0 ltr:mr-2"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
{t("help")}
|
||||
</button>
|
||||
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={DESKTOP_APP_LINK}
|
||||
className="desktop-hidden hidden items-center px-4 py-2 text-sm text-gray-700 md:flex">
|
||||
<Icon.FiDownload className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-3" />{" "}
|
||||
{t("download_desktop_app")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
onClick={() => signOut({ callbackUrl: "/auth/logout" })}
|
||||
className="flex cursor-pointer items-center px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900">
|
||||
<Icon.FiLogOut
|
||||
className={classNames(
|
||||
"text-gray-500 group-hover:text-gray-700",
|
||||
"h-4 w-4 flex-shrink-0 ltr:mr-2 rtl:ml-3"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{t("sign_out")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
function DeploymentInfo() {
|
||||
const query = useMeQuery();
|
||||
const user = query.data;
|
||||
|
||||
return (
|
||||
<small
|
||||
style={{
|
||||
fontSize: "0.5rem",
|
||||
}}
|
||||
className="mx-3 mt-1 mb-2 hidden opacity-50 lg:block">
|
||||
© {new Date().getFullYear()} Cal.com, Inc. v.{pkg.version + "-"}
|
||||
{process.env.NEXT_PUBLIC_WEBSITE_URL === "https://cal.com" ? "h" : "sh"}
|
||||
<span className="lowercase" data-testid={`plan-${user?.plan.toLowerCase()}`}>
|
||||
-{user?.plan}
|
||||
</span>
|
||||
</small>
|
||||
);
|
||||
}
|
||||
export { default } from "@calcom/ui/v2/core/Shell";
|
||||
export * from "@calcom/ui/v2/core/Shell";
|
||||
@@ -33,8 +33,8 @@ export type ButtonBaseProps = {
|
||||
};
|
||||
export type ButtonProps = ButtonBaseProps &
|
||||
(
|
||||
| (Omit<JSX.IntrinsicElements["a"], "href" | "onClick"> & LinkProps)
|
||||
| (Omit<JSX.IntrinsicElements["button"], "onClick"> & { href?: never })
|
||||
| (Omit<JSX.IntrinsicElements["a"], "href" | "onClick" | "ref"> & LinkProps)
|
||||
| (Omit<JSX.IntrinsicElements["button"], "onClick" | "ref"> & { href?: never })
|
||||
);
|
||||
|
||||
const variantClassName = {
|
||||
@@ -67,7 +67,6 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
StartIcon,
|
||||
EndIcon,
|
||||
shallow,
|
||||
flex,
|
||||
combined = false,
|
||||
// attributes propagated from `HTMLAnchorProps` or `HTMLButtonProps`
|
||||
...passThroughProps
|
||||
@@ -85,7 +84,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
ref: forwardedRef,
|
||||
className: classNames(
|
||||
// base styles independent what type of button it is
|
||||
"inline-flex justify-center items-center text-sm font-medium relative",
|
||||
"flex items-center text-sm font-medium relative",
|
||||
// different styles depending on size
|
||||
size === "base" && "h-9 px-4 py-2.5 ",
|
||||
size === "lg" && "h-[36px] px-4 py-2.5 ",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
export default function Divider({ className, ...props }: JSX.IntrinsicElements["hr"]) {
|
||||
className = classNames(className, "gray-200");
|
||||
return <hr className={className} {...props} />;
|
||||
}
|
||||
@@ -23,11 +23,13 @@ export default function EmptyScreen({
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className="min-h-80 flex w-full flex-col items-center justify-center rounded-md border border-dashed p-7 lg:p-20">
|
||||
<div
|
||||
data-testid="empty-screen"
|
||||
className="min-h-80 flex w-full flex-col items-center justify-center rounded-md border border-dashed p-7 lg:p-20">
|
||||
<div className="flex h-[72px] w-[72px] items-center justify-center rounded-full bg-gray-200 dark:bg-white">
|
||||
<Icon className="inline-block h-10 w-10 stroke-[1.3px] dark:bg-gray-900 dark:text-gray-600" />
|
||||
</div>
|
||||
<div className="max-w-[420px] text-center">
|
||||
<div className="flex max-w-[420px] flex-col items-center">
|
||||
<h2 className="text-semibold font-cal mt-6 text-xl dark:text-gray-300">{headline}</h2>
|
||||
<p className="mt-3 mb-8 text-sm font-normal leading-6 text-gray-700 dark:text-gray-300">
|
||||
{description}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import Link from "next/link";
|
||||
import { createElement } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
export function List(props: JSX.IntrinsicElements["ul"]) {
|
||||
return (
|
||||
<ul
|
||||
{...props}
|
||||
className={classNames(
|
||||
"divide-y divide-neutral-200 rounded-md border border-l border-r sm:mx-0 sm:overflow-hidden",
|
||||
props.className
|
||||
)}>
|
||||
{props.children}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export type ListItemProps = { expanded?: boolean } & ({ href?: never } & JSX.IntrinsicElements["li"]);
|
||||
export type ListLinkItemProps = {
|
||||
href: string;
|
||||
heading: string;
|
||||
subHeading: string;
|
||||
disabled?: boolean;
|
||||
actions?: JSX.Element;
|
||||
} & JSX.IntrinsicElements["li"];
|
||||
|
||||
export function ListItem(props: ListItemProps) {
|
||||
const { href, expanded, ...passThroughProps } = props;
|
||||
|
||||
const elementType = href ? "a" : "li";
|
||||
|
||||
const element = createElement(
|
||||
elementType,
|
||||
{
|
||||
...passThroughProps,
|
||||
className: classNames(
|
||||
"items-center bg-white min-w-0 flex-1 flex border-gray-200",
|
||||
expanded ? "my-2 border" : "border -mb-px last:mb-0",
|
||||
props.className,
|
||||
(props.onClick || href) && "hover:bg-neutral-50"
|
||||
),
|
||||
},
|
||||
props.children
|
||||
);
|
||||
|
||||
return href ? (
|
||||
<Link passHref href={href}>
|
||||
{element}
|
||||
</Link>
|
||||
) : (
|
||||
element
|
||||
);
|
||||
}
|
||||
|
||||
export function ListLinkItem(props: ListLinkItemProps) {
|
||||
const { href, heading = "", children, disabled = false, actions = <div /> } = props;
|
||||
let subHeading = props.subHeading;
|
||||
if (!subHeading) {
|
||||
subHeading = "";
|
||||
}
|
||||
return (
|
||||
<li
|
||||
className={classNames(
|
||||
"group flex w-full items-center justify-between p-5 hover:bg-neutral-50",
|
||||
disabled ? "hover:bg-white" : ""
|
||||
)}>
|
||||
<Link passHref href={href}>
|
||||
<a
|
||||
className={classNames(
|
||||
"flex-grow truncate text-sm",
|
||||
disabled ? "pointer-events-none cursor-not-allowed opacity-30" : ""
|
||||
)}>
|
||||
<h1 className="text-sm font-semibold leading-none">{heading}</h1>
|
||||
<h2 className="min-h-4 mt-2 text-sm font-normal leading-none">
|
||||
{subHeading.substring(0, 100)}
|
||||
{subHeading.length > 100 && "..."}
|
||||
</h2>
|
||||
<div className="mt-2">{children}</div>
|
||||
</a>
|
||||
</Link>
|
||||
{actions}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
export function ListItemTitle<TComponent extends keyof JSX.IntrinsicElements = "span">(
|
||||
props: JSX.IntrinsicElements[TComponent] & { component?: TComponent }
|
||||
) {
|
||||
const { component = "span", ...passThroughProps } = props;
|
||||
|
||||
return createElement(
|
||||
component,
|
||||
{
|
||||
...passThroughProps,
|
||||
className: classNames("text-sm font-medium text-neutral-900 truncate", props.className),
|
||||
},
|
||||
props.children
|
||||
);
|
||||
}
|
||||
|
||||
export function ListItemText<TComponent extends keyof JSX.IntrinsicElements = "span">(
|
||||
props: JSX.IntrinsicElements[TComponent] & { component?: TComponent }
|
||||
) {
|
||||
const { component = "span", ...passThroughProps } = props;
|
||||
|
||||
return createElement(
|
||||
component,
|
||||
{
|
||||
...passThroughProps,
|
||||
className: classNames("text-sm text-gray-500 truncate", props.className),
|
||||
},
|
||||
props.children
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { User } from "@prisma/client";
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { NextRouter, useRouter } from "next/router";
|
||||
import React, { Fragment, ReactNode, useEffect, useState } from "react";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
@@ -25,7 +25,9 @@ import Dropdown, {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@calcom/ui/Dropdown";
|
||||
import { CollectionIcon, Icon } from "@calcom/ui/Icon";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Loader } from "@calcom/ui/v2";
|
||||
import { useViewerI18n } from "@calcom/web/components/I18nLanguageHandler";
|
||||
|
||||
/* TODO: Get this from endpoint */
|
||||
import pkg from "../../../../apps/web/package.json";
|
||||
@@ -159,6 +161,7 @@ type LayoutProps = {
|
||||
flexChildrenContainer?: boolean;
|
||||
isPublic?: boolean;
|
||||
customLoader?: ReactNode;
|
||||
withoutMain?: boolean;
|
||||
};
|
||||
|
||||
const CustomBrandingContainer = () => {
|
||||
@@ -170,6 +173,9 @@ export default function Shell(props: LayoutProps) {
|
||||
useRedirectToLoginIfUnauthenticated(props.isPublic);
|
||||
useRedirectToOnboardingIfNeeded();
|
||||
useTheme("light");
|
||||
const { session } = useRedirectToLoginIfUnauthenticated(props.isPublic);
|
||||
|
||||
if (!session && !props.isPublic) return null;
|
||||
|
||||
return (
|
||||
<KBarRoot>
|
||||
@@ -362,8 +368,18 @@ type NavigationItemType = {
|
||||
icon?: SVGComponent;
|
||||
child?: NavigationItemType[];
|
||||
pro?: true;
|
||||
isCurrent?: ({
|
||||
item,
|
||||
isChild,
|
||||
router,
|
||||
}: {
|
||||
item: NavigationItemType;
|
||||
isChild?: boolean;
|
||||
router: NextRouter;
|
||||
}) => boolean;
|
||||
};
|
||||
|
||||
const requiredCredentialNavigationItems = ["Routing Forms"];
|
||||
const navigation: NavigationItemType[] = [
|
||||
{
|
||||
name: "event_types_page_title",
|
||||
@@ -383,7 +399,7 @@ const navigation: NavigationItemType[] = [
|
||||
{
|
||||
name: "Routing Forms",
|
||||
href: "/apps/routing_forms/forms",
|
||||
icon: CollectionIcon,
|
||||
icon: Icon.FiFileText,
|
||||
},
|
||||
{
|
||||
name: "workflows",
|
||||
@@ -395,6 +411,10 @@ const navigation: NavigationItemType[] = [
|
||||
name: "apps",
|
||||
href: "/apps",
|
||||
icon: Icon.FiGrid,
|
||||
isCurrent: ({ router, item }) => {
|
||||
const path = router.asPath.split("?")[0];
|
||||
return !!item.child?.some((child) => path === child.href);
|
||||
},
|
||||
child: [
|
||||
{
|
||||
name: "app_store",
|
||||
@@ -413,15 +433,13 @@ const navigation: NavigationItemType[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const requiredCredentialNavigationItems = ["Routing Forms"];
|
||||
|
||||
const Navigation = () => {
|
||||
return (
|
||||
<nav className="mt-2 flex-1 space-y-1 lg:mt-5">
|
||||
<nav className="mt-2 flex-1 space-y-1 md:px-2 lg:mt-5 lg:px-0">
|
||||
{navigation.map((item) => (
|
||||
<NavigationItem key={item.name} item={item} />
|
||||
))}
|
||||
<span className="group flex items-center rounded-sm px-2 py-2 text-sm font-medium text-neutral-500 hover:bg-gray-50 hover:text-neutral-900 lg:hidden">
|
||||
<span className="group flex items-center rounded-sm px-3 py-3 text-sm font-medium text-neutral-500 hover:bg-gray-50 hover:text-neutral-900 lg:hidden">
|
||||
<KBarTrigger />
|
||||
</span>
|
||||
</nav>
|
||||
@@ -436,6 +454,10 @@ function useShouldDisplayNavigationItem(item: NavigationItemType) {
|
||||
return !requiredCredentialNavigationItems.includes(item.name) || !!routingForms;
|
||||
}
|
||||
|
||||
const defaultIsCurrent: NavigationItemType["isCurrent"] = ({ isChild, item, router }) => {
|
||||
return isChild ? item.href === router.asPath : router.asPath.startsWith(item.href);
|
||||
};
|
||||
|
||||
const NavigationItem: React.FC<{
|
||||
item: NavigationItemType;
|
||||
isChild?: boolean;
|
||||
@@ -443,7 +465,8 @@ const NavigationItem: React.FC<{
|
||||
const { item, isChild } = props;
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const current = isChild ? item.href === router.asPath : router.asPath.startsWith(item.href);
|
||||
const isCurrent: NavigationItemType["isCurrent"] = item.isCurrent || defaultIsCurrent;
|
||||
const current = isCurrent({ isChild: !!isChild, item, router });
|
||||
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
||||
|
||||
if (!shouldDisplayNavigationItem) return null;
|
||||
@@ -454,15 +477,15 @@ const NavigationItem: React.FC<{
|
||||
<a
|
||||
aria-label={t(item.name)}
|
||||
className={classNames(
|
||||
"group flex items-center rounded-md py-3 text-sm font-medium text-neutral-500 hover:bg-gray-50 hover:text-neutral-900 lg:px-[14px] [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:hover:text-neutral-900",
|
||||
"group flex items-center rounded-md py-3 px-3 text-sm font-medium text-neutral-500 hover:bg-gray-50 hover:text-neutral-900 lg:px-[14px] [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:hover:text-neutral-900",
|
||||
isChild
|
||||
? "[&[aria-current='page']]:text-brand-900 hidden pl-10 lg:flex"
|
||||
? "[&[aria-current='page']]:text-brand-900 hidden pl-16 lg:flex lg:pl-11"
|
||||
: "[&[aria-current='page']]:text-brand-900 "
|
||||
)}
|
||||
aria-current={current ? "page" : undefined}>
|
||||
{item.icon && (
|
||||
<item.icon
|
||||
className="h-5 w-5 flex-shrink-0 text-neutral-400 group-hover:text-neutral-500 ltr:mr-3 rtl:ml-3 [&[aria-current='page']]:text-inherit"
|
||||
className="h-4 w-4 flex-shrink-0 text-neutral-400 group-hover:text-neutral-500 ltr:mr-3 rtl:ml-3 md:h-5 md:w-5 [&[aria-current='page']]:text-inherit"
|
||||
aria-hidden="true"
|
||||
aria-current={current ? "page" : undefined}
|
||||
/>
|
||||
@@ -471,6 +494,7 @@ const NavigationItem: React.FC<{
|
||||
</a>
|
||||
</Link>
|
||||
{item.child &&
|
||||
isCurrent({ router, isChild, item }) &&
|
||||
router.asPath.startsWith(item.href) &&
|
||||
item.child.map((item) => <NavigationItem key={item.name} item={item} isChild />)}
|
||||
</Fragment>
|
||||
@@ -489,7 +513,7 @@ const MobileNavigation = () => {
|
||||
<>
|
||||
<nav
|
||||
className={classNames(
|
||||
"bottom-nav fixed bottom-0 z-30 flex w-full bg-white shadow md:hidden",
|
||||
"bottom-nav fixed bottom-0 z-30 -mx-4 flex w-full bg-white shadow md:hidden",
|
||||
isEmbed && "hidden"
|
||||
)}>
|
||||
{navigation
|
||||
@@ -512,7 +536,8 @@ const MobileNavigationItem: React.FC<{
|
||||
const { item, itemIdx, isChild } = props;
|
||||
const router = useRouter();
|
||||
const { t } = useLocale();
|
||||
const current = isChild ? item.href === router.asPath : router.asPath.startsWith(item.href);
|
||||
const isCurrent: NavigationItemType["isCurrent"] = item.isCurrent || defaultIsCurrent;
|
||||
const current = isCurrent({ isChild: !!isChild, item, router });
|
||||
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
||||
if (!shouldDisplayNavigationItem) return null;
|
||||
return (
|
||||
@@ -531,7 +556,7 @@ const MobileNavigationItem: React.FC<{
|
||||
aria-current={current ? "page" : undefined}
|
||||
/>
|
||||
)}
|
||||
<span className="truncate">{t(item.name)}</span>
|
||||
<span className="block truncate">{t(item.name)}</span>
|
||||
</a>
|
||||
</Link>
|
||||
);
|
||||
@@ -565,10 +590,8 @@ function SideBarContainer() {
|
||||
}
|
||||
|
||||
function SideBar() {
|
||||
const [visible, setVisible] = useState(true);
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<aside className="hidden w-14 flex-col border-r border-gray-100 bg-gray-50 px-2 md:flex lg:w-56 lg:flex-shrink-0 lg:px-4">
|
||||
<aside className="hidden w-14 flex-col border-r border-gray-100 bg-gray-50 md:flex lg:w-56 lg:flex-shrink-0 lg:px-4">
|
||||
<div className="flex h-0 flex-1 flex-col overflow-y-auto pt-3 pb-4 lg:pt-5">
|
||||
<div className="items-center justify-between md:hidden lg:flex">
|
||||
<Link href="/event-types">
|
||||
@@ -607,15 +630,20 @@ function SideBar() {
|
||||
);
|
||||
}
|
||||
|
||||
function MainContainer(props: LayoutProps) {
|
||||
export function ShellMain(props: LayoutProps) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<main className="relative z-0 flex flex-1 flex-col overflow-y-auto bg-white focus:outline-none lg:px-12 lg:py-8">
|
||||
{/* show top navigation for md and smaller (tablet and phones) */}
|
||||
<TopNavContainer />
|
||||
<ErrorBoundary>
|
||||
<>
|
||||
<div className="flex items-baseline">
|
||||
{!!props.backPath && (
|
||||
<Icon.FiArrowLeft
|
||||
className="mr-3 hover:cursor-pointer"
|
||||
onClick={() => router.push(props.backPath as string)}
|
||||
/>
|
||||
)}
|
||||
{props.heading && (
|
||||
<div
|
||||
className={classNames(props.large && "bg-gray-100 py-8", "flex items-center px-2 pt-4 md:p-0")}>
|
||||
<div className={classNames(props.large && "py-8", "flex w-full items-center px-2 pt-4 md:p-0")}>
|
||||
{props.HeadingLeftIcon && <div className="ltr:mr-4">{props.HeadingLeftIcon}</div>}
|
||||
<div className="mb-4 w-full">
|
||||
<>
|
||||
@@ -632,9 +660,21 @@ function MainContainer(props: LayoutProps) {
|
||||
{props.CTA && <div className="mb-4 flex-shrink-0">{props.CTA}</div>}
|
||||
</div>
|
||||
)}
|
||||
<div className={classNames("", props.flexChildrenContainer && "flex flex-1 flex-col")}>
|
||||
{props.children}
|
||||
</div>
|
||||
</div>
|
||||
<div className={classNames("", props.flexChildrenContainer && "flex flex-1 flex-col")}>
|
||||
{props.children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function MainContainer(props: LayoutProps) {
|
||||
return (
|
||||
<main className="relative z-0 flex flex-1 flex-col overflow-y-auto bg-white py-2 px-4 focus:outline-none lg:py-8 lg:px-12">
|
||||
{/* show top navigation for md and smaller (tablet and phones) */}
|
||||
<TopNavContainer />
|
||||
<ErrorBoundary>
|
||||
{!props.withoutMain ? <ShellMain {...props}>{props.children}</ShellMain> : props.children}
|
||||
</ErrorBoundary>
|
||||
{/* show bottom navigation for md and smaller (tablet and phones) */}
|
||||
<MobileNavigationContainer />
|
||||
|
||||
@@ -25,7 +25,7 @@ export function Tooltip({
|
||||
onOpenChange={onOpenChange}>
|
||||
<TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>
|
||||
<TooltipPrimitive.Content
|
||||
className="-mt-2 rounded-md bg-gray-900 px-2 py-1 text-xs font-semibold text-white shadow-lg"
|
||||
className="-mt-2 rounded-md bg-gray-900 px-2 py-1 text-xs font-semibold text-white shadow-lg"
|
||||
side={side}
|
||||
align="center"
|
||||
{...props}>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MouseEvent } from "react";
|
||||
import { MouseEvent, useState } from "react";
|
||||
import { Icon } from "react-feather";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
@@ -17,28 +17,32 @@ export type BannerProps = {
|
||||
variant: keyof typeof stylesByVariant;
|
||||
errorMessage?: string;
|
||||
Icon?: Icon;
|
||||
onDismiss: (event: MouseEvent<HTMLElement, MouseEvent>) => void;
|
||||
onAction?: (event: MouseEvent<HTMLElement, MouseEvent>) => void;
|
||||
onDismiss: (event: MouseEvent<HTMLElement, globalThis.MouseEvent>) => void;
|
||||
onAction?: (event: MouseEvent<HTMLElement, globalThis.MouseEvent>) => void;
|
||||
actionText?: string;
|
||||
} & JSX.IntrinsicElements["div"];
|
||||
|
||||
const Banner = (props: BannerProps) => {
|
||||
const { variant, errorMessage, title, description, ...rest } = props;
|
||||
const { variant, errorMessage, title, description, className, Icon, ...rest } = props;
|
||||
const buttonStyle = classNames(stylesByVariant[variant].text, stylesByVariant[variant].hover);
|
||||
const [show, setShow] = useState(true);
|
||||
if (!show) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
"flex items-center rounded-md px-4 py-4",
|
||||
stylesByVariant[variant].background,
|
||||
stylesByVariant[variant].text,
|
||||
props.className
|
||||
className
|
||||
)}
|
||||
{...rest}>
|
||||
<div className={classNames("flex flex-row text-sm")}>
|
||||
<div className="mr-3">{props.Icon && <props.Icon className="h-4 w-4" />}</div>
|
||||
<div className="mr-3">{Icon && <Icon className="h-4 w-4" />}</div>
|
||||
<div className="flex flex-col space-y-2">
|
||||
<h1 className="font-semibold leading-none">{title}</h1>
|
||||
{description && <h2 className="font-normal leading-none">{description}</h2>}
|
||||
{description && <h2 className="font-normal leading-4">{description}</h2>}
|
||||
{props.variant === "error" && <p className="ml-4 pt-2 font-mono text-xs">{errorMessage}</p>}
|
||||
</div>
|
||||
</div>
|
||||
@@ -48,7 +52,13 @@ const Banner = (props: BannerProps) => {
|
||||
Action
|
||||
</Button>
|
||||
)}
|
||||
<Button color="minimal" className={buttonStyle} onClick={() => props.onDismiss}>
|
||||
<Button
|
||||
color="minimal"
|
||||
className={buttonStyle}
|
||||
onClick={(e) => {
|
||||
setShow(false);
|
||||
props.onDismiss(e);
|
||||
}}>
|
||||
Dismiss
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { useId } from "@radix-ui/react-id";
|
||||
import { Root as ToggleGroupPrimitive, Item as ToggleGroupItemPrimitive } from "@radix-ui/react-toggle-group";
|
||||
import { useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Label } from "./fields";
|
||||
|
||||
const boolean = (yesNo: "yes" | "no") => (yesNo === "yes" ? true : yesNo === "no" ? false : undefined);
|
||||
const yesNo = (boolean?: boolean) => (boolean === true ? "yes" : boolean === false ? "no" : undefined);
|
||||
|
||||
export const BooleanToggleGroup = function BooleanToggleGroup({
|
||||
defaultValue = true,
|
||||
value,
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
onValueChange = () => {},
|
||||
}: {
|
||||
defaultValue?: boolean;
|
||||
value?: boolean;
|
||||
onValueChange?: (value?: boolean) => void;
|
||||
}) {
|
||||
// Maintain a state because it is not necessary that onValueChange the parent component would re-render. Think react-hook-form
|
||||
// Also maintain a string as boolean isn't accepted as ToggleGroupPrimitive value
|
||||
const [yesNoValue, setYesNoValue] = useState<"yes" | "no" | undefined>(yesNo(value));
|
||||
|
||||
if (!yesNoValue) {
|
||||
setYesNoValue(yesNo(defaultValue));
|
||||
onValueChange(defaultValue);
|
||||
return null;
|
||||
}
|
||||
const commonClass =
|
||||
"mb-2 inline-flex items-center justify-center rounded-md py-[10px] px-4 text-sm font-medium leading-4 md:mb-0";
|
||||
const selectedClass = classNames(commonClass, "bg-gray-200 text-gray-900");
|
||||
const unselectedClass = classNames(commonClass, "text-gray-600 hover:bg-gray-100 hover:text-gray-900");
|
||||
return (
|
||||
<ToggleGroupPrimitive
|
||||
value={yesNoValue}
|
||||
type="single"
|
||||
className="rounded-sm"
|
||||
onValueChange={(yesNoValue: "yes" | "no") => {
|
||||
setYesNoValue(yesNoValue);
|
||||
onValueChange(boolean(yesNoValue));
|
||||
}}>
|
||||
<ToggleGroupItemPrimitive
|
||||
className={classNames(boolean(yesNoValue) ? selectedClass : unselectedClass)}
|
||||
value="yes">
|
||||
Yes
|
||||
</ToggleGroupItemPrimitive>
|
||||
<ToggleGroupItemPrimitive
|
||||
className={classNames(!boolean(yesNoValue) ? selectedClass : unselectedClass)}
|
||||
value="no">
|
||||
No
|
||||
</ToggleGroupItemPrimitive>
|
||||
</ToggleGroupPrimitive>
|
||||
);
|
||||
};
|
||||
|
||||
export const BooleanToggleGroupField = function BooleanToggleGroupField(
|
||||
props: Parameters<typeof BooleanToggleGroup>[0] & {
|
||||
label?: string;
|
||||
containerClassName?: string;
|
||||
name?: string;
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
className?: string;
|
||||
error?: string;
|
||||
}
|
||||
) {
|
||||
const { t } = useLocale();
|
||||
const { label = t(props.name || ""), containerClassName, labelProps, className, ...passThrough } = props;
|
||||
const id = useId();
|
||||
return (
|
||||
<div className={classNames(containerClassName)}>
|
||||
<div className={className}>
|
||||
{!!label && (
|
||||
<Label htmlFor={id} {...labelProps} className={classNames(props.error && "text-red-900")}>
|
||||
{label}
|
||||
</Label>
|
||||
)}
|
||||
</div>
|
||||
<BooleanToggleGroup {...passThrough} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import Divider from "../Divider";
|
||||
|
||||
type Action = { check: () => boolean; fn: () => void };
|
||||
export default function FormCard({
|
||||
children,
|
||||
label,
|
||||
deleteField,
|
||||
moveUp,
|
||||
moveDown,
|
||||
className,
|
||||
...restProps
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
label?: string;
|
||||
deleteField?: Action | null;
|
||||
moveUp?: Action | null;
|
||||
moveDown?: Action | null;
|
||||
className?: string;
|
||||
} & JSX.IntrinsicElements["div"]) {
|
||||
className = classNames(className, "group relative w-full rounded-md p-4 border border-gray-200");
|
||||
|
||||
return (
|
||||
<div className={className} {...restProps}>
|
||||
<div>
|
||||
{moveUp?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-0 -ml-[13px] -mt-0 mb-4 hidden h-7 w-7 scale-0 rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:block"
|
||||
onClick={() => moveUp?.fn()}>
|
||||
<Icon.FiArrowUp />
|
||||
</button>
|
||||
) : null}
|
||||
{moveDown?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-0 mt-8 -ml-[13px] hidden h-7 w-7 scale-0 rounded-full border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 sm:block"
|
||||
onClick={() => moveDown?.fn()}>
|
||||
<Icon.FiArrowDown />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm font-semibold leading-none">{label}</span>
|
||||
{deleteField?.check() ? (
|
||||
<button
|
||||
onClick={() => {
|
||||
deleteField?.fn();
|
||||
}}
|
||||
color="secondary">
|
||||
<Icon.FiTrash className="h-4 w-4 text-gray-400" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<Divider className="mt-3 mb-6" />
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
import ReactSelect, { components, GroupBase, InputProps, Props } from "react-select";
|
||||
import { useId } from "@radix-ui/react-id";
|
||||
import * as React from "react";
|
||||
import ReactSelect, { components, GroupBase, InputProps, Props, SingleValue, MultiValue } from "react-select";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Label } from "./fields";
|
||||
|
||||
export type SelectProps<
|
||||
Option,
|
||||
@@ -60,4 +65,106 @@ function Select<
|
||||
);
|
||||
}
|
||||
|
||||
export const SelectField = function SelectField<
|
||||
Option,
|
||||
isMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>(
|
||||
props: {
|
||||
name?: string;
|
||||
containerClassName?: string;
|
||||
label?: string;
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
className?: string;
|
||||
error?: string;
|
||||
} & SelectProps<Option, isMulti, Group>
|
||||
) {
|
||||
const { t } = useLocale();
|
||||
const { label = t(props.name || ""), containerClassName, labelProps, className, ...passThrough } = props;
|
||||
const id = useId();
|
||||
return (
|
||||
<div className={classNames(containerClassName)}>
|
||||
<div className={classNames(className)}>
|
||||
{!!label && (
|
||||
<Label htmlFor={id} {...labelProps} className={classNames(props.error && "text-red-900")}>
|
||||
{label}
|
||||
</Label>
|
||||
)}
|
||||
</div>
|
||||
<Select {...passThrough} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: It should replace Select after through testing
|
||||
*/
|
||||
export function SelectWithValidation<
|
||||
Option extends { label: string; value: string },
|
||||
isMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
required = false,
|
||||
onChange,
|
||||
value,
|
||||
...remainingProps
|
||||
}: SelectProps<Option, isMulti, Group> & { required?: boolean }) {
|
||||
const [hiddenInputValue, _setHiddenInputValue] = React.useState(() => {
|
||||
if (value instanceof Array || !value) {
|
||||
return;
|
||||
}
|
||||
return value.value || "";
|
||||
});
|
||||
|
||||
const setHiddenInputValue = React.useCallback((value: MultiValue<Option> | SingleValue<Option>) => {
|
||||
let hiddenInputValue = "";
|
||||
if (value instanceof Array) {
|
||||
hiddenInputValue = value.map((val) => val.value).join(",");
|
||||
} else {
|
||||
hiddenInputValue = value?.value || "";
|
||||
}
|
||||
_setHiddenInputValue(hiddenInputValue);
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
setHiddenInputValue(value);
|
||||
}, [value, setHiddenInputValue]);
|
||||
|
||||
return (
|
||||
<div className={classNames("relative", remainingProps.className)}>
|
||||
<Select
|
||||
value={value}
|
||||
{...remainingProps}
|
||||
onChange={(value, ...remainingArgs) => {
|
||||
setHiddenInputValue(value);
|
||||
if (onChange) {
|
||||
onChange(value, ...remainingArgs);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{required && (
|
||||
<input
|
||||
tabIndex={-1}
|
||||
autoComplete="off"
|
||||
style={{
|
||||
opacity: 0,
|
||||
width: "100%",
|
||||
height: 1,
|
||||
position: "absolute",
|
||||
}}
|
||||
value={hiddenInputValue}
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
onChange={() => {}}
|
||||
// TODO:Not able to get focus to work
|
||||
// onFocus={() => selectRef.current?.focus()}
|
||||
required={required}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Select;
|
||||
@@ -17,7 +17,7 @@ import showToast from "@calcom/ui/v2/core/notifications";
|
||||
|
||||
import { Alert } from "../../../Alert";
|
||||
|
||||
type InputProps = Omit<JSX.IntrinsicElements["input"], "name"> & { name: string };
|
||||
type InputProps = JSX.IntrinsicElements["input"];
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(props, ref) {
|
||||
return (
|
||||
@@ -164,13 +164,12 @@ const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputF
|
||||
const id = useId();
|
||||
const { t: _t } = useLocale();
|
||||
const t = props.t || _t;
|
||||
const name = props.name || "";
|
||||
const {
|
||||
label = t(props.name),
|
||||
label = t(name),
|
||||
labelProps,
|
||||
/** Prevents displaying untranslated placeholder keys */
|
||||
placeholder = t(props.name + "_placeholder") !== props.name + "_placeholder"
|
||||
? t(props.name + "_placeholder")
|
||||
: "",
|
||||
placeholder = t(name + "_placeholder") !== name + "_placeholder" ? t(name + "_placeholder") : "",
|
||||
className,
|
||||
addOnLeading,
|
||||
addOnSuffix,
|
||||
@@ -186,7 +185,7 @@ const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputF
|
||||
|
||||
return (
|
||||
<div className={classNames(containerClassName)}>
|
||||
{!!props.name && (
|
||||
{!!name && (
|
||||
<Label
|
||||
htmlFor={id}
|
||||
{...labelProps}
|
||||
@@ -231,7 +230,7 @@ const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputF
|
||||
) : (
|
||||
<Input id={id} placeholder={placeholder} className={className} {...passThrough} ref={ref} />
|
||||
)}
|
||||
<HintsOrErrors hintErrors={hintErrors} fieldName={props.name} t={t} />
|
||||
<HintsOrErrors hintErrors={hintErrors} fieldName={name} t={t} />
|
||||
{hint && <div className="text-gray mt-2 flex items-center text-sm text-gray-700">{hint}</div>}
|
||||
</div>
|
||||
);
|
||||
@@ -276,7 +275,7 @@ export const EmailField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
);
|
||||
});
|
||||
|
||||
type TextAreaProps = Omit<JSX.IntrinsicElements["textarea"], "name"> & { name: string };
|
||||
type TextAreaProps = JSX.IntrinsicElements["textarea"];
|
||||
|
||||
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(function TextAreaInput(props, ref) {
|
||||
return (
|
||||
@@ -284,7 +283,7 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(function
|
||||
ref={ref}
|
||||
{...props}
|
||||
className={classNames(
|
||||
"my-2 block h-9 w-full rounded-md border border-gray-300 py-2 px-3 shadow-sm hover:border-gray-400 focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1 sm:text-sm",
|
||||
"my-2 block w-full rounded-md border border-gray-300 py-2 px-3 shadow-sm hover:border-gray-400 focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1 sm:text-sm",
|
||||
props.className
|
||||
)}
|
||||
/>
|
||||
@@ -295,6 +294,7 @@ type TextAreaFieldProps = {
|
||||
label?: ReactNode;
|
||||
t?: (key: string) => string;
|
||||
} & React.ComponentProps<typeof TextArea> & {
|
||||
name: string;
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,5 +2,6 @@ export * from "./radio-area";
|
||||
export * from "./fields";
|
||||
export { default as Checkbox } from "./Checkbox";
|
||||
export { default as DatePicker } from "./DatePicker";
|
||||
export { default as Select } from "./Select";
|
||||
export { default as Select, SelectWithValidation, SelectField } from "./Select";
|
||||
|
||||
export { default as FormStep } from "./FormStep";
|
||||
@@ -9,6 +9,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
export type HorizontalTabItemProps = {
|
||||
name: string;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
} & (
|
||||
| {
|
||||
/** If you want to change query param tabName as per current tab */
|
||||
@@ -54,7 +55,8 @@ const HorizontalTabItem = ({ name, href, tabName, ...props }: HorizontalTabItemP
|
||||
className={classNames(
|
||||
isCurrent ? "bg-gray-200 text-gray-900" : " text-gray-600 hover:bg-gray-100 hover:text-gray-900 ",
|
||||
"mb-2 inline-flex items-center justify-center whitespace-nowrap rounded-md py-[10px] px-4 text-sm font-medium leading-4 md:mb-0",
|
||||
props.disabled && "pointer-events-none !opacity-30"
|
||||
props.disabled && "pointer-events-none !opacity-30",
|
||||
props.className
|
||||
)}
|
||||
aria-current={isCurrent ? "page" : undefined}>
|
||||
{t(name)}
|
||||
|
||||
@@ -6,7 +6,7 @@ export default function showToast(message: string, variant: "success" | "warning
|
||||
case "success":
|
||||
toast.custom(
|
||||
() => (
|
||||
<div className="bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md">
|
||||
<div className="data-testid-toast-success bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md">
|
||||
<Check className="h-4 w-4" />
|
||||
<p>{message}</p>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user