* Icon and IconName * Button and ButtonGroup * UserAvatar * AvatarGroup * Avatar * WizardLayout * Dialogs * EmptyScreen * showToast and TextField * Editor * Skeleton * Skeleton * TopBanner and showToast * Button again * more * perf: Remove app-store reference from @calcom/ui * more * Fixing types * Icon * Fixed casing * dropdown * more * Select * more * Badge * List * more * Divider * more * fix * fix type check * refactor * fix * fix * fix * fix * fix * fix * fix * fix type check * fix * fix * fix * fix * more * more * more * more * add index file to components/command * fix * fix * fix * fix imports * fix * fix * fix * fix * fix * fix * fix * fix build errors * fix build errors * fix --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
101 lines
3.1 KiB
TypeScript
101 lines
3.1 KiB
TypeScript
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { Button } from "../button";
|
|
import { EmailField } from "../form";
|
|
import { Icon } from "../icon";
|
|
import { Tooltip } from "../tooltip";
|
|
|
|
interface MultiEmailProps {
|
|
value: string[];
|
|
readOnly: boolean;
|
|
label: string;
|
|
setValue: (value: string[]) => void;
|
|
placeholder?: string;
|
|
}
|
|
|
|
function MultiEmail({ value, readOnly, label, setValue, placeholder }: MultiEmailProps) {
|
|
const { t } = useLocale();
|
|
value = value || [];
|
|
const inputClassName =
|
|
"dark:placeholder:text-muted focus:border-emphasis border-subtle block w-full rounded-md border-default text-sm focus:ring-black disabled:bg-emphasis disabled:hover:cursor-not-allowed dark:selection:bg-green-500 disabled:dark:text-subtle";
|
|
return (
|
|
<>
|
|
{value.length ? (
|
|
<div>
|
|
<label htmlFor="emails" className="text-default my-2 block text-sm font-medium">
|
|
{label}
|
|
</label>
|
|
<ul>
|
|
{value.map((field, index) => (
|
|
<li key={index}>
|
|
<EmailField
|
|
disabled={readOnly}
|
|
value={field}
|
|
className={inputClassName}
|
|
onChange={(e) => {
|
|
const updatedValue = [...value];
|
|
updatedValue[index] = e.target.value;
|
|
setValue(updatedValue);
|
|
}}
|
|
placeholder={placeholder}
|
|
label={<></>}
|
|
required
|
|
onClickAddon={() => {
|
|
const updatedValue = [...value];
|
|
updatedValue.splice(index, 1);
|
|
setValue(updatedValue);
|
|
}}
|
|
addOnSuffix={
|
|
!readOnly ? (
|
|
<Tooltip content="Remove email">
|
|
<button className="m-1" type="button">
|
|
<Icon name="x" width={12} className="text-default" />
|
|
</button>
|
|
</Tooltip>
|
|
) : null
|
|
}
|
|
/>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{!readOnly && (
|
|
<Button
|
|
data-testid="add-another-email"
|
|
type="button"
|
|
color="minimal"
|
|
StartIcon="user-plus"
|
|
className="my-2.5"
|
|
onClick={() => {
|
|
const updatedValue = [...value];
|
|
updatedValue.push("");
|
|
setValue(updatedValue);
|
|
}}>
|
|
{t("add_another")}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<></>
|
|
)}
|
|
|
|
{!value.length && !readOnly && (
|
|
<Button
|
|
data-testid="add-emails"
|
|
color="minimal"
|
|
variant="button"
|
|
StartIcon="user-plus"
|
|
onClick={() => {
|
|
const updatedValue = [...value];
|
|
updatedValue.push("");
|
|
setValue(updatedValue);
|
|
}}
|
|
className="mr-auto">
|
|
{label}
|
|
</Button>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default MultiEmail;
|