feat: dry run behaviour for event type atoms (#20689)

This commit is contained in:
Rajiv Sahal
2025-04-15 22:23:51 +05:30
committed by GitHub
parent b99ea16b31
commit ce995c39f2
2 changed files with 35 additions and 17 deletions
@@ -27,6 +27,7 @@ type CreateEventTypeProps = {
buttons?: ActionButtonsClassNames;
};
onCancel?: () => void;
isDryRun?: boolean;
};
const ActionButtons = ({
@@ -67,6 +68,7 @@ export const CreateEventTypePlatformWrapper = ({
onError,
customClassNames,
onCancel,
isDryRun = false,
}: CreateEventTypeProps) => {
const { form, isManagedEventType } = useCreateEventTypeForm();
const createEventTypeQuery = useCreateEventType({ onSuccess, onError });
@@ -86,15 +88,16 @@ export const CreateEventTypePlatformWrapper = ({
form={form}
isManagedEventType={isManagedEventType}
handleSubmit={(values) => {
createTeamEventTypeQuery.mutate({
lengthInMinutes: values.length,
title: values.title,
slug: values.slug,
description: values.description ?? "",
schedulingType: values.schedulingType ?? "COLLECTIVE",
hosts: [],
teamId,
});
!isDryRun &&
createTeamEventTypeQuery.mutate({
lengthInMinutes: values.length,
title: values.title,
slug: values.slug,
description: values.description ?? "",
schedulingType: values.schedulingType ?? "COLLECTIVE",
hosts: [],
teamId,
});
}}
SubmitButton={(isPending) =>
ActionButtons({
@@ -115,12 +118,13 @@ export const CreateEventTypePlatformWrapper = ({
form={form}
isManagedEventType={isManagedEventType}
handleSubmit={(values) => {
createEventTypeQuery.mutate({
lengthInMinutes: values.length,
title: values.title,
slug: values.slug,
description: values.description ?? "",
});
!isDryRun &&
createEventTypeQuery.mutate({
lengthInMinutes: values.length,
title: values.title,
slug: values.slug,
description: values.description ?? "",
});
}}
SubmitButton={(isPending) =>
ActionButtons({
@@ -56,6 +56,7 @@ export type EventTypePlatformWrapperProps = {
allowDelete: boolean;
customClassNames?: EventTypeCustomClassNames;
disableToasts?: boolean;
isDryRun?: boolean;
};
const EventType = ({
@@ -68,6 +69,7 @@ const EventType = ({
allowDelete = true,
customClassNames,
disableToasts = false,
isDryRun = false,
...props
}: EventTypeSetupProps & EventTypePlatformWrapperProps) => {
const { t } = useLocale();
@@ -141,7 +143,13 @@ const EventType = ({
const { form, handleSubmit } = useEventTypeForm({
eventType,
onSubmit: (data) => updateMutation.mutate(data),
onSubmit: (data) => {
if (!isDryRun) {
updateMutation.mutate(data);
} else {
toast({ description: t("event_type_updated_successfully", { eventTypeTitle: eventType.title }) });
}
},
});
const slug = form.watch("slug") ?? eventType.slug;
@@ -244,12 +252,16 @@ const EventType = ({
});
const onDelete = () => {
if (allowDelete) {
if (allowDelete && !isDryRun) {
isTeamEventTypeDeleted.current = true;
team?.id
? deleteTeamEventTypeMutation.mutate({ eventTypeId: id, teamId: team.id })
: deleteMutation.mutate(id);
}
if (isDryRun) {
handleDeleteSuccess();
}
};
const onConflict = (conflicts: ChildrenEventType[]) => {
@@ -307,6 +319,7 @@ export const EventTypePlatformWrapper = ({
onDeleteError,
allowDelete = true,
customClassNames,
isDryRun,
}: EventTypePlatformWrapperProps) => {
const { data: eventTypeQueryData } = useAtomsEventTypeById(id);
const queryClient = useQueryClient();
@@ -338,6 +351,7 @@ export const EventTypePlatformWrapper = ({
onDeleteError={onDeleteError}
allowDelete={allowDelete}
customClassNames={customClassNames}
isDryRun={isDryRun}
/>
);
};