From deea49c5d9e7d7596b2db1d5e05f5ea005a82e16 Mon Sep 17 00:00:00 2001 From: mohitb35 <44917347+mohitb35@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:02:22 +0530 Subject: [PATCH] feat: updates validation logic for edit profile - matches server logic for firstname, lastname, name, address, city - adds translations to editProfile.json - groups translation text for field labels & validation errors together - removes unreqd translation files from serverSideTranslations for page --- pages/profile/edit.tsx | 21 +---- public/static/locales/en/editProfile.json | 48 +++++++--- .../Settings/EditProfile/EditProfileForm.tsx | 87 ++++++++++++++----- 3 files changed, 101 insertions(+), 55 deletions(-) diff --git a/pages/profile/edit.tsx b/pages/profile/edit.tsx index ff1099c4be..f4d35d3b27 100644 --- a/pages/profile/edit.tsx +++ b/pages/profile/edit.tsx @@ -25,26 +25,7 @@ export async function getStaticProps({ locale }: GetStaticPropsContext) { props: { ...(await serverSideTranslations( locale || 'en', - [ - 'bulkCodes', - 'common', - 'country', - 'donate', - 'donationLink', - 'editProfile', - 'giftfunds', - 'leaderboard', - 'managePayouts', - 'manageProjects', - 'maps', - 'me', - 'planet', - 'planetcash', - 'redeem', - 'registerTrees', - 'tenants', - 'treemapper', - ], + ['editProfile', 'me', 'common', 'country'], null, ['en', 'de', 'fr', 'es', 'it', 'pt-BR', 'cs'] )), diff --git a/public/static/locales/en/editProfile.json b/public/static/locales/en/editProfile.json index c475988c6e..b92f52cd63 100644 --- a/public/static/locales/en/editProfile.json +++ b/public/static/locales/en/editProfile.json @@ -2,10 +2,8 @@ "loginTitle": "{{log}} - Login", "signUpText": "Complete Signup", "profileTypes": "{{item.title}}", - "profileName": "Name of {{type}}", "createAccount": "Create Account", "individual": "Person", - "iamA": "I am a", "tpo": "Reforestation Organisation", "education": "School", "organization": "Company", @@ -13,16 +11,8 @@ "profileCreationFailed": "Error in creating profile. Please try again.", "profileCreationError": "Error in creating profile.", "edit": "Edit Profile", - "privateAccount": "Private Account", "privateAccountTxt": "Your profile is hidden and only your first name appears in the leaderboard", - "subscribe": "Subscribe to news via email", - "profileDescription": "Profile Desciption", - "descriptionRequired": "You have exceeded the maximum length", - "website": "Website", - "websiteError": "Invalid website URL", - "websiteRequired": "Please enter valid Website URL", "save": "Save", - "nameValidation": "Please enter a name", "profilePicUpdated": "Profile picture is being updated...", "profileSaved": "Saved successfully!", "profileSaveFailed": "Error in updating profile.", @@ -32,5 +22,39 @@ "continue": "Continue", "cancel": "Cancel", "termAndCondition": "I agree to the <0>Terms and Conditions of the Plant-for-the-Planet platform.", - "termAndConditionError": "Please Accept the Terms and Conditions" -} \ No newline at end of file + "termAndConditionError": "Please Accept the Terms and Conditions", + "fieldLabels": { + "profileType": "I am a", + "firstName": "First Name", + "lastName": "Last Name", + "name": "Name of {{type}}", + "email": "Email", + "address": "Address", + "city": "City", + "zipCode": "Postal/Zip Code", + "country": "Country", + "bio": "Profile Desciption", + "website": "Website", + "privateAccount": "Private Account", + "subscribe": "Subscribe to news via email" + }, + "validationErrors": { + "maxChars": "Should be {{max}} characters or less", + "firstNameRequired": "First Name field is required", + "firstNameInvalid": "First name is invalid. Only these special characters are allowed: space ' . -", + "lastNameRequired": "Last Name field is required", + "lastNameInvalid": "Last name is invalid. Only these special characters are allowed: space ' -", + "emailRequired": "Email is required", + "nameRequired": "Please enter a name", + "nameInvalid": "Name is invalid. Only these special characters are allowed: space . , ' & ( ) ! -", + "addressRequired": "Address is required", + "addressInvalid": "Address is invalid. Only these special characters are allowed: space . , # - /", + "cityRequired": "City is required", + "cityInvalid": "City is invalid. Only letters and these special characters are allowed: space . , ( ) -", + "zipCodeRequired": "Zip Code is required", + "zipCodeInvalid": "Zip Code is invalid", + "websiteInvalid": "Please enter valid Website URL", + "countryRequired": "Country is required", + "companyRequired": "Company Name is required" + } +} diff --git a/src/features/user/Settings/EditProfile/EditProfileForm.tsx b/src/features/user/Settings/EditProfile/EditProfileForm.tsx index d62b08a98b..002ed75e8a 100644 --- a/src/features/user/Settings/EditProfile/EditProfileForm.tsx +++ b/src/features/user/Settings/EditProfile/EditProfileForm.tsx @@ -63,7 +63,7 @@ export default function EditProfileForm() { const { user, setUser, token, contextLoaded, logoutUser } = useUserProps(); const [isUploadingData, setIsUploadingData] = React.useState(false); - const { t, ready } = useTranslation(['editProfile', 'donate']); + const { t, ready } = useTranslation(['editProfile']); const defaultProfileDetails = useMemo(() => { return { @@ -342,7 +342,7 @@ export default function EditProfileForm() { } }} renderInput={(params) => ( - + )} /> ) : null} @@ -350,10 +350,20 @@ export default function EditProfileForm() { ( ( ( ( { suggestAddress(event.target.value); handleChange(event); @@ -457,10 +489,16 @@ export default function EditProfileForm() { ( ( @@ -504,7 +545,7 @@ export default function EditProfileForm() { className={styles.mainText} style={{ cursor: 'pointer' }} > - {t('editProfile:privateAccount')} + {t('fieldLabels.privateAccount')} {' '}
{watchIsPrivate && ( @@ -533,7 +574,7 @@ export default function EditProfileForm() { className={styles.mainText} style={{ cursor: 'pointer' }} > - {t('editProfile:subscribe')} + {t('fieldLabels.subscribe')} ( (