Skip to content

Commit

Permalink
Merge branch 'main' into fix-add-more-data-to-booking-paid-webhook-10…
Browse files Browse the repository at this point in the history
…679-cal-2328
  • Loading branch information
alannnc authored Sep 5, 2023
2 parents 9fde56f + 2e12f09 commit 0dc1fe8
Show file tree
Hide file tree
Showing 58 changed files with 1,132 additions and 422 deletions.
10 changes: 10 additions & 0 deletions apps/ai/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ plugins.push(withBundleAnalyzer({ enabled: process.env.ANALYZE === "true" }));

/** @type {import("next").NextConfig} */
const nextConfig = {
async redirects() {
return [
{
source: '/',
destination: 'https://cal.com/ai',
permanent: true,
},
]
},
i18n: {
defaultLocale: "en",
locales: ["en"],
Expand All @@ -13,3 +22,4 @@ const nextConfig = {
};

module.exports = () => plugins.reduce((acc, next) => next(acc), nextConfig);

9 changes: 8 additions & 1 deletion apps/web/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export default function Login({
totpEmail,
}: inferSSRProps<typeof _getServerSideProps> & WithNonceProps) {
const searchParams = useSearchParams();
const isTeamInvite = searchParams.get("teamInvite");

const { t } = useLocale();
const router = useRouter();
const formSchema = z
Expand Down Expand Up @@ -95,7 +97,9 @@ export default function Login({
callbackUrl = safeCallbackUrl || "";

const LoginFooter = (
<a href={`${WEBSITE_URL}/signup`} className="text-brand-500 font-medium">
<a
href={callbackUrl !== "" ? `${WEBSITE_URL}/signup?callbackUrl=${callbackUrl}` : `${WEBSITE_URL}/signup`}
className="text-brand-500 font-medium">
{t("dont_have_an_account")}
</a>
);
Expand Down Expand Up @@ -184,6 +188,9 @@ export default function Login({
? LoginFooter
: null
}>
{isTeamInvite && (
<Alert severity="info" message={t("signin_or_signup_to_accept_invite")} className="mb-4 mt-4" />
)}
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(onSubmit)} noValidate data-testid="login-form">
<div>
Expand Down
30 changes: 22 additions & 8 deletions apps/web/pages/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isSAMLLoginEnabled } from "@calcom/features/ee/sso/lib/saml";
import { useFlagMap } from "@calcom/features/flags/context/provider";
import { getFeatureFlagMap } from "@calcom/features/flags/server/utils";
import { IS_SELF_HOSTED, WEBAPP_URL } from "@calcom/lib/constants";
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import slugify from "@calcom/lib/slugify";
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
Expand All @@ -34,6 +35,23 @@ type FormValues = z.infer<typeof signupSchema>;

type SignupProps = inferSSRProps<typeof getServerSideProps>;

const getSafeCallbackUrl = (url: string | null) => {
if (!url) return null;

let callbackUrl = url;

if (/"\//.test(callbackUrl)) callbackUrl = callbackUrl.substring(1);

// If not absolute URL, make it absolute
if (!/^https?:\/\//.test(callbackUrl)) {
callbackUrl = `${WEBAPP_URL}/${callbackUrl}`;
}

const safeCallbackUrl = getSafeRedirectUrl(callbackUrl);

return safeCallbackUrl;
};

export default function Signup({ prepopulateFormValues, token, orgSlug }: SignupProps) {
const searchParams = useSearchParams();
const telemetry = useTelemetry();
Expand All @@ -55,6 +73,7 @@ export default function Signup({ prepopulateFormValues, token, orgSlug }: Signup
throw new Error(err.message);
}
};
const callbackUrl = getSafeCallbackUrl(searchParams.get("callbackUrl"));

const signUp: SubmitHandler<FormValues> = async (data) => {
await fetch("/api/auth/signup", {
Expand All @@ -72,13 +91,10 @@ export default function Signup({ prepopulateFormValues, token, orgSlug }: Signup
.then(async () => {
telemetry.event(telemetryEventTypes.signup, collectPageParameters());
const verifyOrGettingStarted = flags["email-verification"] ? "auth/verify-email" : "getting-started";

await signIn<"credentials">("credentials", {
...data,
callbackUrl: `${
searchParams?.get("callbackUrl")
? `${WEBAPP_URL}/${searchParams.get("callbackUrl")}`
: `${WEBAPP_URL}/${verifyOrGettingStarted}`
}?from=signup`,
callbackUrl: `${callbackUrl ? callbackUrl : `${WEBAPP_URL}/${verifyOrGettingStarted}`}?from=signup`,
});
})
.catch((err) => {
Expand Down Expand Up @@ -157,9 +173,7 @@ export default function Signup({ prepopulateFormValues, token, orgSlug }: Signup
className="w-full justify-center"
onClick={() =>
signIn("Cal.com", {
callbackUrl: searchParams?.get("callbackUrl")
? `${WEBAPP_URL}/${searchParams.get("callbackUrl")}`
: `${WEBAPP_URL}/getting-started`,
callbackUrl: callbackUrl ? callbackUrl : `${WEBAPP_URL}/getting-started`,
})
}>
{t("login_instead")}
Expand Down
17 changes: 17 additions & 0 deletions apps/web/pages/teams/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { GetServerSidePropsContext } from "next";

import { getLayout } from "@calcom/features/MainLayout";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { TeamsListing } from "@calcom/features/ee/teams/components";
import { ShellMain } from "@calcom/features/shell/Shell";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Button } from "@calcom/ui";
Expand Down Expand Up @@ -41,6 +43,21 @@ function Teams() {
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const ssr = await ssrInit(context);
await ssr.viewer.me.prefetch();
const session = await getServerSession({ req: context.req, res: context.res });
const token = context.query?.token;
const resolvedUrl = context.resolvedUrl;

const callbackUrl = token ? getSafeRedirectUrl(`${WEBAPP_URL}${resolvedUrl}`) : null;

if (!session) {
return {
redirect: {
destination: callbackUrl ? `/auth/login?callbackUrl=${callbackUrl}&teamInvite=true` : "/auth/login",
permanent: false,
},
props: {},
};
}

return { props: { trpcState: ssr.dehydrate() } };
};
Expand Down
61 changes: 61 additions & 0 deletions apps/web/playwright/fixtures/routingForms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { v4 as uuidv4 } from "uuid";

import { prisma } from "@calcom/prisma";

type Route = {
id: string;
action: {
type: string;
value: string;
};
isFallback: boolean;
queryValue: {
id: string;
type: string;
};
};

export const createRoutingFormsFixture = () => {
return {
async create({
userId,
teamId,
name,
fields,
routes = [],
}: {
name: string;
userId: number;
teamId: number | null;
routes?: Route[];
fields: {
type: string;
label: string;
identifier?: string;
required: boolean;
}[];
}) {
return await prisma.app_RoutingForms_Form.create({
data: {
name,
userId,
teamId,
routes: [
...routes,
// Add a fallback route always, this is taken care of tRPC route normally but do it manually while running the query directly.
{
id: "898899aa-4567-489a-bcde-f1823f708646",
action: { type: "customPageMessage", value: "Fallback Message" },
isFallback: true,
queryValue: { id: "898899aa-4567-489a-bcde-f1823f708646", type: "group" },
},
],
fields: fields.map((f) => ({
id: uuidv4(),
...f,
})),
},
});
},
};
};
5 changes: 5 additions & 0 deletions apps/web/playwright/lib/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ExpectedUrlDetails } from "../../../../playwright.config";
import { createBookingsFixture } from "../fixtures/bookings";
import { createEmbedsFixture, createGetActionFiredDetails } from "../fixtures/embeds";
import { createPaymentsFixture } from "../fixtures/payments";
import { createRoutingFormsFixture } from "../fixtures/routingForms";
import { createServersFixture } from "../fixtures/servers";
import { createUsersFixture } from "../fixtures/users";

Expand All @@ -23,6 +24,7 @@ export interface Fixtures {
servers: ReturnType<typeof createServersFixture>;
prisma: typeof prisma;
emails?: API;
routingForms: ReturnType<typeof createRoutingFormsFixture>;
}

declare global {
Expand Down Expand Up @@ -71,6 +73,9 @@ export const test = base.extend<Fixtures>({
prisma: async ({}, use) => {
await use(prisma);
},
routingForms: async ({}, use) => {
await use(createRoutingFormsFixture());
},
emails: async ({}, use) => {
if (IS_MAILHOG_ENABLED) {
const mailhogAPI = mailhog();
Expand Down
Loading

0 comments on commit 0dc1fe8

Please sign in to comment.