Skip to content

Commit

Permalink
chore/migrate workflows page
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroHryshyn committed Dec 6, 2023
1 parent b5b1533 commit 536c47c
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,4 @@ E2E_TEST_OIDC_USER_PASSWORD=
AB_TEST_BUCKET_PROBABILITY=50
# whether we redirect to the future/event-types from event-types or not
APP_ROUTER_EVENT_TYPES_ENABLED=1
APP_ROUTER_WORKFLOWS_ENABLED=1
3 changes: 2 additions & 1 deletion apps/web/abTest/middlewareFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { NextResponse, URLPattern } from "next/server";
import z from "zod";

const ROUTES: [URLPattern, boolean][] = [
["/event-types", process.env.APP_ROUTER_EVENT_TYPES_ENABLED === "1"] as const,
["/event-types", Boolean(process.env.APP_ROUTER_EVENT_TYPES_ENABLED)] as const,
["/workflows/:path*", Boolean(process.env.APP_ROUTER_WORKFLOWS_ENABLED)] as const,
].map(([pathname, enabled]) => [
new URLPattern({
pathname,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { headers } from "next/headers";
import { notFound } from "next/navigation";
import { z } from "zod";

import Workflow from "@calcom/features/ee/workflows/pages/workflow";

import PageWrapper from "@components/PageWrapperAppDir";

type Params = { workflow: string };

type WorkflowPageProps = {
params: Params;
};

const querySchema = z.object({
workflow: z.string(),
});

async function getProps({ params }: { params: Params }) {
const safeParams = querySchema.safeParse(params);

console.log("Built workflow page:", safeParams);
if (!safeParams.success) {
return notFound();
}
return { workflow: safeParams.data.workflow };
}

export default async function WorkflowPage({ params }: WorkflowPageProps) {
const props = await getProps({ params });
const h = headers();
const nonce = h.get("x-nonce") ?? undefined;

return (
<PageWrapper getLayout={null} requiresLicense={false} nonce={nonce} themeBasis={null} {...props}>
<Workflow />
</PageWrapper>
);
}

export const dynamicParams = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { _generateMetadata } from "app/_utils";

import Workflows from "@calcom/features/ee/workflows/pages/index";

import type { CalPageWrapper } from "@components/PageWrapper";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("workflows"),
(t) => t("workflows_to_automate_notifications")
);

const WorkflowsPage = Workflows as CalPageWrapper;

export default WorkflowsPage;
3 changes: 3 additions & 0 deletions apps/web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export const config = {
"/apps/routing_forms/:path*",
"/event-types",
"/future/event-types/",

"/workflows/:path*",
"/future/workflows/:path*/",
],
};

Expand Down
34 changes: 34 additions & 0 deletions apps/web/playwright/ab-tests-redirect.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect } from "@playwright/test";

import { test } from "./lib/fixtures";

test.describe.configure({ mode: "parallel" });

test.describe("workflows/ A/B tests", () => {
test("should point to the future/workflows", async ({ page, users, context }) => {
await context.addCookies([
{
name: "x-calcom-future-routes-override",
value: "1",
url: "http://localhost:3000",
},
]);
const user = await users.create();

await user.apiLogin();

await page.goto("/workflows");

await page.waitForLoadState();

const dataNextJsRouter = await page.evaluate(() =>
window.document.documentElement.getAttribute("data-nextjs-router")
);

expect(dataNextJsRouter).toEqual("app");

const locator = page.getByRole("heading", { name: "Workflows" });

await expect(locator).toBeVisible();
});
});
2 changes: 2 additions & 0 deletions packages/features/ee/workflows/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import type { Dispatch, SetStateAction } from "react";
Expand Down
2 changes: 2 additions & 0 deletions packages/features/ee/workflows/pages/workflow.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import type { WorkflowStep } from "@prisma/client";
import { isValidPhoneNumber } from "libphonenumber-js";
Expand Down
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"ANALYZE",
"API_KEY_PREFIX",
"APP_ROUTER_EVENT_TYPES_ENABLED",
"APP_ROUTER_WORKFLOWS_ENABLED",
"APP_USER_NAME",
"BASECAMP3_CLIENT_ID",
"BASECAMP3_CLIENT_SECRET",
Expand Down

0 comments on commit 536c47c

Please sign in to comment.