fix: handle cancelation reason when user is host (#18681)
* handle cancelation reason when user is host * add attendee reason warning * add cancellation reason to tests when we are the host * req.body and not req * fix: isloggedIn logic * use new isLoggedInUser from ssr instead of client * update e2e tests to fill in reason when hosts --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
9 files changed
+53
-8
No files matched your search
@@ -163,10 +163,24 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
});
|
||||
|
||||
const userId = session?.user?.id;
|
||||
const isLoggedInUserHost =
|
||||
userId &&
|
||||
(eventType.users.some((user) => user.id === userId) ||
|
||||
eventType.hosts.some(({ user }) => user.id === userId));
|
||||
|
||||
const checkIfUserIsHost = (userId?: number | null) => {
|
||||
if (!userId) return false;
|
||||
|
||||
return (
|
||||
bookingInfo?.user?.id === userId ||
|
||||
eventType.users.some(
|
||||
(user) =>
|
||||
user.id === userId && bookingInfo.attendees.some((attendee) => attendee.email === user.email)
|
||||
) ||
|
||||
eventType.hosts.some(
|
||||
({ user }) =>
|
||||
user.id === userId && bookingInfo.attendees.some((attendee) => attendee.email === user.email)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const isLoggedInUserHost = checkIfUserIsHost(userId);
|
||||
|
||||
if (!isLoggedInUserHost) {
|
||||
// Removing hidden fields from responses
|
||||
@@ -195,6 +209,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
userTimeFormat,
|
||||
requiresLoginToUpdate,
|
||||
rescheduledToUid,
|
||||
isLoggedInUserHost,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -132,7 +132,6 @@ export default function Success(props: PageProps) {
|
||||
) {
|
||||
rescheduleLocation = bookingInfo.responses.location.optionValue;
|
||||
}
|
||||
|
||||
const locationVideoCallUrl: string | undefined = bookingMetadataSchema.parse(
|
||||
bookingInfo?.metadata || {}
|
||||
)?.videoCallUrl;
|
||||
@@ -149,6 +148,7 @@ export default function Success(props: PageProps) {
|
||||
props?.userTimeFormat ? props.userTimeFormat === 24 : isBrowserLocale24h()
|
||||
);
|
||||
const { data: session } = useSession();
|
||||
const isHost = props.isLoggedInUserHost;
|
||||
|
||||
const [date, setDate] = useState(dayjs.utc(bookingInfo.startTime));
|
||||
|
||||
@@ -317,7 +317,6 @@ export default function Success(props: PageProps) {
|
||||
return t(`needs_to_be_confirmed_or_rejected${titleSuffix}`);
|
||||
}
|
||||
if (bookingInfo.user) {
|
||||
const isHost = bookingInfo.user.id === session?.user?.id;
|
||||
const isAttendee = bookingInfo.attendees.find((attendee) => attendee.email === session?.user?.email);
|
||||
const attendee = bookingInfo.attendees[0]?.name || bookingInfo.attendees[0]?.email || "Nameless";
|
||||
const host = bookingInfo.user.name || bookingInfo.user.email;
|
||||
@@ -778,6 +777,7 @@ export default function Success(props: PageProps) {
|
||||
seatReferenceUid={seatReferenceUid}
|
||||
bookingCancelledEventProps={bookingCancelledEventProps}
|
||||
currentUserEmail={currentUserEmail}
|
||||
isHost={isHost}
|
||||
/>
|
||||
</>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user