1 import React, { useState } from 'react';
3 import { c } from 'ttag';
5 import { Button } from '@proton/atoms';
6 import type { ModalStateProps } from '@proton/components';
17 } from '@proton/components';
18 import { useLoading } from '@proton/hooks';
19 import { requiredValidator } from '@proton/shared/lib/helpers/formValidators';
20 import noop from '@proton/utils/noop';
22 import type { Device } from '../../../store';
23 import { useActions } from '../../../store';
30 const RenameDeviceModal = ({ device, onClose, ...modalProps }: Props & ModalStateProps) => {
31 const { renameDevice } = useActions();
32 const [submitting, withSubmitting] = useLoading();
34 const { validator, onFormSubmit } = useFormErrors();
35 const [model, setModel] = useState(() => {
41 const handleSubmit = async () => {
42 if (!onFormSubmit()) {
47 shareId: device.shareId,
48 linkId: device.linkId,
51 haveLegacyName: device.haveLegacyName,
57 const deviceNameValidation = validator([requiredValidator(model.name)]);
62 disableCloseOnEscape={submitting}
65 onSubmit={() => withSubmitting(handleSubmit()).catch(noop)}
69 <ModalTwoHeader closeButtonProps={{ disabled: submitting }} title={c('Title').t`Rename device`} />
71 <Row className="my-4">
75 label={c('Label').t`Device name`}
76 placeholder={c('Placeholder').t`Enter device name`}
77 title={c('Label').t`Enter device name`}
78 error={deviceNameValidation}
80 onValue={(value: string) => setModel({ name: value })}
85 <Button type="button" onClick={onClose} disabled={submitting}>
86 {c('Action').t`Cancel`}
88 <Button type="submit" loading={submitting} disabled={device.name === model.name} color="norm">
89 {c('Action').t`Rename`}
96 export default RenameDeviceModal;
97 export const useRenameDeviceModal = () => {
98 return useModalTwoStatic(RenameDeviceModal);