Skip to content
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

fix: bulk update event type availability #18850

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AppList, type HandleDisconnect } from "@calcom/features/apps/components
import type { UpdateUsersDefaultConferencingAppParams } from "@calcom/features/apps/components/AppSetDefaultLinkDialog";
import DisconnectIntegrationModal from "@calcom/features/apps/components/DisconnectIntegrationModal";
import type { RemoveAppParams } from "@calcom/features/apps/components/DisconnectIntegrationModal";
import type { BulkUpdatParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import type { BulkUpdateParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { AppCategories } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc/react";
Expand Down Expand Up @@ -75,7 +75,7 @@ const IntegrationsContainer = ({
);
};

const handleBulkUpdateDefaultLocation = ({ eventTypeIds, callback }: BulkUpdatParams) => {
const handleBulkUpdateDefaultLocation = ({ eventTypeIds, callback }: BulkUpdateParams) => {
updateLocationsMutation.mutate(
{
eventTypeIds,
Expand Down
45 changes: 28 additions & 17 deletions apps/web/modules/availability/[schedule]/schedule-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouter } from "next/navigation";
import { useState } from "react";

import { AvailabilitySettings } from "@calcom/atoms/monorepo";
import type { BulkUpdatParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import type { BulkUpdateParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import { withErrorFromUnknown } from "@calcom/lib/getClientErrorFromUnknown";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
Expand Down Expand Up @@ -53,19 +53,9 @@ export const AvailabilitySettingsWebWrapper = ({
const { data: eventTypesQueryData, isFetching: isEventTypesFetching } =
trpc.viewer.eventTypes.bulkEventFetch.useQuery();

const bulkUpdateFunction = ({ eventTypeIds, callback }: BulkUpdatParams) => {
bulkUpdateDefaultAvailabilityMutation.mutate(
{
eventTypeIds,
},
{
onSuccess: () => {
utils.viewer.availability.list.invalidate();
callback();
showToast(t("success"), "success");
},
}
);
const bulkUpdateFunction = ({ eventTypeIds, callback }: BulkUpdateParams) => {
setBulkUpdateEventTypeIds(eventTypeIds);
callback();
};

const handleBulkEditDialogToggle = () => {
Expand Down Expand Up @@ -114,6 +104,8 @@ export const AvailabilitySettingsWebWrapper = ({
},
});

const [bulkUpdateEventTypeIds, setBulkUpdateEventTypeIds] = useState<BulkUpdateParams["eventTypeIds"]>([]);

// TODO: reimplement Skeletons for this page in here
if (isPending) return null;

Expand All @@ -137,18 +129,37 @@ export const AvailabilitySettingsWebWrapper = ({
scheduleId && deleteMutation.mutate({ scheduleId });
}}
handleSubmit={async ({ dateOverrides, ...values }) => {
scheduleId &&
updateMutation.mutate({
if (scheduleId) {
await updateMutation.mutateAsync({
scheduleId,
dateOverrides: dateOverrides.flatMap((override) => override.ranges),
...values,
});

if (!values.isDefault || !bulkUpdateEventTypeIds.length || updateMutation.isError) return;

bulkUpdateDefaultAvailabilityMutation.mutate(
{ eventTypeIds: bulkUpdateEventTypeIds },
{
onSuccess: () => {
utils.viewer.availability.list.invalidate();
showToast(t("success"), "success");
},
onError: (err) => {
if (err instanceof HttpError) {
const message = `${err.statusCode}: ${err.message}`;
showToast(message, "error");
}
},
}
);
}
}}
bulkUpdateModalProps={{
isOpen: isBulkUpdateModalOpen,
setIsOpen: setIsBulkUpdateModalOpen,
save: bulkUpdateFunction,
isSaving: bulkUpdateDefaultAvailabilityMutation.isPending,
isSaving: false,
eventTypes: eventTypesQueryData?.eventTypes,
isEventTypesFetching,
handleBulkEditDialogToggle: handleBulkEditDialogToggle,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/modules/availability/availability-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useCallback, useState } from "react";

import SkeletonLoader from "@calcom/features/availability/components/SkeletonLoader";
import { BulkEditDefaultForEventsModal } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import type { BulkUpdatParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import type { BulkUpdateParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import { NewScheduleButton, ScheduleListItem } from "@calcom/features/schedules";
import Shell from "@calcom/features/shell/Shell";
import { AvailabilitySliderTable } from "@calcom/features/timezone-buddy/components/AvailabilitySliderTable";
Expand Down Expand Up @@ -86,7 +86,7 @@ export function AvailabilityList({ schedules }: RouterOutputs["viewer"]["availab
const { data: eventTypesQueryData, isFetching: isEventTypesFetching } =
trpc.viewer.eventTypes.bulkEventFetch.useQuery();

const bulkUpdateFunction = ({ eventTypeIds, callback }: BulkUpdatParams) => {
const bulkUpdateFunction = ({ eventTypeIds, callback }: BulkUpdateParams) => {
bulkUpdateDefaultAvailabilityMutation.mutate(
{
eventTypeIds,
Expand Down
3 changes: 2 additions & 1 deletion apps/web/server/lib/router/getServerSideProps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GetServerSidePropsContext } from "next";
import { stringify } from "querystring";
import z from "zod";
import { GetServerSidePropsContext } from "next";

import { enrichFormWithMigrationData } from "@calcom/app-store/routing-forms/enrichFormWithMigrationData";
import { getAbsoluteEventTypeRedirectUrlWithEmbedSupport } from "@calcom/app-store/routing-forms/getEventTypeRedirectUrl";
import getFieldIdentifier from "@calcom/app-store/routing-forms/lib/getFieldIdentifier";
Expand Down
4 changes: 2 additions & 2 deletions packages/features/apps/components/AppList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AppListCard from "@calcom/features/apps/components/AppListCard";
import type { UpdateUsersDefaultConferencingAppParams } from "@calcom/features/apps/components/AppSetDefaultLinkDialog";
import { AppSetDefaultLinkDialog } from "@calcom/features/apps/components/AppSetDefaultLinkDialog";
import type {
BulkUpdatParams,
BulkUpdateParams,
EventTypes,
} from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import { BulkEditDefaultForEventsModal } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
Expand Down Expand Up @@ -37,7 +37,7 @@ interface AppListProps {
listClassName?: string;
defaultConferencingApp: RouterOutputs["viewer"]["getUsersDefaultConferencingApp"];
handleUpdateUserDefaultConferencingApp: (params: UpdateUsersDefaultConferencingAppParams) => void;
handleBulkUpdateDefaultLocation: (params: BulkUpdatParams) => void;
handleBulkUpdateDefaultLocation: (params: BulkUpdateParams) => void;
isBulkUpdateDefaultLocationPending: boolean;
eventTypes?: EventTypes;
isEventTypesFetching?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const BulkUpdateEventSchema = z.object({
eventTypeIds: z.array(z.number()),
});

export type BulkUpdatParams = { eventTypeIds: number[]; callback: () => void };
export type BulkUpdateParams = { eventTypeIds: number[]; callback: () => void };
export type EventTypes = Array<{ id: number; title: string }>;

export function BulkEditDefaultForEventsModal({
Expand All @@ -19,7 +19,7 @@ export function BulkEditDefaultForEventsModal({
}: {
open: boolean;
setOpen: (open: boolean) => void;
bulkUpdateFunction: (params: BulkUpdatParams) => void;
bulkUpdateFunction: (params: BulkUpdateParams) => void;
isPending: boolean;
description: string;
isEventTypesFetching?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Controller, useFieldArray, useForm, useFormContext, useWatch } from "re

import dayjs from "@calcom/dayjs";
import type {
BulkUpdatParams,
BulkUpdateParams,
EventTypes,
} from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import { BulkEditDefaultForEventsModal } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
Expand Down Expand Up @@ -110,7 +110,7 @@ type AvailabilitySettingsProps = {
bulkUpdateModalProps?: {
isOpen: boolean;
setIsOpen: Dispatch<SetStateAction<boolean>>;
save: (params: BulkUpdatParams) => void;
save: (params: BulkUpdateParams) => void;
isSaving: boolean;
eventTypes?: EventTypes;
isEventTypesFetching?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { AtomsWrapper } from "../../src/components/atoms-wrapper";
import { useToast } from "../../src/components/ui/use-toast";
import type {
BulkUpdatParams,
BulkUpdateParams,
UpdateUsersDefaultConferencingAppParams,
} from "./ConferencingAppsViewWebWrapper";
import { useAtomBulkUpdateEventTypesToDefaultLocation } from "./hooks/useAtomBulkUpdateEventTypesToDefaultLocation";
Expand Down Expand Up @@ -149,7 +149,7 @@ export const ConferencingAppsViewPlatformWrapper = ({
});
};

const handleBulkUpdateDefaultLocation = ({ eventTypeIds, callback }: BulkUpdatParams) => {
const handleBulkUpdateDefaultLocation = ({ eventTypeIds, callback }: BulkUpdateParams) => {
bulkUpdateEventTypesToDefaultLocation.mutate(eventTypeIds, {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [defaultConferencingAppQueryKey] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type UpdateUsersDefaultConferencingAppParams = {
onErrorCallback: () => void;
};

export type BulkUpdatParams = { eventTypeIds: number[]; callback: () => void };
export type BulkUpdateParams = { eventTypeIds: number[]; callback: () => void };
type RemoveAppParams = { credentialId: number; teamId?: number; callback: () => void };

const SkeletonLoader = () => {
Expand Down Expand Up @@ -130,7 +130,7 @@ export const ConferencingAppsViewWebWrapper = ({
);
};

const handleBulkUpdateDefaultLocation = ({ eventTypeIds, callback }: BulkUpdatParams) => {
const handleBulkUpdateDefaultLocation = ({ eventTypeIds, callback }: BulkUpdateParams) => {
updateLocationsMutation.mutate(
{
eventTypeIds,
Expand Down
Loading