-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: no show status conflict #18667
Open
MehulZR
wants to merge
4
commits into
calcom:main
Choose a base branch
from
MehulZR:fix_no_show_status_conflict
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+142
−89
Open
fix: no show status conflict #18667
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,8 @@ import { ReassignDialog } from "@components/dialog/ReassignDialog"; | |
import { RerouteDialog } from "@components/dialog/RerouteDialog"; | ||
import { RescheduleDialog } from "@components/dialog/RescheduleDialog"; | ||
|
||
import { BOOKING_LIST_LIMIT } from "~/bookings/views/bookings-listing-view"; | ||
|
||
type BookingListingStatus = RouterInputs["viewer"]["bookings"]["get"]["filters"]["status"]; | ||
|
||
type BookingItem = RouterOutputs["viewer"]["bookings"]["get"]["bookings"][number]; | ||
|
@@ -68,6 +70,7 @@ type BookingItemProps = BookingItem & { | |
userTimeFormat: number | null | undefined; | ||
userEmail: string | undefined; | ||
}; | ||
bookingListFilters: RouterInputs["viewer"]["bookings"]["get"]["filters"]; | ||
}; | ||
|
||
type ParsedBooking = ReturnType<typeof buildParsedBooking>; | ||
|
@@ -133,6 +136,53 @@ function BookingListItem(booking: BookingItemProps) { | |
utils.viewer.bookings.invalidate(); | ||
}, | ||
}); | ||
const noShowMutation = trpc.viewer.markNoShow.useMutation({ | ||
onSuccess: async (data, { bookingUid }) => { | ||
utils.viewer.bookings.get.setInfiniteData( | ||
{ | ||
limit: BOOKING_LIST_LIMIT, | ||
filters: booking.bookingListFilters, | ||
}, | ||
(prevData) => { | ||
if (!prevData) return { pages: [], pageParams: [] }; | ||
|
||
return { | ||
...prevData, | ||
pages: prevData.pages.map((page) => { | ||
return { | ||
...page, | ||
bookings: page.bookings.map((booking) => { | ||
if (bookingUid !== booking.uid) return booking; | ||
|
||
return { | ||
...booking, | ||
attendees: booking.attendees.map((attendee) => { | ||
const affectedAttendee = data.attendees.find((val) => { | ||
return val.email === attendee.email; | ||
}); | ||
|
||
return { | ||
...attendee, | ||
noShow: affectedAttendee ? affectedAttendee.noShow : attendee.noShow, | ||
}; | ||
}), | ||
}; | ||
}), | ||
}; | ||
}), | ||
}; | ||
} | ||
); | ||
|
||
showToast(t(data.message), "success"); | ||
}, | ||
onError: (err) => { | ||
showToast(err.message, "error"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make it t(err.message) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no translations for the message returned by the backend. |
||
}, | ||
}); | ||
const noShowMutationHelper = (input: RouterInputs["viewer"]["markNoShow"]) => { | ||
return noShowMutation.mutate(input); | ||
}; | ||
|
||
const isUpcoming = new Date(booking.endTime) >= new Date(); | ||
const isOngoing = isUpcoming && new Date() >= new Date(booking.startTime); | ||
|
@@ -480,6 +530,7 @@ function BookingListItem(booking: BookingItemProps) { | |
attendees={attendeeList} | ||
setIsOpen={setIsNoShowDialogOpen} | ||
isOpen={isNoShowDialogOpen} | ||
noShowMutationHelper={noShowMutationHelper} | ||
/> | ||
)} | ||
<Dialog open={rejectionDialogIsOpen} onOpenChange={setRejectionDialogIsOpen}> | ||
|
@@ -641,6 +692,7 @@ function BookingListItem(booking: BookingItemProps) { | |
currentEmail={userEmail} | ||
bookingUid={booking.uid} | ||
isBookingInPast={isBookingInPast} | ||
noShowMutationHelper={noShowMutationHelper} | ||
/> | ||
)} | ||
{isCancelled && booking.rescheduled && ( | ||
|
@@ -867,32 +919,25 @@ type NoShowProps = { | |
isBookingInPast: boolean; | ||
}; | ||
|
||
const Attendee = (attendeeProps: AttendeeProps & NoShowProps) => { | ||
const { email, name, bookingUid, isBookingInPast, noShow: noShowAttendee, phoneNumber } = attendeeProps; | ||
const Attendee = ({ | ||
noShowMutationHelper, | ||
...attendeeProps | ||
}: AttendeeProps & | ||
NoShowProps & { noShowMutationHelper: (input: RouterInputs["viewer"]["markNoShow"]) => void }) => { | ||
const { email, name, bookingUid, isBookingInPast, noShow, phoneNumber } = attendeeProps; | ||
const { t } = useLocale(); | ||
|
||
const [noShow, setNoShow] = useState(noShowAttendee); | ||
const [openDropdown, setOpenDropdown] = useState(false); | ||
const { copyToClipboard, isCopied } = useCopy(); | ||
|
||
const noShowMutation = trpc.viewer.markNoShow.useMutation({ | ||
onSuccess: async (data) => { | ||
showToast(data.message, "success"); | ||
}, | ||
onError: (err) => { | ||
showToast(err.message, "error"); | ||
}, | ||
}); | ||
|
||
function toggleNoShow({ | ||
attendee, | ||
bookingUid, | ||
}: { | ||
attendee: { email: string; noShow: boolean }; | ||
bookingUid: string; | ||
}) { | ||
noShowMutation.mutate({ bookingUid, attendees: [attendee] }); | ||
setNoShow(!noShow); | ||
noShowMutationHelper({ bookingUid, attendees: [attendee] }); | ||
} | ||
|
||
return ( | ||
|
@@ -977,25 +1022,15 @@ type GroupedAttendeeProps = { | |
bookingUid: string; | ||
}; | ||
|
||
const GroupedAttendees = (groupedAttendeeProps: GroupedAttendeeProps) => { | ||
const { bookingUid } = groupedAttendeeProps; | ||
const attendees = groupedAttendeeProps.attendees.map((attendee) => { | ||
return { | ||
id: attendee.id, | ||
email: attendee.email, | ||
name: attendee.name, | ||
noShow: attendee.noShow || false, | ||
}; | ||
}); | ||
const GroupedAttendees = ({ | ||
noShowMutationHelper, | ||
...groupedAttendeeProps | ||
}: GroupedAttendeeProps & { | ||
noShowMutationHelper: (input: RouterInputs["viewer"]["markNoShow"]) => void; | ||
}) => { | ||
const { bookingUid, attendees } = groupedAttendeeProps; | ||
const { t } = useLocale(); | ||
const noShowMutation = trpc.viewer.markNoShow.useMutation({ | ||
onSuccess: async (data) => { | ||
showToast(t(data.message), "success"); | ||
}, | ||
onError: (err) => { | ||
showToast(err.message, "error"); | ||
}, | ||
}); | ||
|
||
const { control, handleSubmit } = useForm<{ | ||
attendees: AttendeeProps[]; | ||
}>({ | ||
|
@@ -1012,7 +1047,7 @@ const GroupedAttendees = (groupedAttendeeProps: GroupedAttendeeProps) => { | |
|
||
const onSubmit = (data: { attendees: AttendeeProps[] }) => { | ||
const filteredData = data.attendees.slice(1); | ||
noShowMutation.mutate({ bookingUid, attendees: filteredData }); | ||
noShowMutationHelper({ bookingUid, attendees: filteredData }); | ||
setOpenDropdown(false); | ||
}; | ||
|
||
|
@@ -1075,63 +1110,53 @@ const NoShowAttendeesDialog = ({ | |
isOpen, | ||
setIsOpen, | ||
bookingUid, | ||
noShowMutationHelper, | ||
}: { | ||
attendees: AttendeeProps[]; | ||
isOpen: boolean; | ||
setIsOpen: (value: boolean) => void; | ||
bookingUid: string; | ||
noShowMutationHelper: (input: RouterInputs["viewer"]["markNoShow"]) => void; | ||
}) => { | ||
const { t } = useLocale(); | ||
const [noShowAttendees, setNoShowAttendees] = useState( | ||
attendees.map((attendee) => ({ | ||
id: attendee.id, | ||
email: attendee.email, | ||
name: attendee.name, | ||
noShow: attendee.noShow || false, | ||
})) | ||
); | ||
|
||
const noShowMutation = trpc.viewer.markNoShow.useMutation({ | ||
onSuccess: async (data) => { | ||
const newValue = data.attendees[0]; | ||
setNoShowAttendees((old) => | ||
old.map((attendee) => | ||
attendee.email === newValue.email ? { ...attendee, noShow: newValue.noShow } : attendee | ||
) | ||
); | ||
showToast(t(data.message), "success"); | ||
}, | ||
onError: (err) => { | ||
showToast(err.message, "error"); | ||
}, | ||
}); | ||
const [noShowAttendees, setNoShowAttendees] = useState(attendees); | ||
|
||
return ( | ||
<Dialog open={isOpen} onOpenChange={() => setIsOpen(false)}> | ||
<DialogContent title={t("mark_as_no_show_title")} description={t("no_show_description")}> | ||
{noShowAttendees.map((attendee) => ( | ||
<form | ||
key={attendee.id} | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
noShowMutation.mutate({ | ||
bookingUid, | ||
attendees: [{ email: attendee.email, noShow: !attendee.noShow }], | ||
}); | ||
}}> | ||
<div className="bg-muted flex items-center justify-between rounded-md px-4 py-2"> | ||
<span className="text-emphasis flex flex-col text-sm"> | ||
{attendee.name} | ||
{attendee.email && <span className="text-muted">({attendee.email})</span>} | ||
</span> | ||
<Button color="minimal" type="submit" StartIcon={attendee.noShow ? "eye-off" : "eye"}> | ||
{attendee.noShow ? t("unmark_as_no_show") : t("mark_as_no_show")} | ||
</Button> | ||
</div> | ||
</form> | ||
<div key={attendee.id} className="bg-muted flex items-center justify-between rounded-md px-4 py-2"> | ||
<span className="text-emphasis flex flex-col text-sm"> | ||
{attendee.name} | ||
{attendee.email && <span className="text-muted">({attendee.email})</span>} | ||
</span> | ||
<Button | ||
color="minimal" | ||
StartIcon={attendee.noShow ? "eye-off" : "eye"} | ||
onClick={() => { | ||
const updatedNoShowAttendees = noShowAttendees.map((a) => { | ||
return { | ||
...a, | ||
noShow: a.id === attendee.id ? !attendee.noShow : a.noShow, | ||
}; | ||
}); | ||
|
||
setNoShowAttendees(updatedNoShowAttendees); | ||
}}> | ||
{attendee.noShow ? t("unmark_as_no_show") : t("mark_as_no_show")} | ||
</Button> | ||
</div> | ||
))} | ||
<DialogFooter> | ||
<DialogClose>{t("done")}</DialogClose> | ||
<DialogClose | ||
onClick={() => | ||
noShowMutationHelper({ | ||
bookingUid, | ||
attendees: noShowAttendees, | ||
}) | ||
}> | ||
{t("done")} | ||
</DialogClose> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
|
@@ -1208,12 +1233,14 @@ const DisplayAttendees = ({ | |
currentEmail, | ||
bookingUid, | ||
isBookingInPast, | ||
noShowMutationHelper, | ||
}: { | ||
attendees: AttendeeProps[]; | ||
user: UserProps | null; | ||
currentEmail?: string | null; | ||
bookingUid: string; | ||
isBookingInPast: boolean; | ||
noShowMutationHelper: (inputs: RouterInputs["viewer"]["markNoShow"]) => void; | ||
}) => { | ||
const { t } = useLocale(); | ||
attendees.sort((a, b) => a.id - b.id); | ||
|
@@ -1222,25 +1249,44 @@ const DisplayAttendees = ({ | |
<div className="text-emphasis text-sm"> | ||
{user && <FirstAttendee user={user} currentEmail={currentEmail} />} | ||
{attendees.length > 1 ? <span>, </span> : <span> {t("and")} </span>} | ||
<Attendee {...attendees[0]} bookingUid={bookingUid} isBookingInPast={isBookingInPast} /> | ||
<Attendee | ||
{...attendees[0]} | ||
bookingUid={bookingUid} | ||
isBookingInPast={isBookingInPast} | ||
noShowMutationHelper={noShowMutationHelper} | ||
/> | ||
{attendees.length > 1 && ( | ||
<> | ||
<div className="text-emphasis inline-block text-sm"> {t("and")} </div> | ||
{attendees.length > 2 ? ( | ||
<Tooltip | ||
content={attendees.slice(1).map((attendee) => ( | ||
<p key={attendee.email}> | ||
<Attendee {...attendee} bookingUid={bookingUid} isBookingInPast={isBookingInPast} /> | ||
<Attendee | ||
{...attendee} | ||
bookingUid={bookingUid} | ||
isBookingInPast={isBookingInPast} | ||
noShowMutationHelper={noShowMutationHelper} | ||
/> | ||
</p> | ||
))}> | ||
{isBookingInPast ? ( | ||
<GroupedAttendees attendees={attendees} bookingUid={bookingUid} /> | ||
<GroupedAttendees | ||
attendees={attendees} | ||
bookingUid={bookingUid} | ||
noShowMutationHelper={noShowMutationHelper} | ||
/> | ||
) : ( | ||
<GroupedGuests guests={attendees} /> | ||
)} | ||
</Tooltip> | ||
) : ( | ||
<Attendee {...attendees[1]} bookingUid={bookingUid} isBookingInPast={isBookingInPast} /> | ||
<Attendee | ||
{...attendees[1]} | ||
bookingUid={bookingUid} | ||
isBookingInPast={isBookingInPast} | ||
noShowMutationHelper={noShowMutationHelper} | ||
/> | ||
)} | ||
</> | ||
)} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why looping through all the pages ?
Instead , we can find the index of the page containing the booking using
findIndex()
Also can we make
noShowMutation
function more readable