// Copyright 2024 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useCallback, useMemo, useState } from 'react'; import { v4 as generateUuid } from 'uuid'; import { Modal } from './Modal'; import type { LocalizerType } from '../types/I18N'; import { Button, ButtonVariant } from './Button'; import { Avatar, AvatarSize } from './Avatar'; import { Input } from './Input'; import { CallLinkNameMaxByteLength, CallLinkNameMaxLength, type CallLinkType, } from '../types/CallLink'; import { getColorForCallLink } from '../util/getColorForCallLink'; export type CallLinkAddNameModalProps = Readonly<{ i18n: LocalizerType; callLink: CallLinkType; onClose: () => void; onUpdateCallLinkName: (name: string) => void; }>; export function CallLinkAddNameModal({ i18n, callLink, onClose, onUpdateCallLinkName, }: CallLinkAddNameModalProps): JSX.Element { const [formId] = useState(() => generateUuid()); const [nameId] = useState(() => generateUuid()); const [nameInput, setNameInput] = useState(callLink.name); const parsedForm = useMemo(() => { const name = nameInput.trim(); if (name === callLink.name) { return null; } return { name }; }, [nameInput, callLink]); const handleNameInputChange = useCallback((nextNameInput: string) => { setNameInput(nextNameInput); }, []); const handleSubmit = useCallback(() => { if (parsedForm == null) { return; } onUpdateCallLinkName(parsedForm.name); onClose(); }, [parsedForm, onUpdateCallLinkName, onClose]); return ( } >
); }