feat: Internal Notes for bookings (#18804)
* 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 <[email protected]> * nits * type fixs * fix type * fix type * fix nullable option lost in merge --------- Co-authored-by: Eunjae Lee <[email protected]>
This commit is contained in:
1 parent
1fd4c3fd4c
commit
656d6dc195
22 files changed
+683
-22
No files matched your search
@@ -5,7 +5,63 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
|
||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
||||
import type { RecurringEvent } from "@calcom/types/Calendar";
|
||||
import { Button, Icon, Label, TextArea } from "@calcom/ui";
|
||||
import { Button, Icon, Label, TextArea, Select } from "@calcom/ui";
|
||||
|
||||
interface InternalNotePresetsSelectProps {
|
||||
internalNotePresets: { id: number; name: string }[];
|
||||
onPresetSelect: (
|
||||
option: {
|
||||
value: number | string;
|
||||
label: string;
|
||||
} | null
|
||||
) => void;
|
||||
}
|
||||
|
||||
const InternalNotePresetsSelect = ({
|
||||
internalNotePresets,
|
||||
onPresetSelect,
|
||||
}: InternalNotePresetsSelectProps) => {
|
||||
const { t } = useLocale();
|
||||
const [showOtherInput, setShowOtherInput] = useState(false);
|
||||
|
||||
if (!internalNotePresets?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleSelectChange = (option: { value: number | string; label: string } | null) => {
|
||||
if (option?.value === "other") {
|
||||
setShowOtherInput(true);
|
||||
} else {
|
||||
setShowOtherInput(false);
|
||||
onPresetSelect && onPresetSelect(option);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mb-4 flex flex-col">
|
||||
<Label>{t("internal_booking_note")}</Label>
|
||||
<Select
|
||||
className="mb-2"
|
||||
options={[
|
||||
...internalNotePresets?.map((preset) => ({
|
||||
label: preset.name,
|
||||
value: preset.id,
|
||||
})),
|
||||
{ label: t("other"), value: "other" },
|
||||
]}
|
||||
onChange={handleSelectChange}
|
||||
placeholder={t("internal_booking_note")}
|
||||
/>
|
||||
{showOtherInput && (
|
||||
<TextArea
|
||||
rows={3}
|
||||
placeholder={t("internal_booking_note_description")}
|
||||
onChange={(e) => onPresetSelect?.({ value: "other", label: e.target.value })}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
type Props = {
|
||||
booking: {
|
||||
@@ -19,6 +75,7 @@ type Props = {
|
||||
};
|
||||
recurringEvent: RecurringEvent | null;
|
||||
team?: string | null;
|
||||
teamId?: number;
|
||||
setIsCancellationMode: (value: boolean) => void;
|
||||
theme: string | null;
|
||||
allRemainingBookings: boolean;
|
||||
@@ -34,17 +91,25 @@ type Props = {
|
||||
eventType: unknown;
|
||||
};
|
||||
isHost: boolean;
|
||||
internalNotePresets: { id: number; name: string; cancellationReason: string | null }[];
|
||||
};
|
||||
|
||||
export default function CancelBooking(props: Props) {
|
||||
const [cancellationReason, setCancellationReason] = useState<string>("");
|
||||
const { t } = useLocale();
|
||||
const refreshData = useRefreshData();
|
||||
const { booking, allRemainingBookings, seatReferenceUid, bookingCancelledEventProps, currentUserEmail } =
|
||||
props;
|
||||
const {
|
||||
booking,
|
||||
allRemainingBookings,
|
||||
seatReferenceUid,
|
||||
bookingCancelledEventProps,
|
||||
currentUserEmail,
|
||||
teamId,
|
||||
} = props;
|
||||
const [loading, setLoading] = useState(false);
|
||||
const telemetry = useTelemetry();
|
||||
const [error, setError] = useState<string | null>(booking ? null : t("booking_already_cancelled"));
|
||||
const [internalNote, setInternalNote] = useState<{ id: number; name: string } | null>(null);
|
||||
|
||||
const cancelBookingRef = useCallback((node: HTMLTextAreaElement) => {
|
||||
if (node !== null) {
|
||||
@@ -71,7 +136,31 @@ export default function CancelBooking(props: Props) {
|
||||
)}
|
||||
{!error && (
|
||||
<div className="mt-5 sm:mt-6">
|
||||
{props.isHost && teamId && (
|
||||
<>
|
||||
<InternalNotePresetsSelect
|
||||
internalNotePresets={props.internalNotePresets}
|
||||
onPresetSelect={(option) => {
|
||||
if (!option) return;
|
||||
|
||||
if (option.value === "other") {
|
||||
setInternalNote({ id: -1, name: option.label });
|
||||
} else {
|
||||
const foundInternalNote = props.internalNotePresets.find(
|
||||
(preset) => preset.id === Number(option.value)
|
||||
);
|
||||
if (foundInternalNote) {
|
||||
setInternalNote(foundInternalNote);
|
||||
setCancellationReason(foundInternalNote.cancellationReason || "");
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Label>{props.isHost ? t("cancellation_reason_host") : t("cancellation_reason")}</Label>
|
||||
|
||||
<TextArea
|
||||
data-testid="cancel_reason"
|
||||
ref={cancelBookingRef}
|
||||
@@ -113,6 +202,7 @@ export default function CancelBooking(props: Props) {
|
||||
// @NOTE: very important this shouldn't cancel with number ID use uid instead
|
||||
seatReferenceUid,
|
||||
cancelledBy: currentUserEmail,
|
||||
internalNote: internalNote,
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
Reference in new issue
Block a user