diff --git a/apps/meteor/client/views/omnichannel/modals/CloseChatModal.tsx b/apps/meteor/client/views/omnichannel/modals/CloseChatModal.tsx index 8d88307497bea..b25474b36bec2 100644 --- a/apps/meteor/client/views/omnichannel/modals/CloseChatModal.tsx +++ b/apps/meteor/client/views/omnichannel/modals/CloseChatModal.tsx @@ -4,7 +4,6 @@ import { FieldGroup, Button, TextInput, - Modal, Box, CheckBox, Divider, @@ -12,13 +11,6 @@ import { FieldLabel, FieldRow, FieldError, - ModalHeader, - ModalIcon, - ModalTitle, - ModalClose, - ModalFooter, - ModalFooterControllers, - ModalContent, } from '@rocket.chat/fuselage'; import { GenericModal } from '@rocket.chat/ui-client'; import { usePermission, useSetting, useUserPreference, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; @@ -88,31 +80,58 @@ const CloseChatModal = ({ department, visitorEmail, onCancel, onConfirm }: Close }; const onSubmit = useCallback( - ({ comment, tags, transcriptPDF, transcriptEmail, subject }: CloseChatModalFormData) => { - const preferences = { - omnichannelTranscriptPDF: !!transcriptPDF, - omnichannelTranscriptEmail: alwaysSendTranscript ? true : !!transcriptEmail, - }; - const requestData = transcriptEmail && visitorEmail ? { email: visitorEmail, subject } : undefined; - - if (!comment?.trim() && commentRequired) { - setError('comment', { type: 'custom', message: t('Required_field', { field: t('Comment') }) }); - } - - if (transcriptEmail && !subject) { - setError('subject', { type: 'custom', message: t('Required_field', { field: t('Subject') }) }); - } - - if (!tags?.length && tagRequired) { - setError('tags', { type: 'custom', message: t('error-tags-must-be-assigned-before-closing-chat') }); - } - - if (!errors.comment || errors.tags) { - onConfirm(comment, tags, preferences, requestData); - } - }, - [commentRequired, tagRequired, visitorEmail, errors, setError, t, onConfirm, alwaysSendTranscript], - ); + ({ comment, tags, transcriptPDF, transcriptEmail, subject }: CloseChatModalFormData) => { + const preferences = { + omnichannelTranscriptPDF: !!transcriptPDF, + omnichannelTranscriptEmail: alwaysSendTranscript ? true : !!transcriptEmail, + }; + + const requestData = + transcriptEmail && visitorEmail ? { email: visitorEmail, subject } : undefined; + + let hasError = false; + + if (!comment?.trim() && commentRequired) { + setError('comment', { + type: 'custom', + message: t('Required_field', { field: t('Comment') }), + }); + hasError = true; + } + + if (transcriptEmail && !subject) { + setError('subject', { + type: 'custom', + message: t('Required_field', { field: t('Subject') }), + }); + hasError = true; + } + + if (!tags?.length && tagRequired) { + setError('tags', { + type: 'custom', + message: t('error-tags-must-be-assigned-before-closing-chat'), + }); + hasError = true; + } + + if (hasError) { + return; + } + + onConfirm(comment, tags, preferences, requestData); + }, + [ + commentRequired, + tagRequired, + visitorEmail, + setError, + t, + onConfirm, + alwaysSendTranscript, + ], +); + const cannotSubmit = useMemo(() => { const cannotSendTag = (tagRequired && !tags?.length) || errors.tags; @@ -141,112 +160,110 @@ const CloseChatModal = ({ department, visitorEmail, onCancel, onConfirm }: Close }, [register, tagRequired]); useEffect(() => { - if (transcriptEmail) { - if (!visitorEmail) { - dispatchToastMessage({ type: 'error', message: t('Customer_without_registered_email') }); - return; - } - setValue('subject', subject || customSubject || t('Transcript_of_your_livechat_conversation')); - } - }, [transcriptEmail, setValue, visitorEmail, subject, t, customSubject, dispatchToastMessage]); + if (!transcriptEmail) { + return; + } + + if (!visitorEmail) { + dispatchToastMessage({ type: 'error', message: t('Customer_without_registered_email') }); + return; + } + + setValue( + 'subject', + customSubject || t('Transcript_of_your_livechat_conversation'), + { shouldDirty: false }, + ); +}, [transcriptEmail, setValue, visitorEmail, t, customSubject, dispatchToastMessage]); + if (commentRequired || tagRequired || canSendTranscript) { return ( - // TODO: Replace Modal with GenericModal - } > - - - {t('Wrap_up_conversation')} - - - - {t('Close_room_description')} - - - {t('Comment')} - - - - {errors.comment?.message} - - - - {errors.tags?.message} - - {canSendTranscript && ( - <> - - - {t('Chat_transcript')} + {t('Close_room_description')} + + + + {t('Comment')} + + + + {errors.comment?.message} + + + + + {errors.tags?.message} + + + + {canSendTranscript && ( + <> + + + {t('Chat_transcript')} + + + {canSendTranscriptPDF && ( + + + {t('Omnichannel_transcript_pdf')} + + - {canSendTranscriptPDF && ( + )} + + {canSendTranscriptEmail && ( + <> - {t('Omnichannel_transcript_pdf')} - + {t('Omnichannel_transcript_email')} + - )} - {canSendTranscriptEmail && ( - <> - - - {t('Omnichannel_transcript_email')} - - - - {transcriptEmail && ( - <> - - {t('Contact_email')} - - - - - - {t('Subject')} - - - - {errors.subject?.message} - - - )} - - )} - - - {canSendTranscriptPDF && canSendTranscriptEmail - ? t('These_options_affect_this_conversation_only_To_set_default_selections_go_to_My_Account_Omnichannel') - : t('This_option_affect_this_conversation_only_To_set_default_selection_go_to_My_Account_Omnichannel')} - - - - )} - - - - - - - - - + + {transcriptEmail && ( + <> + + {t('Contact_email')} + + + + + + + {t('Subject')} + + + + {errors.subject?.message} + + + )} + + )} + + )} + + ); } diff --git a/apps/meteor/client/views/omnichannel/modals/EnterpriseDepartmentsModal.tsx b/apps/meteor/client/views/omnichannel/modals/EnterpriseDepartmentsModal.tsx index 1561619827da6..fcd6999b20199 100644 --- a/apps/meteor/client/views/omnichannel/modals/EnterpriseDepartmentsModal.tsx +++ b/apps/meteor/client/views/omnichannel/modals/EnterpriseDepartmentsModal.tsx @@ -1,73 +1,49 @@ -import { - Button, - Modal, - Box, - ModalHeader, - ModalHeaderText, - ModalTagline, - ModalTitle, - ModalClose, - ModalContent, - ModalHeroImage, - ModalFooter, - ModalFooterControllers, -} from '@rocket.chat/fuselage'; -import { useOutsideClick } from '@rocket.chat/fuselage-hooks'; +import { Button, Box } from '@rocket.chat/fuselage'; import { useRouter } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; -import { useRef } from 'react'; import { useTranslation } from 'react-i18next'; +import GenericModal from '../../../components/GenericModal'; import { useExternalLink } from '../../../hooks/useExternalLink'; import { useCheckoutUrl } from '../../admin/subscription/hooks/useCheckoutUrl'; -// TODO: use `GenericModal` instead of creating a new modal from scratch -// This seems a upSell modal for enterprise feature const EnterpriseDepartmentsModal = ({ closeModal }: { closeModal: () => void }): ReactElement => { const { t } = useTranslation(); const router = useRouter(); - const ref = useRef(null); const openExternalLink = useExternalLink(); - const manageSubscriptionUrl = useCheckoutUrl()({ target: 'new-departments-page', action: 'upgrade' }); - - const goToManageSubscriptionPage = (): void => { - openExternalLink(manageSubscriptionUrl); - closeModal(); - }; + const manageSubscriptionUrl = useCheckoutUrl()({ + target: 'new-departments-page', + action: 'upgrade', + }); const onClose = (): void => { router.navigate('/omnichannel/departments'); closeModal(); }; - useOutsideClick([ref], onClose); + const onUpgrade = (): void => { + openExternalLink(manageSubscriptionUrl); + closeModal(); + }; return ( - - - - {t('Premium_capability')} - {t('Departments')} - - - - - - - {t('Premium_Departments_title')} - - {t('Premium_Departments_description_upgrade')} - - - - - - - - + + + {t('Premium_Departments_title')} + + {t('Premium_Departments_description_upgrade')} + ); }; diff --git a/apps/meteor/client/views/omnichannel/modals/ForwardChatModal.tsx b/apps/meteor/client/views/omnichannel/modals/ForwardChatModal.tsx index 3bc17602ce755..c34492beb32b1 100644 --- a/apps/meteor/client/views/omnichannel/modals/ForwardChatModal.tsx +++ b/apps/meteor/client/views/omnichannel/modals/ForwardChatModal.tsx @@ -4,19 +4,12 @@ import { FieldGroup, Button, TextAreaInput, - Modal, Box, Divider, FieldLabel, FieldRow, - ModalHeader, - ModalIcon, - ModalTitle, - ModalClose, - ModalContent, - ModalFooter, - ModalFooterControllers, } from '@rocket.chat/fuselage'; +import { GenericModal } from '@rocket.chat/ui-client'; import { useEndpoint, useSetting } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import { useCallback, useEffect, useId } from 'react'; @@ -38,7 +31,7 @@ type ForwardChatModalProps = { room: IOmnichannelRoom; }; -const ForwardChatModal = ({ onForward, onCancel, room, ...props }: ForwardChatModalProps): ReactElement => { +const ForwardChatModal = ({ onForward, onCancel, room }: ForwardChatModalProps): ReactElement => { const { t } = useTranslation(); const getUserData = useEndpoint('GET', '/v1/users.info'); const idleAgentsAllowedForForwarding = useSetting('Livechat_enabled_when_agent_idle', true); @@ -83,74 +76,66 @@ const ForwardChatModal = ({ onForward, onCancel, room, ...props }: ForwardChatMo }, [register]); return ( - } - {...props} + - - - {t('Forward_chat')} - - - - - - {t('Forward_to_department')} - - { - setValue('department', value); - }} - /> - - - {t('or')} - - {t('Forward_to_user')} - - { - setValue('username', value); - }} - /> - - - - - {t('Leave_a_comment')}{' '} - - ({t('Optional')}) - - - - - - - - - - - - - - - + + + {t('Forward_to_department')} + + { + setValue('department', value); + }} + /> + + + + {t('or')} + + + {t('Forward_to_user')} + + { + setValue('username', value); + }} + /> + + + + + + {t('Leave_a_comment')}{' '} + + ({t('Optional')}) + + + + + + + + ); }; diff --git a/apps/meteor/client/views/omnichannel/modals/ReturnChatQueueModal.tsx b/apps/meteor/client/views/omnichannel/modals/ReturnChatQueueModal.tsx index 09c912dec0d48..6984a8002e385 100644 --- a/apps/meteor/client/views/omnichannel/modals/ReturnChatQueueModal.tsx +++ b/apps/meteor/client/views/omnichannel/modals/ReturnChatQueueModal.tsx @@ -1,14 +1,4 @@ -import { - Button, - Modal, - ModalClose, - ModalContent, - ModalFooter, - ModalFooterControllers, - ModalHeader, - ModalIcon, - ModalTitle, -} from '@rocket.chat/fuselage'; +import { GenericModal } from '@rocket.chat/ui-client'; import { useTranslation } from 'react-i18next'; type ReturnChatQueueModalProps = { @@ -16,27 +6,21 @@ type ReturnChatQueueModalProps = { onCancel: () => void; }; -// TODO: use `GenericModal` instead of creating a new modal from scratch -const ReturnChatQueueModal = ({ onCancel, onMoveChat, ...props }: ReturnChatQueueModalProps) => { +const ReturnChatQueueModal = ({ onCancel, onMoveChat }: ReturnChatQueueModalProps) => { const { t } = useTranslation(); return ( - - - - {t('Return_to_the_queue')} - - - {t('Would_you_like_to_return_the_queue')} - - - - - - - + + {t('Would_you_like_to_return_the_queue')} + ); };