Hotfix To Seats on Event Types (#4528)

* Hotfix

* Add seats input to event type page
pull/4562/head^2
Joe Au-Yeung 2022-09-17 16:44:29 -04:00 committed by GitHub
parent e7dd0ff3e9
commit 33e8198779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 16 deletions

View File

@ -199,16 +199,12 @@ const BookingPage = ({
// There should only exists one default userData variable for primaryAttendee.
const defaultUserValues = {
email: booking?.attendees[0].email
? booking.attendees[0].email
email: rescheduleUid
? booking?.attendees[0].email
: router.query.email
? (router.query.email as string)
: "",
name: booking?.attendees[0].name
? booking.attendees[0].name
: router.query.name
? (router.query.name as string)
: "",
name: rescheduleUid ? booking?.attendees[0].name : router.query.name ? (router.query.name as string) : "",
};
const defaultValues = () => {

View File

@ -41,6 +41,8 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupInfered
const [showEventNameTip, setShowEventNameTip] = useState(false);
const [hashedLinkVisible, setHashedLinkVisible] = useState(!!eventType.hashedLink);
const [hashedUrl, setHashedUrl] = useState(eventType.hashedLink?.link);
const [seatsInputVisible, setSeatsInputVisible] = useState(!!eventType.seatsPerTimeSlot);
const [seatsPerTimeSlot, setSeatsPerTimeSlot] = useState(eventType.seatsPerTimeSlot);
const [customInputs, setCustomInputs] = useState<EventTypeCustomInput[]>(
eventType.customInputs.sort((a, b) => a.id - b.id) || []
);
@ -293,6 +295,46 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupInfered
</>
)}
/>
<hr />
<Controller
name="seatsPerTimeSlot"
control={formMethods.control}
defaultValue={seatsPerTimeSlot}
render={({ field: { value, onChange } }) => (
<>
<div className="flex space-x-3">
<Switch
name="seatsPerTimeSlot"
checked={seatsInputVisible}
onCheckedChange={(e) => {
setSeatsInputVisible(e);
onChange(e ? seatsPerTimeSlot : null);
}}
fitToHeight={true}
/>
<div className="flex flex-col">
<Label className="text-sm font-semibold leading-none text-black">{t("offer_seats")}</Label>
<p className="-mt-2 text-sm leading-normal text-gray-600">{t("offer_seats_description")}</p>
</div>
</div>
{seatsInputVisible && (
<div className="">
<TextField
required
name="seatsPerTimeSlot"
label={t("number_of_seats")}
type="number"
defaultValue={seatsPerTimeSlot || 2}
addOnSuffix={<>{t("seats")}</>}
onChange={(e) => {
formMethods.setValue("seatsPerTimeSlot", Number(e.target.value));
}}
/>
</div>
)}
</>
)}
/>
{showEventNameTip && (
<Dialog open={showEventNameTip} onOpenChange={setShowEventNameTip}>
<DialogContent

View File

@ -338,15 +338,18 @@ async function handler(req: NextApiRequest) {
}
);
// Add an if conditional if there are no seats on the event type
// Assign to only one user when ROUND_ROBIN
if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) {
users = [await getLuckyUser("MAXIMIZE_AVAILABILITY", { availableUsers, eventTypeId: eventType.id })];
} else {
// excluding ROUND_ROBIN, all users have availability required.
if (availableUsers.length !== users.length) {
throw new Error("Some users are unavailable for booking.");
if (!eventType.seatsPerTimeSlot) {
if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) {
users = [await getLuckyUser("MAXIMIZE_AVAILABILITY", { availableUsers, eventTypeId: eventType.id })];
} else {
// excluding ROUND_ROBIN, all users have availability required.
if (availableUsers.length !== users.length) {
throw new Error("Some users are unavailable for booking.");
}
users = availableUsers;
}
users = availableUsers;
}
console.log("available users", users);

View File

@ -843,7 +843,7 @@
"redirect_url_upgrade_description": "In order to use this feature, you need to upgrade to a Pro account.",
"duplicate": "Duplicate",
"offer_seats": "Offer seats",
"offer_seats_description": "Offer seats to bookings (This disables guests & opt in bookings)",
"offer_seats_description": "Offer seats for booking. This automatically disables guest & opt-in bookings.",
"seats_available": "Seats available",
"number_of_seats": "Number of seats per booking",
"enter_number_of_seats": "Enter number of seats",
@ -1265,5 +1265,6 @@
"no_calendar_installed": "No calendar installed",
"no_calendar_installed_description": "You have not yet connected any of your calendars",
"add_a_calendar": "Add a calendar",
"change_email_hint": "You may need to log out and back in to see any change take effect"
"change_email_hint": "You may need to log out and back in to see any change take effect",
"seats": "seats"
}