11import type { IMessage } from '@rocket.chat/core-typings' ;
22import { css } from '@rocket.chat/css-in-js' ;
3- import { TextAreaInput , FieldGroup , Field , FieldRow , FieldError , Box } from '@rocket.chat/fuselage' ;
3+ import { TextAreaInput , FieldGroup , Field , FieldRow , FieldError , FieldLabel , FieldDescription , Box } from '@rocket.chat/fuselage' ;
44import { GenericModal } from '@rocket.chat/ui-client' ;
5- import { useToastMessageDispatch , useTranslation , useEndpoint } from '@rocket.chat/ui-contexts' ;
5+ import { useToastMessageDispatch , useEndpoint } from '@rocket.chat/ui-contexts' ;
66import type { ReactElement } from 'react' ;
7- import { useForm } from 'react-hook-form' ;
7+ import { useId } from 'react' ;
8+ import { useForm , Controller } from 'react-hook-form' ;
9+ import { useTranslation } from 'react-i18next' ;
810
911import MarkdownText from '../../../../components/MarkdownText' ;
1012import MessageContentBody from '../../../../components/message/MessageContentBody' ;
@@ -23,12 +25,17 @@ const wordBreak = css`
2325` ;
2426
2527const ReportMessageModal = ( { message, onClose } : ReportMessageModalProps ) : ReactElement => {
26- const t = useTranslation ( ) ;
28+ const { t } = useTranslation ( ) ;
29+ const reasonForReportId = useId ( ) ;
2730 const {
28- register ,
31+ control ,
2932 formState : { errors } ,
3033 handleSubmit,
31- } = useForm < ReportMessageModalsFields > ( ) ;
34+ } = useForm < ReportMessageModalsFields > ( {
35+ defaultValues : {
36+ description : '' ,
37+ } ,
38+ } ) ;
3239 const dispatchToastMessage = useToastMessageDispatch ( ) ;
3340 const reportMessage = useEndpoint ( 'POST' , '/v1/chat.reportMessage' ) ;
3441
@@ -49,20 +56,39 @@ const ReportMessageModal = ({ message, onClose }: ReportMessageModalProps): Reac
4956 < GenericModal
5057 wrapperFunction = { ( props ) => < Box is = 'form' onSubmit = { handleSubmit ( handleReportMessage ) } { ...props } /> }
5158 variant = 'danger'
52- title = { t ( 'Report_this_message_question_mark' ) }
53- onClose = { onClose }
59+ title = { t ( 'Report_message' ) }
5460 onCancel = { onClose }
55- confirmText = { t ( 'Report_exclamation_mark ' ) }
61+ confirmText = { t ( 'Report ' ) }
5662 >
5763 < Box mbe = { 24 } className = { wordBreak } >
5864 { message . md ? < MessageContentBody md = { message . md } /> : < MarkdownText variant = 'inline' parseEmoji content = { message . msg } /> }
5965 </ Box >
6066 < FieldGroup >
6167 < Field >
68+ < FieldLabel htmlFor = { reasonForReportId } > { t ( 'Report_reason' ) } </ FieldLabel >
69+ < FieldDescription id = { `${ reasonForReportId } -description` } > { t ( 'Let_moderators_know_what_the_issue_is' ) } </ FieldDescription >
6270 < FieldRow >
63- < TextAreaInput { ...register ( 'description' , { required : true } ) } placeholder = { t ( 'Why_do_you_want_to_report_question_mark' ) } />
71+ < Controller
72+ rules = { { required : t ( 'Required_field' , { field : t ( 'Report_reason' ) } ) } }
73+ name = 'description'
74+ control = { control }
75+ render = { ( { field } ) => (
76+ < TextAreaInput
77+ { ...field }
78+ id = { reasonForReportId }
79+ rows = { 3 }
80+ aria-required = 'true'
81+ aria-invalid = { ! ! errors . description }
82+ aria-describedby = { `${ reasonForReportId } -description ${ reasonForReportId } -error` }
83+ />
84+ ) }
85+ />
6486 </ FieldRow >
65- { errors . description && < FieldError > { t ( 'You_need_to_write_something' ) } </ FieldError > }
87+ { errors . description && (
88+ < FieldError role = 'alert' id = { `${ reasonForReportId } -error` } >
89+ { errors . description . message }
90+ </ FieldError >
91+ ) }
6692 </ Field >
6793 </ FieldGroup >
6894 </ GenericModal >
0 commit comments