Skip to content

Commit

Permalink
chore: [app-router-migration 18] Migrate "/settings/organizations/*" …
Browse files Browse the repository at this point in the history
…pages (calcom#13042)

* manual: app-directory-boilerplate-calcom

* manual: import components directly

* manual: move files to correct route groups and add metadata

* manual: Change structure & Refactor to make code up to date

* manual: refactors

* Fix

* manual: fix type of arg of getData

* manual: fix type error

* fix type bugs

* fix

* fixing the build

* wip

---------

Co-authored-by: Greg Pabian <[email protected]>
  • Loading branch information
hbjORbj and grzpab authored Jan 12, 2024
1 parent 65d9704 commit 0bdc45a
Show file tree
Hide file tree
Showing 48 changed files with 428 additions and 43 deletions.
7 changes: 2 additions & 5 deletions apps/web/app/future/apps/categories/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import LegacyPage from "@pages/apps/categories/index";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import type { GetServerSidePropsContext } from "next";

import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { APP_NAME } from "@calcom/lib/constants";

import type { buildLegacyCtx } from "@lib/buildLegacyCtx";

import { ssrInit } from "@server/lib/ssr";

export const generateMetadata = async () => {
Expand All @@ -17,11 +16,9 @@ export const generateMetadata = async () => {
);
};

const getData = async (ctx: ReturnType<typeof buildLegacyCtx>) => {
// @ts-expect-error Argument of type '{ query: Params; params: Params; req: { headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }; }' is not assignable to parameter of type 'GetServerSidePropsContext'.
const getData = async (ctx: GetServerSidePropsContext) => {
const ssr = await ssrInit(ctx);

// @ts-expect-error Type '{ headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }' is not assignable to type 'NextApiRequest | IncomingMessage
const session = await getServerSession({ req: ctx.req });

let appStore;
Expand Down
7 changes: 2 additions & 5 deletions apps/web/app/future/apps/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AppsPage from "@pages/apps";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import type { GetServerSidePropsContext } from "next";

import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
import { getLayout } from "@calcom/features/MainLayoutAppDir";
Expand All @@ -10,8 +11,6 @@ import getUserAdminTeams from "@calcom/features/ee/teams/lib/getUserAdminTeams";
import { APP_NAME } from "@calcom/lib/constants";
import type { AppCategories } from "@calcom/prisma/enums";

import type { buildLegacyCtx } from "@lib/buildLegacyCtx";

import { ssrInit } from "@server/lib/ssr";

export const generateMetadata = async () => {
Expand All @@ -21,11 +20,9 @@ export const generateMetadata = async () => {
);
};

const getData = async (ctx: ReturnType<typeof buildLegacyCtx>) => {
// @ts-expect-error Argument of type '{ query: Params; params: Params; req: { headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }; }' is not assignable to parameter of type 'GetServerSidePropsContext'.
const getData = async (ctx: GetServerSidePropsContext) => {
const ssr = await ssrInit(ctx);

// @ts-expect-error Type '{ headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }' is not assignable to type 'NextApiRequest
const session = await getServerSession({ req: ctx.req });

let appStore, userAdminTeams: UserAdminTeams;
Expand Down
5 changes: 2 additions & 3 deletions apps/web/app/future/bookings/[status]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import type { GetServerSidePropsContext } from "next";
import { notFound } from "next/navigation";
import { z } from "zod";

import { getLayout } from "@calcom/features/MainLayoutAppDir";
import { APP_NAME } from "@calcom/lib/constants";

import type { buildLegacyCtx } from "@lib/buildLegacyCtx";

import { ssgInit } from "@server/lib/ssg";

const validStatuses = ["upcoming", "recurring", "past", "cancelled", "unconfirmed"] as const;
Expand All @@ -26,7 +25,7 @@ export const generateStaticParams = async () => {
return validStatuses.map((status) => ({ status }));
};

const getData = async (ctx: ReturnType<typeof buildLegacyCtx>) => {
const getData = async (ctx: GetServerSidePropsContext) => {
const parsedParams = querySchema.safeParse(ctx.params);

if (!parsedParams.success) {
Expand Down
8 changes: 3 additions & 5 deletions apps/web/app/future/getting-started/[[...step]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import LegacyPage from "@pages/getting-started/[[...step]]";
import { WithLayout } from "app/layoutHOC";
import type { GetServerSidePropsContext } from "next";
import { cookies, headers } from "next/headers";
import { redirect } from "next/navigation";

import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import prisma from "@calcom/prisma";

import type { buildLegacyCtx } from "@lib/buildLegacyCtx";

import { ssrInit } from "@server/lib/ssr";

const getData = async (ctx: ReturnType<typeof buildLegacyCtx>) => {
const getData = async (ctx: GetServerSidePropsContext) => {
const req = { headers: headers(), cookies: cookies() };

//@ts-expect-error Type '{ headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }' is not assignable to type 'NextApiRequest
Expand All @@ -19,7 +18,6 @@ const getData = async (ctx: ReturnType<typeof buildLegacyCtx>) => {
if (!session?.user?.id) {
return redirect("/auth/login");
}
// @ts-expect-error Argument of type '{ query: Params; params: Params; req: { headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }; }' is not assignable to parameter of type 'GetServerSidePropsContext'.
const ssr = await ssrInit(ctx);
await ssr.viewer.me.prefetch();

Expand Down Expand Up @@ -54,7 +52,7 @@ const getData = async (ctx: ReturnType<typeof buildLegacyCtx>) => {

return {
dehydratedState: ssr.dehydrate(),
hasPendingInvites: user.teams.find((team: any) => team.accepted === false) ?? false,
hasPendingInvites: user.teams.find((team) => team.accepted === false) ?? false,
requiresLicense: false,
themeBasis: null,
};
Expand Down
11 changes: 11 additions & 0 deletions apps/web/app/future/settings/organizations/[id]/about/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import LegacyPage, { WrappedAboutOrganizationPage } from "@pages/settings/organizations/[id]/about";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("about_your_organization"),
(t) => t("about_your_organization_description")
);

export default WithLayout({ Page: LegacyPage, getLayout: WrappedAboutOrganizationPage });
11 changes: 11 additions & 0 deletions apps/web/app/future/settings/organizations/[id]/add-teams/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import LegacyPage, { WrapperAddNewTeamsPage } from "@pages/settings/organizations/[id]/add-teams";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("create_your_teams"),
(t) => t("create_your_teams_description")
);

export default WithLayout({ Page: LegacyPage, getLayout: WrapperAddNewTeamsPage });
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import LegacyPage, {
buildWrappedOnboardTeamMembersPage,
} from "@pages/settings/organizations/[id]/onboard-admins";
import { type Params } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { headers } from "next/headers";

import PageWrapper from "@components/PageWrapperAppDir";

type PageProps = Readonly<{
params: Params;
}>;

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("invite_organization_admins"),
(t) => t("invite_organization_admins_description")
);

const Page = ({ params }: PageProps) => {
const h = headers();
const nonce = h.get("x-nonce") ?? undefined;

return (
<PageWrapper
getLayout={(page: React.ReactElement) => buildWrappedOnboardTeamMembersPage(params.id, page)}
requiresLicense={false}
nonce={nonce}
themeBasis={null}>
<LegacyPage />
</PageWrapper>
);
};

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import LegacyPage, { WrappedSetPasswordPage } from "@pages/settings/organizations/[id]/set-password";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("set_a_password"),
(t) => t("set_a_password_description")
);

export default WithLayout({ Page: LegacyPage, getLayout: WrappedSetPasswordPage });
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
11 changes: 11 additions & 0 deletions apps/web/app/future/settings/organizations/appearance/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/organizations/pages/settings/appearance";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("appearance"),
(t) => t("appearance_org_description")
);

export default Page;
5 changes: 5 additions & 0 deletions apps/web/app/future/settings/organizations/billing/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
10 changes: 10 additions & 0 deletions apps/web/app/future/settings/organizations/billing/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Page from "@pages/settings/billing/index";
import { _generateMetadata } from "app/_utils";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("billing"),
(t) => t("manage_billing_description")
);

export default Page;
5 changes: 5 additions & 0 deletions apps/web/app/future/settings/organizations/general/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
11 changes: 11 additions & 0 deletions apps/web/app/future/settings/organizations/general/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/organizations/pages/settings/general";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("general"),
(t) => t("general_description")
);

export default Page;
5 changes: 5 additions & 0 deletions apps/web/app/future/settings/organizations/members/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
11 changes: 11 additions & 0 deletions apps/web/app/future/settings/organizations/members/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/organizations/pages/settings/members";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("organization_members"),
(t) => t("organization_description")
);

export default Page;
34 changes: 34 additions & 0 deletions apps/web/app/future/settings/organizations/new/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import LegacyPage, { WrappedCreateNewOrganizationPage } from "@pages/settings/organizations/new/index";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { notFound } from "next/navigation";

import { getFeatureFlagMap } from "@calcom/features/flags/server/utils";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("set_up_your_organization"),
(t) => t("organizations_description")
);

const getPageProps = async (context: GetServerSidePropsContext) => {
const prisma = await import("@calcom/prisma").then((mod) => mod.default);
const flags = await getFeatureFlagMap(prisma);
// Check if organizations are enabled
if (flags["organizations"] !== true) {
return notFound();
}

const querySlug = context.query.slug as string;

return {
querySlug: querySlug ?? null,
};
};

export default WithLayout({
getLayout: WrappedCreateNewOrganizationPage,
Page: LegacyPage,
getData: getPageProps,
});
5 changes: 5 additions & 0 deletions apps/web/app/future/settings/organizations/profile/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
11 changes: 11 additions & 0 deletions apps/web/app/future/settings/organizations/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/organizations/pages/settings/profile";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("profile"),
(t) => t("profile_org_description")
);

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/teams/pages/team-appearance-view";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("booking_appearance"),
(t) => t("appearance_team_description")
);

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/organizations/pages/settings/other-team-members-view";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("team_members"),
(t) => t("members_team_description")
);

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/organizations/pages/settings/other-team-profile-view";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("profile"),
(t) => t("profile_team_description")
);

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WithLayout } from "app/layoutHOC";

import { getLayout } from "@calcom/features/settings/layouts/SettingsLayoutAppDir";

export default WithLayout({ getLayout });
11 changes: 11 additions & 0 deletions apps/web/app/future/settings/organizations/teams/other/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _generateMetadata } from "app/_utils";

import Page from "@calcom/features/ee/organizations/pages/settings/other-team-listing-view";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("org_admin_other_teams"),
(t) => t("org_admin_other_teams_description")
);

export default Page;
Loading

0 comments on commit 0bdc45a

Please sign in to comment.