Skip to content

Commit ec3656e

Browse files
authored
fix: add isDryRun behaviour for date overrides (calcom#24464)
* chore: add `isDryRun` prop for date overrides * chore: add changesets * chore: implement PR feedback * fix: merge conflicts
1 parent ae4b807 commit ec3656e

5 files changed

Lines changed: 37 additions & 7 deletions

File tree

.changeset/crazy-spoons-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@calcom/atoms": patch
3+
---
4+
5+
This PR adds dry run behaviour for date overrides in the `AvailabilitySettings` atom

packages/features/schedules/components/DateOverrideInputDialog.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DateOverrideForm = ({
2626
onChange,
2727
userTimeFormat,
2828
weekStart,
29+
isDryRun = false,
2930
}: {
3031
workingHours?: WorkingHours[];
3132
onChange: (newValue: TimeRange[]) => void;
@@ -34,6 +35,7 @@ const DateOverrideForm = ({
3435
onClose?: () => void;
3536
userTimeFormat: number | null;
3637
weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6;
38+
isDryRun?: boolean;
3739
}) => {
3840
const [browsingDate, setBrowsingDate] = useState<Dayjs>();
3941
const { t, i18n, isLocaleReady } = useLocale();
@@ -109,13 +111,19 @@ const DateOverrideForm = ({
109111

110112
if (selectedDates.length === 0) return;
111113

114+
if (isDryRun) {
115+
setSelectedDates([]);
116+
return;
117+
}
118+
112119
if (datesUnavailable) {
113120
selectedDates.map((date) => {
114121
datesInRanges.push({
115122
start: date.utc(true).startOf("day").toDate(),
116123
end: date.utc(true).startOf("day").toDate(),
117124
});
118125
});
126+
onChange(datesInRanges);
119127
} else {
120128
selectedDates.map((date) => {
121129
values.range.map((item) => {
@@ -129,9 +137,9 @@ const DateOverrideForm = ({
129137
});
130138
});
131139
});
140+
onChange(datesInRanges);
132141
}
133142

134-
onChange(datesInRanges);
135143
setSelectedDates([]);
136144
}}
137145
className="p-6 sm:flex sm:p-0 xl:flex-row">
@@ -215,6 +223,7 @@ const DateOverrideInputDialog = ({
215223
userTimeFormat: number | null;
216224
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
217225
className?: string;
226+
isDryRun?: boolean;
218227
}) => {
219228
const [open, setOpen] = useState(false);
220229
return (

packages/features/schedules/components/DateOverrideList.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const DateOverrideList = ({
2727
fields,
2828
weekStart = 0,
2929
handleAvailabilityUpdate = noop,
30+
isDryRun = false,
3031
}: {
3132
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3233
replace: any;
@@ -38,6 +39,7 @@ const DateOverrideList = ({
3839
travelSchedules?: RouterOutputs["viewer"]["travelSchedules"]["get"];
3940
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
4041
handleAvailabilityUpdate?: VoidFunction;
42+
isDryRun?: boolean;
4143
}) => {
4244
const { t, i18n } = useLocale();
4345
const isPlatform = useIsPlatform();
@@ -109,10 +111,12 @@ const DateOverrideList = ({
109111
}))}
110112
weekStart={weekStart}
111113
onChange={(ranges) => {
112-
// update has very weird side-effects with sorting.
113-
replace([...fields.filter((currentItem) => currentItem.id !== item.id), { ranges }]);
114-
delete unsortedFieldArrayMap[item.id];
115-
handleAvailabilityUpdate();
114+
if (!isDryRun) {
115+
// update has very weird side-effects with sorting.
116+
replace([...fields.filter((currentItem) => currentItem.id !== item.id), { ranges }]);
117+
delete unsortedFieldArrayMap[item.id];
118+
handleAvailabilityUpdate();
119+
}
116120
}}
117121
Trigger={
118122
<DialogTrigger asChild>
@@ -145,7 +149,9 @@ const DateOverrideList = ({
145149
StartIcon="trash-2"
146150
onClick={() => {
147151
replace([...fields.filter((currentItem) => currentItem.id !== item.id)]);
148-
handleAvailabilityUpdate();
152+
if (!isDryRun) {
153+
handleAvailabilityUpdate();
154+
}
149155
}}
150156
/>
151157
</Tooltip>

packages/platform/atoms/availability/AvailabilitySettings.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ type AvailabilitySettingsProps = {
125125
handleBulkEditDialogToggle: () => void;
126126
};
127127
callbacksRef?: React.MutableRefObject<{ onSuccess?: () => void; onError?: (error: Error) => void }>;
128+
isDryRun?: boolean;
128129
};
129130

130131
const DeleteDialogButton = ({
@@ -190,6 +191,7 @@ const DateOverride = ({
190191
overridesModalClassNames,
191192
classNames,
192193
handleSubmit,
194+
isDryRun = false,
193195
}: {
194196
workingHours: WorkingHours[];
195197
userTimeFormat: number | null;
@@ -203,6 +205,7 @@ const DateOverride = ({
203205
button?: string;
204206
};
205207
handleSubmit: (data: AvailabilityFormValues) => Promise<void>;
208+
isDryRun?: boolean;
206209
}) => {
207210
const { append, replace, fields } = useFieldArray<AvailabilityFormValues, "dateOverrides">({
208211
name: "dateOverrides",
@@ -213,7 +216,9 @@ const DateOverride = ({
213216

214217
const handleAvailabilityUpdate = () => {
215218
const updatedValues = getValues() as AvailabilityFormValues;
216-
handleSubmit(updatedValues);
219+
if (!isDryRun) {
220+
handleSubmit(updatedValues);
221+
}
217222
};
218223

219224
return (
@@ -240,6 +245,7 @@ const DateOverride = ({
240245
hour12={Boolean(userTimeFormat === 12)}
241246
travelSchedules={travelSchedules}
242247
handleAvailabilityUpdate={handleAvailabilityUpdate}
248+
isDryRun={isDryRun}
243249
/>
244250
<DateOverrideInputDialog
245251
className={overridesModalClassNames}
@@ -251,6 +257,7 @@ const DateOverride = ({
251257
}}
252258
userTimeFormat={userTimeFormat}
253259
weekStart={weekStart}
260+
isDryRun={isDryRun}
254261
Trigger={
255262
<Button
256263
className={classNames?.button}
@@ -308,6 +315,7 @@ export const AvailabilitySettings = forwardRef<AvailabilitySettingsFormRef, Avai
308315
allowSetToDefault = true,
309316
allowDelete = true,
310317
callbacksRef,
318+
isDryRun,
311319
} = props;
312320
const [openSidebar, setOpenSidebar] = useState(false);
313321
const { t, i18n } = useLocale();
@@ -675,6 +683,7 @@ export const AvailabilitySettings = forwardRef<AvailabilitySettingsFormRef, Avai
675683
{enableOverrides && (
676684
<BookerStoreProvider>
677685
<DateOverride
686+
isDryRun={isDryRun}
678687
workingHours={schedule.workingHours}
679688
userTimeFormat={timeFormat}
680689
handleSubmit={handleSubmit}

packages/platform/atoms/availability/wrappers/AvailabilitySettingsPlatformWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export const AvailabilitySettingsPlatformWrapper = forwardRef<
203203
allowSetToDefault={allowSetToDefault}
204204
onFormStateChange={onFormStateChange}
205205
callbacksRef={callbacksRef}
206+
isDryRun={isDryRun}
206207
/>
207208
</AtomsWrapper>
208209
);

0 commit comments

Comments
 (0)