-
Notifications
You must be signed in to change notification settings - Fork 12k
[CAL-5114] Implement Deleting Past Bookings #23503
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||
| import type { Dispatch, SetStateAction } from "react"; | ||||||||||||||
|
|
||||||||||||||
| import { Dialog } from "@calcom/features/components/controlled-dialog"; | ||||||||||||||
| import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||||||||||||||
| import { trpc } from "@calcom/trpc/react"; | ||||||||||||||
| import { Button } from "@calcom/ui/components/button"; | ||||||||||||||
| import { DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/components/dialog"; | ||||||||||||||
| import { Icon } from "@calcom/ui/components/icon"; | ||||||||||||||
|
|
||||||||||||||
| interface DeleteBookingDialogProps { | ||||||||||||||
| isOpenDialog: boolean; | ||||||||||||||
| setIsOpenDialog: Dispatch<SetStateAction<boolean>>; | ||||||||||||||
| bookingId: number; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export const DeleteBookingDialog = (props: DeleteBookingDialogProps) => { | ||||||||||||||
| const { isOpenDialog, setIsOpenDialog, bookingId } = props; | ||||||||||||||
| const { t } = useLocale(); | ||||||||||||||
| const utils = trpc.useUtils(); | ||||||||||||||
| const deleteMutation = trpc.viewer.bookings.delete.useMutation({ | ||||||||||||||
| onSuccess: async () => { | ||||||||||||||
| setIsOpenDialog(false); | ||||||||||||||
| await utils.viewer.bookings.invalidate(); | ||||||||||||||
| }, | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}> | ||||||||||||||
| <DialogContent enableOverflow> | ||||||||||||||
| <div className="flex flex-row space-x-3"> | ||||||||||||||
| <div className="bg-subtle flex h-10 w-10 flex-shrink-0 justify-center rounded-full "> | ||||||||||||||
| <Icon name="trash" className="m-auto h-6 w-6" /> | ||||||||||||||
| </div> | ||||||||||||||
| <div className="w-full pt-1"> | ||||||||||||||
| <DialogHeader title={t("delete")} /> | ||||||||||||||
| <p className="text-subtle text-sm"> | ||||||||||||||
| Are you sure you want to delete this event? This action cannot be undone. | ||||||||||||||
| </p> | ||||||||||||||
|
Comment on lines
+36
to
+38
Contributor
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. 🛠️ Refactor suggestion Localize the confirmation text. - <p className="text-subtle text-sm">
- Are you sure you want to delete this event? This action cannot be undone.
- </p>
+ <p className="text-subtle text-sm">
+ {t("delete_booking_confirmation")}
+ </p>If the key doesn’t exist, add it to locales. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| </div> | ||||||||||||||
| </div> | ||||||||||||||
| <DialogFooter showDivider className="mt-8"> | ||||||||||||||
| <Button type="button" color="secondary" onClick={() => setIsOpenDialog(false)}> | ||||||||||||||
| {t("cancel")} | ||||||||||||||
| </Button> | ||||||||||||||
| <Button | ||||||||||||||
| type="button" | ||||||||||||||
| color="destructive" | ||||||||||||||
| onClick={() => deleteMutation.mutate({ bookingId })} | ||||||||||||||
| disabled={deleteMutation.isPending}> | ||||||||||||||
| {t("delete")} | ||||||||||||||
| </Button> | ||||||||||||||
| </DialogFooter> | ||||||||||||||
| </DialogContent> | ||||||||||||||
| </Dialog> | ||||||||||||||
| ); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| export default DeleteBookingDialog; | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -815,6 +815,7 @@ model Booking { | |
| rating Int? | ||
| ratingFeedback String? | ||
| noShowHost Boolean? @default(false) | ||
| deleted Boolean? | ||
| scheduledTriggers WebhookScheduledTriggers[] | ||
| oneTimePassword String? @unique @default(uuid()) | ||
| /// @zod.email() | ||
|
|
@@ -1726,7 +1727,7 @@ model BookingDenormalized { | |
| } | ||
|
|
||
| view BookingTimeStatusDenormalized { | ||
| id Int @id @unique | ||
| id Int @unique | ||
|
Comment on lines
-1729
to
+1730
Contributor
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. why? |
||
| uid String | ||
| eventTypeId Int? | ||
| title String | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
|
|
||
| import { prisma } from "@calcom/prisma"; | ||
|
|
||
| import { deleteHandler } from "../delete.handler"; | ||
| import type { BookingsProcedureContext } from "../util"; | ||
|
|
||
| vi.mock("@calcom/prisma", () => { | ||
| return { | ||
| prisma: { | ||
| booking: { | ||
| update: vi.fn(), | ||
| }, | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| describe("viewer.bookings.delete handler", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("deletes a past booking by setting deleted flag only", async () => { | ||
| const past = new Date(Date.now() - 24 * 60 * 60 * 1000); | ||
| const ctx: BookingsProcedureContext = { | ||
| booking: { | ||
| id: 1, | ||
| uid: "uid", | ||
| eventTypeId: 1, | ||
| title: "title", | ||
| description: null, | ||
| customInputs: null, | ||
| responses: null, | ||
| startTime: past, | ||
| endTime: past, | ||
| location: null, | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| status: "accepted", | ||
| paid: false, | ||
| userId: 1, | ||
| cancellationReason: null, | ||
| rejectionReason: null, | ||
| reassignReason: null, | ||
| reassignById: null, | ||
| dynamicEventSlugRef: null, | ||
| dynamicGroupSlugRef: null, | ||
| rescheduled: null, | ||
| fromReschedule: null, | ||
| recurringEventId: null, | ||
| smsReminderNumber: null, | ||
| metadata: {}, | ||
| isRecorded: false, | ||
| iCalUID: "", | ||
| iCalSequence: 0, | ||
| rating: null, | ||
| ratingFeedback: null, | ||
| noShowHost: false, | ||
| oneTimePassword: "otp", | ||
| cancelledBy: null, | ||
| rescheduledBy: null, | ||
| tracking: null, | ||
| routingFormResponses: [], | ||
| expenseLogs: [], | ||
| attendees: [], | ||
| references: [], | ||
| destinationCalendar: null, | ||
| eventType: null, | ||
| user: null, | ||
| seatsReferences: [], | ||
| instantMeetingToken: null, | ||
| assignmentReason: [], | ||
| scheduledTriggers: [], | ||
| }, | ||
| }; | ||
|
Comment on lines
+25
to
+75
Contributor
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. I don't know why this is needed 🤔 |
||
|
|
||
| await deleteHandler({ ctx, input: { bookingId: 1 } as any }); | ||
|
|
||
| expect(prisma.booking.update).toHaveBeenCalledWith({ | ||
| where: { id: 1 }, | ||
| data: { deleted: true }, | ||
| }); | ||
| }); | ||
|
|
||
| it("throws when trying to delete a future booking", async () => { | ||
| const future = new Date(Date.now() + 24 * 60 * 60 * 1000); | ||
| const ctx: BookingsProcedureContext = { | ||
| booking: { | ||
| id: 2, | ||
| uid: "uid2", | ||
| eventTypeId: 1, | ||
| title: "title2", | ||
| description: null, | ||
| customInputs: null, | ||
| responses: null, | ||
| startTime: future, | ||
| endTime: future, | ||
| location: null, | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| status: "accepted", | ||
| paid: false, | ||
| userId: 1, | ||
| cancellationReason: null, | ||
| rejectionReason: null, | ||
| reassignReason: null, | ||
| reassignById: null, | ||
| dynamicEventSlugRef: null, | ||
| dynamicGroupSlugRef: null, | ||
| rescheduled: null, | ||
| fromReschedule: null, | ||
| recurringEventId: null, | ||
| smsReminderNumber: null, | ||
| metadata: {}, | ||
| isRecorded: false, | ||
| iCalUID: "", | ||
| iCalSequence: 0, | ||
| rating: null, | ||
| ratingFeedback: null, | ||
| noShowHost: false, | ||
| oneTimePassword: "otp", | ||
| cancelledBy: null, | ||
| rescheduledBy: null, | ||
| tracking: null, | ||
| routingFormResponses: [], | ||
| expenseLogs: [], | ||
| attendees: [], | ||
| references: [], | ||
| destinationCalendar: null, | ||
| eventType: null, | ||
| user: null, | ||
| seatsReferences: [], | ||
| instantMeetingToken: null, | ||
| assignmentReason: [], | ||
| scheduledTriggers: [], | ||
| }, | ||
| }; | ||
|
|
||
| await expect(deleteHandler({ ctx, input: { bookingId: 2 } as any })).rejects.toThrow( | ||
| "Cannot delete future bookings" | ||
| ); | ||
| expect(prisma.booking.update).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
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.
Should use translations