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
@@ -1,5 +1,5 @@
|
||||
import { withAppDirSsr } from "app/WithAppDirSsr";
|
||||
import { PageProps } from "app/_types";
|
||||
import type { PageProps } from "app/_types";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { withAppDirSsr } from "app/WithAppDirSsr";
|
||||
import { PageProps } from "app/_types";
|
||||
import type { PageProps } from "app/_types";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { withAppDirSsr } from "app/WithAppDirSsr";
|
||||
import { PageProps as ServerPageProps } from "app/_types";
|
||||
import type { PageProps as ServerPageProps } from "app/_types";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
|
||||
+6
-7
@@ -1,23 +1,22 @@
|
||||
import { _generateMetadata, getTranslate } from "app/_utils";
|
||||
|
||||
import TeamBookingLimitsView from "@calcom/features/ee/teams/pages/team-booking-limits-view";
|
||||
import TeamSettingsView from "@calcom/features/ee/teams/pages/team-settings-view";
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
|
||||
export const generateMetadata = async () =>
|
||||
await _generateMetadata(
|
||||
(t) => t("booking_limits"),
|
||||
(t) => t("booking_limits_team_description")
|
||||
(t) => t("settings"),
|
||||
(t) => t("team_settings_description")
|
||||
);
|
||||
|
||||
const Page = async () => {
|
||||
const t = await getTranslate();
|
||||
|
||||
return (
|
||||
<SettingsHeader
|
||||
title={t("booking_limits")}
|
||||
description={t("booking_limits_team_description")}
|
||||
title={t("settings")}
|
||||
description={t("team_settings_description")}
|
||||
borderInShellHeader={false}>
|
||||
<TeamBookingLimitsView />
|
||||
<TeamSettingsView />
|
||||
</SettingsHeader>
|
||||
);
|
||||
};
|
||||
@@ -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",
|
||||
|
||||
@@ -60,6 +60,7 @@ export const getEventTypesFromDB = async (id: number) => {
|
||||
},
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
name: true,
|
||||
hideBranding: true,
|
||||
|
||||
@@ -193,6 +193,20 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
}
|
||||
|
||||
const { currentOrgDomain } = orgDomainConfig(context.req);
|
||||
|
||||
async function getInternalNotePresets(teamId: number) {
|
||||
return await prisma.internalNotePreset.findMany({
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
cancellationReason: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
orgSlug: currentOrgDomain,
|
||||
@@ -210,6 +224,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
requiresLoginToUpdate,
|
||||
rescheduledToUid,
|
||||
isLoggedInUserHost,
|
||||
internalNotePresets: eventType?.team?.id ? await getInternalNotePresets(eventType.team.id) : [],
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -771,6 +771,7 @@ export default function Success(props: PageProps) {
|
||||
profile={{ name: props.profile.name, slug: props.profile.slug }}
|
||||
recurringEvent={eventType.recurringEvent}
|
||||
team={eventType?.team?.name}
|
||||
teamId={eventType?.team?.id}
|
||||
setIsCancellationMode={setIsCancellationMode}
|
||||
theme={isSuccessBookingPage ? props.profile.theme : "light"}
|
||||
allRemainingBookings={allRemainingBookings}
|
||||
@@ -778,6 +779,7 @@ export default function Success(props: PageProps) {
|
||||
bookingCancelledEventProps={bookingCancelledEventProps}
|
||||
currentUserEmail={currentUserEmail}
|
||||
isHost={isHost}
|
||||
internalNotePresets={props.internalNotePresets}
|
||||
/>
|
||||
</>
|
||||
))}
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"cancellation_reason": "Reason for cancellation (optional)",
|
||||
"cancellation_reason_host": "Reason for cancellation",
|
||||
"cancellation_reason_placeholder": "Why are you cancelling?",
|
||||
"notify_attendee_cancellation_reason_warning":"Please note that the cancellation reason will be visible to the attendee.",
|
||||
"notify_attendee_cancellation_reason_warning":"Cancellation reason will be shared with guests",
|
||||
"rejection_reason_placeholder": "Why are you rejecting?",
|
||||
"rejection_reason": "Reason for rejecting",
|
||||
"rejection_reason_title": "Reject the booking request?",
|
||||
@@ -2666,6 +2666,7 @@
|
||||
"x_marked_as_no_show": "{{x}} marked as no-show",
|
||||
"x_unmarked_as_no_show": "{{x}} unmarked as no-show",
|
||||
"team_select_info": "triggers for all team event types and all team members' personal event types",
|
||||
"team_settings_description":"Manage settings for you team",
|
||||
"no_show_updated": "No-show status updated for attendees",
|
||||
"email_copied": "Email copied",
|
||||
"phone_number_copied": "Phone Number Copied",
|
||||
@@ -2930,6 +2931,13 @@
|
||||
"managed_users_description": "See all the managed users created by your OAuth client",
|
||||
"select_oAuth_client": "Select Oauth Client",
|
||||
"on_every_instance": "On every instance",
|
||||
"internal_booking_note": "Internal Note",
|
||||
"internal_note_cancellation_reason": "Reason shared with customer (optional)",
|
||||
"internal_booking_note_description": "This note will be visible to only members of your team",
|
||||
"internal_note_presets":"Internal Cancelation Notes Presets",
|
||||
"internal_note_presets_description" : "Create presets for internal notes that can be applied to bookings",
|
||||
"internal_note_presets_updated_successfully" : "Internal note presets updated successfully",
|
||||
"add_preset" : "Add Preset",
|
||||
"authorize": "Authorize",
|
||||
"next": "Next",
|
||||
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
|
||||
|
||||
Reference in new issue
Block a user