fix: common schedule toggling incorrectly (#17517)
* fix: common schedule toggling incorrectly * type fixes to util.ts * fix another type error
This commit is contained in:
1 parent
4b38d73120
commit
993bf23986
5 files changed
+130
-128
No files matched your search
+25
-27
@@ -54,7 +54,6 @@ type HostSchedulesQueryType =
|
||||
|
||||
type EventTypeTeamScheduleProps = {
|
||||
hostSchedulesQuery: HostSchedulesQueryType;
|
||||
hosts?: Host[];
|
||||
};
|
||||
|
||||
type TeamMember = Pick<TeamMembers[number], "avatar" | "name" | "id">;
|
||||
@@ -392,13 +391,13 @@ const TeamMemberSchedule = ({
|
||||
};
|
||||
|
||||
const TeamAvailability = ({
|
||||
hosts,
|
||||
teamMembers,
|
||||
hostSchedulesQuery,
|
||||
}: EventTypeTeamScheduleProps & { teamMembers: TeamMember[] }) => {
|
||||
const { t } = useLocale();
|
||||
const { watch } = useFormContext<FormValues>();
|
||||
const [animationRef] = useAutoAnimate<HTMLUListElement>();
|
||||
|
||||
const hosts = watch("hosts");
|
||||
return (
|
||||
<>
|
||||
<div className="border-subtle flex flex-col rounded-md">
|
||||
@@ -439,42 +438,41 @@ const TeamAvailability = ({
|
||||
);
|
||||
};
|
||||
|
||||
const useCommonScheduleState = (initialScheduleId: number | null) => {
|
||||
const { setValue } = useFormContext<FormValues>();
|
||||
const [useHostSchedulesForTeamEvent, setUseHostSchedulesForTeamEvent] = useState(!initialScheduleId);
|
||||
// Reset the main schedule
|
||||
const clearMainSchedule = () => {
|
||||
setValue("schedule", null, { shouldDirty: Boolean(initialScheduleId) });
|
||||
};
|
||||
// Toggle function
|
||||
const toggleScheduleState = (checked: boolean) => {
|
||||
const useHostSchedulesForTeamEvent = !checked;
|
||||
setUseHostSchedulesForTeamEvent(useHostSchedulesForTeamEvent);
|
||||
if (useHostSchedulesForTeamEvent) clearMainSchedule();
|
||||
};
|
||||
return {
|
||||
useHostSchedulesForTeamEvent,
|
||||
toggleScheduleState,
|
||||
};
|
||||
};
|
||||
|
||||
const UseCommonScheduleSettingsToggle = ({ eventType, ...rest }: EventTypeScheduleProps) => {
|
||||
const { t } = useLocale();
|
||||
const { setValue, resetField, getValues, watch } = useFormContext<FormValues>();
|
||||
|
||||
const [useHostSchedulesForTeamEvent, setUseHostSchedulesForTeamEvent] = useState(
|
||||
!Boolean(eventType.schedule)
|
||||
);
|
||||
|
||||
const watchHosts = watch("hosts");
|
||||
|
||||
const { useHostSchedulesForTeamEvent, toggleScheduleState } = useCommonScheduleState(eventType.schedule);
|
||||
return (
|
||||
<>
|
||||
<SettingsToggle
|
||||
checked={!useHostSchedulesForTeamEvent}
|
||||
onCheckedChange={(checked) => {
|
||||
setUseHostSchedulesForTeamEvent(!checked);
|
||||
if (checked) {
|
||||
if (Boolean(eventType.schedule)) resetField("schedule");
|
||||
getValues("hosts").map((_, index) => {
|
||||
setValue(`hosts.${index}.scheduleId`, null, { shouldDirty: true });
|
||||
});
|
||||
} else {
|
||||
setValue("schedule", null, { shouldDirty: Boolean(eventType.schedule) });
|
||||
}
|
||||
}}
|
||||
onCheckedChange={toggleScheduleState}
|
||||
title={t("choose_common_schedule_team_event")}
|
||||
description={t("choose_common_schedule_team_event_description")}>
|
||||
{/* handles the state for which 'schedule' ID is set, as it's unknown until the Select dropdown is loaded */}
|
||||
<EventTypeSchedule eventType={eventType} {...rest} />
|
||||
</SettingsToggle>
|
||||
{useHostSchedulesForTeamEvent && (
|
||||
<div className="lg:ml-14">
|
||||
<TeamAvailability
|
||||
hosts={watchHosts}
|
||||
teamMembers={rest.teamMembers}
|
||||
hostSchedulesQuery={rest.hostSchedulesQuery}
|
||||
/>
|
||||
<TeamAvailability teamMembers={rest.teamMembers} hostSchedulesQuery={rest.hostSchedulesQuery} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -37,6 +37,33 @@ export type TeamMember = {
|
||||
defaultScheduleId: number | null;
|
||||
};
|
||||
|
||||
type EventLocation = {
|
||||
type: EventLocationType["type"];
|
||||
address?: string;
|
||||
attendeeAddress?: string;
|
||||
somewhereElse?: string;
|
||||
link?: string;
|
||||
hostPhoneNumber?: string;
|
||||
displayLocationPublicly?: boolean;
|
||||
phone?: string;
|
||||
hostDefault?: string;
|
||||
credentialId?: number;
|
||||
teamName?: string;
|
||||
};
|
||||
|
||||
type PhoneCallConfig = {
|
||||
generalPrompt: string;
|
||||
enabled: boolean;
|
||||
beginMessage: string;
|
||||
yourPhoneNumber: string;
|
||||
numberToCall: string;
|
||||
guestName?: string;
|
||||
guestEmail?: string;
|
||||
guestCompany?: string;
|
||||
templateType: string;
|
||||
schedulerName?: string;
|
||||
};
|
||||
|
||||
export type FormValues = {
|
||||
id: number;
|
||||
title: string;
|
||||
@@ -59,31 +86,8 @@ export type FormValues = {
|
||||
hideCalendarNotes: boolean;
|
||||
multiplePrivateLinks: string[] | undefined;
|
||||
eventTypeColor: z.infer<typeof eventTypeColor>;
|
||||
locations: {
|
||||
type: EventLocationType["type"];
|
||||
address?: string;
|
||||
attendeeAddress?: string;
|
||||
somewhereElse?: string;
|
||||
link?: string;
|
||||
hostPhoneNumber?: string;
|
||||
displayLocationPublicly?: boolean;
|
||||
phone?: string;
|
||||
hostDefault?: string;
|
||||
credentialId?: number;
|
||||
teamName?: string;
|
||||
}[];
|
||||
aiPhoneCallConfig: {
|
||||
generalPrompt: string;
|
||||
enabled: boolean;
|
||||
beginMessage: string;
|
||||
yourPhoneNumber: string;
|
||||
numberToCall: string;
|
||||
guestName?: string;
|
||||
guestEmail?: string;
|
||||
guestCompany?: string;
|
||||
templateType: string;
|
||||
schedulerName?: string;
|
||||
};
|
||||
locations: EventLocation[];
|
||||
aiPhoneCallConfig: PhoneCallConfig;
|
||||
customInputs: CustomInputParsed[];
|
||||
schedule: number | null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user