Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/condo/domains/user/components/UserProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const UserProfileForm: React.FC = () => {
const ApplyChangesMessage = intl.formatMessage({ id: 'ApplyChanges' })
const MinLengthError = intl.formatMessage({ id: 'field.ClientName.minLengthError' })
const MaxLengthError = intl.formatMessage({ id: 'field.ClientName.maxLengthError' })
const FullNameInvalidCharMessage = intl.formatMessage({ id:'field.FullName.invalidChar' })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after colon in id: (should be id: )

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

const ProfileUpdateTitle = intl.formatMessage({ id: 'profile.Update' })
const EmailIsAlreadyRegisteredMsg = intl.formatMessage({ id: 'pages.auth.EmailIsAlreadyRegistered' })
const ChangePasswordLabel = intl.formatMessage({ id: 'profile.ChangePassword' })
Expand Down Expand Up @@ -197,12 +198,12 @@ export const UserProfileForm: React.FC = () => {
router.push('/user')
}, [router])

const { requiredValidator, emailValidator, changeMessage, minLengthValidator, maxLengthValidator } = useValidations()
const { requiredValidator, emailValidator, changeMessage, minLengthValidator, maxLengthValidator, specCharValidator } = useValidations()
const minClientNameRule = changeMessage(minLengthValidator(2), MinLengthError)
const maxClientNameRule = changeMessage(maxLengthValidator(100), MaxLengthError)
const validations = {
email: [emailValidator],
name: [requiredValidator, minClientNameRule, maxClientNameRule],
name: [requiredValidator, changeMessage(specCharValidator, FullNameInvalidCharMessage), minClientNameRule, maxClientNameRule],
}
Comment on lines +201 to 207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add trimValidator to prevent whitespace-only names from passing validation.

On Line 206, specCharValidator allows spaces, so whitespace-only input can pass character checks and then be trimmed to '' in formAction, resulting in a silent no-op update. Please add trimValidator to name rules (same pattern used in apps/condo/domains/organization/components/EmployeeForm/CreateEmployeeForm.tsx).

Suggested patch
-    const { requiredValidator, emailValidator, changeMessage, minLengthValidator, maxLengthValidator, specCharValidator } = useValidations()
+    const { requiredValidator, emailValidator, changeMessage, minLengthValidator, maxLengthValidator, trimValidator, specCharValidator } = useValidations()
@@
-        name: [requiredValidator, changeMessage(specCharValidator, FullNameInvalidCharMessage), minClientNameRule, maxClientNameRule],
+        name: [
+            requiredValidator,
+            trimValidator,
+            changeMessage(specCharValidator, FullNameInvalidCharMessage),
+            minClientNameRule,
+            maxClientNameRule,
+        ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { requiredValidator, emailValidator, changeMessage, minLengthValidator, maxLengthValidator, specCharValidator } = useValidations()
const minClientNameRule = changeMessage(minLengthValidator(2), MinLengthError)
const maxClientNameRule = changeMessage(maxLengthValidator(100), MaxLengthError)
const validations = {
email: [emailValidator],
name: [requiredValidator, minClientNameRule, maxClientNameRule],
name: [requiredValidator, changeMessage(specCharValidator, FullNameInvalidCharMessage), minClientNameRule, maxClientNameRule],
}
const { requiredValidator, emailValidator, changeMessage, minLengthValidator, maxLengthValidator, trimValidator, specCharValidator } = useValidations()
const minClientNameRule = changeMessage(minLengthValidator(2), MinLengthError)
const maxClientNameRule = changeMessage(maxLengthValidator(100), MaxLengthError)
const validations = {
email: [emailValidator],
name: [
requiredValidator,
trimValidator,
changeMessage(specCharValidator, FullNameInvalidCharMessage),
minClientNameRule,
maxClientNameRule,
],
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/condo/domains/user/components/UserProfileForm.tsx` around lines 201 -
207, The name field validation currently uses requiredValidator,
specCharValidator, minClientNameRule, and maxClientNameRule but misses
trimValidator, allowing whitespace-only names to pass; update the validations
object returned by useValidations() to include trimValidator in the name rules
(e.g., add trimValidator before requiredValidator or alongside it) so
whitespace-only input is rejected, following the same pattern used in
CreateEmployeeForm (keep using changeMessage wrappers for error messages where
applicable).


const initialValues = useMemo(() => ({
Expand Down
Loading