2022-08-03 22:22:38 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui";
|
|
|
|
import { FiChevronDown } from "@calcom/ui/components/icon";
|
2022-08-03 22:22:38 +00:00
|
|
|
|
|
|
|
interface IAddVariablesDropdown {
|
2023-01-09 14:15:11 +00:00
|
|
|
addVariable: (variable: string) => void;
|
2022-11-25 14:34:55 +00:00
|
|
|
isTextEditor?: boolean;
|
2023-01-09 14:15:11 +00:00
|
|
|
variables: string[];
|
2022-08-03 22:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dropdown>
|
2022-11-23 02:55:25 +00:00
|
|
|
<DropdownMenuTrigger className="pt-[6px] focus:bg-gray-50">
|
2022-11-25 14:34:55 +00:00
|
|
|
<div className="items-center ">
|
|
|
|
{props.isTextEditor ? (
|
|
|
|
<>
|
|
|
|
<div className="hidden sm:flex">
|
|
|
|
{t("add_variable")}
|
2023-01-23 23:08:01 +00:00
|
|
|
<FiChevronDown className="mt-[2px] ml-1 h-4 w-4" />
|
2022-11-25 14:34:55 +00:00
|
|
|
</div>
|
|
|
|
<div className="block sm:hidden">+</div>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<div className="flex">
|
|
|
|
{t("add_variable")}
|
2023-01-23 23:08:01 +00:00
|
|
|
<FiChevronDown className="mt-[2px] ml-1 h-4 w-4" />
|
2022-11-25 14:34:55 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2022-11-23 02:55:25 +00:00
|
|
|
</div>
|
2022-08-03 22:22:38 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent className="h-40 overflow-scroll">
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="pt-4 pb-1">
|
|
|
|
<div className="mb-2 px-4 text-left text-xs text-gray-500">
|
|
|
|
{t("add_dynamic_variables").toLocaleUpperCase()}
|
|
|
|
</div>
|
2023-01-09 14:15:11 +00:00
|
|
|
{props.variables.map((variable) => (
|
2022-11-23 02:55:25 +00:00
|
|
|
<DropdownMenuItem key={variable} className="hover:ring-0">
|
|
|
|
<button
|
|
|
|
key={variable}
|
|
|
|
type="button"
|
|
|
|
className="w-full px-4 py-2"
|
2023-01-09 14:15:11 +00:00
|
|
|
onClick={() => props.addVariable(t(`${variable}_variable`))}>
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="sm:grid sm:grid-cols-2">
|
|
|
|
<div className="mr-3 text-left md:col-span-1">
|
2023-01-09 14:15:11 +00:00
|
|
|
{`{${t(`${variable}_variable`).toUpperCase().replace(/ /g, "_")}}`}
|
2022-11-23 02:55:25 +00:00
|
|
|
</div>
|
|
|
|
<div className="hidden text-left text-gray-600 sm:col-span-1 sm:flex">
|
|
|
|
{t(`${variable}_info`)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
))}
|
|
|
|
</div>
|
2022-08-03 22:22:38 +00:00
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
);
|
|
|
|
};
|