feat: automatic no show (#16727)
Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: zomars <[email protected]>
This commit is contained in:
43 files changed
+1103
-69
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
import { useFormContext } from "react-hook-form";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { TimeUnit } from "@calcom/prisma/enums";
|
||||
@@ -13,27 +13,23 @@ import {
|
||||
TextField,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import type { FormValues } from "../pages/workflow";
|
||||
|
||||
const TIME_UNITS = [TimeUnit.DAY, TimeUnit.HOUR, TimeUnit.MINUTE] as const;
|
||||
|
||||
type Props = {
|
||||
form: UseFormReturn<FormValues>;
|
||||
disabled: boolean;
|
||||
};
|
||||
|
||||
const TimeUnitAddonSuffix = ({
|
||||
DropdownItems,
|
||||
timeUnitOptions,
|
||||
form,
|
||||
}: {
|
||||
form: UseFormReturn<FormValues>;
|
||||
DropdownItems: JSX.Element;
|
||||
timeUnitOptions: { [x: string]: string };
|
||||
}) => {
|
||||
// because isDropdownOpen already triggers a render cycle we can use getValues()
|
||||
// instead of watch() function
|
||||
const timeUnit = form.getValues("timeUnit");
|
||||
const form = useFormContext();
|
||||
const timeUnit = form.getValues("timeUnit") ?? TimeUnit.MINUTE;
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
||||
return (
|
||||
<Dropdown onOpenChange={setIsDropdownOpen}>
|
||||
@@ -51,7 +47,8 @@ const TimeUnitAddonSuffix = ({
|
||||
};
|
||||
|
||||
export const TimeTimeUnitInput = (props: Props) => {
|
||||
const { form } = props;
|
||||
const form = useFormContext();
|
||||
|
||||
const { t } = useLocale();
|
||||
const timeUnitOptions = TIME_UNITS.reduce((acc, option) => {
|
||||
acc[option] = t(`${option.toLowerCase()}_timeUnit`);
|
||||
@@ -70,7 +67,6 @@ export const TimeTimeUnitInput = (props: Props) => {
|
||||
{...form.register("time", { valueAsNumber: true })}
|
||||
addOnSuffix={
|
||||
<TimeUnitAddonSuffix
|
||||
form={form}
|
||||
timeUnitOptions={timeUnitOptions}
|
||||
DropdownItems={
|
||||
<>
|
||||
@@ -80,7 +76,7 @@ export const TimeTimeUnitInput = (props: Props) => {
|
||||
key={index}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
form.setValue("timeUnit", timeUnit);
|
||||
form.setValue("timeUnit", timeUnit, { shouldDirty: true });
|
||||
}}>
|
||||
{timeUnitOptions[timeUnit]}
|
||||
</DropdownItem>
|
||||
|
||||
Reference in new issue
Block a user