Feature: Routing Forms Typeform App and other improvements (#3625)
* Add Embed ModalBox for routing forms * Add duplicate form support * Fix duplication logic * Change to feathericons everywhere and other fixes * Dont allow routes for fallback route * Fix all TS issues * Fix tests * Support routing using query params * Support multiselect in router endpoint * Fix the issue where app goes in embed mode after viewing embed once * Add router url tests * Add Responses download and form toggling tests * Add required validation test * Change Icons everywhere * App typeform app * Improvements in cli * Add typeform how-to-use page * Add typeform how-to-use page and screenshots * Fix TS error * Add missing image * Update CliApp.tsx * Revert unexpected zapier change * Revert yarn.lock, not sure why it was modified Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
4cb5a56d41
commit
c3fbf8224b
67 files changed
+1434
-667
No files matched your search
@@ -45,7 +45,7 @@ const AdditionalCalendarSelector = ({ isLoading }: AdditionalCalendarSelectorPro
|
||||
const options = data.items.map((item) => ({
|
||||
label: item.name,
|
||||
slug: item.slug,
|
||||
image: item.imageSrc,
|
||||
image: item.logo,
|
||||
type: item.type,
|
||||
}));
|
||||
return (
|
||||
|
||||
@@ -6,9 +6,6 @@ import { components, ControlProps } from "react-select";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import showToast from "@calcom/lib/notification";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { SVGComponent } from "@calcom/types/SVGComponent";
|
||||
import { Button, Switch } from "@calcom/ui";
|
||||
import { Dialog, DialogClose, DialogContent } from "@calcom/ui/Dialog";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
@@ -41,7 +38,7 @@ type PreviewState = {
|
||||
brandColor: string;
|
||||
};
|
||||
};
|
||||
const queryParamsForDialog = ["embedType", "tabName", "eventTypeId"];
|
||||
const queryParamsForDialog = ["embedType", "tabName", "embedUrl"];
|
||||
|
||||
const getDimension = (dimension: string) => {
|
||||
if (dimension.match(/^\d+$/)) {
|
||||
@@ -626,11 +623,11 @@ const ChooseEmbedTypesDialogContent = () => {
|
||||
};
|
||||
|
||||
const EmbedTypeCodeAndPreviewDialogContent = ({
|
||||
eventTypeId,
|
||||
embedType,
|
||||
embedUrl,
|
||||
}: {
|
||||
eventTypeId: EventType["id"];
|
||||
embedType: EmbedType;
|
||||
embedUrl: string;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
@@ -645,13 +642,6 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
|
||||
const refOfEmbedCodesRefs = useRef(embedCodeRefs);
|
||||
const embed = embeds.find((embed) => embed.type === embedType);
|
||||
|
||||
const { data: eventType, isLoading } = trpc.useQuery([
|
||||
"viewer.eventTypes.get",
|
||||
{
|
||||
id: +eventTypeId,
|
||||
},
|
||||
]);
|
||||
|
||||
const [isEmbedCustomizationOpen, setIsEmbedCustomizationOpen] = useState(true);
|
||||
const [isBookingCustomizationOpen, setIsBookingCustomizationOpen] = useState(true);
|
||||
const [previewState, setPreviewState] = useState({
|
||||
@@ -693,18 +683,12 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
|
||||
});
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!embed || !eventType) {
|
||||
if (!embed || !embedUrl) {
|
||||
close();
|
||||
return null;
|
||||
}
|
||||
|
||||
const calLink = `${eventType.team ? `team/${eventType.team.slug}` : eventType.users[0].username}/${
|
||||
eventType.slug
|
||||
}`;
|
||||
const calLink = decodeURIComponent(embedUrl);
|
||||
|
||||
const addToPalette = (update: typeof previewState["palette"]) => {
|
||||
setPreviewState((previewState) => {
|
||||
@@ -1118,41 +1102,46 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
|
||||
|
||||
export const EmbedDialog = () => {
|
||||
const router = useRouter();
|
||||
const eventTypeId: EventType["id"] = +(router.query.eventTypeId as string);
|
||||
const embedUrl: string = router.query.embedUrl as string;
|
||||
return (
|
||||
<Dialog name="embed" clearQueryParamsOnClose={queryParamsForDialog}>
|
||||
<Dialog
|
||||
name="embed"
|
||||
clearQueryParamsOnClose={queryParamsForDialog}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) window.resetEmbedStatus();
|
||||
}}>
|
||||
{!router.query.embedType ? (
|
||||
<ChooseEmbedTypesDialogContent />
|
||||
) : (
|
||||
<EmbedTypeCodeAndPreviewDialogContent
|
||||
eventTypeId={eventTypeId}
|
||||
embedType={router.query.embedType as EmbedType}
|
||||
embedUrl={embedUrl}
|
||||
/>
|
||||
)}
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export const EmbedButton = ({
|
||||
eventTypeId,
|
||||
StartIcon,
|
||||
children,
|
||||
className = "",
|
||||
...props
|
||||
}: {
|
||||
eventTypeId: EventType["id"];
|
||||
StartIcon?: SVGComponent;
|
||||
type EmbedButtonProps<T> = {
|
||||
embedUrl: string;
|
||||
children?: React.ReactNode;
|
||||
className: string;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
as?: T;
|
||||
};
|
||||
|
||||
export const EmbedButton = <T extends React.ElementType>({
|
||||
embedUrl,
|
||||
children,
|
||||
className = "",
|
||||
as,
|
||||
...props
|
||||
}: EmbedButtonProps<T> & React.ComponentPropsWithoutRef<T>) => {
|
||||
const router = useRouter();
|
||||
className = classNames(className, "hidden lg:flex");
|
||||
const openEmbedModal = () => {
|
||||
const query = {
|
||||
...router.query,
|
||||
dialog: "embed",
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
};
|
||||
router.push(
|
||||
{
|
||||
@@ -1163,19 +1152,16 @@ export const EmbedButton = ({
|
||||
{ shallow: true }
|
||||
);
|
||||
};
|
||||
const Component = as ?? Button;
|
||||
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
StartIcon={StartIcon}
|
||||
size="sm"
|
||||
className={className}
|
||||
<Component
|
||||
{...props}
|
||||
data-test-eventtype-id={eventTypeId}
|
||||
data-testid="event-type-embed"
|
||||
className={className}
|
||||
data-test-embed-url={embedUrl}
|
||||
data-testid="embed"
|
||||
onClick={() => openEmbedModal()}>
|
||||
{children}
|
||||
</Button>
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
@@ -106,10 +106,11 @@ function CalendarList(props: Props) {
|
||||
<List>
|
||||
{data.items.map((item) => (
|
||||
<IntegrationListItem
|
||||
name={item.name}
|
||||
slug={item.slug}
|
||||
key={item.title}
|
||||
title={item.title}
|
||||
imageSrc={item.imageSrc}
|
||||
logo={item.logo}
|
||||
description={item.description}
|
||||
actions={
|
||||
<InstallAppButton
|
||||
@@ -150,7 +151,7 @@ function ConnectedCalendarsList(props: Props) {
|
||||
<IntegrationListItem
|
||||
slug={item.integration.slug}
|
||||
title={item.integration.title}
|
||||
imageSrc={item.integration.imageSrc}
|
||||
logo={item.integration.logo}
|
||||
description={item.primary?.externalId || "No external Id"}
|
||||
actions={
|
||||
<DisconnectIntegration
|
||||
|
||||
@@ -8,21 +8,24 @@ import classNames from "@lib/classNames";
|
||||
function IntegrationListItem(props: {
|
||||
imageSrc?: string;
|
||||
slug: string;
|
||||
title: string;
|
||||
name?: string;
|
||||
title?: string;
|
||||
description: string;
|
||||
actions?: ReactNode;
|
||||
children?: ReactNode;
|
||||
logo: string;
|
||||
}): JSX.Element {
|
||||
const title = props.name || props.title;
|
||||
return (
|
||||
<ListItem expanded={!!props.children} className={classNames("flex-col")}>
|
||||
<div className={classNames("flex w-full flex-1 items-center space-x-2 p-3 rtl:space-x-reverse")}>
|
||||
{
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
props.imageSrc && <img className="h-10 w-10" src={props.imageSrc} alt={props.title} />
|
||||
props.logo && <img className="h-10 w-10" src={props.logo} alt={title} />
|
||||
}
|
||||
<div className="flex-grow truncate pl-2">
|
||||
<ListItemTitle component="h3">
|
||||
<Link href={"/apps/" + props.slug}>{props.title}</Link>
|
||||
<Link href={"/apps/" + props.slug}>{props.name || title}</Link>
|
||||
</ListItemTitle>
|
||||
<ListItemText component="p">{props.description}</ListItemText>
|
||||
</div>
|
||||
|
||||
@@ -109,6 +109,10 @@ const nextConfig = {
|
||||
source: "/forms/:formId",
|
||||
destination: "/apps/routing_forms/routing-link/:formId",
|
||||
},
|
||||
{
|
||||
source: "/router",
|
||||
destination: "/apps/routing_forms/router",
|
||||
},
|
||||
/* TODO: have these files being served from another deployment or CDN {
|
||||
source: "/embed/embed.js",
|
||||
destination: process.env.NEXT_PUBLIC_EMBED_LIB_URL?,
|
||||
|
||||
@@ -7,6 +7,9 @@ function toRunBeforeReactOnClient() {
|
||||
window.isEmbed = () => {
|
||||
return window.sessionStorage.getItem("calEmbedMode") === "true";
|
||||
};
|
||||
window.resetEmbedStatus = () => {
|
||||
window.sessionStorage.removeItem("calEmbedMode");
|
||||
};
|
||||
|
||||
window.getEmbedTheme = () => {
|
||||
const url = new URL(document.URL);
|
||||
|
||||
@@ -2,38 +2,47 @@ import { GetServerSidePropsContext } from "next";
|
||||
import { NextRouter, 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 { getSession } from "@lib/auth";
|
||||
|
||||
type AppPage = {
|
||||
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 };
|
||||
};
|
||||
|
||||
type Found = {
|
||||
notFound: false;
|
||||
Component: AppPage["default"];
|
||||
getServerSideProps: AppPage["getServerSideProps"];
|
||||
};
|
||||
|
||||
type NotFound = {
|
||||
notFound: true;
|
||||
};
|
||||
|
||||
// TODO: It is a candidate for apps.*.generated.*
|
||||
const AppsRouting = {
|
||||
routing_forms: RoutingFormsRoutingConfig,
|
||||
typeform: TypeformRoutingConfig,
|
||||
};
|
||||
|
||||
function getRoute(appName: string, pages: string[]) {
|
||||
const routingConfig = AppsRouting[appName as keyof typeof AppsRouting];
|
||||
type NotFound = {
|
||||
notFound: true;
|
||||
};
|
||||
const routingConfig = AppsRouting[appName as keyof typeof AppsRouting] as Record<string, AppPage>;
|
||||
|
||||
if (!routingConfig) {
|
||||
return {
|
||||
notFound: true,
|
||||
} as NotFound;
|
||||
}
|
||||
|
||||
const mainPage = pages[0];
|
||||
const appPage = routingConfig[mainPage as keyof typeof routingConfig];
|
||||
type Found = {
|
||||
notFound: false;
|
||||
// A component than can accept any properties
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Component: ((props: any) => JSX.Element) & { isThemeSupported?: boolean };
|
||||
getServerSideProps: AppGetServerSideProps;
|
||||
};
|
||||
const appPage = routingConfig[mainPage] as AppPage;
|
||||
|
||||
if (!appPage) {
|
||||
return {
|
||||
notFound: true,
|
||||
|
||||
@@ -118,10 +118,11 @@ const IntegrationsContainer = ({ variant, className = "" }: IntegrationsContaine
|
||||
<List>
|
||||
{data.items.map((item) => (
|
||||
<IntegrationListItem
|
||||
name={item.name}
|
||||
slug={item.slug}
|
||||
key={item.title}
|
||||
title={item.title}
|
||||
imageSrc={item.imageSrc}
|
||||
logo={item.logo}
|
||||
description={item.description}
|
||||
actions={
|
||||
<ConnectOrDisconnectIntegrationButton
|
||||
|
||||
@@ -66,16 +66,6 @@ import WebhookListContainer from "@components/webhook/WebhookListContainer";
|
||||
import { getTranslation } from "@server/lib/i18n";
|
||||
import { TRPCClientError } from "@trpc/client";
|
||||
|
||||
interface Token {
|
||||
name?: string;
|
||||
address: string;
|
||||
symbol: string;
|
||||
}
|
||||
|
||||
interface NFT extends Token {
|
||||
contracts: Array<Token>;
|
||||
}
|
||||
|
||||
type OptionTypeBase = {
|
||||
label: string;
|
||||
value: LocationType;
|
||||
@@ -401,9 +391,8 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
endDate: new Date(eventType.periodEndDate || Date.now()),
|
||||
});
|
||||
|
||||
const permalink = `${CAL_URL}/${team ? `team/${team.slug}` : eventType.users[0].username}/${
|
||||
eventType.slug
|
||||
}`;
|
||||
const embedLink = `${team ? `team/${team.slug}` : eventType.users[0].username}/${eventType.slug}`;
|
||||
const permalink = `${CAL_URL}/${embedLink}`;
|
||||
|
||||
const placeholderHashedLink = `${CAL_URL}/d/${hashedUrl}/${eventType.slug}`;
|
||||
|
||||
@@ -1944,9 +1933,13 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
</button>
|
||||
)}
|
||||
<EmbedButton
|
||||
as="button"
|
||||
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"
|
||||
eventTypeId={eventType.id}
|
||||
/>
|
||||
embedUrl={encodeURIComponent(embedLink)}>
|
||||
<Icon.FiCode className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" aria-hidden="true" />
|
||||
{t("embed")}
|
||||
</EmbedButton>
|
||||
{/* This will only show if the user is not a member (ADMIN,OWNER) and if there is no current membership
|
||||
- meaning you are within an eventtype that does not belong to a team */}
|
||||
{(props.currentUserMembership?.role !== "MEMBER" || !props.currentUserMembership) && (
|
||||
|
||||
@@ -224,199 +224,238 @@ 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">
|
||||
<ul className="divide-y divide-neutral-200" data-testid="event-types">
|
||||
{types.map((type, index) => (
|
||||
<li
|
||||
key={type.id}
|
||||
className={classNames(type.$disabled && "select-none")}
|
||||
data-disabled={type.$disabled ? 1 : 0}>
|
||||
<div
|
||||
className={classNames(
|
||||
"flex items-center justify-between hover:bg-neutral-50 ",
|
||||
type.$disabled && "hover:bg-white"
|
||||
)}>
|
||||
{types.map((type, index) => {
|
||||
const embedLink = `${group.profile.slug}/${type.slug}`;
|
||||
const calLink = `${CAL_URL}/${embedLink}`;
|
||||
return (
|
||||
<li
|
||||
key={type.id}
|
||||
className={classNames(type.$disabled && "select-none")}
|
||||
data-disabled={type.$disabled ? 1 : 0}>
|
||||
<div
|
||||
className={classNames(
|
||||
"group flex w-full items-center justify-between px-4 py-4 hover:bg-neutral-50 sm:px-6",
|
||||
"flex items-center justify-between hover:bg-neutral-50 ",
|
||||
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"
|
||||
onClick={() => moveEventType(index, -1)}>
|
||||
<Icon.FiArrowUp className="h-5 w-5" />
|
||||
</button>
|
||||
<div
|
||||
className={classNames(
|
||||
"group flex w-full items-center justify-between px-4 py-4 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"
|
||||
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"
|
||||
onClick={() => moveEventType(index, 1)}>
|
||||
<Icon.FiArrowDown className="h-5 w-5" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<MemoizedItem
|
||||
type={type}
|
||||
group={group}
|
||||
readOnly={readOnly}
|
||||
connectedCalendars={connectedCalendarsQuery.data?.connectedCalendars}
|
||||
/>
|
||||
<div className="mt-4 hidden flex-shrink-0 sm:mt-0 sm:ml-5 sm:flex">
|
||||
<div className="flex justify-between space-x-2 rtl:space-x-reverse">
|
||||
{type.users?.length > 1 && (
|
||||
<AvatarGroup
|
||||
border="border-2 border-white"
|
||||
className={classNames("relative top-1 right-3", type.$disabled && " opacity-30")}
|
||||
size={8}
|
||||
truncateAfter={4}
|
||||
items={type.users.map((organizer) => ({
|
||||
alt: organizer.name || "",
|
||||
image: `${WEBAPP_URL}/${organizer.username}/avatar.png`,
|
||||
title: organizer.name || "",
|
||||
}))}
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
className={classNames(
|
||||
"flex justify-between space-x-2 rtl:space-x-reverse ",
|
||||
type.$disabled && "pointer-events-none cursor-not-allowed"
|
||||
)}>
|
||||
<Tooltip side="top" content={t("preview") as string}>
|
||||
<Button
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(!type.$disabled && "group-hover:text-black")}
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
href={`${CAL_URL}/${group.profile.slug}/${type.slug}`}
|
||||
<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"
|
||||
onClick={() => moveEventType(index, 1)}>
|
||||
<Icon.FiArrowDown className="h-5 w-5" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<MemoizedItem
|
||||
type={type}
|
||||
group={group}
|
||||
readOnly={readOnly}
|
||||
connectedCalendars={connectedCalendarsQuery.data?.connectedCalendars}
|
||||
/>
|
||||
<div className="mt-4 hidden flex-shrink-0 sm:mt-0 sm:ml-5 sm:flex">
|
||||
<div className="flex justify-between space-x-2 rtl:space-x-reverse">
|
||||
{type.users?.length > 1 && (
|
||||
<AvatarGroup
|
||||
border="border-2 border-white"
|
||||
className={classNames("relative top-1 right-3", type.$disabled && " opacity-30")}
|
||||
size={8}
|
||||
truncateAfter={4}
|
||||
items={type.users.map((organizer) => ({
|
||||
alt: organizer.name || "",
|
||||
image: `${WEBAPP_URL}/${organizer.username}/avatar.png`,
|
||||
title: organizer.name || "",
|
||||
}))}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
<div
|
||||
className={classNames(
|
||||
"flex justify-between space-x-2 rtl:space-x-reverse ",
|
||||
type.$disabled && "pointer-events-none cursor-not-allowed"
|
||||
)}>
|
||||
<Tooltip side="top" content={t("preview") as string}>
|
||||
<Button
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(!type.$disabled && "group-hover:text-black")}
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
href={calLink}
|
||||
/>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip side="top" content={t("copy_link") as string}>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(type.$disabled ? " opacity-30" : "group-hover:text-black")}
|
||||
StartIcon={Icon.FiLink}
|
||||
onClick={() => {
|
||||
showToast(t("link_copied"), "success");
|
||||
navigator.clipboard.writeText(`${CAL_URL}/${group.profile.slug}/${type.slug}`);
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild data-testid={"event-type-options-" + type.id}>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(type.$disabled ? " opacity-30" : "group-hover:text-black")}
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Link href={"/event-types/" + type.id} passHref={true}>
|
||||
<Tooltip side="top" content={t("copy_link") as string}>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(type.$disabled ? " opacity-30" : "group-hover:text-black")}
|
||||
StartIcon={Icon.FiLink}
|
||||
onClick={() => {
|
||||
showToast(t("link_copied"), "success");
|
||||
navigator.clipboard.writeText(calLink);
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild data-testid={"event-type-options-" + type.id}>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(type.$disabled ? " opacity-30" : "group-hover:text-black")}
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Link href={"/event-types/" + type.id} passHref={true}>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
disabled={type.$disabled}
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiEdit2}
|
||||
className="w-full">
|
||||
{t("edit") as string}
|
||||
</Button>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
disabled={type.$disabled}
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiEdit2}
|
||||
className="w-full">
|
||||
{t("edit") as string}
|
||||
data-testid={"event-type-duplicate-" + type.id}
|
||||
StartIcon={Icon.FiCopy}
|
||||
onClick={() => openModal(group, type)}>
|
||||
{t("duplicate") as string}
|
||||
</Button>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<EmbedButton
|
||||
color="minimal"
|
||||
size="sm"
|
||||
type="button"
|
||||
StartIcon={Icon.FiCode}
|
||||
className={classNames(
|
||||
"w-full rounded-none",
|
||||
type.$disabled && " pointer-events-none cursor-not-allowed opacity-30"
|
||||
)}
|
||||
embedUrl={encodeURIComponent(embedLink)}>
|
||||
{t("embed")}
|
||||
</EmbedButton>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
{/* readonly is only set when we are on a team - if we are on a user event type null will be the value. */}
|
||||
{(group.metadata?.readOnly === false || group.metadata.readOnly === null) && (
|
||||
<DropdownMenuItem>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogTypeId(type.id);
|
||||
}}
|
||||
color="warn"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
{t("delete") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mr-5 flex flex-shrink-0 sm:hidden">
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild data-testid={"event-type-options-" + type.id}>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(type.$disabled && " opacity-30")}
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent portalled>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Link href={calLink}>
|
||||
<Button
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
className="w-full rounded-none">
|
||||
{t("preview") as string}
|
||||
</Button>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
className="w-full rounded-none text-left"
|
||||
data-testid={"event-type-duplicate-" + type.id}
|
||||
StartIcon={Icon.FiClipboard}
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(calLink);
|
||||
showToast(t("link_copied"), "success");
|
||||
}}>
|
||||
{t("copy_link") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
{isNativeShare ? (
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
disabled={type.$disabled}
|
||||
className="w-full rounded-none"
|
||||
data-testid={"event-type-duplicate-" + type.id}
|
||||
StartIcon={Icon.FiCopy}
|
||||
onClick={() => openModal(group, type)}>
|
||||
{t("duplicate") as string}
|
||||
StartIcon={Icon.FiUpload}
|
||||
onClick={() => {
|
||||
navigator
|
||||
.share({
|
||||
title: t("share"),
|
||||
text: t("share_event"),
|
||||
url: calLink,
|
||||
})
|
||||
.then(() => showToast(t("link_shared"), "success"))
|
||||
.catch(() => showToast(t("failed"), "error"));
|
||||
}}>
|
||||
{t("share") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<EmbedButton
|
||||
StartIcon={Icon.FiCode}
|
||||
className={classNames(
|
||||
"w-full rounded-none",
|
||||
type.$disabled && " pointer-events-none cursor-not-allowed opacity-30"
|
||||
)}
|
||||
eventTypeId={type.id}>
|
||||
{t("embed")}
|
||||
</EmbedButton>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
{/* readonly is only set when we are on a team - if we are on a user event type null will be the value. */}
|
||||
{(group.metadata?.readOnly === false || group.metadata.readOnly === null) && (
|
||||
<DropdownMenuItem>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogTypeId(type.id);
|
||||
}}
|
||||
color="warn"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
{t("delete") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mr-5 flex flex-shrink-0 sm:hidden">
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild data-testid={"event-type-options-" + type.id}>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(type.$disabled && " opacity-30")}
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent portalled>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Link href={`${CAL_URL}/${group.profile.slug}/${type.slug}`}>
|
||||
) : null}
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
color="minimal"
|
||||
type="button"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiExternalLink}
|
||||
className="w-full rounded-none">
|
||||
{t("preview") as string}
|
||||
href={"/event-types/" + type.id}
|
||||
color="minimal"
|
||||
className="w-full rounded-none"
|
||||
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 text-left"
|
||||
data-testid={"event-type-duplicate-" + type.id}
|
||||
StartIcon={Icon.FiClipboard}
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(`${CAL_URL}/${group.profile.slug}/${type.slug}`);
|
||||
showToast(t("link_copied"), "success");
|
||||
}}>
|
||||
{t("copy_link") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
{isNativeShare ? (
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
@@ -424,64 +463,32 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
||||
size="sm"
|
||||
className="w-full rounded-none"
|
||||
data-testid={"event-type-duplicate-" + type.id}
|
||||
StartIcon={Icon.FiUpload}
|
||||
onClick={() => {
|
||||
navigator
|
||||
.share({
|
||||
title: t("share"),
|
||||
text: t("share_event"),
|
||||
url: `${CAL_URL}/${group.profile.slug}/${type.slug}`,
|
||||
})
|
||||
.then(() => showToast(t("link_shared"), "success"))
|
||||
.catch(() => showToast(t("failed"), "error"));
|
||||
}}>
|
||||
{t("share") as string}
|
||||
StartIcon={Icon.FiCopy}
|
||||
onClick={() => openModal(group, type)}>
|
||||
{t("duplicate") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
href={"/event-types/" + type.id}
|
||||
color="minimal"
|
||||
className="w-full rounded-none"
|
||||
StartIcon={Icon.FiEdit2}>
|
||||
{t("edit") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
className="w-full rounded-none"
|
||||
data-testid={"event-type-duplicate-" + type.id}
|
||||
StartIcon={Icon.FiCopy}
|
||||
onClick={() => openModal(group, type)}>
|
||||
{t("duplicate") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogTypeId(type.id);
|
||||
}}
|
||||
color="warn"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
{t("delete") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogTypeId(type.id);
|
||||
}}
|
||||
color="warn"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
{t("delete") as string}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
|
||||
<ConfirmationDialogContent
|
||||
|
||||
@@ -12,32 +12,32 @@ async function gotToPreviewTab(page: Page) {
|
||||
}
|
||||
|
||||
async function clickEmbedButton(page: Page) {
|
||||
const embedButton = page.locator("[data-testid=event-type-embed]");
|
||||
const eventTypeId = await embedButton.getAttribute("data-test-eventtype-id");
|
||||
const embedButton = page.locator("[data-testid=embed]");
|
||||
const embedUrl = await embedButton.getAttribute("data-test-embed-url");
|
||||
embedButton.click();
|
||||
return eventTypeId;
|
||||
return embedUrl;
|
||||
}
|
||||
|
||||
async function clickFirstEventTypeEmbedButton(page: Page) {
|
||||
const menu = page.locator("[data-testid*=event-type-options]").first();
|
||||
await menu.click();
|
||||
const eventTypeId = await clickEmbedButton(page);
|
||||
return eventTypeId;
|
||||
const embedUrl = await clickEmbedButton(page);
|
||||
return embedUrl;
|
||||
}
|
||||
|
||||
async function expectToBeNavigatingToEmbedTypesDialog(
|
||||
page: Page,
|
||||
{ eventTypeId, basePage }: { eventTypeId: string | null; basePage: string }
|
||||
{ embedUrl, basePage }: { embedUrl: string | null; basePage: string }
|
||||
) {
|
||||
if (!eventTypeId) {
|
||||
throw new Error("Couldn't find eventTypeId");
|
||||
if (!embedUrl) {
|
||||
throw new Error("Couldn't find embedUrl");
|
||||
}
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return (
|
||||
url.pathname === basePage &&
|
||||
url.searchParams.get("dialog") === "embed" &&
|
||||
url.searchParams.get("eventTypeId") === eventTypeId
|
||||
url.searchParams.get("embedUrl") === embedUrl
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -45,17 +45,17 @@ async function expectToBeNavigatingToEmbedTypesDialog(
|
||||
|
||||
async function expectToBeNavigatingToEmbedCodeAndPreviewDialog(
|
||||
page: Page,
|
||||
{ eventTypeId, embedType, basePage }: { eventTypeId: string | null; embedType: string; basePage: string }
|
||||
{ embedUrl, embedType, basePage }: { embedUrl: string | null; embedType: string; basePage: string }
|
||||
) {
|
||||
if (!eventTypeId) {
|
||||
throw new Error("Couldn't find eventTypeId");
|
||||
if (!embedUrl) {
|
||||
throw new Error("Couldn't find embedUrl");
|
||||
}
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return (
|
||||
url.pathname === basePage &&
|
||||
url.searchParams.get("dialog") === "embed" &&
|
||||
url.searchParams.get("eventTypeId") === eventTypeId &&
|
||||
url.searchParams.get("embedUrl") === embedUrl &&
|
||||
url.searchParams.get("embedType") === embedType &&
|
||||
url.searchParams.get("tabName") === "embed-code"
|
||||
);
|
||||
@@ -93,16 +93,16 @@ test.describe("Embed Code Generator Tests", () => {
|
||||
});
|
||||
|
||||
test("open Embed Dialog and choose Inline for First Event Type", async ({ page }) => {
|
||||
const eventTypeId = await clickFirstEventTypeEmbedButton(page);
|
||||
const embedUrl = await clickFirstEventTypeEmbedButton(page);
|
||||
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
basePage: "/event-types",
|
||||
});
|
||||
|
||||
chooseEmbedType(page, "inline");
|
||||
|
||||
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
embedType: "inline",
|
||||
basePage: "/event-types",
|
||||
});
|
||||
@@ -115,17 +115,17 @@ test.describe("Embed Code Generator Tests", () => {
|
||||
});
|
||||
|
||||
test("open Embed Dialog and choose floating-popup for First Event Type", async ({ page }) => {
|
||||
const eventTypeId = await clickFirstEventTypeEmbedButton(page);
|
||||
const embedUrl = await clickFirstEventTypeEmbedButton(page);
|
||||
|
||||
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
basePage: "/event-types",
|
||||
});
|
||||
|
||||
chooseEmbedType(page, "floating-popup");
|
||||
|
||||
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
embedType: "floating-popup",
|
||||
basePage: "/event-types",
|
||||
});
|
||||
@@ -136,17 +136,17 @@ test.describe("Embed Code Generator Tests", () => {
|
||||
});
|
||||
|
||||
test("open Embed Dialog and choose element-click for First Event Type", async ({ page }) => {
|
||||
const eventTypeId = await clickFirstEventTypeEmbedButton(page);
|
||||
const embedUrl = await clickFirstEventTypeEmbedButton(page);
|
||||
|
||||
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
basePage: "/event-types",
|
||||
});
|
||||
|
||||
chooseEmbedType(page, "element-click");
|
||||
|
||||
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
embedType: "element-click",
|
||||
basePage: "/event-types",
|
||||
});
|
||||
@@ -165,17 +165,17 @@ test.describe("Embed Code Generator Tests", () => {
|
||||
});
|
||||
|
||||
test("open Embed Dialog for the Event Type", async ({ page }) => {
|
||||
const eventTypeId = await clickEmbedButton(page);
|
||||
const embedUrl = await clickEmbedButton(page);
|
||||
|
||||
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
basePage: `/event-types/${sixtyMinProEventId}`,
|
||||
});
|
||||
|
||||
chooseEmbedType(page, "inline");
|
||||
|
||||
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
||||
eventTypeId,
|
||||
embedUrl,
|
||||
basePage: `/event-types/${sixtyMinProEventId}`,
|
||||
embedType: "inline",
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"scripts": {
|
||||
"app-e2e-quick": "turbo run app-e2e-quick",
|
||||
"app-store:build": "yarn workspace @calcom/app-store-cli build",
|
||||
"app-store:watch": "yarn workspace @calcom/app-store-cli watch",
|
||||
"app-store": "yarn workspace @calcom/app-store-cli cli",
|
||||
"build": "turbo run build --scope=\"@calcom/web\" --include-dependencies",
|
||||
"clean": "find . -name node_modules -o -name .next -o -name .turbo -o -name dist -type d -prune | xargs rm -rf",
|
||||
|
||||
@@ -50,7 +50,6 @@ const BaseAppFork = {
|
||||
appDescription,
|
||||
appName,
|
||||
slug,
|
||||
appTitle,
|
||||
publisherName,
|
||||
publisherEmail,
|
||||
}) {
|
||||
@@ -70,7 +69,6 @@ const BaseAppFork = {
|
||||
let config = {
|
||||
"/*": "Don't modify slug - If required, do it using cli edit command",
|
||||
name: appName,
|
||||
title: appTitle,
|
||||
// Plan to remove it. DB already has it and name of dir is also the same.
|
||||
slug: slug,
|
||||
type: `${slug}_${category}`,
|
||||
@@ -91,6 +89,10 @@ const BaseAppFork = {
|
||||
...config,
|
||||
};
|
||||
fs.writeFileSync(`${appDirPath}/config.json`, JSON.stringify(config, null, 2));
|
||||
fs.writeFileSync(
|
||||
`${appDirPath}/README.mdx`,
|
||||
fs.readFileSync(`${appDirPath}/README.mdx`).toString().replace("_DESCRIPTION_", appDescription)
|
||||
);
|
||||
message = !editMode ? "Forked base app" : "Updated app";
|
||||
yield message;
|
||||
},
|
||||
@@ -103,10 +105,16 @@ const BaseAppFork = {
|
||||
const Seed = {
|
||||
seedConfigPath: absolutePath("../prisma/seed-app-store.config.json"),
|
||||
update: function ({ slug, category, noDbUpdate }) {
|
||||
const seedConfig = JSON.parse(fs.readFileSync(this.seedConfigPath).toString());
|
||||
let configContent = "[]";
|
||||
try {
|
||||
if (fs.statSync(this.seedConfigPath)) {
|
||||
configContent = fs.readFileSync(this.seedConfigPath).toString();
|
||||
}
|
||||
} catch (e) {}
|
||||
const seedConfig = JSON.parse(configContent);
|
||||
|
||||
if (!seedConfig.find((app) => app.slug === slug)) {
|
||||
seedConfig.push({
|
||||
"/*": "This file is auto-generated and managed by `yarn app-store`. Don't edit manually but it is to be committed",
|
||||
dirName: slug,
|
||||
categories: [category],
|
||||
slug: slug,
|
||||
@@ -114,6 +122,10 @@ const Seed = {
|
||||
});
|
||||
}
|
||||
|
||||
// Add the message as a property to first item so that it stays always at the top
|
||||
seedConfig[0]["/*"] =
|
||||
"This file is auto-generated and updated by `yarn app-store create/edit`. Don't edit it manually";
|
||||
|
||||
fs.writeFileSync(this.seedConfigPath, JSON.stringify(seedConfig, null, 2));
|
||||
if (!noDbUpdate) {
|
||||
execSync(`cd ${workspaceDir} && yarn db-seed`);
|
||||
@@ -139,8 +151,7 @@ const CreateApp = ({ noDbUpdate, slug = null, editMode = false }) => {
|
||||
const [appInputData, setAppInputData] = useState({});
|
||||
const [inputIndex, setInputIndex] = useState(0);
|
||||
const fields = [
|
||||
{ label: "App Name", name: "appName", type: "text" },
|
||||
{ label: "App Title", name: "appTitle", type: "text" },
|
||||
{ label: "App Title", name: "appName", type: "text" },
|
||||
{ label: "App Description", name: "appDescription", type: "text" },
|
||||
{
|
||||
label: "Category of App",
|
||||
@@ -164,13 +175,12 @@ const CreateApp = ({ noDbUpdate, slug = null, editMode = false }) => {
|
||||
const fieldValue = appInputData[fieldName] || "";
|
||||
const appName = appInputData["appName"];
|
||||
const category = appInputData["appCategory"];
|
||||
const appTitle = appInputData["appTitle"];
|
||||
const appDescription = appInputData["appDescription"];
|
||||
const publisherName = appInputData["publisherName"];
|
||||
const publisherEmail = appInputData["publisherEmail"];
|
||||
const [result, setResult] = useState("...");
|
||||
const [status, setStatus] = useState<"inProgress" | "done">("inProgress");
|
||||
const allFieldsFilled = inputIndex === fields.length;
|
||||
|
||||
const [progressUpdate, setProgressUpdate] = useState("");
|
||||
useEffect(() => {
|
||||
// When all fields have been filled
|
||||
if (allFieldsFilled) {
|
||||
@@ -179,12 +189,11 @@ const CreateApp = ({ noDbUpdate, slug = null, editMode = false }) => {
|
||||
appDescription,
|
||||
appName,
|
||||
slug,
|
||||
appTitle,
|
||||
publisherName,
|
||||
publisherEmail,
|
||||
});
|
||||
for (const item of it) {
|
||||
setResult(item);
|
||||
setProgressUpdate(item);
|
||||
}
|
||||
|
||||
Seed.update({ slug, category, noDbUpdate });
|
||||
@@ -193,11 +202,7 @@ const CreateApp = ({ noDbUpdate, slug = null, editMode = false }) => {
|
||||
|
||||
// FIXME: Even after CLI showing this message, it is stuck doing work before exiting
|
||||
// So we ask the user to wait for some time
|
||||
setResult(
|
||||
`App has been given slug: ${slug}. Just wait for a few seconds for the process to complete and start editing ${getAppDirPath(
|
||||
slug
|
||||
)} to work on your app.`
|
||||
);
|
||||
setStatus("done");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -211,18 +216,61 @@ const CreateApp = ({ noDbUpdate, slug = null, editMode = false }) => {
|
||||
|
||||
if (allFieldsFilled) {
|
||||
return (
|
||||
<>
|
||||
<Box flexDirection="column">
|
||||
<Text>
|
||||
{editMode
|
||||
? `Editing app with slug ${slug}`
|
||||
: `Creating app with name '${appName}' of type '${category}'`}
|
||||
</Text>
|
||||
<Text>{result}</Text>
|
||||
<Text>
|
||||
Please note that you should use cli only to rename an app directory as it needs to be updated in DB
|
||||
as well
|
||||
<Text>{progressUpdate}</Text>
|
||||
{status === "done" ? (
|
||||
<Box flexDirection="column" paddingTop={2} paddingBottom={2}>
|
||||
<Text bold italic>
|
||||
Just wait for few seconds to process to exit and you are good to go. Your App code exists at $
|
||||
{getAppDirPath(slug)}
|
||||
</Text>
|
||||
<Text bold italic>
|
||||
App Summary:
|
||||
</Text>
|
||||
<Box flexDirection="column">
|
||||
<Box flexDirection="row">
|
||||
<Text color="green">Slug: </Text>
|
||||
<Text>{slug}</Text>
|
||||
</Box>
|
||||
<Box flexDirection="row">
|
||||
<Text color="green">App URL: </Text>
|
||||
<Text>{`http://localhost:3000/apps/${slug}`}</Text>
|
||||
</Box>
|
||||
<Box flexDirection="row">
|
||||
<Text color="green">Name: </Text>
|
||||
<Text>{appName}</Text>
|
||||
</Box>
|
||||
<Box flexDirection="row">
|
||||
<Text color="green">Description: </Text>
|
||||
<Text>{appDescription}</Text>
|
||||
</Box>
|
||||
<Box flexDirection="row">
|
||||
<Text color="green">Category: </Text>
|
||||
<Text>{category}</Text>
|
||||
</Box>
|
||||
<Box flexDirection="row">
|
||||
<Text color="green">Publisher Name: </Text>
|
||||
<Text>{publisherName}</Text>
|
||||
</Box>
|
||||
<Box flexDirection="row">
|
||||
<Text color="green">Publisher Email: </Text>
|
||||
<Text>{publisherEmail}</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
) : (
|
||||
<Text>Please wait...</Text>
|
||||
)}
|
||||
<Text italic color="gray">
|
||||
Note: You should not rename app directory manually. Use cli only to do that as it needs to be
|
||||
updated in DB as well
|
||||
</Text>
|
||||
</>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -235,44 +283,51 @@ const CreateApp = ({ noDbUpdate, slug = null, editMode = false }) => {
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Box>
|
||||
<Text color="green">{`${fieldLabel}:`}</Text>
|
||||
{field.type == "text" ? (
|
||||
<TextInput
|
||||
value={fieldValue}
|
||||
onSubmit={(value) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
setInputIndex((index) => {
|
||||
return index + 1;
|
||||
});
|
||||
}}
|
||||
onChange={(value) => {
|
||||
setAppInputData((appInputData) => {
|
||||
return {
|
||||
...appInputData,
|
||||
[fieldName]: value,
|
||||
};
|
||||
});
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<SelectInput<string>
|
||||
items={field.options}
|
||||
onSelect={(item) => {
|
||||
setAppInputData((appInputData) => {
|
||||
return {
|
||||
...appInputData,
|
||||
[fieldName]: item.value,
|
||||
};
|
||||
});
|
||||
setInputIndex((index) => {
|
||||
return index + 1;
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Box flexDirection="column">
|
||||
<Box>
|
||||
<Text color="green">{`${fieldLabel}:`}</Text>
|
||||
{field.type == "text" ? (
|
||||
<TextInput
|
||||
value={fieldValue}
|
||||
onSubmit={(value) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
setInputIndex((index) => {
|
||||
return index + 1;
|
||||
});
|
||||
}}
|
||||
onChange={(value) => {
|
||||
setAppInputData((appInputData) => {
|
||||
return {
|
||||
...appInputData,
|
||||
[fieldName]: value,
|
||||
};
|
||||
});
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<SelectInput<string>
|
||||
items={field.options}
|
||||
onSelect={(item) => {
|
||||
setAppInputData((appInputData) => {
|
||||
return {
|
||||
...appInputData,
|
||||
[fieldName]: item.value,
|
||||
};
|
||||
});
|
||||
setInputIndex((index) => {
|
||||
return index + 1;
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
<Box>
|
||||
<Text color="gray" italic>
|
||||
{field.explainer}
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1 +1,13 @@
|
||||
Edit README.mdx file to update it.
|
||||
---
|
||||
description: _DESCRIPTION_
|
||||
---
|
||||
{/* Feel free to edit description or add other frontmatter. Frontmatter would be available in the components here as variables by same name */}
|
||||
|
||||
<div>
|
||||
{description}
|
||||
</div>
|
||||
<hr />
|
||||
<div style={{color:"gray", fontStyle:"italic"}} >
|
||||
<div>Edit README.mdx file to update the content.</div>
|
||||
<div>Edit config.json to update logo </div>
|
||||
</div>
|
||||
@@ -1,25 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
|
||||
import checkSession from "../../_utils/auth";
|
||||
import { checkInstalled, createDefaultInstallation } from "../../_utils/installation";
|
||||
import appConfig from "../config.json";
|
||||
|
||||
export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = checkSession(req);
|
||||
const slug = appConfig.slug;
|
||||
const appType = appConfig.type;
|
||||
|
||||
await checkInstalled(slug, session.user.id);
|
||||
await createDefaultInstallation({
|
||||
appType,
|
||||
userId: session.user.id,
|
||||
slug,
|
||||
key: {},
|
||||
});
|
||||
|
||||
return { url: "/apps/installed" };
|
||||
}
|
||||
|
||||
export default defaultResponder(getHandler);
|
||||
@@ -1,5 +1,17 @@
|
||||
import { defaultHandler } from "@calcom/lib/server";
|
||||
import { AppDeclarativeHandler } from "@calcom/types/AppHandler";
|
||||
|
||||
export default defaultHandler({
|
||||
GET: import("./_getAdd"),
|
||||
});
|
||||
import { createDefaultInstallation } from "../../_utils/installation";
|
||||
import appConfig from "../config.json";
|
||||
|
||||
const handler: AppDeclarativeHandler = {
|
||||
// Instead of passing appType and slug from here, api/integrations/[..args] should be able to derive and pass these directly to createCredential
|
||||
appType: appConfig.type,
|
||||
slug: appConfig.slug,
|
||||
supportsMultipleInstalls: false,
|
||||
handlerType: "add",
|
||||
redirectUrl: "/apps/installed",
|
||||
createCredential: ({ appType, user, slug }) =>
|
||||
createDefaultInstallation({ appType, userId: user.id, slug, key: {} }),
|
||||
};
|
||||
|
||||
export default handler;
|
||||
Whitespace-only changes.
@@ -1,19 +0,0 @@
|
||||
import type { InstallAppButtonProps } from "@calcom/app-store/types";
|
||||
|
||||
import useAddAppMutation from "../../_utils/useAddAppMutation";
|
||||
import appConfig from "../config.json";
|
||||
|
||||
export default function InstallAppButton(props: InstallAppButtonProps) {
|
||||
const mutation = useAddAppMutation(appConfig.type);
|
||||
|
||||
return (
|
||||
<>
|
||||
{props.render({
|
||||
onClick() {
|
||||
mutation.mutate("");
|
||||
},
|
||||
loading: mutation.isLoading,
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
export default function Icon() {
|
||||
return (
|
||||
<svg
|
||||
width="40"
|
||||
height="40"
|
||||
viewBox="0 0 256 256"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
preserveAspectRatio="xMidYMid">
|
||||
<path
|
||||
d="M159.999 128.056a76.55 76.55 0 0 1-4.915 27.024 76.745 76.745 0 0 1-27.032 4.923h-.108c-9.508-.012-18.618-1.75-27.024-4.919A76.557 76.557 0 0 1 96 128.056v-.112a76.598 76.598 0 0 1 4.91-27.02A76.492 76.492 0 0 1 127.945 96h.108a76.475 76.475 0 0 1 27.032 4.923 76.51 76.51 0 0 1 4.915 27.02v.112zm94.223-21.389h-74.716l52.829-52.833a128.518 128.518 0 0 0-13.828-16.349v-.004a129 129 0 0 0-16.345-13.816l-52.833 52.833V1.782A128.606 128.606 0 0 0 128.064 0h-.132c-7.248.004-14.347.62-21.265 1.782v74.716L53.834 23.665A127.82 127.82 0 0 0 37.497 37.49l-.028.02A128.803 128.803 0 0 0 23.66 53.834l52.837 52.833H1.782S0 120.7 0 127.956v.088c0 7.256.615 14.367 1.782 21.289h74.716l-52.837 52.833a128.91 128.91 0 0 0 30.173 30.173l52.833-52.837v74.72a129.3 129.3 0 0 0 21.24 1.778h.181a129.15 129.15 0 0 0 21.24-1.778v-74.72l52.838 52.837a128.994 128.994 0 0 0 16.341-13.82l.012-.012a129.245 129.245 0 0 0 13.816-16.341l-52.837-52.833h74.724c1.163-6.91 1.77-14 1.778-21.24v-.186c-.008-7.24-.615-14.33-1.778-21.24z"
|
||||
fill="#FF4A00"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export { default as InstallAppButton } from "./InstallAppButton";
|
||||
export { default as Icon } from "./icon";
|
||||
@@ -1 +1,3 @@
|
||||
{}
|
||||
{
|
||||
"/*": "This file would be automatically updated by cli according to the inputs"
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
export * as api from "./api";
|
||||
export * as components from "./components";
|
||||
export { metadata } from "./_metadata";
|
||||
@@ -26,6 +26,7 @@ import { metadata as riverside_meta } from "./riverside/_metadata";
|
||||
import { metadata as slackmessaging_meta } from "./slackmessaging/_metadata";
|
||||
import { metadata as stripepayment_meta } from "./stripepayment/_metadata";
|
||||
import { metadata as tandemvideo_meta } from "./tandemvideo/_metadata";
|
||||
import { metadata as typeform_meta } from "./typeform/_metadata";
|
||||
import { metadata as vital_meta } from "./vital/_metadata";
|
||||
import { metadata as whereby_meta } from "./whereby/_metadata";
|
||||
import { metadata as wipemycalother_meta } from "./wipemycalother/_metadata";
|
||||
@@ -55,6 +56,7 @@ export const appStoreMetadata = {
|
||||
slackmessaging: slackmessaging_meta,
|
||||
stripepayment: stripepayment_meta,
|
||||
tandemvideo: tandemvideo_meta,
|
||||
typeform: typeform_meta,
|
||||
vital: vital_meta,
|
||||
whereby: whereby_meta,
|
||||
wipemycalother: wipemycalother_meta,
|
||||
|
||||
@@ -23,6 +23,7 @@ export const apiHandlers = {
|
||||
slackmessaging: import("./slackmessaging/api"),
|
||||
stripepayment: import("./stripepayment/api"),
|
||||
tandemvideo: import("./tandemvideo/api"),
|
||||
typeform: import("./typeform/api"),
|
||||
vital: import("./vital/api"),
|
||||
whereby: import("./whereby/api"),
|
||||
wipemycalother: import("./wipemycalother/api"),
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Response } from "../../pages/routing-link/[...appPages]";
|
||||
import { Response } from "../../types/types";
|
||||
|
||||
function escapeCsvText(str: string) {
|
||||
return str.replace(/,/, "%2C");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import NavTabs from "@components/NavTabs";
|
||||
|
||||
import { getSerializableForm } from "../utils";
|
||||
import { getSerializableForm } from "../lib/getSerializableForm";
|
||||
|
||||
export default function RoutingNavBar({
|
||||
form,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ReactNode } from "react";
|
||||
import Shell from "@calcom/ui/Shell";
|
||||
|
||||
import RoutingNavBar from "../components/RoutingNavBar";
|
||||
import { getSerializableForm } from "../utils";
|
||||
import { getSerializableForm } from "../lib/getSerializableForm";
|
||||
|
||||
const RoutingShell: React.FC<{
|
||||
form: ReturnType<typeof getSerializableForm>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ExternalLinkIcon, LinkIcon, DownloadIcon, TrashIcon } from "@heroicons/react/solid";
|
||||
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";
|
||||
@@ -8,8 +8,11 @@ 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 { getSerializableForm } from "../utils";
|
||||
import { EmbedButton, EmbedDialog } from "@components/Embed";
|
||||
|
||||
import { getSerializableForm } from "../lib/getSerializableForm";
|
||||
|
||||
export default function SideBar({
|
||||
form,
|
||||
@@ -19,6 +22,7 @@ export default function SideBar({
|
||||
appUrl: string;
|
||||
}) {
|
||||
const { t } = useLocale();
|
||||
|
||||
const utils = trpc.useContext();
|
||||
const router = useRouter();
|
||||
const mutation = trpc.useMutation("viewer.app_routing_forms.form", {
|
||||
@@ -42,11 +46,12 @@ export default function SideBar({
|
||||
},
|
||||
});
|
||||
|
||||
const formLink = `${CAL_URL}/forms/${form.id}`;
|
||||
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">
|
||||
<div className="px-2" data-testid="toggle-form">
|
||||
<Switch
|
||||
checked={!form.disabled}
|
||||
onCheckedChange={(isChecked) => {
|
||||
@@ -61,9 +66,10 @@ export default function SideBar({
|
||||
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">
|
||||
<ExternalLinkIcon className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" aria-hidden="true" />
|
||||
<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);
|
||||
@@ -71,19 +77,30 @@ export default function SideBar({
|
||||
}}
|
||||
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">
|
||||
<LinkIcon className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" />
|
||||
<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">
|
||||
<DownloadIcon className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2" />
|
||||
<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">
|
||||
<TrashIcon className="h-4 w-4 text-red-500 ltr:mr-2 rtl:ml-2" />
|
||||
<Icon.FiTrash className="h-4 w-4 text-red-500 ltr:mr-2 rtl:ml-2" />
|
||||
{t("delete")}
|
||||
</DialogTrigger>
|
||||
<ConfirmationDialogContent
|
||||
@@ -98,6 +115,7 @@ export default function SideBar({
|
||||
longer be able to book using it.
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
<EmbedDialog />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
+3
-2
@@ -83,8 +83,9 @@ const MultiSelectWidget = ({
|
||||
setValue,
|
||||
value,
|
||||
...remainingProps
|
||||
}: SelectWidgetProps & {
|
||||
}: Omit<SelectWidgetProps, "value"> & {
|
||||
listValues: { title: string; value: string }[];
|
||||
value?: string[];
|
||||
}) => {
|
||||
//TODO: Use Select here.
|
||||
//TODO: Let's set listValue itself as label and value instead of using title.
|
||||
@@ -98,7 +99,7 @@ const MultiSelectWidget = ({
|
||||
};
|
||||
});
|
||||
|
||||
const defaultValue = selectItems.filter((item) => value?.value?.includes(item.value));
|
||||
const defaultValue = selectItems.filter((item) => value?.includes(item.value));
|
||||
|
||||
return (
|
||||
<Select
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Field } from "../types/types";
|
||||
|
||||
const getFieldIdentifier = (field: Field) => field.identifier || field.label;
|
||||
|
||||
export default getFieldIdentifier;
|
||||
+3
-7
@@ -1,6 +1,7 @@
|
||||
import { App_RoutingForms_Form } from "@prisma/client";
|
||||
|
||||
import { zodFields, zodRoutes } from "./zod";
|
||||
import { SerializableForm } from "../types/types";
|
||||
import { zodFields, zodRoutes } from "../zod";
|
||||
|
||||
export function getSerializableForm<TForm extends App_RoutingForms_Form>(form: TForm) {
|
||||
const routesParsed = zodRoutes.safeParse(form.routes);
|
||||
@@ -14,12 +15,7 @@ export function getSerializableForm<TForm extends App_RoutingForms_Form>(form: T
|
||||
}
|
||||
|
||||
// Ideally we shouldb't have needed to explicitly type it but due to some reason it's not working reliably with VSCode TypeCheck
|
||||
const serializableForm: Omit<TForm, "fields" | "routes" | "createdAt" | "updatedAt"> & {
|
||||
fields: typeof fieldsParsed["data"];
|
||||
routes: typeof routesParsed["data"];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
} = {
|
||||
const serializableForm: SerializableForm<TForm> = {
|
||||
...form,
|
||||
fields: fieldsParsed.data,
|
||||
routes: routesParsed.data,
|
||||
@@ -0,0 +1,66 @@
|
||||
import jsonLogic from "json-logic-js";
|
||||
import { Utils as QbUtils } from "react-awesome-query-builder";
|
||||
|
||||
import { getQueryBuilderConfig } from "../pages/route-builder/[...appPages]";
|
||||
import { Response, Route, SerializableForm } from "../types/types";
|
||||
import { App_RoutingForms_Form } from ".prisma/client";
|
||||
|
||||
export function processRoute({
|
||||
form,
|
||||
response,
|
||||
}: {
|
||||
form: SerializableForm<App_RoutingForms_Form>;
|
||||
response: Record<string, Pick<Response[string], "value">>;
|
||||
}) {
|
||||
const queryBuilderConfig = getQueryBuilderConfig(form);
|
||||
|
||||
const routes = form.routes || [];
|
||||
|
||||
let decidedAction: Route["action"] | null = null;
|
||||
|
||||
const fallbackRoute = routes.find((route) => route.isFallback);
|
||||
|
||||
if (!fallbackRoute) {
|
||||
throw new Error("Fallback route is missing");
|
||||
}
|
||||
|
||||
const reorderedRoutes = routes.filter((route) => !route.isFallback).concat([fallbackRoute]);
|
||||
|
||||
reorderedRoutes.some((route) => {
|
||||
if (!route) {
|
||||
return false;
|
||||
}
|
||||
const state = {
|
||||
tree: QbUtils.checkTree(QbUtils.loadTree(route.queryValue), queryBuilderConfig),
|
||||
config: queryBuilderConfig,
|
||||
};
|
||||
const jsonLogicQuery = QbUtils.jsonLogicFormat(state.tree, state.config);
|
||||
const logic = jsonLogicQuery.logic;
|
||||
let result = false;
|
||||
const responseValues: Record<string, string | string[]> = {};
|
||||
for (const [uuid, { value }] of Object.entries(response)) {
|
||||
responseValues[uuid] = value;
|
||||
}
|
||||
|
||||
if (logic) {
|
||||
// Leave the logs for easy debugging of routing form logic test.
|
||||
console.log("Checking logic with response", logic, responseValues);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
result = jsonLogic.apply(logic as any, responseValues);
|
||||
} else {
|
||||
// If no logic is provided, then consider it a match
|
||||
result = true;
|
||||
}
|
||||
if (result) {
|
||||
decidedAction = route.action;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!decidedAction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Without type assertion, it is never. See why https://github.com/microsoft/TypeScript/issues/16928
|
||||
return decidedAction as Route["action"];
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
import * as formEdit from "./form-edit/[...appPages]";
|
||||
import * as forms from "./forms/[...appPages]";
|
||||
import * as RouteBuilder from "./route-builder/[...appPages]";
|
||||
import * as Router from "./router/[...appPages]";
|
||||
import * as RoutingLink from "./routing-link/[...appPages]";
|
||||
|
||||
const routingConfig = {
|
||||
@@ -9,6 +10,7 @@ const routingConfig = {
|
||||
"route-builder": RouteBuilder,
|
||||
forms: forms,
|
||||
"routing-link": RoutingLink,
|
||||
router: Router,
|
||||
};
|
||||
|
||||
export default routingConfig;
|
||||
@@ -18,7 +18,7 @@ import EditableHeading from "@components/ui/EditableHeading";
|
||||
|
||||
import RoutingShell from "../../components/RoutingShell";
|
||||
import SideBar from "../../components/SideBar";
|
||||
import { getSerializableForm } from "../../utils";
|
||||
import { getSerializableForm } from "../../lib/getSerializableForm";
|
||||
|
||||
export const FieldTypes = [
|
||||
{
|
||||
@@ -131,14 +131,14 @@ function Field({
|
||||
<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">
|
||||
Nickname
|
||||
Identifier
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<input
|
||||
type="text"
|
||||
required
|
||||
placeholder="Identifies field in webhook payloads"
|
||||
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"
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
// TODO: i18n
|
||||
import {
|
||||
TrashIcon,
|
||||
DotsHorizontalIcon,
|
||||
DuplicateIcon,
|
||||
PencilIcon,
|
||||
PlusIcon,
|
||||
LinkIcon,
|
||||
ExternalLinkIcon,
|
||||
CollectionIcon,
|
||||
} from "@heroicons/react/solid";
|
||||
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";
|
||||
@@ -20,39 +13,40 @@ 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 { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
|
||||
import { getSerializableForm } from "../../utils";
|
||||
import { EmbedButton, EmbedDialog } from "@components/Embed";
|
||||
|
||||
export default function RoutingForms({
|
||||
forms,
|
||||
appUrl,
|
||||
}: inferSSRProps<typeof getServerSideProps> & { appUrl: string }) {
|
||||
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 deleteMutation = trpc.useMutation("viewer.app_routing_forms.deleteForm", {
|
||||
onSuccess: () => {
|
||||
showToast("Form deleted", "success");
|
||||
router.replace(router.asPath);
|
||||
},
|
||||
onSettled: () => {
|
||||
utils.invalidateQueries(["viewer.app_routing_forms.forms"]);
|
||||
},
|
||||
onError: () => {
|
||||
showToast("Something went wrong", "error");
|
||||
},
|
||||
});
|
||||
const utils = trpc.useContext();
|
||||
const { t } = useLocale();
|
||||
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");
|
||||
@@ -62,20 +56,105 @@ export default function RoutingForms({
|
||||
showToast(`Something went wrong`, "error");
|
||||
},
|
||||
});
|
||||
const formId = uuidv4();
|
||||
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={() => {
|
||||
const form = {
|
||||
id: formId,
|
||||
name: `Form-${formId.slice(0, 8)}`,
|
||||
};
|
||||
mutation.mutate({ ...form, addFallback: true });
|
||||
}}
|
||||
onClick={() => openModal({ action: "new" })}
|
||||
data-testid="new-routing-form"
|
||||
StartIcon={PlusIcon}>
|
||||
StartIcon={Icon.FiPlus}>
|
||||
New Form
|
||||
</Button>
|
||||
);
|
||||
@@ -103,7 +182,8 @@ export default function RoutingForms({
|
||||
if (!form) {
|
||||
return null;
|
||||
}
|
||||
const formLink = `${CAL_URL}/forms/${form.id}`;
|
||||
const embedLink = `forms/${form.id}`;
|
||||
const formLink = `${CAL_URL}/${embedLink}`;
|
||||
const description = form.description || "";
|
||||
const disabled = form.disabled;
|
||||
form.routes = form.routes || [];
|
||||
@@ -148,72 +228,94 @@ export default function RoutingForms({
|
||||
disabled && "pointer-events-none cursor-not-allowed"
|
||||
)}>
|
||||
<Tooltip content={t("preview") as string}>
|
||||
<a
|
||||
href={formLink}
|
||||
<Button
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className={classNames(
|
||||
"btn-icon appearance-none",
|
||||
disabled && " opacity-30"
|
||||
)}>
|
||||
<ExternalLinkIcon
|
||||
className={classNames("h-5 w-5", !disabled && "group-hover:text-black")}
|
||||
/>
|
||||
</a>
|
||||
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
|
||||
<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);
|
||||
}}
|
||||
className={classNames("btn-icon", disabled && " opacity-30")}>
|
||||
<LinkIcon
|
||||
className={classNames("h-5 w-5", !disabled && "group-hover:text-black")}
|
||||
/>
|
||||
</button>
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger className="h-10 w-10 cursor-pointer rounded-sm border border-transparent text-neutral-500 hover:border-gray-300 hover:text-neutral-900 focus:border-gray-300">
|
||||
<DotsHorizontalIcon className="h-5 w-5 group-hover:text-gray-800" />
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
color="minimal"
|
||||
className={classNames(disabled && " opacity-30")}
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Link href={appUrl + "/form-edit/" + form.id} passHref={true}>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
disabled={disabled}
|
||||
color="minimal"
|
||||
className={classNames("w-full rounded-none")}
|
||||
StartIcon={PencilIcon}>
|
||||
{t("edit")}
|
||||
StartIcon={Icon.FiEdit2}>
|
||||
{t("edit") as string}
|
||||
</Button>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<DropdownMenuItem className="outline-none">
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="sm"
|
||||
className={classNames("hidden w-full rounded-none")}
|
||||
StartIcon={DuplicateIcon}>
|
||||
{t("duplicate")}
|
||||
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={() => {
|
||||
deleteMutation.mutate({
|
||||
id: form.id,
|
||||
});
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogFormId(form.id);
|
||||
}}
|
||||
color="warn"
|
||||
size="sm"
|
||||
StartIcon={TrashIcon}
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
{t("delete")}
|
||||
</Button>
|
||||
@@ -226,8 +328,30 @@ export default function RoutingForms({
|
||||
);
|
||||
})}
|
||||
</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;
|
||||
}
|
||||
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} />
|
||||
</div>
|
||||
</div>
|
||||
</Shell>
|
||||
|
||||
@@ -20,13 +20,28 @@ import RoutingShell from "../../components/RoutingShell";
|
||||
import SideBar from "../../components/SideBar";
|
||||
import QueryBuilderInitialConfig from "../../components/react-awesome-query-builder/config/config";
|
||||
import "../../components/react-awesome-query-builder/styles.css";
|
||||
import { getSerializableForm } from "../../utils";
|
||||
import { getSerializableForm } from "../../lib/getSerializableForm";
|
||||
import { FieldTypes } from "../form-edit/[...appPages]";
|
||||
|
||||
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"]) {
|
||||
const fields: Record<string, any> = {};
|
||||
const fields: Record<
|
||||
string,
|
||||
{
|
||||
label: string;
|
||||
type: string;
|
||||
valueSources: ["value"];
|
||||
fieldSettings: {
|
||||
listValues?: {
|
||||
value: string;
|
||||
title: string;
|
||||
}[];
|
||||
};
|
||||
}
|
||||
> = {};
|
||||
form.fields?.forEach((field) => {
|
||||
if (FieldTypes.map((f) => f.value).includes(field.type)) {
|
||||
const optionValues = field.selectText?.trim().split("\n");
|
||||
@@ -275,15 +290,20 @@ const Route = ({
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<hr className="my-6 text-gray-200" />
|
||||
<Query
|
||||
{...config}
|
||||
value={route.state.tree}
|
||||
onChange={(immutableTree, config) => {
|
||||
onChange(route, immutableTree, config as QueryBuilderUpdatedConfig);
|
||||
}}
|
||||
renderBuilder={renderBuilder}
|
||||
/>
|
||||
|
||||
{((route.isFallback && hasRules(route)) || !route.isFallback) && (
|
||||
<>
|
||||
<hr className="my-6 text-gray-200" />
|
||||
<Query
|
||||
{...config}
|
||||
value={route.state.tree}
|
||||
onChange={(immutableTree, config) => {
|
||||
onChange(route, immutableTree, config as QueryBuilderUpdatedConfig);
|
||||
}}
|
||||
renderBuilder={renderBuilder}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -390,11 +410,9 @@ const Routes = ({
|
||||
e.preventDefault();
|
||||
}}>
|
||||
{mainRoutes.map((route, key) => {
|
||||
const jsonLogicQuery = QbUtils.jsonLogicFormat(route.state.tree, route.state.config);
|
||||
console.log(`Route: ${JSON.stringify({ action: route.action, jsonLogicQuery })}`);
|
||||
return (
|
||||
<Route
|
||||
key={key}
|
||||
key={route.id}
|
||||
config={config}
|
||||
route={route}
|
||||
moveUp={{
|
||||
@@ -422,6 +440,7 @@ const Routes = ({
|
||||
color="secondary"
|
||||
StartIcon={PlusIcon}
|
||||
size="sm"
|
||||
data-testid="add-route"
|
||||
onClick={() => {
|
||||
const newEmptyRoute = getEmptyRoute();
|
||||
const newRoutes = [
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import Head from "next/head";
|
||||
import z from "zod";
|
||||
|
||||
import { AppGetServerSidePropsContext, AppPrisma } from "@calcom/types/AppGetServerSideProps";
|
||||
import { inferSSRProps } from "@calcom/types/inferSSRProps";
|
||||
|
||||
import getFieldIdentifier from "../../lib/getFieldIdentifier";
|
||||
import { getSerializableForm } from "../../lib/getSerializableForm";
|
||||
import { processRoute } from "../../lib/processRoute";
|
||||
import { Response } from "../../types/types";
|
||||
|
||||
export default function Router({ form, message }: inferSSRProps<typeof getServerSideProps>) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{form.name} | Cal.com Forms</title>
|
||||
</Head>
|
||||
<div className="mx-auto my-0 max-w-3xl md:my-24">
|
||||
<div className="w-full max-w-4xl ltr:mr-2 rtl:ml-2">
|
||||
<div className="-mx-4 rounded-sm border border-neutral-200 bg-white p-4 py-6 sm:mx-0 sm:px-8">
|
||||
<div>{message}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const querySchema = z
|
||||
.object({
|
||||
form: z.string(),
|
||||
slug: z.string(),
|
||||
pages: z.array(z.string()),
|
||||
})
|
||||
.catchall(z.string());
|
||||
|
||||
export const getServerSideProps = async function getServerSideProps(
|
||||
context: AppGetServerSidePropsContext,
|
||||
prisma: AppPrisma
|
||||
) {
|
||||
const queryParsed = querySchema.safeParse(context.query);
|
||||
if (!queryParsed.success) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { form: formId, slug: _slug, pages: _pages, ...fieldsResponses } = queryParsed.data;
|
||||
const form = await prisma.app_RoutingForms_Form.findUnique({
|
||||
where: {
|
||||
id: formId,
|
||||
},
|
||||
});
|
||||
if (!form) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
const serializableForm = getSerializableForm(form);
|
||||
|
||||
const response: Record<string, Pick<Response[string], "value">> = {};
|
||||
serializableForm.fields?.forEach((field) => {
|
||||
const rawFieldResponse = fieldsResponses[getFieldIdentifier(field)] || "";
|
||||
console.log(field);
|
||||
const fieldResponse =
|
||||
field.type === "multiselect" ? rawFieldResponse.split(",").map((r) => r.trim()) : rawFieldResponse;
|
||||
response[field.id] = {
|
||||
value: fieldResponse,
|
||||
};
|
||||
});
|
||||
|
||||
const decidedAction = processRoute({ form: serializableForm, response });
|
||||
|
||||
if (!decidedAction) {
|
||||
throw new Error("No matching route could be found");
|
||||
}
|
||||
|
||||
//TODO: Maybe take action after successful mutation
|
||||
if (decidedAction.type === "customPageMessage") {
|
||||
return {
|
||||
props: {
|
||||
form: serializableForm,
|
||||
message: decidedAction.value,
|
||||
},
|
||||
};
|
||||
} else if (decidedAction.type === "eventTypeRedirectUrl") {
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/${decidedAction.value}`,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else if (decidedAction.type === "externalRedirectUrl") {
|
||||
return {
|
||||
redirect: {
|
||||
destination: `${decidedAction.value}`,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
form: serializableForm,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,8 +1,6 @@
|
||||
import jsonLogic from "json-logic-js";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState, useRef, FormEvent } from "react";
|
||||
import { Utils as QbUtils } from "react-awesome-query-builder";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
@@ -16,27 +14,19 @@ import { AppGetServerSidePropsContext, AppPrisma } from "@calcom/types/AppGetSer
|
||||
import { inferSSRProps } from "@calcom/types/inferSSRProps";
|
||||
import { Button } from "@calcom/ui";
|
||||
|
||||
import { getSerializableForm } from "../../utils";
|
||||
import { useExposePlanGlobally } from "@lib/hooks/useExposePlanGlobally";
|
||||
|
||||
import { getSerializableForm } from "../../lib/getSerializableForm";
|
||||
import { processRoute } from "../../lib/processRoute";
|
||||
import { Response, Route } from "../../types/types";
|
||||
import { getQueryBuilderConfig } from "../route-builder/[...appPages]";
|
||||
|
||||
export type Response = Record<
|
||||
string,
|
||||
{
|
||||
value: string | string[];
|
||||
label: string;
|
||||
}
|
||||
>;
|
||||
|
||||
type Form = inferSSRProps<typeof getServerSideProps>["form"];
|
||||
|
||||
type Route = NonNullable<Form["routes"]>[0];
|
||||
|
||||
function RoutingForm({ form, profile }: inferSSRProps<typeof getServerSideProps>) {
|
||||
const [customPageMessage, setCustomPageMessage] = useState<Route["action"]["value"]>("");
|
||||
const formFillerIdRef = useRef(uuidv4());
|
||||
const isEmbed = useIsEmbed();
|
||||
useTheme(profile.theme);
|
||||
|
||||
useExposePlanGlobally(profile.plan);
|
||||
// TODO: We might want to prevent spam from a single user by having same formFillerId across pageviews
|
||||
// But technically, a user can fill form multiple times due to any number of reasons and we currently can't differentiate b/w that.
|
||||
// - like a network error
|
||||
@@ -158,6 +148,7 @@ function RoutingForm({ form, profile }: inferSSRProps<typeof getServerSideProps>
|
||||
/* @ts-ignore */
|
||||
required={!!field.required}
|
||||
listValues={options}
|
||||
data-testid="field"
|
||||
setValue={(value) => {
|
||||
setResponse((response) => {
|
||||
response = response || {};
|
||||
@@ -202,55 +193,6 @@ function RoutingForm({ form, profile }: inferSSRProps<typeof getServerSideProps>
|
||||
);
|
||||
}
|
||||
|
||||
function processRoute({ form, response }: { form: Form; response: Response }) {
|
||||
const queryBuilderConfig = getQueryBuilderConfig(form);
|
||||
|
||||
const routes = form.routes || [];
|
||||
|
||||
let decidedAction: Route["action"] | null = null;
|
||||
|
||||
const fallbackRoute = routes.find((route) => route.isFallback);
|
||||
|
||||
if (!fallbackRoute) {
|
||||
throw new Error("Fallback route is missing");
|
||||
}
|
||||
|
||||
const reorderedRoutes = routes.filter((route) => !route.isFallback).concat([fallbackRoute]);
|
||||
|
||||
reorderedRoutes.some((route) => {
|
||||
if (!route) {
|
||||
return false;
|
||||
}
|
||||
const state = {
|
||||
tree: QbUtils.checkTree(QbUtils.loadTree(route.queryValue), queryBuilderConfig),
|
||||
config: queryBuilderConfig,
|
||||
};
|
||||
const jsonLogicQuery = QbUtils.jsonLogicFormat(state.tree, state.config);
|
||||
const logic = jsonLogicQuery.logic;
|
||||
let result = false;
|
||||
const responseValues: Record<string, string | string[]> = {};
|
||||
for (const [uuid, { value }] of Object.entries(response)) {
|
||||
responseValues[uuid] = value;
|
||||
}
|
||||
|
||||
if (logic) {
|
||||
// Leave the logs for easy debugging of routing form logic test.
|
||||
console.log("Checking logic with response", logic, responseValues);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
result = jsonLogic.apply(logic as any, responseValues);
|
||||
} else {
|
||||
// If no logic is provided, then consider it a match
|
||||
result = true;
|
||||
}
|
||||
if (result) {
|
||||
decidedAction = route.action;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return decidedAction;
|
||||
}
|
||||
|
||||
export default function RoutingLink({ form, profile }: inferSSRProps<typeof getServerSideProps>) {
|
||||
return <RoutingForm form={form} profile={profile} />;
|
||||
}
|
||||
@@ -284,6 +226,7 @@ export const getServerSideProps = async function getServerSideProps(
|
||||
theme: true,
|
||||
brandColor: true,
|
||||
darkBrandColor: true,
|
||||
plan: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -301,6 +244,7 @@ export const getServerSideProps = async function getServerSideProps(
|
||||
theme: form.user.theme,
|
||||
brandColor: form.user.brandColor,
|
||||
darkBrandColor: form.user.darkBrandColor,
|
||||
plan: form.user.plan,
|
||||
},
|
||||
form: getSerializableForm(form),
|
||||
},
|
||||
|
||||
@@ -10,3 +10,11 @@ export async function cleanUpForms() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function cleanUpSeededForm(formId: string) {
|
||||
return await prisma.app_RoutingForms_FormResponse.deleteMany({
|
||||
where: {
|
||||
formId,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,11 +1,27 @@
|
||||
import { expect, Page } from "@playwright/test";
|
||||
|
||||
import { seededForm } from "@calcom/prisma/seed-app-store";
|
||||
|
||||
import { test } from "../fixtures/fixtures";
|
||||
import { cleanUpForms, todo } from "../lib/testUtils";
|
||||
import { cleanUpForms, cleanUpSeededForm } from "../lib/testUtils";
|
||||
|
||||
async function gotoRoutingLink(page: Page, formId: string) {
|
||||
await page.goto(`/forms/${formId}`);
|
||||
// HACK: There seems to be some issue with the inputs to the form getting reset if we don't wait.
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
}
|
||||
|
||||
async function addForm(page: Page) {
|
||||
await page.click('[data-testid="new-routing-form"]');
|
||||
await page.fill("input[name]", "Test Form Name");
|
||||
await page.click('[data-testid="add-form"]');
|
||||
await page.waitForSelector('[data-testid="add-field"]');
|
||||
const url = page.url();
|
||||
const formId = new URL(url).pathname.split("/").at(-1);
|
||||
if (!formId) {
|
||||
throw new Error("Form ID couldn't be determined from url");
|
||||
}
|
||||
return formId;
|
||||
}
|
||||
|
||||
async function verifySelectOptions(
|
||||
@@ -54,21 +70,31 @@ async function fillForm(
|
||||
}
|
||||
|
||||
test.use({ storageState: `playwright/artifacts/${process.env.APP_USER_NAME}StorageState.json` });
|
||||
test.describe("Forms", () => {
|
||||
test("should be able to add a new form and see it in forms list", async ({ page }) => {
|
||||
test.describe("Routing Forms", () => {
|
||||
test("should be able to add a new form and view it", async ({ page }) => {
|
||||
page.goto("/");
|
||||
|
||||
await page.click('[href="/apps/routing_forms/forms"]');
|
||||
await page.waitForSelector('[data-testid="empty-screen"]');
|
||||
|
||||
await addForm(page);
|
||||
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 }) => {
|
||||
@@ -95,6 +121,7 @@ test.describe("Forms", () => {
|
||||
expect(await page.locator(".data-testid-field-type").first().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(
|
||||
{
|
||||
@@ -105,8 +132,98 @@ test.describe("Forms", () => {
|
||||
page
|
||||
);
|
||||
});
|
||||
todo("Test Routing Link");
|
||||
|
||||
test.describe("Seeded Routing Form ", () => {
|
||||
test("Routing Link should accept submission while routing works and responses can be downloaded", async ({
|
||||
page,
|
||||
}) => {
|
||||
await gotoRoutingLink(page, seededForm.id);
|
||||
await page.fill('[data-testid="field"]', "event-routing");
|
||||
page.click('button[type="submit"]');
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.pathname.endsWith("/pro/30min");
|
||||
},
|
||||
});
|
||||
|
||||
await gotoRoutingLink(page, seededForm.id);
|
||||
await page.fill('[data-testid="field"]', "external-redirect");
|
||||
page.click('button[type="submit"]');
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.hostname.includes("google.com");
|
||||
},
|
||||
});
|
||||
|
||||
await gotoRoutingLink(page, seededForm.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}`);
|
||||
const [download] = await Promise.all([
|
||||
// Start waiting for the download
|
||||
page.waitForEvent("download"),
|
||||
// Perform the action that initiates download
|
||||
page.click('[data-testid="download-responses"]'),
|
||||
]);
|
||||
const downloadStream = await download.createReadStream();
|
||||
expect(download.suggestedFilename()).toEqual(`${seededForm.name}-${seededForm.id}.csv`);
|
||||
const csv: string = await new Promise((resolve) => {
|
||||
let body = "";
|
||||
downloadStream?.on("data", (chunk) => {
|
||||
body += chunk;
|
||||
});
|
||||
downloadStream?.on("end", () => {
|
||||
resolve(body);
|
||||
});
|
||||
});
|
||||
|
||||
expect(csv.trim()).toEqual(
|
||||
`
|
||||
"Test field :=> event-routing"
|
||||
"Test field :=> external-redirect"
|
||||
"Test field :=> custom-page"`.trim()
|
||||
);
|
||||
});
|
||||
|
||||
test("Router URL should work", async ({ page }) => {
|
||||
page.goto(`/router?form=${seededForm.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`);
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.hostname.includes("google.com");
|
||||
},
|
||||
});
|
||||
|
||||
await page.goto(`/router?form=${seededForm.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.isVisible("text=Multiselect chosen");
|
||||
});
|
||||
|
||||
test("Routing Link should validate fields", async ({ page }) => {
|
||||
await gotoRoutingLink(page, seededForm.id);
|
||||
page.click('button[type="submit"]');
|
||||
const firstInputMissingValue = await page.evaluate(() => {
|
||||
return document.querySelectorAll("input")[0].validity.valueMissing;
|
||||
});
|
||||
expect(firstInputMissingValue).toBe(true);
|
||||
expect(await page.locator('button[type="submit"][disabled]').count()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.afterAll(() => {
|
||||
cleanUpForms();
|
||||
});
|
||||
|
||||
test.afterEach(() => {
|
||||
cleanUpSeededForm(seededForm.id);
|
||||
});
|
||||
});
|
||||
@@ -157,9 +157,10 @@ const app_RoutingForms = createRouter()
|
||||
input: z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
async resolve({ ctx: { prisma }, input }) {
|
||||
async resolve({ ctx: { prisma, user }, input }) {
|
||||
const form = await prisma.app_RoutingForms_Form.findFirst({
|
||||
where: {
|
||||
userId: user.id,
|
||||
id: input.id,
|
||||
},
|
||||
});
|
||||
@@ -176,25 +177,61 @@ const app_RoutingForms = createRouter()
|
||||
fields: zodFields,
|
||||
routes: zodRoutes,
|
||||
addFallback: z.boolean().optional(),
|
||||
duplicateFrom: z.string().nullable().optional(),
|
||||
}),
|
||||
async resolve({ ctx: { user, prisma }, input }) {
|
||||
const { name, id, description, disabled, addFallback } = input;
|
||||
const { name, id, description, disabled, addFallback, duplicateFrom } = input;
|
||||
let { routes } = input;
|
||||
let { fields } = input;
|
||||
|
||||
if (duplicateFrom) {
|
||||
const sourceForm = await prisma.app_RoutingForms_Form.findFirst({
|
||||
where: {
|
||||
userId: user.id,
|
||||
id: duplicateFrom,
|
||||
},
|
||||
select: {
|
||||
fields: true,
|
||||
routes: true,
|
||||
},
|
||||
});
|
||||
if (!sourceForm) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: `Form to duplicate: ${duplicateFrom} not found`,
|
||||
});
|
||||
}
|
||||
const fieldParsed = zodFields.safeParse(sourceForm.fields);
|
||||
const routesParsed = zodRoutes.safeParse(sourceForm.routes);
|
||||
if (!fieldParsed.success || !routesParsed.success) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: "Could not parse source form's fields or routes",
|
||||
});
|
||||
}
|
||||
// Duplicate just routes and fields
|
||||
// We don't want name, description and responses to be copied
|
||||
routes = routesParsed.data;
|
||||
fields = fieldParsed.data;
|
||||
}
|
||||
|
||||
fields = fields || [];
|
||||
|
||||
if (addFallback) {
|
||||
const uuid = uuidv4();
|
||||
routes = routes || [];
|
||||
routes.push({
|
||||
id: uuid,
|
||||
isFallback: true,
|
||||
action: {
|
||||
type: "customPageMessage",
|
||||
value: "Thank you for your interest! We will be in touch soon.",
|
||||
},
|
||||
queryValue: { id: uuid, type: "group" },
|
||||
});
|
||||
// Add a fallback route if there is none
|
||||
if (!routes.find((route) => route.isFallback)) {
|
||||
routes.push({
|
||||
id: uuid,
|
||||
isFallback: true,
|
||||
action: {
|
||||
type: "customPageMessage",
|
||||
value: "Thank you for your interest! We will be in touch soon.",
|
||||
},
|
||||
queryValue: { id: uuid, type: "group" },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return await prisma.app_RoutingForms_Form.upsert({
|
||||
@@ -230,9 +267,10 @@ const app_RoutingForms = createRouter()
|
||||
id: z.string(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
return await ctx.prisma.app_RoutingForms_Form.delete({
|
||||
return await ctx.prisma.app_RoutingForms_Form.deleteMany({
|
||||
where: {
|
||||
id: input.id,
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { App_RoutingForms_Form } from "@prisma/client";
|
||||
import z from "zod";
|
||||
|
||||
import { zodFields, zodRoutes } from "../zod";
|
||||
|
||||
export type Response = Record<
|
||||
string,
|
||||
{
|
||||
value: string | string[];
|
||||
label: string;
|
||||
}
|
||||
>;
|
||||
|
||||
export type Fields = z.infer<typeof zodFields>;
|
||||
export type Field = Fields[number];
|
||||
export type Routes = z.infer<typeof zodRoutes>;
|
||||
export type Route = Routes[0];
|
||||
export type SerializableForm<T extends App_RoutingForms_Form> = Omit<
|
||||
T,
|
||||
"fields" | "routes" | "createdAt" | "updatedAt"
|
||||
> & {
|
||||
routes: Routes;
|
||||
fields: Fields;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
@@ -12,6 +12,7 @@ export const zodFields = z
|
||||
})
|
||||
)
|
||||
.optional();
|
||||
|
||||
export const zodRoutes = z
|
||||
.union([
|
||||
z.array(
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
description: Adds a link to copy Typeform Redirect URL to integrate with Routing Forms.
|
||||
items:
|
||||
- /api/app-store/typeform/copy-typeform-redirect-url.png
|
||||
- /api/app-store/typeform/how-it-looks-in-typeform.png
|
||||
---
|
||||
{/* Feel free to edit description or add other frontmatter. Frontmatter would be available in the components here as variables by same name */}
|
||||
|
||||
<Slider items={items} />
|
||||
<div>
|
||||
{description}
|
||||
<div style={{fontStyle:"italic"}}>You should have Routing Forms app installed to be able to use this app.</div>
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { App } from "@calcom/types/App";
|
||||
|
||||
import config from "./config.json";
|
||||
|
||||
export const metadata = {
|
||||
category: "other",
|
||||
// FIXME: Currently for an app to be shown as installed, it must have this variable set. Either hardcoded or if it depends on some env variable, that should be checked here
|
||||
installed: true,
|
||||
rating: 0,
|
||||
reviews: 0,
|
||||
trending: true,
|
||||
verified: true,
|
||||
...config,
|
||||
} as App;
|
||||
|
||||
export default metadata;
|
||||
@@ -0,0 +1,17 @@
|
||||
import { AppDeclarativeHandler } from "@calcom/types/AppHandler";
|
||||
|
||||
import { createDefaultInstallation } from "../../_utils/installation";
|
||||
import appConfig from "../config.json";
|
||||
|
||||
const handler: AppDeclarativeHandler = {
|
||||
// Instead of passing appType and slug from here, api/integrations/[..args] should be able to derive and pass these directly to createCredential
|
||||
appType: appConfig.type,
|
||||
slug: appConfig.slug,
|
||||
supportsMultipleInstalls: false,
|
||||
handlerType: "add",
|
||||
redirectUrl: "/apps/typeform/how-to-use",
|
||||
createCredential: ({ appType, user, slug }) =>
|
||||
createDefaultInstallation({ appType, userId: user.id, slug, key: {} }),
|
||||
};
|
||||
|
||||
export default handler;
|
||||
@@ -0,0 +1 @@
|
||||
export { default as add } from "./add";
|
||||
@@ -0,0 +1,32 @@
|
||||
import getFieldIdentifier from "@calcom/app-store/ee/routing_forms/lib/getFieldIdentifier";
|
||||
import { SerializableForm } from "@calcom/app-store/ee/routing_forms/types/types";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import useApp from "@calcom/lib/hooks/useApp";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import showToast from "@calcom/lib/notification";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import { App_RoutingForms_Form } from ".prisma/client";
|
||||
|
||||
export default function CopyRedirectUrlButton({ form }: { form: SerializableForm<App_RoutingForms_Form> }) {
|
||||
const { t } = useLocale();
|
||||
|
||||
const { data: typeformApp } = useApp("typeform");
|
||||
|
||||
let typeformRedirectUrl = `${CAL_URL}/router?form=${form.id}`;
|
||||
form.fields?.forEach((field) => {
|
||||
typeformRedirectUrl += `&${getFieldIdentifier(field)}={Recalled_Response_For_This_Field}`;
|
||||
});
|
||||
return typeformApp ? (
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(typeformRedirectUrl);
|
||||
showToast("Typeform Redirect URL copied! You can go and set the URL in Typeform form.", "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 Typeform Redirect URL")}
|
||||
</button>
|
||||
) : null;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default as CopyRedirectUrlButton } from "./CopyRedirectUrlButton";
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"/*": "Don't modify slug - If required, do it using cli edit command",
|
||||
"name": "Typeform",
|
||||
"slug": "typeform",
|
||||
"type": "typeform_other",
|
||||
"logo": "/api/app-store/typeform/icon.svg",
|
||||
"url": "https://cal.com/apps/typeform",
|
||||
"variant": "other",
|
||||
"categories": [
|
||||
"other"
|
||||
],
|
||||
"publisher": "Cal.com",
|
||||
"email": "[email protected]",
|
||||
"description": "Adds a link to copy Typeform Redirect URL",
|
||||
"__createdUsingCli": true
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * as api from "./api";
|
||||
export * as components from "./components";
|
||||
export { metadata } from "./_metadata";
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"private": true,
|
||||
"name": "@calcom/typeform",
|
||||
"version": "0.0.0",
|
||||
"main": "./index.ts",
|
||||
"description": "Adds a link to copy Typeform Redirect URL",
|
||||
"dependencies": {
|
||||
"@calcom/lib": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@calcom/types": "*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//TODO: Generate this file automatically so that like in Next.js file based routing can work automatically
|
||||
import * as HowToUse from "./how-to-use/[...appPages]";
|
||||
|
||||
const routingConfig = {
|
||||
"how-to-use": HowToUse,
|
||||
};
|
||||
|
||||
export default routingConfig;
|
||||
@@ -0,0 +1,79 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Button, Icon } from "@calcom/ui";
|
||||
|
||||
export default function HowToUse() {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<div className="flex h-screen bg-gray-200">
|
||||
<div className="m-auto rounded bg-white p-10">
|
||||
<div className="flex flex-row">
|
||||
<div className="mr-5">
|
||||
<img className="w-11" src="/api/app-store/typeform/icon.svg" alt="Zapier Logo" />
|
||||
</div>
|
||||
<div className="ml-5">
|
||||
<div className="text-md text-gray-800">How to route a Typeform with Cal.com Routing</div>
|
||||
<ol className="mt-5 mb-5 ml-5 mr-5 list-decimal">
|
||||
<li>
|
||||
Make sure that you have{" "}
|
||||
<Link href="/apps/routing_forms" className="text-base text-gray-500">
|
||||
<a className="text-base text-gray-500">Routing Forms</a>
|
||||
</Link>{" "}
|
||||
app installed
|
||||
</li>
|
||||
<li>
|
||||
Create a Routing Form with fields on the basis of which you want your typeform routing to work
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/api/app-store/typeform/copy-typeform-redirect-url.png">
|
||||
<a target="_blank" className="inline-flex items-baseline text-base text-gray-500">
|
||||
<Icon.FiExternalLink
|
||||
className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
Click "Copy Typeform Redirect URL"
|
||||
</a>
|
||||
</Link>
|
||||
</li>
|
||||
<li>Create a Typeform that you want to route through Cal.com form's routing</li>
|
||||
<li>
|
||||
Add the copied URL as{" "}
|
||||
<Link href="https://www.typeform.com/help/a/end-screens-and-redirects-360051791392/#h_01G0CFXF21W2EQ8PXKSB4KSC8P">
|
||||
<a target="_blank" className="inline-flex items-baseline text-base text-gray-500">
|
||||
<Icon.FiExternalLink
|
||||
className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
Redirect to your typeform
|
||||
</a>
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
Use{" "}
|
||||
<Link href="https://www.typeform.com/help/a/use-recall-information-to-reference-typeform-answers-variables-and-more-360052320011/">
|
||||
<a target="_blank" className="inline-flex items-baseline text-base text-gray-500">
|
||||
<Icon.FiExternalLink
|
||||
className="h-4 w-4 text-neutral-500 ltr:mr-2 rtl:ml-2"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
Recall Information in Typeform
|
||||
</a>
|
||||
</Link>{" "}
|
||||
to add values to query params.
|
||||
</li>
|
||||
<li>
|
||||
You're set! Now, when the Typeform gets responses they would be routed through Cal.com
|
||||
routing
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<Link href="/apps/installed" passHref={true}>
|
||||
<Button color="secondary">{t("done")}</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="245" height="55" viewBox="0 0 245 55" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M158.248 38.0664C153.148 38.0664 150.529 33.8672 150.529 28.7095C150.529 23.5519 153.102 19.5809 158.248 19.5809C163.486 19.5809 165.968 23.7344 165.968 28.7095C165.922 33.9585 163.303 38.0664 158.248 38.0664ZM108.348 19.5809C111.334 19.5809 112.575 21.3154 112.575 22.8216C112.575 26.473 108.853 28.0705 101.088 28.2988C101.088 23.7801 103.661 19.5809 108.348 19.5809ZM75.2644 38.0664C70.4398 38.0664 68.418 34.1411 68.418 28.7095C68.418 23.3237 70.4857 19.5809 75.2644 19.5809C80.135 19.5809 82.4325 23.4606 82.4325 28.7095C82.4325 34.1867 80.0431 38.0664 75.2644 38.0664ZM34.4617 14.2407H26.9261L39.4242 42.9046C37.0349 48.1992 35.7483 49.5228 34.0941 49.5228C32.3481 49.5228 30.6939 48.1079 29.4992 46.8755L26.1909 51.2573C28.4424 53.6307 31.521 55 34.6915 55C38.6431 55 41.6757 52.7178 43.4218 48.61L57.8498 14.195H50.452L42.9164 34.7344L34.4617 14.2407ZM234.064 19.5809C237.74 19.5809 238.475 22.0913 238.475 27.9793V43.4523H245V23.917C245 16.888 240.175 13.8299 235.718 13.8299C231.767 13.8299 228.137 16.2946 226.115 20.8589C224.966 16.4772 221.29 13.8299 217.017 13.8299C213.295 13.8299 209.573 16.2033 207.552 20.6307V14.2407H201.027V43.4066H207.552V30.9461C207.552 24.6473 210.86 19.5809 215.363 19.5809C219.039 19.5809 219.728 22.0913 219.728 27.9793V43.4523H226.253L226.207 30.9461C226.207 24.6473 229.561 19.5809 234.064 19.5809ZM181.794 14.2407H178.696V43.4066H185.22V32.2241C185.22 25.1494 188.345 20.3568 192.986 20.3568C194.18 20.3568 195.191 20.4025 196.294 20.8589L197.305 13.9668C196.478 13.8755 195.743 13.7842 195.007 13.7842C190.413 13.7842 187.104 16.9336 185.174 20.9959V14.2407H181.794ZM158.248 13.7842C149.61 13.7842 143.774 20.3568 143.774 28.6639C143.774 37.2905 149.702 43.7261 158.248 43.7261C166.933 43.7261 172.86 37.1079 172.86 28.6639C172.814 20.3112 166.795 13.7842 158.248 13.7842ZM108.715 38.0664C105.315 38.0664 102.788 36.332 101.731 32.8174C110.369 32.4523 118.824 30.3527 118.824 22.7303C118.824 18.3485 114.505 13.8299 108.302 13.8299C99.939 13.8299 94.2873 20.6307 94.2873 28.7095C94.2873 37.1535 99.8471 43.7718 108.164 43.7718C113.953 43.7718 117.629 41.444 120.524 38.0664L117.354 33.7759C113.999 37.1992 111.932 38.0664 108.715 38.0664ZM76.551 13.7842C73.2427 13.7842 69.9344 15.7012 68.6478 18.7137V14.2407H62.123V54.8631H68.6478V40.3485C70.0263 42.4481 73.1967 43.8174 75.9996 43.8174C84.684 43.8174 89.2789 37.3817 89.2789 28.7095C89.2329 20.1286 84.7299 13.7842 76.551 13.7842ZM30.7858 2.55602H0V8.90042H12.0386V43.4066H18.885V8.90042H30.7858V2.55602ZM127.784 14.2407H123.878V20.083H127.784V43.4066H134.309V20.083H140.65V14.2407H134.309V9.67635C134.309 6.75519 135.504 5.75104 138.215 5.75104C139.225 5.75104 140.144 6.0249 141.385 6.43568L142.855 0.958506C141.661 0.273859 139.271 0 137.709 0C131.46 0 127.784 3.74274 127.784 10.2241V14.2407Z" fill="#131313"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.9 KiB |
@@ -16,6 +16,7 @@ declare global {
|
||||
CalComPageStatus: string;
|
||||
CalComPlan: string;
|
||||
isEmbed: () => boolean;
|
||||
resetEmbedStatus: () => void;
|
||||
getEmbedNamespace: () => string | null;
|
||||
getEmbedTheme: () => "dark" | "light" | null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
export default function useApp(appId: string) {
|
||||
const { status } = useSession();
|
||||
|
||||
return trpc.useQuery(["viewer.appById", { appId }], {
|
||||
enabled: status === "authenticated",
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "App_RoutingForms_FormResponse" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||
@@ -507,6 +507,7 @@ model App_RoutingForms_FormResponse {
|
||||
form App_RoutingForms_Form @relation(fields: [formId], references: [id], onDelete: Cascade)
|
||||
formId String
|
||||
response Json
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([formFillerId, formId])
|
||||
}
|
||||
|
||||
@@ -1,36 +1,49 @@
|
||||
[
|
||||
{
|
||||
"/*": "This file is auto-generated and managed by `yarn app-store`. Don't edit manually but it is to be committed",
|
||||
"/*": "This file is auto-generated and updated by `yarn app-store create/edit`. Don't edit it manually",
|
||||
"dirName": "routing_forms",
|
||||
"categories": ["other"],
|
||||
"categories": [
|
||||
"other"
|
||||
],
|
||||
"slug": "routing_forms",
|
||||
"type": "routing_forms_other"
|
||||
},
|
||||
{
|
||||
"dirName": "whereby",
|
||||
"categories": ["video"],
|
||||
"categories": [
|
||||
"video"
|
||||
],
|
||||
"slug": "whereby",
|
||||
"type": "whereby_video"
|
||||
},
|
||||
{
|
||||
"/*": "This file is auto-generated and managed by `yarn app-store`. Don't edit manually but it is to be committed",
|
||||
"dirName": "around",
|
||||
"categories": ["video"],
|
||||
"categories": [
|
||||
"video"
|
||||
],
|
||||
"slug": "around",
|
||||
"type": "around_video"
|
||||
},
|
||||
{
|
||||
"/*": "This file is auto-generated and managed by `yarn app-store`. Don't edit manually but it is to be committed",
|
||||
"dirName": "riverside",
|
||||
"categories": ["video"],
|
||||
"categories": [
|
||||
"video"
|
||||
],
|
||||
"slug": "riverside",
|
||||
"type": "riverside_video"
|
||||
},
|
||||
{
|
||||
"/*": "This file is auto-generated and managed by `yarn app-store`. Don't edit manually but it is to be committed",
|
||||
"dirName": "typeform",
|
||||
"categories": [
|
||||
"other"
|
||||
],
|
||||
"slug": "typeform",
|
||||
"type": "typeform_other"
|
||||
},
|
||||
{
|
||||
"dirName": "ping",
|
||||
"categories": ["video"],
|
||||
"slug": "ping",
|
||||
"type": "ping_video"
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -1,16 +1,20 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { uuid } from "short-uuid";
|
||||
|
||||
import prisma from ".";
|
||||
|
||||
export const seededForm = {
|
||||
id: "948ae412-d995-4865-875a-48302588de03",
|
||||
name: "Seeded Form - Pro",
|
||||
};
|
||||
|
||||
require("dotenv").config({ path: "../../.env.appStore" });
|
||||
|
||||
async function seedAppData() {
|
||||
const form = await prisma.app_RoutingForms_Form.findUnique({
|
||||
where: {
|
||||
id: "948ae412-d995-4865-875a-48302588de03",
|
||||
id: seededForm.id,
|
||||
},
|
||||
});
|
||||
if (form) {
|
||||
@@ -31,7 +35,7 @@ async function seedAppData() {
|
||||
|
||||
await prisma.app_RoutingForms_Form.create({
|
||||
data: {
|
||||
id: "948ae412-d995-4865-875a-48302588de03",
|
||||
id: seededForm.id,
|
||||
routes: [
|
||||
{
|
||||
id: "8a898988-89ab-4cde-b012-31823f708642",
|
||||
@@ -93,6 +97,26 @@ async function seedAppData() {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
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" },
|
||||
@@ -102,13 +126,21 @@ async function seedAppData() {
|
||||
],
|
||||
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: {
|
||||
username: "pro",
|
||||
},
|
||||
},
|
||||
name: "Seeded Form - Pro",
|
||||
name: seededForm.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { getCalendarCredentials, getConnectedCalendars } from "@calcom/core/Cale
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { sendCancelledEmails, sendFeedbackEmail } from "@calcom/emails";
|
||||
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
|
||||
import jackson from "@calcom/lib/jackson";
|
||||
import {
|
||||
|
||||
Vendored
+6
-3
@@ -23,13 +23,16 @@ export interface App {
|
||||
| `${string}_other`
|
||||
| `${string}_other_calendar`;
|
||||
/** The display name for the app, TODO settle between this or name */
|
||||
title: string;
|
||||
title?: string;
|
||||
/** The display name for the app */
|
||||
name: string;
|
||||
/** A brief description, usually found in the app's package.json */
|
||||
description: string;
|
||||
/** The icon to display in /apps/installed */
|
||||
imageSrc: string;
|
||||
/**
|
||||
* @deprecated logo is used instead
|
||||
* The icon to display in /apps/installed
|
||||
*/
|
||||
imageSrc?: string;
|
||||
/** TODO determine if we should use this instead of category */
|
||||
variant: "calendar" | "payment" | "conferencing" | "video" | "other" | "other_calendar";
|
||||
/** The slug for the app store public page inside `/apps/[slug] */
|
||||
|
||||
@@ -14,6 +14,7 @@ import HelpMenuItem from "@calcom/features/ee/support/components/HelpMenuItem";
|
||||
import CustomBranding from "@calcom/lib/CustomBranding";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { 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";
|
||||
@@ -123,9 +124,7 @@ const Layout = ({
|
||||
}: LayoutProps & { status: SessionContextValue["status"]; plan?: UserPlan; isLoading: boolean }) => {
|
||||
const isEmbed = useIsEmbed();
|
||||
const router = useRouter();
|
||||
const { data: routingForms } = trpc.useQuery(["viewer.appById", { appId: "routing_forms" }], {
|
||||
enabled: status === "authenticated",
|
||||
});
|
||||
const { data: routingForms } = useApp("routing_forms");
|
||||
|
||||
const { t } = useLocale();
|
||||
const navigation = [
|
||||
|
||||
@@ -27,7 +27,7 @@ const headless = !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS;
|
||||
const config: PlaywrightTestConfig = {
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: 1,
|
||||
workers: os.cpus().length,
|
||||
workers: headless ? os.cpus().length : 1,
|
||||
timeout: 60_000,
|
||||
maxFailures: headless ? 10 : undefined,
|
||||
reporter: [
|
||||
|
||||
Reference in new issue
Block a user