Files
cal.diy/apps/web/app/future/availability/[schedule]/page.tsx
T
cf16cd3ed2 feat: Implement Dub.co for conversion tracking (#16165)
* FEAT: Implement Dub.co for conversion tracking

* add link creation, @vercel/functions

* use refer.cal.com/:username instead of go.cal.com/r/:username

* sale conversion tracking

* add copy referral link

* limit to IS_CALCOM only

* Update yarn.lock

* fix DubAnalytics

* use workaround for isNewUser

* pass req to getOptions

* Update next-auth-options.ts

* fix ts errors

* only show DubAnalytics outside EU

* add Dub Analytics to /signup

* use WEBSITE_URL instead

* on-demand generate links

* add migration

* add check for existing link + change fetch method to poast

* remove refer.cal.com from PoweredByCal

* limit DubAnalytics to /signup only

* simplify generate-referral-link

* restore yarn.lock

* add yarn with dub sdk in

* add yarn with dub sdk in

* yarn

* Update yarn.lock

---------

Co-authored-by: sean <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
2024-09-12 12:33:10 -07:00

73 lines
2.2 KiB
TypeScript

import type { PageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { notFound } from "next/navigation";
import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
import { ScheduleRepository } from "@calcom/lib/server/repository/schedule";
import { TravelScheduleRepository } from "@calcom/lib/server/repository/travelSchedule";
import { UserRepository } from "@calcom/lib/server/repository/user";
import { AvailabilitySettingsWebWrapper } from "~/availability/[schedule]/schedule-view";
export const generateMetadata = async ({ params }: PageProps) => {
const scheduleId = params?.schedule ? Number(params.schedule) : -1;
const schedule = await ScheduleRepository.findScheduleById({ id: scheduleId });
if (!schedule) {
return await _generateMetadata(
(t) => t("availability"),
() => ""
);
}
return await _generateMetadata(
(t) => (schedule.name ? `${schedule.name} | ${t("availability")}` : t("availability")),
() => ""
);
};
const Page = async ({ params }: PageProps) => {
if (params?.schedule) {
notFound();
}
const scheduleId = Number(params.schedule);
const session = await getServerSessionForAppDir();
const userId = session?.user?.id;
if (!userId) {
notFound();
}
let userData, schedule, travelSchedules;
try {
userData = await UserRepository.getTimeZoneAndDefaultScheduleId({
userId,
});
if (!userData?.timeZone || !userData?.defaultScheduleId) {
throw new Error("timeZone and defaultScheduleId not found");
}
} catch (e) {
notFound();
}
try {
schedule = await ScheduleRepository.findDetailedScheduleById({
scheduleId,
isManagedEventType: false,
userId,
timeZone: userData.timeZone,
defaultScheduleId: userData.defaultScheduleId,
});
} catch (e) {}
try {
travelSchedules = await TravelScheduleRepository.findTravelSchedulesByUserId(userId);
} catch (e) {}
return <AvailabilitySettingsWebWrapper scheduleFetched={schedule} travelSchedules={travelSchedules} />;
};
export default WithLayout({ ServerPage: Page });