feat: OOO booking-forwarding (#12653)

* feat-profile-forwarding

* fix for promises of handling

* fix badge success color

* clean up

* fix suggested changes

* Changed design on booking-forward pages and moar test

* taking care of suggested changes, trpc errors and code cleaning

* improve text

* fix conflicting data-testid

* fix unique data-testid

* fix error css-global, email button styles, error conditional

* rename files to match functionality, remove away ui

* Add translations and migration

* remove log

* small fixes + improvements

* fix styles to match new design

* merge fixes

* Fix styles dark mode

* Solving merge conflicts from earlier

* Fix/change test to match new elements

* use trash icon button insted of dots (design issues)

* only send email if toUserId is set

* Fix date picker dark mode

* merge with remote

* removed status field from table and email its now for notify

* small text improvement in email

* check for team plan not paid plan

* fixes and clean up due to removing status

* fix old send request name to new behaviour

* more naming improvements and text

* remove status from handle-type

* code clean up

* fix type error

---------

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-01-10 17:04:02 +00:00
1 parent dfaa6d28e4
commit 96af17d8d7
24 files changed
+1249 -62

No files matched your search

@@ -0,0 +1,71 @@
import prisma from "@calcom/prisma";
interface HandleTypeRedirectionProps {
userId: number;
slug: string;
username: string;
}
export const handleTypeRedirection = async (props: HandleTypeRedirectionProps) => {
const { userId, slug, username } = props;
const outOfOfficeEntryActive = await prisma.outOfOfficeEntry.findFirst({
select: {
userId: true,
start: true,
end: true,
toUserId: true,
toUser: {
select: {
id: true,
username: true,
},
},
},
where: {
userId: userId,
start: {
lte: new Date(),
},
end: {
gte: new Date(),
},
},
});
let redirectToSameEventSlug = false;
// @TODO: Should I validate if new user has same type as slug?
if (outOfOfficeEntryActive) {
if (outOfOfficeEntryActive.toUserId === null) {
return {
outOfOffice: true,
};
}
if (outOfOfficeEntryActive?.toUser) {
const eventType = await prisma.eventType.findFirst({
select: {
slug: true,
userId: true,
},
where: {
slug,
userId: outOfOfficeEntryActive.toUserId,
},
});
if (eventType) {
redirectToSameEventSlug = true;
}
return {
redirect: {
destination: `/${outOfOfficeEntryActive.toUser.username}${
redirectToSameEventSlug ? `/${slug}` : ""
}?redirected=true&username=${username}`,
permanent: false,
},
};
}
}
return {};
};
@@ -0,0 +1,59 @@
import prisma from "@calcom/prisma";
interface HandleUserRedirectionProps {
username: string;
}
export const handleUserRedirection = async (props: HandleUserRedirectionProps) => {
const { username } = props;
const fromUser = await prisma.user.findFirst({
where: {
username,
},
select: {
id: true,
},
});
if (fromUser) {
// If user is found quickly verify bookingRedirect
const outOfOfficeEntryActive = await prisma.outOfOfficeEntry.findFirst({
select: {
toUser: {
select: {
username: true,
},
},
toUserId: true,
userId: true,
start: true,
end: true,
},
where: {
userId: fromUser.id,
start: {
lte: new Date(),
},
end: {
gte: new Date(),
},
},
});
if (outOfOfficeEntryActive && outOfOfficeEntryActive.toUserId === null) {
return {
outOfOffice: true,
};
}
if (outOfOfficeEntryActive && outOfOfficeEntryActive.toUser?.username) {
return {
redirect: {
destination: `/${outOfOfficeEntryActive.toUser.username}?redirected=true&username=${username}`,
permanent: false,
},
};
}
}
return {};
};
+28 -1
View File
@@ -1,6 +1,6 @@
import { LazyMotion, m, AnimatePresence } from "framer-motion";
import dynamic from "next/dynamic";
import { usePathname, useRouter } from "next/navigation";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useEffect, useRef } from "react";
import StickyBox from "react-sticky-box";
import { shallow } from "zustand/shallow";
@@ -81,6 +81,12 @@ const BookerComponent = ({
const hasDarkBackground = isEmbed && embedType !== "inline";
const embedUiConfig = useEmbedUiConfig();
const { t } = useLocale();
const searchParams = useSearchParams();
const isRedirect = searchParams?.get("redirected") === "true" || false;
const fromUserNameRedirected = searchParams?.get("username") || "";
// In Embed we give preference to embed configuration for the layout.If that's not set, we use the App configuration for the event layout
// But if it's mobile view, there is only one layout supported which is 'mobile'
const layout = isEmbed ? (isMobile ? "mobile" : validateLayout(embedUiConfig.layout) || _layout) : _layout;
@@ -221,6 +227,7 @@ const BookerComponent = ({
return (
<>
{event.data ? <BookingPageTagManager eventType={event.data} /> : null}
{bookerState !== "booking" && event.data?.isInstantEvent && (
<div
className="animate-fade-in-up fixed bottom-2 z-40 my-2 opacity-0"
@@ -235,6 +242,26 @@ const BookerComponent = ({
"text-default flex min-h-full w-full flex-col items-center",
layout === BookerLayouts.MONTH_VIEW ? "overflow-visible" : "overflow-clip"
)}>
{/* redirect from other user profile */}
{isRedirect && (
<div className="mb-8 rounded-md bg-blue-100 p-4 dark:border dark:bg-transparent">
<h2 className="text-default mb-2 text-sm font-semibold">
{t("user_redirect_title", {
username: fromUserNameRedirected,
})}{" "}
🏝️
</h2>
<p className="text-default text-sm">
{t("user_redirect_description", {
profile: {
username: username,
},
username: fromUserNameRedirected,
})}{" "}
😄
</p>
</div>
)}
<div
ref={animationScope}
className={classNames(
@@ -11,12 +11,12 @@
}
}
.recharts-cartesian-grid-horizontal line{
@apply stroke-emphasis
.recharts-cartesian-grid-horizontal line {
@apply stroke-emphasis;
}
.tremor-DateRangePicker-button button{
@apply !h-9 !max-h-9 border-default hover:border-emphasis
.tremor-DateRangePicker-button button {
@apply border-default hover:border-emphasis !h-9 !max-h-9;
}
.tremor-DateRangePicker-calendarButton,
@@ -24,12 +24,12 @@
@apply border-subtle bg-default focus-within:ring-emphasis hover:border-subtle dark:focus-within:ring-emphasis hover:bg-subtle text-sm leading-4 placeholder:text-sm placeholder:font-normal focus-within:ring-0;
}
.tremor-DateRangePicker-dropdownModal{
@apply divide-none
.tremor-DateRangePicker-dropdownModal {
@apply divide-none;
}
.tremor-DropdownItem-root{
@apply !h-9 !max-h-9 bg-default hover:bg-subtle text-default hover:text-emphasis
.tremor-DropdownItem-root {
@apply bg-default hover:bg-subtle text-default hover:text-emphasis !h-9 !max-h-9;
}
.tremor-DateRangePicker-calendarButtonText,
@@ -37,56 +37,54 @@
@apply text-default;
}
.tremor-DateRangePicker-calendarHeaderText{
@apply !text-default
.tremor-DateRangePicker-calendarHeaderText {
@apply !text-default;
}
.tremor-DateRangePicker-calendarHeader svg{
@apply text-default
.tremor-DateRangePicker-calendarHeader svg {
@apply text-default;
}
.tremor-DateRangePicker-calendarHeader button{
@apply hover:bg-emphasis shadow-none focus:ring-0
.tremor-DateRangePicker-calendarHeader button {
@apply hover:bg-emphasis shadow-none focus:ring-0;
}
.tremor-DateRangePicker-calendarHeader button:hover svg{
@apply text-emphasis
.tremor-DateRangePicker-calendarHeader button:hover svg {
@apply text-emphasis;
}
.tremor-DateRangePicker-calendarButtonIcon{
@apply text-default
.tremor-DateRangePicker-calendarButtonIcon {
@apply text-default;
}
.tremor-DateRangePicker-calendarModal,
.tremor-DateRangePicker-dropdownModal {
@apply bg-default border-subtle shadow-dropdown
@apply bg-default border-subtle shadow-dropdown;
}
.tremor-DateRangePicker-calendarBodyDate button{
@apply text-default hover:bg-emphasis
.tremor-DateRangePicker-calendarBodyDate button {
@apply text-default hover:bg-emphasis;
}
.tremor-DateRangePicker-calendarBodyDate button:disabled,
.tremor-DateRangePicker-calendarBodyDate button[disabled]{
@apply opacity-25
.tremor-DateRangePicker-calendarBodyDate button[disabled] {
@apply opacity-25;
}
.tremor-DateRangePicker-calendarHeader button{
@apply border-default text-default
.tremor-DateRangePicker-calendarHeader button {
@apply border-default text-default;
}
.tremor-DateRangePicker-calendarBodyDate .bg-gray-100{
@apply bg-subtle
.tremor-DateRangePicker-calendarBodyDate .bg-gray-100 {
@apply bg-subtle;
}
.tremor-DateRangePicker-calendarBodyDate .bg-gray-500{
@apply !bg-brand-default text-inverted
.tremor-DateRangePicker-calendarBodyDate .bg-gray-500 {
@apply !bg-brand-default text-inverted;
}
.tremor-Card-root {
@apply p-5 bg-default;
@apply bg-default p-5;
}
.tremor-TableCell-root {
@@ -43,6 +43,7 @@ const tabs: VerticalTabItemProps[] = [
{ name: "calendars", href: "/settings/my-account/calendars" },
{ name: "conferencing", href: "/settings/my-account/conferencing" },
{ name: "appearance", href: "/settings/my-account/appearance" },
{ name: "out_of_office", href: "/settings/my-account/out-of-office" },
// TODO
// { name: "referrals", href: "/settings/my-account/referrals" },
],
+3 -4
View File
@@ -420,6 +420,7 @@ function UserDropdown({ small }: UserDropdownProps) {
<Dropdown open={menuOpen}>
<DropdownMenuTrigger asChild onClick={() => setMenuOpen((menuOpen) => !menuOpen)}>
<button
data-testid="user-dropdown-trigger-button"
className={classNames(
"hover:bg-emphasis todesktop:!bg-transparent group mx-0 flex w-full cursor-pointer appearance-none items-center rounded-full text-left outline-none transition focus:outline-none focus:ring-0 md:rounded-none lg:rounded",
small ? "p-2" : "px-2 py-1.5"
@@ -496,10 +497,8 @@ function UserDropdown({ small }: UserDropdownProps) {
StartIcon={(props) => (
<Moon className={classNames("text-default", props.className)} aria-hidden="true" />
)}
onClick={() => {
mutation.mutate({ away: !user.away });
}}>
{user.away ? t("set_as_free") : t("set_as_away")}
href="/settings/my-account/out-of-office">
{t("out_of_office")}
</DropdownItem>
</DropdownMenuItem>
<DropdownMenuSeparator />