Requires Confirmation Threshold (#5825)

* WIP + react errors fixed

* Booking and Availability page treatment

* Update BookingPage.tsx

Co-authored-by: Bailey Pumfleet <[email protected]>
This commit is contained in:
Leo GiovanettiandBailey Pumfleet authored and GitHub committed 2022-12-05 12:12:14 +00:00
1 parent 58270fa653
commit 1cdcebac01
11 files changed
+228 -44

No files matched your search

@@ -11,11 +11,15 @@ export default function UnconfirmedBookingBadge() {
else
return (
<Link href="/bookings/unconfirmed">
<a title={t("unconfirmed_bookings_tooltip")}>
<Badge rounded variant="orange" className="hover:bg-orange-800 hover:text-orange-100">
<>
<Badge
rounded
title={t("unconfirmed_bookings_tooltip")}
variant="orange"
className="cursor-pointer hover:bg-orange-800 hover:text-orange-100">
{unconfirmedBookingCount}
</Badge>
</a>
</>
</Link>
);
}
@@ -480,6 +480,14 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
const additionalNotes = reqBody.notes;
let requiresConfirmation = eventType?.requiresConfirmation;
const rcThreshold = eventType?.metadata?.requiresConfirmationThreshold;
if (rcThreshold) {
if (dayjs(dayjs(reqBody.start).utc().format()).diff(dayjs(), rcThreshold.unit) > rcThreshold.time) {
requiresConfirmation = false;
}
}
let evt: CalendarEvent = {
type: eventType.title,
title: getEventName(eventNameObject), //this needs to be either forced in english, or fetched for each attendee and organizer separately
@@ -499,7 +507,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
/** For team events & dynamic collective events, we will need to handle each member destinationCalendar eventually */
destinationCalendar: eventType.destinationCalendar || organizerUser.destinationCalendar,
hideCalendarNotes: eventType.hideCalendarNotes,
requiresConfirmation: eventType.requiresConfirmation ?? false,
requiresConfirmation: requiresConfirmation ?? false,
eventTypeId: eventType.id,
seatsShowAttendees: !!eventType.seatsShowAttendees,
};
@@ -651,8 +659,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
// Otherwise, an owner rescheduling should be always accepted.
// Before comparing make sure that userId is set, otherwise undefined === undefined
const userReschedulingIsOwner = userId && originalRescheduledBooking?.user?.id === userId;
const isConfirmedByDefault =
(!eventType.requiresConfirmation && !stripeAppData.price) || userReschedulingIsOwner;
const isConfirmedByDefault = (!requiresConfirmation && !stripeAppData.price) || userReschedulingIsOwner;
async function createBooking() {
if (originalRescheduledBooking) {
@@ -875,7 +882,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
}
// If it's not a reschedule, doesn't require confirmation and there's no price,
// Create a booking
} else if (!eventType.requiresConfirmation && !stripeAppData.price) {
} else if (!requiresConfirmation && !stripeAppData.price) {
// Use EventManager to conditionally use all needed integrations.
const createManager = await eventManager.create(evt);
@@ -981,7 +988,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
const eventTypeInfo: EventTypeInfo = {
eventTitle: eventType.title,
eventDescription: eventType.description,
requiresConfirmation: eventType.requiresConfirmation || null,
requiresConfirmation: requiresConfirmation || null,
price: stripeAppData.price,
currency: eventType.currency,
length: eventType.length,
+9
View File
@@ -1,4 +1,5 @@
import { EventTypeCustomInputType } from "@prisma/client";
import { UnitTypeLongPlural } from "dayjs";
import z, { ZodNullable, ZodObject, ZodOptional } from "zod";
/* eslint-disable no-underscore-dangle */
@@ -26,6 +27,8 @@ export enum Frequency {
SECONDLY = 6,
}
export const RequiresConfirmationThresholdUnits: z.ZodType<UnitTypeLongPlural> = z.enum(["hours", "minutes"]);
export const EventTypeMetaDataSchema = z
.object({
smartContractAddress: z.string().optional(),
@@ -34,6 +37,12 @@ export const EventTypeMetaDataSchema = z
giphyThankYouPage: z.string().optional(),
apps: z.object(appDataSchemas).partial().optional(),
additionalNotesRequired: z.boolean().optional(),
requiresConfirmationThreshold: z
.object({
time: z.number(),
unit: RequiresConfirmationThresholdUnits,
})
.optional(),
config: z
.object({
useHostSchedulesForTeamEvent: z.boolean().optional(),
+2 -2
View File
@@ -14,11 +14,11 @@ const Switch = (
fitToHeight?: boolean;
}
) => {
const { label, ...primitiveProps } = props;
const { label, fitToHeight, ...primitiveProps } = props;
const id = useId();
return (
<div className={classNames("flex h-auto w-auto flex-row items-center", props.fitToHeight && "h-fit")}>
<div className={classNames("flex h-auto w-auto flex-row items-center", fitToHeight && "h-fit")}>
<PrimitiveSwitch.Root
className={classNames(
props.checked ? "bg-gray-900" : "bg-gray-200",
@@ -95,7 +95,9 @@ export const EventTypeDescription = ({ eventType, className }: EventTypeDescript
{eventType.requiresConfirmation && (
<li className="hidden xl:block">
<Badge variant="gray" size="lg" StartIcon={Icon.FiClipboard}>
{t("requires_confirmation")}
{eventType.metadata?.requiresConfirmationThreshold
? t("may_require_confirmation")
: t("requires_confirmation")}
</Badge>
</li>
)}