@@ -17,7 +17,8 @@ interface CollaborationResponseModalProps {
1717 collaborationRequestId : string ;
1818}
1919
20- const MIN_FEEDBACK_LENGTH = 10 ;
20+ const MIN_FEEDBACK_LENGTH = 3 ;
21+ const MAX_FEEDBACK_LENGTH = 255 ;
2122
2223export const CollaborationResponseModal = ( {
2324 isOpen,
@@ -76,18 +77,25 @@ export const CollaborationResponseModal = ({
7677 } ,
7778 } ) ;
7879
79- const isValidFeedback = feedback . trim ( ) . length >= MIN_FEEDBACK_LENGTH ;
80- const charactersRemaining = MIN_FEEDBACK_LENGTH - feedback . trim ( ) . length ;
80+ const isValidFeedback = ( value : string ) => {
81+ const trimmed = value . trim ( ) ;
82+ return trimmed . length >= MIN_FEEDBACK_LENGTH && trimmed . length <= MAX_FEEDBACK_LENGTH ;
83+ } ;
84+
85+ const isFeedbackValid = isValidFeedback ( feedback ) ;
86+ const feedbackLength = feedback . trim ( ) . length ;
87+ const charactersRemaining = MIN_FEEDBACK_LENGTH - feedbackLength ;
8188
8289 const handleFeedbackChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
83- setFeedback ( e . target . value ) ;
84- if ( showError && e . target . value . trim ( ) . length >= MIN_FEEDBACK_LENGTH ) {
90+ const newValue = e . target . value . slice ( 0 , MAX_FEEDBACK_LENGTH ) ;
91+ setFeedback ( newValue ) ;
92+ if ( showError && isValidFeedback ( newValue ) ) {
8593 setShowError ( false ) ;
8694 }
8795 } ;
8896
8997 const handleAction = ( action : "Approved" | "Rejected" ) => {
90- if ( ! isValidFeedback ) {
98+ if ( ! isFeedbackValid ) {
9199 setShowError ( true ) ;
92100 return ;
93101 }
@@ -186,23 +194,22 @@ export const CollaborationResponseModal = ({
186194 placeholder = "Escreva seu feedback sobre a solicitação..."
187195 rows = { 5 }
188196 disabled = { approveCollaborationMutation . isPending }
197+ maxLength = { MAX_FEEDBACK_LENGTH }
189198 className = { showError ? styles . textareaError : "" }
190199 />
191200 < div className = { styles . feedbackInfo } >
192201 < span
193202 className = { `${ styles . charCounter } ${
194- charactersRemaining > 0 ? styles . charCounterError : ""
203+ ! isFeedbackValid ? styles . charCounterError : ""
195204 } `}
196205 >
197- { charactersRemaining > 0
198- ? `${ charactersRemaining } caracteres restantes`
199- : `${ feedback . trim ( ) . length } caracteres` }
206+ { feedbackLength } / { MAX_FEEDBACK_LENGTH } caracteres
207+ { charactersRemaining > 0 && ` (mínimo ${ MIN_FEEDBACK_LENGTH } )` }
200208 </ span >
201209 </ div >
202210 { showError && (
203211 < span className = { styles . errorMessage } >
204- O feedback deve ter pelo menos { MIN_FEEDBACK_LENGTH } { " " }
205- caracteres
212+ O feedback deve ter entre { MIN_FEEDBACK_LENGTH } e { MAX_FEEDBACK_LENGTH } caracteres
206213 </ span >
207214 ) }
208215 </ div >
@@ -223,7 +230,7 @@ export const CollaborationResponseModal = ({
223230 onClick = { ( ) => handleAction ( "Rejected" ) }
224231 disabled = {
225232 approveCollaborationMutation . isPending ||
226- ! isValidFeedback ||
233+ ! isFeedbackValid ||
227234 pendingAction === "Rejected"
228235 }
229236 className = { styles . rejectButton }
@@ -234,7 +241,7 @@ export const CollaborationResponseModal = ({
234241 onClick = { ( ) => handleAction ( "Approved" ) }
235242 disabled = {
236243 approveCollaborationMutation . isPending ||
237- ! isValidFeedback ||
244+ ! isFeedbackValid ||
238245 pendingAction === "Approved"
239246 }
240247 className = { styles . approveButton }
0 commit comments