* migration + migrate booking limit page to team settings * new pages * use settings toggle for displaying content * get current team presets * update mutation * i18n for settings page * remove redudant await * cancelation UI for select * handle other selection * extract into a util * inital cancelation reason flow * fix i18n to be more readable * add cancel reason logic * nits * improve copy * ensure is teamMember and not isAdmin for getting internalNotes * improvie spacing between elements * fix types * more type fixes * correct types * Update packages/features/bookings/lib/handleNewBooking/getEventTypesFromDB.ts * use input component and remove mb-2 to allign with icon button * Update packages/trpc/server/routers/viewer/teams/updateInternalNotesPresets.handler.ts Co-authored-by: Eunjae Lee <hey@eunjae.dev> * nits * type fixs * fix type * fix type * fix nullable option lost in merge --------- Co-authored-by: Eunjae Lee <hey@eunjae.dev>
83 lines
1.6 KiB
TypeScript
83 lines
1.6 KiB
TypeScript
import { HttpError } from "@calcom/lib/http-error";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { type BookingToDelete } from "./handleCancelBooking";
|
|
|
|
type InternalNote = {
|
|
id: number;
|
|
name: string;
|
|
value?: string;
|
|
};
|
|
|
|
export async function handleInternalNote({
|
|
internalNote,
|
|
booking,
|
|
userId,
|
|
teamId,
|
|
}: {
|
|
internalNote: InternalNote;
|
|
booking: BookingToDelete;
|
|
userId: number;
|
|
teamId: number;
|
|
}) {
|
|
const userIsHost = booking?.eventType?.hosts.find((host) => {
|
|
if (host.user.id === userId) return true;
|
|
});
|
|
|
|
const userIsOwnerOfEventType = booking?.eventType?.owner?.id === userId;
|
|
|
|
if (!userIsHost && !userIsOwnerOfEventType) {
|
|
throw new HttpError({
|
|
statusCode: 403,
|
|
message: "You do not have permission to add an internal note to this booking.",
|
|
});
|
|
}
|
|
|
|
// "Other"
|
|
if (internalNote.id === -1) {
|
|
return prisma.bookingInternalNote.create({
|
|
data: {
|
|
booking: {
|
|
connect: {
|
|
id: booking.id,
|
|
},
|
|
},
|
|
text: internalNote.value,
|
|
createdBy: {
|
|
connect: {
|
|
id: userId,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
// "Preset"
|
|
await prisma.internalNotePreset.findFirstOrThrow({
|
|
where: {
|
|
teamId: teamId,
|
|
id: internalNote.id,
|
|
},
|
|
});
|
|
|
|
return prisma.bookingInternalNote.create({
|
|
data: {
|
|
notePreset: {
|
|
connect: {
|
|
id: internalNote.id,
|
|
},
|
|
},
|
|
createdBy: {
|
|
connect: {
|
|
id: userId,
|
|
},
|
|
},
|
|
booking: {
|
|
connect: {
|
|
id: booking.id,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|