chore: App router migration (/workflows) fix metadata and remove duplicate file for getStaticProps (#16452)

* Fix metadata

* add use client directive to workflow component
This commit is contained in:
Benny Joo
2024-09-02 23:00:48 +05:30
committed by GitHub
parent 779eb19e7a
commit 55d75a9786
6 changed files with 67 additions and 72 deletions
@@ -1,18 +1,21 @@
import LegacyPage from "@pages/workflows/[workflow]";
import { withAppDirSsg } from "app/WithAppDirSsg";
import type { PageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { headers, cookies } from "next/headers";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import LegacyPage from "@calcom/features/ee/workflows/pages/workflow";
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
import { getStaticProps } from "~/workflows/workflow-single-view.getStaticProps";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { getStaticProps } from "@lib/workflows/[workflow]/getStaticProps";
export const generateMetadata = async ({ params, searchParams }: PageProps) => {
const { workflow } = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));
const { workflow: id } = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));
const workflow = await WorkflowRepository.getById({ id: +id });
return await _generateMetadata(
() => workflow ?? "Untitled",
() => (workflow && workflow.name ? workflow.name : "Untitled"),
() => ""
);
};
@@ -21,7 +24,6 @@ const getData = withAppDirSsg(getStaticProps);
export const generateStaticParams = () => [];
// @ts-expect-error TODO: fix this
export default WithLayout({ getLayout: null, getData, Page: LegacyPage })<"P">;
export const dynamic = "force-static";
// generate segments on demand
@@ -1,19 +0,0 @@
import type { GetStaticProps } from "next";
import { z } from "zod";
const querySchema = z.object({
workflow: z.string(),
});
export const getStaticProps: GetStaticProps = (ctx) => {
const params = querySchema.safeParse(ctx.params);
console.log("Built workflow page:", params);
if (!params.success) return { notFound: true };
return {
props: {
workflow: params.data.workflow,
},
revalidate: 10, // seconds
};
};
@@ -1,3 +1,5 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import type { WorkflowStep } from "@prisma/client";
import { useSession } from "next-auth/react";
@@ -0,0 +1,53 @@
import { z } from "zod";
import prisma from "@calcom/prisma";
export const ZGetInputSchema = z.object({
id: z.number(),
});
export type TGetInputSchema = z.infer<typeof ZGetInputSchema>;
export class WorkflowRepository {
static async getById({ id }: TGetInputSchema) {
return await prisma.workflow.findFirst({
where: {
id,
},
select: {
id: true,
name: true,
userId: true,
teamId: true,
isActiveOnAll: true,
team: {
select: {
id: true,
slug: true,
members: true,
name: true,
isOrganization: true,
},
},
time: true,
timeUnit: true,
activeOn: {
select: {
eventType: true,
},
},
activeOnTeams: {
select: {
team: true,
},
},
trigger: true,
steps: {
orderBy: {
stepNumber: "asc",
},
},
},
});
}
}
@@ -1,4 +1,4 @@
import { prisma } from "@calcom/prisma";
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
@@ -14,45 +14,7 @@ type GetOptions = {
};
export const getHandler = async ({ ctx, input }: GetOptions) => {
const workflow = await prisma.workflow.findFirst({
where: {
id: input.id,
},
select: {
id: true,
name: true,
userId: true,
teamId: true,
isActiveOnAll: true,
team: {
select: {
id: true,
slug: true,
members: true,
name: true,
isOrganization: true,
},
},
time: true,
timeUnit: true,
activeOn: {
select: {
eventType: true,
},
},
activeOnTeams: {
select: {
team: true,
},
},
trigger: true,
steps: {
orderBy: {
stepNumber: "asc",
},
},
},
});
const workflow = await WorkflowRepository.getById({ id: input.id });
const isUserAuthorized = await isAuthorized(workflow, ctx.user.id);
@@ -1,7 +1,2 @@
import { z } from "zod";
export const ZGetInputSchema = z.object({
id: z.number(),
});
export type TGetInputSchema = z.infer<typeof ZGetInputSchema>;
export { ZGetInputSchema } from "@calcom/lib/server/repository/workflow";
export type { TGetInputSchema } from "@calcom/lib/server/repository/workflow";