2022-08-31 19:42:37 +00:00
|
|
|
import { useState } from "react";
|
2023-04-12 15:26:31 +00:00
|
|
|
import type { UseFormReturn } from "react-hook-form";
|
2022-08-31 19:42:37 +00:00
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Dropdown,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
2023-01-15 11:40:40 +00:00
|
|
|
DropdownItem,
|
2022-11-23 02:55:25 +00:00
|
|
|
DropdownMenuTrigger,
|
|
|
|
TextField,
|
|
|
|
} from "@calcom/ui";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { ChevronDown } from "@calcom/ui/components/icon";
|
2022-08-31 19:42:37 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
import { getWorkflowTimeUnitOptions } from "../lib/getOptions";
|
|
|
|
import type { FormValues } from "../pages/workflow";
|
2022-08-31 19:42:37 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
form: UseFormReturn<FormValues>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const TimeTimeUnitInput = (props: Props) => {
|
|
|
|
const { form } = props;
|
|
|
|
const { t } = useLocale();
|
|
|
|
const timeUnitOptions = getWorkflowTimeUnitOptions(t);
|
|
|
|
|
|
|
|
const [timeUnit, setTimeUnit] = useState(form.getValues("timeUnit"));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex">
|
|
|
|
<div className="grow">
|
|
|
|
<TextField
|
|
|
|
type="number"
|
|
|
|
min="1"
|
|
|
|
label=""
|
|
|
|
defaultValue={form.getValues("time") || 24}
|
|
|
|
className="-mt-2 rounded-r-none text-sm focus:ring-0"
|
|
|
|
{...form.register("time", { valueAsNumber: true })}
|
2023-01-17 17:08:00 +00:00
|
|
|
addOnSuffix={
|
|
|
|
<Dropdown>
|
|
|
|
<DropdownMenuTrigger asChild>
|
2023-04-28 11:26:31 +00:00
|
|
|
<button className="flex items-center">
|
2023-01-17 17:08:00 +00:00
|
|
|
<div className="mr-1 w-3/4">
|
|
|
|
{timeUnit ? t(`${timeUnit.toLowerCase()}_timeUnit`) : "undefined"}{" "}
|
|
|
|
</div>
|
|
|
|
<div className="w-1/4 pt-1">
|
2023-04-12 15:26:31 +00:00
|
|
|
<ChevronDown />
|
2023-01-17 17:08:00 +00:00
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
{timeUnitOptions.map((option, index) => (
|
|
|
|
<DropdownMenuItem key={index} className="outline-none">
|
|
|
|
<DropdownItem
|
|
|
|
key={index}
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
setTimeUnit(option.value);
|
|
|
|
form.setValue("timeUnit", option.value);
|
|
|
|
}}>
|
|
|
|
{option.label}
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
))}
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
}
|
2022-08-31 19:42:37 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|