fix: Make routing-form a preinstalled app (#9836)

Co-authored-by: zomars <[email protected]>
This commit is contained in:
Hariom Balharaandzomars authored and GitHub committed 2023-07-26 16:44:19 +00:00
1 parent 9c389c307c
commit f1acedff77
16 files changed
+70 -77

No files matched your search

+1 -1
View File
@@ -39,4 +39,4 @@ jobs:
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: app-store-results-${{ matrix.shard }}_${{ strategy.job-total }} name: app-store-results-${{ matrix.shard }}_${{ strategy.job-total }}
path: app-store-results path: test-results
+1 -1
View File
@@ -41,4 +41,4 @@ jobs:
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: embed-react-results-${{ matrix.shard }}_${{ strategy.job-total }} name: embed-react-results-${{ matrix.shard }}_${{ strategy.job-total }}
path: embed-react-results path: test-results
+1 -1
View File
@@ -39,4 +39,4 @@ jobs:
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: embed-core-results-${{ matrix.shard }}_${{ strategy.job-total }} name: embed-core-results-${{ matrix.shard }}_${{ strategy.job-total }}
path: embed-core-results path: test-results
+23 -5
View File
@@ -54,10 +54,9 @@ const middleware: NextMiddleware = async (req) => {
} }
} }
// Don't 404 old routing_forms links const res = routingForms.handle(url);
if (url.pathname.startsWith("/apps/routing_forms")) { if (res) {
url.pathname = url.pathname.replace("/apps/routing_forms", "/apps/routing-forms"); return res;
return NextResponse.rewrite(url);
} }
if (url.pathname.startsWith("/api/trpc/")) { if (url.pathname.startsWith("/api/trpc/")) {
@@ -76,15 +75,34 @@ const middleware: NextMiddleware = async (req) => {
}); });
}; };
const routingForms = {
handle: (url: URL) => {
// Next.config.js Redirects don't handle Client Side navigations and we need that.
// So, we add the rewrite here instead.
if (url.pathname.startsWith("/routing-forms/")) {
url.pathname = url.pathname.replace(/^\/routing-forms\//, "/apps/routing-forms/");
return NextResponse.rewrite(url);
}
// Don't 404 old routing_forms links
if (url.pathname.startsWith("/apps/routing_forms")) {
url.pathname = url.pathname.replace(/^\/apps\/routing_forms\//, "/apps/routing-forms/");
return NextResponse.rewrite(url);
}
},
// Matcher paths that are required by the handle function to work
paths: ["/apps/routing_forms/:path*", "/routing-forms/:path*"],
};
export const config = { export const config = {
matcher: [ matcher: [
"/((?!_next|.*avatar.png$|favicon.ico$).*)", "/((?!_next|.*avatar.png$|favicon.ico$).*)",
"/api/collect-events/:path*", "/api/collect-events/:path*",
"/api/auth/:path*", "/api/auth/:path*",
"/apps/routing_forms/:path*",
"/:path*/embed", "/:path*/embed",
"/api/trpc/:path*", "/api/trpc/:path*",
"/auth/login", "/auth/login",
...routingForms.paths,
], ],
}; };
+8 -1
View File
@@ -1,6 +1,7 @@
import type { GetServerSidePropsContext } from "next"; import type { GetServerSidePropsContext } from "next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { getAppWithMetadata } from "@calcom/app-store/_appRegistry";
import RoutingFormsRoutingConfig from "@calcom/app-store/routing-forms/pages/app-routing.config"; import RoutingFormsRoutingConfig from "@calcom/app-store/routing-forms/pages/app-routing.config";
import TypeformRoutingConfig from "@calcom/app-store/typeform/pages/app-routing.config"; import TypeformRoutingConfig from "@calcom/app-store/typeform/pages/app-routing.config";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
@@ -127,6 +128,12 @@ export async function getServerSideProps(
params.appPages = pages.slice(1); params.appPages = pages.slice(1);
const session = await getServerSession({ req, res }); const session = await getServerSession({ req, res });
const user = session?.user; const user = session?.user;
const app = await getAppWithMetadata({ slug: appName });
if (!app) {
return {
notFound: true,
};
}
const result = await route.getServerSideProps( const result = await route.getServerSideProps(
context as GetServerSidePropsContext<{ context as GetServerSidePropsContext<{
@@ -153,7 +160,7 @@ export async function getServerSideProps(
return { return {
props: { props: {
appName, appName,
appUrl: `/apps/${appName}`, appUrl: app.simplePath || `/apps/${appName}`,
...result.props, ...result.props,
}, },
}; };
+1 -8
View File
@@ -409,13 +409,6 @@ test.describe("FORM_SUBMITTED", async () => {
await page.waitForLoadState("networkidle"); await page.waitForLoadState("networkidle");
// Install Routing Forms App
await page.goto(`/apps/routing-forms`);
// eslint-disable-next-line playwright/no-conditional-in-test
await page.click('[data-testid="install-app-button"]');
await page.click('[data-testid="install-app-button-personal"]');
await page.waitForLoadState("networkidle"); await page.waitForLoadState("networkidle");
await page.goto(`/settings/developer/webhooks/new`); await page.goto(`/settings/developer/webhooks/new`);
@@ -428,7 +421,7 @@ test.describe("FORM_SUBMITTED", async () => {
expect(page.locator(`text='${webhookReceiver.url}'`)).toBeDefined(); expect(page.locator(`text='${webhookReceiver.url}'`)).toBeDefined();
await page.waitForLoadState("networkidle"); await page.waitForLoadState("networkidle");
await page.goto("/apps/routing-forms/forms"); await page.goto("/routing-forms/forms");
await page.click('[data-testid="new-routing-form"]'); await page.click('[data-testid="new-routing-form"]');
// Choose to create the Form for the user(which is the first option) and not the team // Choose to create the Form for the user(which is the first option) and not the team
await page.click('[data-testid="option-0"]'); await page.click('[data-testid="option-0"]');
+3 -1
View File
@@ -2,6 +2,7 @@
"/*": "Don't modify slug - If required, do it using cli edit command", "/*": "Don't modify slug - If required, do it using cli edit command",
"name": "Routing Forms", "name": "Routing Forms",
"title": "Routing Forms", "title": "Routing Forms",
"isGlobal": true,
"slug": "routing-forms", "slug": "routing-forms",
"type": "routing-forms_other", "type": "routing-forms_other",
"logo": "icon-dark.svg", "logo": "icon-dark.svg",
@@ -9,10 +10,11 @@
"variant": "other", "variant": "other",
"categories": ["automation"], "categories": ["automation"],
"publisher": "Cal.com, Inc.", "publisher": "Cal.com, Inc.",
"simplePath": "/routing-forms",
"email": "[email protected]", "email": "[email protected]",
"licenseRequired": true, "licenseRequired": true,
"teamsPlanRequired": { "teamsPlanRequired": {
"upgradeUrl": "/apps/routing-forms/forms" "upgradeUrl": "/routing-forms/forms"
}, },
"description": "It would allow a booker to connect with the right person or choose the right event, faster. It would work by taking inputs from the booker and using that data to route to the correct booker/event as configured by Cal user", "description": "It would allow a booker to connect with the right person or choose the right event, faster. It would work by taking inputs from the booker and using that data to route to the correct booker/event as configured by Cal user",
"__createdUsingCli": true "__createdUsingCli": true
@@ -27,7 +27,7 @@ export const ResponseEmail = ({
color: "#3e3e3e", color: "#3e3e3e",
}}> }}>
<p style={{ fontWeight: 400, lineHeight: "24px" }}> <p style={{ fontWeight: 400, lineHeight: "24px" }}>
<a href={`${WEBAPP_URL}/apps/routing-forms/form-edit/${form.id}`} style={{ color: "#3e3e3e" }}> <a href={`${WEBAPP_URL}/routing-forms/form-edit/${form.id}`} style={{ color: "#3e3e3e" }}>
<>Manage this form</> <>Manage this form</>
</a> </a>
</p> </p>
@@ -425,7 +425,7 @@ export default function FormEditPage({
FormEditPage.getLayout = (page: React.ReactElement) => { FormEditPage.getLayout = (page: React.ReactElement) => {
return ( return (
<Shell backPath="/apps/routing-forms/forms" withoutMain={true}> <Shell backPath="/routing-forms/forms" withoutMain={true}>
{page} {page}
</Shell> </Shell>
); );
@@ -199,7 +199,7 @@ export default function ReporterWrapper({
ReporterWrapper.getLayout = (page: React.ReactElement) => { ReporterWrapper.getLayout = (page: React.ReactElement) => {
return ( return (
<Shell backPath="/apps/routing-forms/forms" withoutMain={true}> <Shell backPath="/routing-forms/forms" withoutMain={true}>
{page} {page}
</Shell> </Shell>
); );
@@ -562,7 +562,7 @@ export default function RouteBuilder({
RouteBuilder.getLayout = (page: React.ReactElement) => { RouteBuilder.getLayout = (page: React.ReactElement) => {
return ( return (
<Shell backPath="/apps/routing-forms/forms" withoutMain={true}> <Shell backPath="/routing-forms/forms" withoutMain={true}>
{page} {page}
</Shell> </Shell>
); );
@@ -17,7 +17,7 @@ test.describe("Routing Forms", () => {
const formId = await addForm(page); const formId = await addForm(page);
await page.click('[href="/apps/routing-forms/forms"]'); await page.click('[href*="/forms"]');
await page.waitForSelector('[data-testid="routing-forms-list"]'); await page.waitForSelector('[data-testid="routing-forms-list"]');
// Ensure that it's visible in forms list // Ensure that it's visible in forms list
@@ -54,7 +54,7 @@ test.describe("Routing Forms", () => {
await expectCurrentFormToHaveFields(page, createdFields, types); await expectCurrentFormToHaveFields(page, createdFields, types);
await page.click('[href*="/apps/routing-forms/route-builder/"]'); await page.click('[href*="/route-builder/"]');
await selectNewRoute(page); await selectNewRoute(page);
await page.click('[data-testid="add-rule"]'); await page.click('[data-testid="add-rule"]');
@@ -86,7 +86,7 @@ test.describe("Routing Forms", () => {
}); });
// Add F1 as Router to F2 // Add F1 as Router to F2
await page.goto(`/apps/routing-forms/route-builder/${form2Id}`); await page.goto(`/routing-forms/route-builder/${form2Id}`);
await selectNewRoute(page, { await selectNewRoute(page, {
// It should be F1. TODO: Verify that it's F1 // It should be F1. TODO: Verify that it's F1
routeSelectNumber: 2, routeSelectNumber: 2,
@@ -94,7 +94,7 @@ test.describe("Routing Forms", () => {
await saveCurrentForm(page); await saveCurrentForm(page);
// Expect F1 fields to be available in F2 // Expect F1 fields to be available in F2
await page.goto(`/apps/routing-forms/form-edit/${form2Id}`); await page.goto(`/routing-forms/form-edit/${form2Id}`);
//FIXME: Figure out why this delay is required. Without it field count comes out to be 1 only //FIXME: Figure out why this delay is required. Without it field count comes out to be 1 only
await new Promise((resolve) => setTimeout(resolve, 1000)); await new Promise((resolve) => setTimeout(resolve, 1000));
@@ -108,7 +108,7 @@ test.describe("Routing Forms", () => {
}, },
}); });
await page.goto(`/apps/routing-forms/form-edit/${form2Id}`); await page.goto(`/routing-forms/form-edit/${form2Id}`);
//FIXME: Figure out why this delay is required. Without it field count comes out to be 1 only //FIXME: Figure out why this delay is required. Without it field count comes out to be 1 only
await new Promise((resolve) => setTimeout(resolve, 1000)); await new Promise((resolve) => setTimeout(resolve, 1000));
expect(await page.locator('[data-testid="field"]').count()).toBe(3); expect(await page.locator('[data-testid="field"]').count()).toBe(3);
@@ -119,7 +119,7 @@ test.describe("Routing Forms", () => {
test("should be able to submit a prefilled form with all types of fields", async ({ page }) => { test("should be able to submit a prefilled form with all types of fields", async ({ page }) => {
const formId = await addForm(page); const formId = await addForm(page);
await page.click('[href*="/apps/routing-forms/route-builder/"]'); await page.click('[href*="/route-builder/"]');
await selectNewRoute(page); await selectNewRoute(page);
await selectOption({ await selectOption({
selector: { selector: {
@@ -183,11 +183,7 @@ test.describe("Routing Forms", () => {
} }
); );
await user.apiLogin(); await user.apiLogin();
// Install app await page.goto(`/routing-forms/forms`);
await page.goto(`/apps/routing-forms`);
await page.click('[data-testid="install-app-button"]');
(await page.waitForSelector('[data-testid="install-app-button-personal"]')).click();
await page.waitForURL((url) => url.pathname === `/apps/routing-forms/forms`);
}); });
test.afterEach(async ({ users }) => { test.afterEach(async ({ users }) => {
@@ -203,28 +199,17 @@ test.describe("Routing Forms", () => {
// This also delete forms on cascade // This also delete forms on cascade
await users.deleteAll(); await users.deleteAll();
}); });
const createUserAndLoginAndInstallApp = async function ({ const createUserAndLogin = async function ({ users, page }: { users: Fixtures["users"]; page: Page }) {
users,
page,
}: {
users: Fixtures["users"];
page: Page;
}) {
const user = await users.create( const user = await users.create(
{ username: "routing-forms" }, { username: "routing-forms" },
{ seedRoutingForms: true, hasTeam: true } { seedRoutingForms: true, hasTeam: true }
); );
await user.apiLogin(); await user.apiLogin();
// Install app
await page.goto(`/apps/routing-forms`);
await page.click('[data-testid="install-app-button"]');
(await page.waitForSelector('[data-testid="install-app-button-personal"]')).click();
await page.waitForURL((url) => url.pathname === `/apps/routing-forms/forms`);
return user; return user;
}; };
test("Routing Link - Reporting and CSV Download ", async ({ page, users }) => { test("Routing Link - Reporting and CSV Download ", async ({ page, users }) => {
const user = await createUserAndLoginAndInstallApp({ users, page }); const user = await createUserAndLogin({ users, page });
const routingForm = user.routingForms[0]; const routingForm = user.routingForms[0];
test.setTimeout(120000); test.setTimeout(120000);
// Fill form when you are logged out // Fill form when you are logged out
@@ -235,7 +220,7 @@ test.describe("Routing Forms", () => {
// Log back in to view form responses. // Log back in to view form responses.
await user.apiLogin(); await user.apiLogin();
await page.goto(`/apps/routing-forms/reporting/${routingForm.id}`); await page.goto(`/routing-forms/reporting/${routingForm.id}`);
const headerEls = page.locator("[data-testid='reporting-header'] th"); const headerEls = page.locator("[data-testid='reporting-header'] th");
// Once the response is there, React would soon render it, so 500ms is enough // Once the response is there, React would soon render it, so 500ms is enough
@@ -305,7 +290,7 @@ test.describe("Routing Forms", () => {
}); });
test("Router URL should work", async ({ page, users }) => { test("Router URL should work", async ({ page, users }) => {
const user = await createUserAndLoginAndInstallApp({ users, page }); const user = await createUserAndLogin({ users, page });
const routingForm = user.routingForms[0]; const routingForm = user.routingForms[0];
// Router should be publicly accessible // Router should be publicly accessible
@@ -328,7 +313,7 @@ test.describe("Routing Forms", () => {
}); });
test("Routing Link should validate fields", async ({ page, users }) => { test("Routing Link should validate fields", async ({ page, users }) => {
const user = await createUserAndLoginAndInstallApp({ users, page }); const user = await createUserAndLogin({ users, page });
const routingForm = user.routingForms[0]; const routingForm = user.routingForms[0];
await gotoRoutingLink({ page, formId: routingForm.id }); await gotoRoutingLink({ page, formId: routingForm.id });
page.click('button[type="submit"]'); page.click('button[type="submit"]');
@@ -340,7 +325,7 @@ test.describe("Routing Forms", () => {
}); });
test("Test preview should return correct route", async ({ page, users }) => { test("Test preview should return correct route", async ({ page, users }) => {
const user = await createUserAndLoginAndInstallApp({ users, page }); const user = await createUserAndLogin({ users, page });
const routingForm = user.routingForms[0]; const routingForm = user.routingForms[0];
page.goto(`apps/routing-forms/form-edit/${routingForm.id}`); page.goto(`apps/routing-forms/form-edit/${routingForm.id}`);
await page.click('[data-testid="test-preview"]'); await page.click('[data-testid="test-preview"]');
@@ -423,7 +408,7 @@ async function fillSeededForm(page: Page, routingFormId: string) {
} }
export async function addForm(page: Page, { name = "Test Form Name" } = {}) { export async function addForm(page: Page, { name = "Test Form Name" } = {}) {
await page.goto("/apps/routing-forms/forms"); await page.goto("/routing-forms/forms");
await page.click('[data-testid="new-routing-form"]'); await page.click('[data-testid="new-routing-form"]');
// Choose to create the Form for the user(which is the first option) and not the team // Choose to create the Form for the user(which is the first option) and not the team
await page.click('[data-testid="option-0"]'); await page.click('[data-testid="option-0"]');
+1 -2
View File
@@ -10,6 +10,5 @@
"publisher": "Cal.com, Inc.", "publisher": "Cal.com, Inc.",
"email": "[email protected]", "email": "[email protected]",
"description": "Adds a link to copy Typeform Redirect URL", "description": "Adds a link to copy Typeform Redirect URL",
"__createdUsingCli": true, "__createdUsingCli": true
"dependencies": ["routing-forms"]
} }
@@ -17,10 +17,6 @@ const installApps = async (page: Page, users: Fixtures["users"]) => {
} }
); );
await user.login(); await user.login();
await page.goto(`/apps/routing-forms`);
await page.click('[data-testid="install-app-button"]');
(await page.waitForSelector('[data-testid="install-app-button-personal"]')).click();
await page.waitForURL((url) => url.pathname === `/apps/routing-forms/forms`);
await page.goto(`/apps/typeform`); await page.goto(`/apps/typeform`);
await page.click('[data-testid="install-app-button"]'); await page.click('[data-testid="install-app-button"]');
(await page.waitForSelector('[data-testid="install-app-button-personal"]')).click(); (await page.waitForSelector('[data-testid="install-app-button-personal"]')).click();
@@ -38,7 +34,7 @@ test.describe("Typeform App", () => {
await installApps(page, users); await installApps(page, users);
context.grantPermissions(["clipboard-read", "clipboard-write"]); context.grantPermissions(["clipboard-read", "clipboard-write"]);
await page.goto(`/apps/routing-forms/forms`); await page.goto(`/routing-forms/forms`);
const formId = await addRoutingForm(page); const formId = await addRoutingForm(page);
await addOneFieldAndDescriptionAndSaveForm(formId, page, { await addOneFieldAndDescriptionAndSaveForm(formId, page, {
description: "", description: "",
@@ -57,14 +53,14 @@ test.describe("Typeform App", () => {
await installApps(page, users); await installApps(page, users);
context.grantPermissions(["clipboard-read", "clipboard-write"]); context.grantPermissions(["clipboard-read", "clipboard-write"]);
await page.goto("/apps/routing-forms/forms"); await page.goto("/routing-forms/forms");
const formId = await addRoutingForm(page); const formId = await addRoutingForm(page);
await addOneFieldAndDescriptionAndSaveForm(formId, page, { await addOneFieldAndDescriptionAndSaveForm(formId, page, {
description: "", description: "",
field: { label: "test", typeIndex: 1 }, field: { label: "test", typeIndex: 1 },
}); });
await page.goto("/apps/routing-forms/forms"); await page.goto("/routing-forms/forms");
await page.click('[data-testid="form-dropdown"]'); await page.click('[data-testid="form-dropdown"]');
await page.click('[data-testid="copy-redirect-url"]'); await page.click('[data-testid="copy-redirect-url"]');
const text = await page.evaluate(async () => { const text = await page.evaluate(async () => {
+5 -17
View File
@@ -539,9 +539,7 @@ const navigation: NavigationItemType[] = [
isCurrent: ({ router, item }) => { isCurrent: ({ router, item }) => {
const path = router.asPath.split("?")[0]; const path = router.asPath.split("?")[0];
// During Server rendering path is /v2/apps but on client it becomes /apps(weird..) // During Server rendering path is /v2/apps but on client it becomes /apps(weird..)
return ( return path.startsWith(item.href) || path.startsWith("/v2" + item.href);
(path.startsWith(item.href) || path.startsWith("/v2" + item.href)) && !path.includes("routing-forms/")
);
}, },
child: [ child: [
{ {
@@ -551,9 +549,7 @@ const navigation: NavigationItemType[] = [
const path = router.asPath.split("?")[0]; const path = router.asPath.split("?")[0];
// During Server rendering path is /v2/apps but on client it becomes /apps(weird..) // During Server rendering path is /v2/apps but on client it becomes /apps(weird..)
return ( return (
(path.startsWith(item.href) || path.startsWith("/v2" + item.href)) && (path.startsWith(item.href) || path.startsWith("/v2" + item.href)) && !path.includes("/installed")
!path.includes("routing-forms/") &&
!path.includes("/installed")
); );
}, },
}, },
@@ -574,10 +570,10 @@ const navigation: NavigationItemType[] = [
}, },
{ {
name: "Routing Forms", name: "Routing Forms",
href: "/apps/routing-forms/forms", href: "/routing-forms/forms",
icon: FileText, icon: FileText,
isCurrent: ({ router }) => { isCurrent: ({ router }) => {
return router.asPath.startsWith("/apps/routing-forms/"); return router.asPath.startsWith("/routing-forms/");
}, },
}, },
{ {
@@ -626,17 +622,9 @@ const Navigation = () => {
}; };
function useShouldDisplayNavigationItem(item: NavigationItemType) { function useShouldDisplayNavigationItem(item: NavigationItemType) {
const { status } = useSession();
const { data: routingForms } = trpc.viewer.appById.useQuery(
{ appId: "routing-forms" },
{
enabled: status === "authenticated" && requiredCredentialNavigationItems.includes(item.name),
trpc: {},
}
);
const flags = useFlagMap(); const flags = useFlagMap();
if (isKeyInObject(item.name, flags)) return flags[item.name]; if (isKeyInObject(item.name, flags)) return flags[item.name];
return !requiredCredentialNavigationItems.includes(item.name) || routingForms?.isInstalled; return true;
} }
const defaultIsCurrent: NavigationItemType["isCurrent"] = ({ isChild, item, router }) => { const defaultIsCurrent: NavigationItemType["isCurrent"] = ({ isChild, item, router }) => {
+5
View File
@@ -115,6 +115,11 @@ export interface App {
* Used to show Connect/Disconnect buttons in App Store * Used to show Connect/Disconnect buttons in App Store
* */ * */
isGlobal?: boolean; isGlobal?: boolean;
/**
* For apps that are accessible on an alternate URL(which is simpler and shorter), this can be set.
* e.g. Routing Forms App is available as /routing-forms in addition to regular /apps/routing-forms.
*/
simplePath?: string;
/** A contact email, mainly to ask for support */ /** A contact email, mainly to ask for support */
email: string; email: string;
/** Needed API Keys (usually for global apps) */ /** Needed API Keys (usually for global apps) */