* feat(appStore): add isOAuth config * refactor(appStore): EventTypeAppSettngsInterface * refactor(qr_code): split EventTypeAppCardInterface and EventTypeAppSettingsInterface * feat(appStore): redirect to onboarding for stripe and basecam * fix(ui/ScrollableArea): overflow indicator not working * feat(apps): new install app flow * fix(configureStep): get disabled props for settings * fix: getAppInstallsBySlug now use teamIds * chore: Alby to AppSettingsInterface * chore: Giphy to appsettings interface * chore: GTM migration * chore: GT4 - migration * chore: fathom migration * chore: paypal * feat: basecamp migration * feat: metapixel migration * feat:plausable * feat:stripe * fix merge issues * fix merge issues in new app install flow steps * wip: callback to onboarding * fix: imports * fix: more imports * feat: use redirect to onboarding on install flow * feat: New app install flow 2 (#14077) * fix: redirect to event-type after oauth flow * When clicking on install new app button, only redirect to the new app install flow if it is an oAuth app or an app that extends the EventType feature in it's config * code refactor, skip event-type step * removed extra consoles * so that no one can change the eventTypeId in url * theme support enabled * only pass eventTypeId instead of whole evetType obj to OmniInstallAppButton * fix: clicking on event-type gives error and redirects to /apps * saved appOnboardingRedirectUrl to OAuth State * fix: a user having no team breaks the onboarding flow * add optional chaining to appMetadata.extendsFeature and appMetadata.isOAuth; * encode appOnboardingRedirectUrl * fix: dark theme ui issues * skip configure step if no-event types if user/team does not have event-type then skip configure step and goto apps/installed/[category] * exclude calendars from apps- onboarding flow * Update getAppOnboardingRedirectUrl.ts * fix: On configure step, inputs aren't showing errors * change route from `apps/onboarding` to `apps/installation` * fix: flow not correctly working for teams * should only allow team ADMIN or OWER to install an app to team * Prevent two payment apps to be enabled * removed loading state * Fix type error * undo new-app-flow from OmniInstallAppButton * remove OAuth Step, handle step numbering * fix: redirect url * getAppOnboardingRedirectUrl refactor * for debugging * Revert "for debugging" This reverts commit b9362c1a8f47f2280e684c213d7ec08d04a8ac4c. * fix: added toaster * feat: added support to select multiple events (almost) * hide button * Move inner form outside outer form using portal Due to limitations with nested forms in React Hook Form, moved the inner form outside the outer form using a portal to ensure proper form handling. * submit buttons refs madness * removed configure step we had to use query params to manage selected event-types, between routes which was causing 2 issues: * each time we selected or unselected an event the whole page was reloaded including getserversideprops being called again and again * the form was reloaded causing more issues * removed extra unwanted code * small fix * fix: type error * fix: types * implemented suggested changes * removed step footer * fixed error.message * removed commented styles * removed step footer * fix: Display team event types instead of user's on event types step when team selected * fix: typo * removed shouldLockDisableProps * refactor setUpdatedEventTypesStatus, fix type * removed extra code * can't delete while saving * added translations * fix: loading in select account step, fix handle onSelect params type * Fix typo --------- Co-authored-by: Joe Au-Yeung <[email protected]> * fix: type errors * fix: failing tests --------- Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Somay Chauhan <[email protected]>
644 lines
19 KiB
TypeScript
644 lines
19 KiB
TypeScript
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
import type {
|
|
ArrayPath,
|
|
Control,
|
|
ControllerRenderProps,
|
|
FieldArrayWithId,
|
|
FieldPath,
|
|
FieldPathValue,
|
|
FieldValues,
|
|
UseFieldArrayRemove,
|
|
} from "react-hook-form";
|
|
import { Controller, useFieldArray, useFormContext } from "react-hook-form";
|
|
import type { GroupBase, Props } from "react-select";
|
|
|
|
import type { ConfigType } from "@calcom/dayjs";
|
|
import dayjs from "@calcom/dayjs";
|
|
import { defaultDayRange as DEFAULT_DAY_RANGE } from "@calcom/lib/availability";
|
|
import classNames from "@calcom/lib/classNames";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { weekdayNames } from "@calcom/lib/weekday";
|
|
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
|
import type { TimeRange } from "@calcom/types/schedule";
|
|
import {
|
|
Button,
|
|
CheckboxField,
|
|
Dropdown,
|
|
DropdownMenuContent,
|
|
DropdownMenuTrigger,
|
|
Select,
|
|
SkeletonText,
|
|
Switch,
|
|
} from "@calcom/ui";
|
|
|
|
export type { TimeRange };
|
|
|
|
export type ScheduleLabelsType = {
|
|
addTime: string;
|
|
copyTime: string;
|
|
deleteTime: string;
|
|
};
|
|
|
|
export type FieldPathByValue<TFieldValues extends FieldValues, TValue> = {
|
|
[Key in FieldPath<TFieldValues>]: FieldPathValue<TFieldValues, Key> extends TValue ? Key : never;
|
|
}[FieldPath<TFieldValues>];
|
|
|
|
export const ScheduleDay = <TFieldValues extends FieldValues>({
|
|
name,
|
|
weekday,
|
|
control,
|
|
CopyButton,
|
|
disabled,
|
|
labels,
|
|
userTimeFormat,
|
|
className,
|
|
}: {
|
|
name: ArrayPath<TFieldValues>;
|
|
weekday: string;
|
|
control: Control<TFieldValues>;
|
|
CopyButton: JSX.Element;
|
|
disabled?: boolean;
|
|
labels?: ScheduleLabelsType;
|
|
userTimeFormat: number | null;
|
|
className?: {
|
|
scheduleDay?: string;
|
|
dayRanges?: string;
|
|
timeRangeField?: string;
|
|
labelAndSwitchContainer?: string;
|
|
};
|
|
}) => {
|
|
const { watch, setValue } = useFormContext();
|
|
const watchDayRange = watch(name);
|
|
|
|
return (
|
|
<div
|
|
className={classNames(
|
|
"mb-4 flex w-full flex-col gap-4 last:mb-0 sm:flex-row sm:px-0",
|
|
className?.scheduleDay
|
|
)}
|
|
data-testid={weekday}>
|
|
{/* Label & switch container */}
|
|
<div
|
|
className={classNames(
|
|
"flex h-[36px] items-center justify-between sm:w-32",
|
|
className?.labelAndSwitchContainer
|
|
)}>
|
|
<div>
|
|
<label className="text-default flex flex-row items-center space-x-2 rtl:space-x-reverse">
|
|
<div>
|
|
<Switch
|
|
disabled={!watchDayRange || disabled}
|
|
defaultChecked={watchDayRange && watchDayRange.length > 0}
|
|
checked={watchDayRange && !!watchDayRange.length}
|
|
onCheckedChange={(isChecked) => {
|
|
setValue(name, (isChecked ? [DEFAULT_DAY_RANGE] : []) as TFieldValues[typeof name]);
|
|
}}
|
|
/>
|
|
</div>
|
|
<span className="inline-block min-w-[88px] text-sm capitalize">{weekday}</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<>
|
|
{watchDayRange ? (
|
|
<div className="flex sm:ml-2">
|
|
<DayRanges
|
|
userTimeFormat={userTimeFormat}
|
|
labels={labels}
|
|
control={control}
|
|
name={name}
|
|
disabled={disabled}
|
|
className={{
|
|
dayRanges: className?.dayRanges,
|
|
timeRangeField: className?.timeRangeField,
|
|
}}
|
|
/>
|
|
{!!watchDayRange.length && !disabled && <div className="block">{CopyButton}</div>}
|
|
</div>
|
|
) : (
|
|
<SkeletonText className="ml-1 mt-2.5 h-6 w-48" />
|
|
)}
|
|
</>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const CopyButton = ({
|
|
getValuesFromDayRange,
|
|
weekStart,
|
|
labels,
|
|
}: {
|
|
getValuesFromDayRange: string;
|
|
weekStart: number;
|
|
labels?: ScheduleLabelsType;
|
|
}) => {
|
|
const { t } = useLocale();
|
|
const [open, setOpen] = useState(false);
|
|
const fieldArrayName = getValuesFromDayRange.substring(0, getValuesFromDayRange.lastIndexOf("."));
|
|
const { setValue, getValues } = useFormContext();
|
|
return (
|
|
<Dropdown open={open} onOpenChange={setOpen}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
className={classNames(
|
|
"text-default",
|
|
open && "ring-brand-500 !bg-subtle outline-none ring-2 ring-offset-1"
|
|
)}
|
|
data-testid="copy-button"
|
|
type="button"
|
|
tooltip={labels?.copyTime ?? t("copy_times_to_tooltip")}
|
|
color="minimal"
|
|
variant="icon"
|
|
StartIcon="copy"
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<CopyTimes
|
|
weekStart={weekStart}
|
|
disabled={parseInt(getValuesFromDayRange.replace(`${fieldArrayName}.`, ""), 10)}
|
|
onClick={(selected) => {
|
|
selected.forEach((day) => setValue(`${fieldArrayName}.${day}`, getValues(getValuesFromDayRange)));
|
|
setOpen(false);
|
|
}}
|
|
onCancel={() => setOpen(false)}
|
|
/>
|
|
</DropdownMenuContent>
|
|
</Dropdown>
|
|
);
|
|
};
|
|
|
|
const Schedule = <
|
|
TFieldValues extends FieldValues,
|
|
TPath extends FieldPathByValue<TFieldValues, TimeRange[][]>
|
|
>(props: {
|
|
name: TPath;
|
|
control: Control<TFieldValues>;
|
|
weekStart?: number;
|
|
disabled?: boolean;
|
|
labels?: ScheduleLabelsType;
|
|
userTimeFormat?: number | null;
|
|
}) => {
|
|
const query = useMeQuery();
|
|
const { timeFormat } = query.data || { timeFormat: null };
|
|
|
|
return <ScheduleComponent userTimeFormat={timeFormat} {...props} />;
|
|
};
|
|
|
|
export const ScheduleComponent = <
|
|
TFieldValues extends FieldValues,
|
|
TPath extends FieldPathByValue<TFieldValues, TimeRange[][]>
|
|
>({
|
|
name,
|
|
control,
|
|
disabled,
|
|
weekStart = 0,
|
|
labels,
|
|
userTimeFormat,
|
|
className,
|
|
}: {
|
|
name: TPath;
|
|
control: Control<TFieldValues>;
|
|
weekStart?: number;
|
|
disabled?: boolean;
|
|
labels?: ScheduleLabelsType;
|
|
userTimeFormat: number | null;
|
|
className?: {
|
|
schedule?: string;
|
|
scheduleDay?: string;
|
|
dayRanges?: string;
|
|
timeRanges?: string;
|
|
labelAndSwitchContainer?: string;
|
|
};
|
|
}) => {
|
|
const { i18n } = useLocale();
|
|
|
|
return (
|
|
<div className={classNames("p-4", className?.schedule)}>
|
|
{/* First iterate for each day */}
|
|
{weekdayNames(i18n.language, weekStart, "long").map((weekday, num) => {
|
|
const weekdayIndex = (num + weekStart) % 7;
|
|
const dayRangeName = `${name}.${weekdayIndex}` as ArrayPath<TFieldValues>;
|
|
return (
|
|
<ScheduleDay
|
|
className={{
|
|
scheduleDay: className?.scheduleDay,
|
|
dayRanges: className?.dayRanges,
|
|
timeRangeField: className?.timeRanges,
|
|
labelAndSwitchContainer: className?.labelAndSwitchContainer,
|
|
}}
|
|
userTimeFormat={userTimeFormat}
|
|
labels={labels}
|
|
disabled={disabled}
|
|
name={dayRangeName}
|
|
key={weekday}
|
|
weekday={weekday}
|
|
control={control}
|
|
CopyButton={
|
|
<CopyButton weekStart={weekStart} labels={labels} getValuesFromDayRange={dayRangeName} />
|
|
}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const DayRanges = <TFieldValues extends FieldValues>({
|
|
name,
|
|
disabled,
|
|
control,
|
|
labels,
|
|
userTimeFormat,
|
|
className,
|
|
}: {
|
|
name: ArrayPath<TFieldValues>;
|
|
control?: Control<TFieldValues>;
|
|
disabled?: boolean;
|
|
labels?: ScheduleLabelsType;
|
|
userTimeFormat: number | null;
|
|
className?: {
|
|
dayRanges?: string;
|
|
timeRangeField?: string;
|
|
};
|
|
}) => {
|
|
const { t } = useLocale();
|
|
const { getValues } = useFormContext();
|
|
|
|
const { remove, fields, prepend, append } = useFieldArray({
|
|
control,
|
|
name,
|
|
});
|
|
|
|
return (
|
|
<div className={classNames("", className?.dayRanges)}>
|
|
{fields.map((field, index: number) => (
|
|
<Fragment key={field.id}>
|
|
<div className="mb-2 flex last:mb-0">
|
|
<Controller
|
|
name={`${name}.${index}`}
|
|
render={({ field }) => (
|
|
<TimeRangeField
|
|
className={className?.timeRangeField}
|
|
userTimeFormat={userTimeFormat}
|
|
{...field}
|
|
/>
|
|
)}
|
|
/>
|
|
{index === 0 && (
|
|
<Button
|
|
disabled={disabled}
|
|
data-testid="add-time-availability"
|
|
tooltip={labels?.addTime ?? t("add_time_availability")}
|
|
className="text-default mx-2 "
|
|
type="button"
|
|
color="minimal"
|
|
variant="icon"
|
|
StartIcon="plus"
|
|
onClick={() => {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const slotRange: any = getDateSlotRange(
|
|
getValues(`${name}.${fields.length - 1}`),
|
|
getValues(`${name}.0`)
|
|
);
|
|
|
|
if (slotRange?.append) {
|
|
append(slotRange.append);
|
|
}
|
|
|
|
if (slotRange?.prepend) {
|
|
prepend(slotRange.prepend);
|
|
}
|
|
}}
|
|
/>
|
|
)}
|
|
{index !== 0 && (
|
|
<RemoveTimeButton index={index} remove={remove} className="text-default mx-2 border-none" />
|
|
)}
|
|
</div>
|
|
</Fragment>
|
|
))}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const RemoveTimeButton = ({
|
|
index,
|
|
remove,
|
|
disabled,
|
|
className,
|
|
labels,
|
|
}: {
|
|
index: number | number[];
|
|
remove: UseFieldArrayRemove;
|
|
className?: string;
|
|
disabled?: boolean;
|
|
labels?: ScheduleLabelsType;
|
|
}) => {
|
|
const { t } = useLocale();
|
|
return (
|
|
<Button
|
|
disabled={disabled}
|
|
type="button"
|
|
variant="icon"
|
|
color="destructive"
|
|
StartIcon="trash"
|
|
onClick={() => remove(index)}
|
|
className={className}
|
|
tooltip={labels?.deleteTime ?? t("delete")}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const TimeRangeField = ({
|
|
className,
|
|
value,
|
|
onChange,
|
|
disabled,
|
|
userTimeFormat,
|
|
}: { className?: string; disabled?: boolean; userTimeFormat: number | null } & ControllerRenderProps) => {
|
|
// this is a controlled component anyway given it uses LazySelect, so keep it RHF agnostic.
|
|
return (
|
|
<div className={classNames("flex flex-row gap-1", className)}>
|
|
<LazySelect
|
|
userTimeFormat={userTimeFormat}
|
|
className="inline-block w-[100px]"
|
|
isDisabled={disabled}
|
|
value={value.start}
|
|
max={value.end}
|
|
onChange={(option) => {
|
|
onChange({ ...value, start: new Date(option?.value as number) });
|
|
}}
|
|
/>
|
|
<span className="text-default mx-2 w-2 self-center"> - </span>
|
|
<LazySelect
|
|
userTimeFormat={userTimeFormat}
|
|
className="inline-block w-[100px] rounded-md"
|
|
isDisabled={disabled}
|
|
value={value.end}
|
|
min={value.start}
|
|
onChange={(option) => {
|
|
onChange({ ...value, end: new Date(option?.value as number) });
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const LazySelect = ({
|
|
value,
|
|
min,
|
|
max,
|
|
userTimeFormat,
|
|
...props
|
|
}: Omit<Props<IOption, false, GroupBase<IOption>>, "value"> & {
|
|
value: ConfigType;
|
|
min?: ConfigType;
|
|
max?: ConfigType;
|
|
userTimeFormat: number | null;
|
|
}) => {
|
|
// Lazy-loaded options, otherwise adding a field has a noticeable redraw delay.
|
|
const { options, filter } = useOptions(userTimeFormat);
|
|
|
|
useEffect(() => {
|
|
filter({ current: value });
|
|
}, [filter, value]);
|
|
|
|
return (
|
|
<Select
|
|
options={options}
|
|
onMenuOpen={() => {
|
|
if (min) filter({ offset: min });
|
|
if (max) filter({ limit: max });
|
|
}}
|
|
value={options.find((option) => option.value === dayjs(value).toDate().valueOf())}
|
|
onMenuClose={() => filter({ current: value })}
|
|
components={{ DropdownIndicator: () => null, IndicatorSeparator: () => null }}
|
|
{...props}
|
|
/>
|
|
);
|
|
};
|
|
|
|
interface IOption {
|
|
readonly label: string;
|
|
readonly value: number;
|
|
}
|
|
|
|
/**
|
|
* Creates an array of times on a 15 minute interval from
|
|
* 00:00:00 (Start of day) to
|
|
* 23:45:00 (End of day with enough time for 15 min booking)
|
|
*/
|
|
/** Begin Time Increments For Select */
|
|
const INCREMENT = Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL) || 15;
|
|
const useOptions = (timeFormat: number | null) => {
|
|
const [filteredOptions, setFilteredOptions] = useState<IOption[]>([]);
|
|
|
|
const options = useMemo(() => {
|
|
const end = dayjs().utc().endOf("day");
|
|
const options: IOption[] = [];
|
|
for (
|
|
let t = dayjs().utc().startOf("day");
|
|
t.isBefore(end);
|
|
t = t.add(INCREMENT + (!t.add(INCREMENT).isSame(t, "day") ? -1 : 0), "minutes")
|
|
) {
|
|
options.push({
|
|
value: t.toDate().valueOf(),
|
|
label: dayjs(t)
|
|
.utc()
|
|
.format(timeFormat === 12 ? "h:mma" : "HH:mm"),
|
|
});
|
|
}
|
|
// allow 23:59
|
|
options.push({
|
|
value: end.toDate().valueOf(),
|
|
label: dayjs(end)
|
|
.utc()
|
|
.format(timeFormat === 12 ? "h:mma" : "HH:mm"),
|
|
});
|
|
return options;
|
|
}, [timeFormat]);
|
|
|
|
const filter = useCallback(
|
|
({ offset, limit, current }: { offset?: ConfigType; limit?: ConfigType; current?: ConfigType }) => {
|
|
if (current) {
|
|
const currentOption = options.find((option) => option.value === dayjs(current).toDate().valueOf());
|
|
if (currentOption) setFilteredOptions([currentOption]);
|
|
} else
|
|
setFilteredOptions(
|
|
options.filter((option) => {
|
|
const time = dayjs(option.value);
|
|
return (!limit || time.isBefore(limit)) && (!offset || time.isAfter(offset));
|
|
})
|
|
);
|
|
},
|
|
[options]
|
|
);
|
|
|
|
return { options: filteredOptions, filter };
|
|
};
|
|
|
|
const getDateSlotRange = (endField?: FieldArrayWithId, startField?: FieldArrayWithId) => {
|
|
const timezoneStartRange = dayjs((startField as unknown as TimeRange).start).utc();
|
|
const nextRangeStart = dayjs((endField as unknown as TimeRange).end).utc();
|
|
const nextRangeEnd =
|
|
nextRangeStart.hour() === 23
|
|
? dayjs(nextRangeStart).add(59, "minutes").add(59, "seconds").add(999, "milliseconds")
|
|
: dayjs(nextRangeStart).add(1, "hour");
|
|
|
|
const endOfDay = nextRangeStart.endOf("day");
|
|
|
|
if (!nextRangeStart.isSame(endOfDay)) {
|
|
return {
|
|
append: {
|
|
start: nextRangeStart.toDate(),
|
|
end: nextRangeEnd.isAfter(endOfDay) ? endOfDay.toDate() : nextRangeEnd.toDate(),
|
|
},
|
|
};
|
|
}
|
|
|
|
const previousRangeStart = dayjs((startField as unknown as TimeRange).start).subtract(1, "hour");
|
|
const startOfDay = timezoneStartRange.startOf("day");
|
|
|
|
if (!timezoneStartRange.isSame(startOfDay)) {
|
|
return {
|
|
prepend: {
|
|
start: previousRangeStart.isBefore(startOfDay) ? startOfDay.toDate() : previousRangeStart.toDate(),
|
|
end: timezoneStartRange.toDate(),
|
|
},
|
|
};
|
|
}
|
|
};
|
|
|
|
const CopyTimes = ({
|
|
disabled,
|
|
onClick,
|
|
onCancel,
|
|
weekStart,
|
|
}: {
|
|
disabled: number;
|
|
onClick: (selected: number[]) => void;
|
|
onCancel: () => void;
|
|
weekStart: number;
|
|
}) => {
|
|
const [selected, setSelected] = useState<number[]>([]);
|
|
const { i18n, t } = useLocale();
|
|
const itteratablesByKeyRef = useRef<(HTMLInputElement | HTMLButtonElement)[]>([]);
|
|
useEffect(() => {
|
|
document.addEventListener("keydown", handleKeyDown);
|
|
return () => {
|
|
document.removeEventListener("keydown", handleKeyDown);
|
|
};
|
|
}, []);
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
const itteratables = itteratablesByKeyRef.current;
|
|
const isActionRequired =
|
|
event.key === "Tab" || event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Enter";
|
|
if (!isActionRequired || !itteratables.length) return;
|
|
event.preventDefault();
|
|
const currentFocused = document.activeElement as HTMLInputElement | HTMLButtonElement;
|
|
let currentIndex = itteratables.findIndex((checkbox) => checkbox === currentFocused);
|
|
if (event.key === "Enter") {
|
|
if (currentIndex === -1) return;
|
|
currentFocused.click();
|
|
return;
|
|
}
|
|
if (currentIndex === -1) {
|
|
itteratables[0].focus();
|
|
} else {
|
|
// Move focus based on the arrow key pressed
|
|
if (event.key === "ArrowUp") {
|
|
currentIndex = (currentIndex - 1 + itteratables.length) % itteratables.length;
|
|
} else if (event.key === "ArrowDown" || event.key === "Tab") {
|
|
currentIndex = (currentIndex + 1) % itteratables.length;
|
|
}
|
|
itteratables[currentIndex].focus();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-2 py-2">
|
|
<div className="p-2">
|
|
<p className="h6 text-emphasis pb-3 pl-1 text-xs font-medium uppercase">{t("copy_times_to")}</p>
|
|
<ol className="space-y-2">
|
|
<li key="select all">
|
|
<label className="text-default flex w-full items-center justify-between">
|
|
<span className="px-1">{t("select_all")}</span>
|
|
<CheckboxField
|
|
description=""
|
|
value={t("select_all")}
|
|
checked={selected.length === 7}
|
|
onChange={(e) => {
|
|
if (e.target.checked) {
|
|
setSelected([0, 1, 2, 3, 4, 5, 6]);
|
|
} else if (!e.target.checked) {
|
|
setSelected([]);
|
|
}
|
|
}}
|
|
ref={(ref) => {
|
|
if (ref) {
|
|
itteratablesByKeyRef.current.push(ref as HTMLInputElement);
|
|
}
|
|
}}
|
|
/>
|
|
</label>
|
|
</li>
|
|
{weekdayNames(i18n.language, weekStart).map((weekday, num) => {
|
|
const weekdayIndex = (num + weekStart) % 7;
|
|
return (
|
|
<li key={weekday}>
|
|
<label className="text-default flex w-full items-center justify-between">
|
|
<span className="px-1">{weekday}</span>
|
|
<CheckboxField
|
|
description=""
|
|
value={weekdayIndex}
|
|
checked={selected.includes(weekdayIndex) || disabled === weekdayIndex}
|
|
disabled={disabled === weekdayIndex}
|
|
onChange={(e) => {
|
|
if (e.target.checked && !selected.includes(weekdayIndex)) {
|
|
setSelected(selected.concat([weekdayIndex]));
|
|
} else if (!e.target.checked && selected.includes(weekdayIndex)) {
|
|
setSelected(selected.filter((item) => item !== weekdayIndex));
|
|
}
|
|
}}
|
|
ref={(ref) => {
|
|
if (ref && disabled !== weekdayIndex) {
|
|
//we don't need to iterate over disabled elements
|
|
itteratablesByKeyRef.current.push(ref as HTMLInputElement);
|
|
}
|
|
}}
|
|
/>
|
|
</label>
|
|
</li>
|
|
);
|
|
})}
|
|
</ol>
|
|
</div>
|
|
<hr className="border-subtle" />
|
|
<div className="space-x-2 px-2 rtl:space-x-reverse">
|
|
<Button
|
|
color="minimal"
|
|
onClick={() => onCancel()}
|
|
ref={(ref) => {
|
|
if (ref) {
|
|
itteratablesByKeyRef.current.push(ref as HTMLButtonElement);
|
|
}
|
|
}}>
|
|
{t("cancel")}
|
|
</Button>
|
|
<Button
|
|
color="primary"
|
|
onClick={() => onClick(selected)}
|
|
ref={(ref) => {
|
|
if (ref) {
|
|
itteratablesByKeyRef.current.push(ref as HTMLButtonElement);
|
|
}
|
|
}}>
|
|
{t("apply")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Schedule;
|