// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { ReactElement } from 'react'; import React, { useRef } from 'react'; import type { LocalizerType } from '../../types/Util'; import { MAX_DEVICE_NAME_LENGTH } from '../../types/InstallScreen'; import { normalizeDeviceName } from '../../util/normalizeDeviceName'; import { getEnvironment, Environment } from '../../environment'; import { Button, ButtonVariant } from '../Button'; import { TitlebarDragArea } from '../TitlebarDragArea'; import { InstallScreenSignalLogo } from './InstallScreenSignalLogo'; export type PropsType = { deviceName: string; i18n: LocalizerType; onSubmit: () => void; setBackupFile: (file: File) => void; setDeviceName: (value: string) => void; }; export function InstallScreenChoosingDeviceNameStep({ deviceName, i18n, onSubmit, setBackupFile, setDeviceName, }: Readonly): ReactElement { const hasFocusedRef = useRef(false); const focusRef = (el: null | HTMLElement) => { if (el) { el.focus(); hasFocusedRef.current = true; } }; const normalizedName = normalizeDeviceName(deviceName); const canSubmit = normalizedName.length > 0 && normalizedName.length <= MAX_DEVICE_NAME_LENGTH; let maybeBackupInput: JSX.Element | undefined; if (getEnvironment() !== Environment.PackagedApp) { maybeBackupInput = ( ); } return (
{ event.preventDefault(); onSubmit(); }} >

{i18n('icu:Install__choose-device-name__description')}

{maybeBackupInput} { setDeviceName(event.target.value); }} placeholder={i18n('icu:Install__choose-device-name__placeholder')} ref={focusRef} spellCheck={false} value={deviceName} dir="auto" />
); }