import type { IWebdavAccountPayload } from '@rocket.chat/core-typings'; import { Modal, Field, FieldGroup, FieldLabel, FieldRow, FieldError, TextInput, PasswordInput, Button, Box, ModalHeader, ModalTitle, ModalClose, ModalContent, ModalFooter, ModalFooterControllers, } from '@rocket.chat/fuselage'; import { useToastMessageDispatch, useMethod } from '@rocket.chat/ui-contexts'; import { useState } from 'react'; import type { SubmitHandler } from 'react-hook-form'; import { useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; type AddWebdavAccountModalPayload = IWebdavAccountPayload; export type AddWebdavAccountModalProps = { onClose: () => void; onConfirm: () => void; }; const AddWebdavAccountModal = ({ onClose, onConfirm }: AddWebdavAccountModalProps) => { const handleAddWebdavAccount = useMethod('addWebdavAccount'); const dispatchToastMessage = useToastMessageDispatch(); const [isLoading, setIsLoading] = useState(false); const { register, handleSubmit, formState: { errors }, } = useForm(); const { t } = useTranslation(); const onSubmit: SubmitHandler = async (data) => { setIsLoading(true); try { await handleAddWebdavAccount(data); return dispatchToastMessage({ type: 'success', message: t('webdav-account-saved') }); } catch (error) { return dispatchToastMessage({ type: 'error', message: error }); } finally { onConfirm(); setIsLoading(false); } }; return ( }> {t('Webdav_add_new_account')} {t('Name_optional')} {t('Webdav_Server_URL')} {errors.serverURL && {errors.serverURL.message}} {t('Username')} {errors.username && {errors.username.message}} {t('Password')} {errors.password && {errors.password.message}} ); }; export default AddWebdavAccountModal;