feat: Add rescheduledBy & canceledBy fields in the DB (#15337)

* feat: Add rescheduledBy & canceledBy fields in the DB

* fix: type check

* fix: type check

* fix: use session user email for reschedule

* fix: unit test

* feat: db field email validation

* feat: rescheduledBy and cancelledBy in webhooks

* revert unrelated changes.

* make session user secondary, default to Anonymous

* if condition not required

* Make cancelledBy optional

Co-authored-by: Syed Ali Shahbaz <[email protected]>

* update cancel booking type

* fix: update cancelledBy in db when requesting reschedule

* remove default value for fields

* fix: type check

* feat: manage fields via api v1

* fix: add fields in booking read api v1

* test: expand to cover new fields

* fix: use cancelledBy param on booking page

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-08-25 11:31:46 +02:00
1 parent 34075ee303
commit b6d31129a3
28 files changed
+139 -20

No files matched your search

+6
View File
@@ -14,6 +14,8 @@ const schemaBookingBaseBodyParams = Booking.pick({
startTime: true,
endTime: true,
status: true,
rescheduledBy: true,
cancelledBy: true,
}).partial();
export const schemaBookingCreateBodyParams = extendedBookingCreateBody.merge(schemaQueryUserId.partial());
@@ -33,6 +35,8 @@ const schemaBookingEditParams = z
title: z.string().optional(),
startTime: iso8601.optional(),
endTime: iso8601.optional(),
cancelledBy: z.string().email({ message: "Invalid Email" }).optional(),
rescheduledBy: z.string().email({ message: "Invalid Email" }).optional(),
// Not supporting responses in edit as that might require re-triggering emails
// responses
})
@@ -88,4 +92,6 @@ export const schemaBookingReadPublic = Booking.extend({
status: true,
responses: true,
fromReschedule: true,
cancelledBy: true,
rescheduledBy: true,
});
@@ -23,6 +23,7 @@ type Props = {
theme: string | null;
allRemainingBookings: boolean;
seatReferenceUid?: string;
currentUserEmail?: string;
bookingCancelledEventProps: {
booking: unknown;
organizer: {
@@ -38,7 +39,8 @@ export default function CancelBooking(props: Props) {
const [cancellationReason, setCancellationReason] = useState<string>("");
const { t } = useLocale();
const router = useRouter();
const { booking, allRemainingBookings, seatReferenceUid, bookingCancelledEventProps } = props;
const { booking, allRemainingBookings, seatReferenceUid, bookingCancelledEventProps, currentUserEmail } =
props;
const [loading, setLoading] = useState(false);
const telemetry = useTelemetry();
const [error, setError] = useState<string | null>(booking ? null : t("booking_already_cancelled"));
@@ -99,6 +101,7 @@ export default function CancelBooking(props: Props) {
allRemainingBookings,
// @NOTE: very important this shouldn't cancel with number ID use uid instead
seatReferenceUid,
cancelledBy: currentUserEmail,
}),
headers: {
"Content-Type": "application/json",
@@ -163,6 +163,8 @@ export default function Success(props: PageProps) {
const [calculatedDuration, setCalculatedDuration] = useState<number | undefined>(undefined);
const [comment, setComment] = useState("");
const parsedRating = rating ? parseInt(rating, 10) : 3;
const currentUserEmail =
searchParams?.get("cancelledBy") ?? searchParams?.get("email") ?? session?.user?.email ?? undefined;
const defaultRating = isNaN(parsedRating) ? 3 : parsedRating > 5 ? 5 : parsedRating < 1 ? 1 : parsedRating;
const [rateValue, setRateValue] = useState<number>(defaultRating);
@@ -700,7 +702,9 @@ export default function Success(props: PageProps) {
<span className="text-default inline">
<span className="underline" data-testid="reschedule-link">
<Link
href={`/reschedule/${seatReferenceUid || bookingInfo?.uid}`}
href={`/reschedule/${seatReferenceUid || bookingInfo?.uid}${
currentUserEmail ? `?rescheduledBy=${currentUserEmail}` : ""
}`}
legacyBehavior>
{t("reschedule")}
</Link>
@@ -738,6 +742,7 @@ export default function Success(props: PageProps) {
allRemainingBookings={allRemainingBookings}
seatReferenceUid={seatReferenceUid}
bookingCancelledEventProps={bookingCancelledEventProps}
currentUserEmail={currentUserEmail}
/>
</>
))}
+17 -2
View File
@@ -19,8 +19,16 @@ export default function Type() {
export async function getServerSideProps(context: GetServerSidePropsContext) {
const session = await getServerSession(context);
const { uid: bookingUid, seatReferenceUid } = z
.object({ uid: z.string(), seatReferenceUid: z.string().optional() })
const {
uid: bookingUid,
seatReferenceUid,
rescheduledBy,
} = z
.object({
uid: z.string(),
seatReferenceUid: z.string().optional(),
rescheduledBy: z.string().optional(),
})
.parse(context.query);
const coepFlag = context.query["flag.coep"];
const { uid, seatReferenceUid: maybeSeatReferenceUid } = await maybeGetBookingUidFromSeat(
@@ -147,6 +155,13 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
if (coepFlag) {
destinationUrlSearchParams.set("flag.coep", coepFlag as string);
}
const currentUserEmail = rescheduledBy ?? session?.user?.email;
if (currentUserEmail) {
destinationUrlSearchParams.set("rescheduledBy", currentUserEmail);
}
return {
redirect: {
destination: `${eventUrl}?${destinationUrlSearchParams.toString()}${
+22 -6
View File
@@ -461,13 +461,19 @@ export function expectSuccessfulBookingCreationEmails({
links: recurrence
? [
{
href: `${bookingUrlOrigin}/booking/${booking.uid}?cancel=true&allRemainingBookings=true`,
href: `${bookingUrlOrigin}/booking/${
booking.uid
}?cancel=true&allRemainingBookings=true&cancelledBy=${encodeURIComponent(
destinationEmail ?? organizer.email
)}`,
text: "cancel",
},
]
: [
{
href: `${bookingUrlOrigin}/reschedule/${booking.uid}`,
href: `${bookingUrlOrigin}/reschedule/${booking.uid}?rescheduledBy=${encodeURIComponent(
destinationEmail ?? organizer.email
)}`,
text: "reschedule",
},
],
@@ -514,13 +520,17 @@ export function expectSuccessfulBookingCreationEmails({
links: recurrence
? [
{
href: `${bookingUrlOrigin}/booking/${booking.uid}?cancel=true&allRemainingBookings=true`,
href: `${bookingUrlOrigin}/booking/${
booking.uid
}?cancel=true&allRemainingBookings=true&cancelledBy=${encodeURIComponent(booker.email)}`,
text: "cancel",
},
]
: [
{
href: `${bookingUrlOrigin}/reschedule/${booking.uid}`,
href: `${bookingUrlOrigin}/reschedule/${booking.uid}?rescheduledBy=${encodeURIComponent(
booker.email
)}`,
text: "reschedule",
},
],
@@ -552,11 +562,17 @@ export function expectSuccessfulBookingCreationEmails({
},
links: [
{
href: `${bookingUrlOrigin}/reschedule/${booking.uid}`,
href: `${bookingUrlOrigin}/reschedule/${booking.uid}?rescheduledBy=${encodeURIComponent(
otherTeamMember.email
)}`,
text: "reschedule",
},
{
href: `${bookingUrlOrigin}/booking/${booking.uid}?cancel=true&allRemainingBookings=false`,
href: `${bookingUrlOrigin}/booking/${
booking.uid
}?cancel=true&allRemainingBookings=false&cancelledBy=${encodeURIComponent(
otherTeamMember.email
)}`,
text: "cancel",
},
],
@@ -26,6 +26,8 @@ export function getMockRequestDataForBooking({
bookingUid?: string;
recurringEventId?: string;
recurringCount?: number;
rescheduledBy?: string;
cancelledBy?: string;
schedulingType?: SchedulingType;
responses: {
email: string;