feat: Add step in team creation form for selecting event type and create a team event (#15286)

* feat: Create team event on a new team creation

* fix

* fixed failed tests

* move team event type form

* fix type error

* requested chnages

* update

* some update and refactor

* fix e2e test

* Update useCreateEventType.ts

* update

* fix type error

* fix e2e

* update

---------

Co-authored-by: Somay Chauhan <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-09-05 12:33:18 -04:00
1 parent 6b57dd6794
commit fced9a6355
12 files changed
+469 -204

No files matched your search

@@ -0,0 +1,11 @@
import LegacyPage, { GetLayout } from "@pages/settings/teams/[id]/event-type";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("add_new_team_event_type"),
(t) => t("new_event_type_to_book_description")
);
export default WithLayout({ Page: LegacyPage, getLayout: GetLayout })<"P">;
@@ -0,0 +1,86 @@
"use client";
import Head from "next/head";
import { useRouter } from "next/navigation";
import { TeamEventTypeForm } from "@calcom/features/ee/teams/components/TeamEventTypeForm";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { WizardLayout } from "@calcom/ui";
import { Button, showToast } from "@calcom/ui";
import PageWrapper from "@components/PageWrapper";
export const CreateTeamEventType = () => {
const searchParams = useCompatSearchParams();
const { t } = useLocale();
const router = useRouter();
const teamId = searchParams?.get("id") ? Number(searchParams.get("id")) : -1;
const onSuccessMutation = () => {
router.push(`/settings/teams/${teamId}/profile`);
};
const onErrorMutation = (err: string) => {
showToast(err, "error");
};
const SubmitButton = (isPending: boolean) => {
return (
<Button
data-testid="finish-button"
type="submit"
color="primary"
className="w-full justify-center"
disabled={isPending}>
{t("finish")}
</Button>
);
};
return (
<TeamEventTypeForm
isTeamAdminOrOwner={true}
teamId={teamId}
SubmitButton={SubmitButton}
onSuccessMutation={onSuccessMutation}
onErrorMutation={onErrorMutation}
isInfiniteScrollEnabled={false}
/>
);
};
const TeamEventTypePage = () => {
const { t } = useLocale();
return (
<>
<Head>
<title>{t("add_new_team_event_type")}</title>
<meta name="description" content={t("new_event_type_to_book_description")} />
</Head>
<CreateTeamEventType />
</>
);
};
export const GetLayout = (page: React.ReactElement) => {
const router = useRouter();
const searchParams = useCompatSearchParams();
const teamId = searchParams?.get("id") ? Number(searchParams.get("id")) : -1;
return (
<WizardLayout
currentStep={3}
maxSteps={3}
isOptionalCallback={() => {
router.push(`/settings/teams/${teamId}/profile`);
}}>
{page}
</WizardLayout>
);
};
TeamEventTypePage.getLayout = GetLayout;
TeamEventTypePage.PageWrapper = PageWrapper;
export default TeamEventTypePage;
@@ -22,7 +22,7 @@ const OnboardTeamMembersPage = () => {
};
export const GetLayout = (page: React.ReactElement) => (
<WizardLayout currentStep={2} maxSteps={2}>
<WizardLayout currentStep={2} maxSteps={3}>
{page}
</WizardLayout>
);
+1 -1
View File
@@ -63,7 +63,7 @@ const CreateNewTeamPage = () => {
};
export const LayoutWrapper = (page: React.ReactElement) => {
return (
<WizardLayout currentStep={1} maxSteps={2}>
<WizardLayout currentStep={1} maxSteps={3}>
{page}
</WizardLayout>
);
@@ -38,10 +38,15 @@ test.describe("Managed Event Types", () => {
await page.getByTestId("invite-new-member-button").click();
// wait for the second member to be added to the pending-member-list.
await page.getByTestId("pending-member-list").locator("li:nth-child(2)").waitFor();
// and publish
await page.locator("[data-testid=publish-button]").click();
await expect(page).toHaveURL(/\/settings\/teams\/(\d+)\/profile$/i);
// Going to create an event type
await expect(page).toHaveURL(/\/settings\/teams\/(\d+)\/event-type$/i);
// create a round-robin event type and finish
await expect(page.locator('button[value="ROUND_ROBIN"]')).toBeVisible();
await page.click('button[value="ROUND_ROBIN"]');
await page.fill("[name=title]", "roundRobin");
await page.getByTestId("finish-button").click();
await page.waitForURL(/\/settings\/teams\/(\d+)\/profile$/i);
// Going to create an managed event type
await page.goto("/event-types");
await page.getByTestId("new-event-type").click();
await page.getByTestId("option-team-1").click();
@@ -64,13 +64,20 @@ test.describe("Teams", () => {
await prisma.user.delete({ where: { email: inviteeEmail } });
});
await test.step("Can finish team creation", async () => {
await test.step("Can finish team invitation", async () => {
await page.getByTestId("publish-button").click();
await expect(page).toHaveURL(/\/settings\/teams\/(\d+)\/profile$/i);
await expect(page).toHaveURL(/\/settings\/teams\/(\d+)\/event-type$/i);
});
await test.step("Can finish team creation", async () => {
await expect(page.locator('button[value="ROUND_ROBIN"]')).toBeVisible();
await page.click('button[value="ROUND_ROBIN"]');
await page.fill("[name=title]", "roundRobin");
await page.getByTestId("finish-button").click();
await page.waitForURL(/\/settings\/teams\/(\d+)\/profile$/i);
});
await test.step("Can disband team", async () => {
await page.waitForURL(/\/settings\/teams\/(\d+)\/profile$/i);
await page.getByTestId("disband-team-button").click();
await page.getByTestId("dialog-confirmation").click();
await page.waitForURL("/teams");
+6 -2
View File
@@ -68,7 +68,9 @@ testBothFutureAndLegacyRoutes.describe("Teams - NonOrg", (routeVariant) => {
await test.step("Finishing brings you to team profile page", async () => {
await page.locator("[data-testid=publish-button]").click();
await expect(page).toHaveURL(/\/settings\/teams\/(\d+)\/profile$/i);
await expect(page).toHaveURL(/\/settings\/teams\/(\d+)\/event-type$/i);
await page.locator("[data-testid=handle-later-button]").click();
await page.waitForURL(/\/settings\/teams\/(\d+)\/profile$/i);
});
await test.step("Can disband team", async () => {
@@ -220,7 +222,9 @@ testBothFutureAndLegacyRoutes.describe("Teams - NonOrg", (routeVariant) => {
await page.waitForURL(/\/settings\/teams\/(\d+)\/onboard-members.*$/i);
// Click text=Continue
await page.locator("[data-testid=publish-button]").click();
await expect(page).toHaveURL(/\/settings\/teams\/(\d+)\/profile$/i);
await page.waitForURL(/\/settings\/teams\/(\d+)\/event-type*$/i);
await page.locator("[data-testid=handle-later-button]").click();
await page.waitForURL(/\/settings\/teams\/(\d+)\/profile$/i);
});
await test.step("Can access user and team with same slug", async () => {