Skip to content

Commit

Permalink
feat: "Add an Override" calendar starts with the day specified in gen…
Browse files Browse the repository at this point in the history
…eral settings (#14663)

* feat: Add an Override calendar starts with the day specified in general settings

* fix: types not matching

* fix: update edit calendar to use user's weekStart

* fix: weekstart defaults to 0 when not provided

---------

Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
  • Loading branch information
shaik-zeeshan and joeauyeung committed May 6, 2024
1 parent 0e431ba commit b2baaea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Expand Up @@ -28,13 +28,15 @@ const DateOverrideForm = ({
excludedDates,
onChange,
userTimeFormat,
weekStart,
}: {
workingHours?: WorkingHours[];
onChange: (newValue: TimeRange[]) => void;
excludedDates: string[];
value?: TimeRange[];
onClose?: () => void;
userTimeFormat: number | null;
weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6;
}) => {
const [browsingDate, setBrowsingDate] = useState<Dayjs>();
const { t, i18n, isLocaleReady } = useLocale();
Expand Down Expand Up @@ -142,7 +144,7 @@ const DateOverrideForm = ({
<DialogHeader title={t("date_overrides_dialog_title")} />
<DatePicker
excludedDates={excludedDates}
weekStart={0}
weekStart={weekStart}
selected={selectedDates}
onChange={(day) => {
if (day) onDateChange(day);
Expand Down Expand Up @@ -204,6 +206,7 @@ const DateOverrideInputDialog = ({
Trigger,
excludedDates = [],
userTimeFormat,
weekStart = 0,
...passThroughProps
}: {
workingHours: WorkingHours[];
Expand All @@ -212,6 +215,7 @@ const DateOverrideInputDialog = ({
onChange: (newValue: TimeRange[]) => void;
value?: TimeRange[];
userTimeFormat: number | null;
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
}) => {
const [open, setOpen] = useState(false);
return (
Expand All @@ -221,6 +225,7 @@ const DateOverrideInputDialog = ({
<DialogContent enableOverflow={true} size="md" className="p-0">
<DateOverrideForm
excludedDates={excludedDates}
weekStart={weekStart}
{...passThroughProps}
onClose={() => setOpen(false)}
userTimeFormat={userTimeFormat}
Expand Down
3 changes: 3 additions & 0 deletions packages/features/schedules/components/DateOverrideList.tsx
Expand Up @@ -19,6 +19,7 @@ const DateOverrideList = ({
hour12,
replace,
fields,
weekStart = 0,
}: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
replace: any;
Expand All @@ -28,6 +29,7 @@ const DateOverrideList = ({
userTimeFormat: number | null;
hour12: boolean;
travelSchedules?: RouterOutputs["viewer"]["getTravelSchedules"];
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
}) => {
const { t, i18n } = useLocale();

Expand Down Expand Up @@ -87,6 +89,7 @@ const DateOverrideList = ({
excludedDates={excludedDates}
workingHours={workingHours}
value={item.ranges}
weekStart={weekStart}
onChange={(ranges) => {
// update has very weird side-effects with sorting.
replace([...fields.filter((currentItem) => currentItem.id !== item.id), { ranges }]);
Expand Down
9 changes: 9 additions & 0 deletions packages/platform/atoms/availability/AvailabilitySettings.tsx
Expand Up @@ -146,10 +146,12 @@ const DateOverride = ({
workingHours,
userTimeFormat,
travelSchedules,
weekStart,
}: {
workingHours: WorkingHours[];
userTimeFormat: number | null;
travelSchedules?: RouterOutputs["viewer"]["getTravelSchedules"];
weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6;
}) => {
const { append, replace, fields } = useFieldArray<AvailabilityFormValues, "dateOverrides">({
name: "dateOverrides",
Expand All @@ -172,6 +174,7 @@ const DateOverride = ({
excludedDates={excludedDates}
replace={replace}
fields={fields}
weekStart={weekStart}
workingHours={workingHours}
userTimeFormat={userTimeFormat}
hour12={Boolean(userTimeFormat === 12)}
Expand All @@ -182,6 +185,7 @@ const DateOverride = ({
excludedDates={excludedDates}
onChange={(ranges) => ranges.forEach((range) => append({ ranges: [range] }))}
userTimeFormat={userTimeFormat}
weekStart={weekStart}
Trigger={
<Button color="secondary" StartIcon="plus" data-testid="add-override">
{t("add_an_override")}
Expand Down Expand Up @@ -487,6 +491,11 @@ export function AvailabilitySettings({
workingHours={schedule.workingHours}
userTimeFormat={timeFormat}
travelSchedules={travelSchedules}
weekStart={
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"].indexOf(
weekStart
) as 0 | 1 | 2 | 3 | 4 | 5 | 6
}
/>
)}
</div>
Expand Down

0 comments on commit b2baaea

Please sign in to comment.