Skip to content

Commit 3f14101

Browse files
Frontend: Profile textbox templates to localizable placeholders (#9248)
1 parent 10805da commit 3f14101

7 files changed

Lines changed: 18 additions & 66 deletions

File tree

app/web/features/profile/edit/EditHostingPreference.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
User,
1010
} from "../../../proto/api_pb";
1111
import { HostingPreferenceData } from "../../../service/user";
12-
import { DEFAULT_ABOUT_HOME_HEADINGS } from "./constants";
1312
import EditHostingPreferenceForm from "./EditHostingPreferenceForm";
1413

1514
export default function EditHostingPreference() {
@@ -26,7 +25,7 @@ export default function EditHostingPreference() {
2625
maxGuests: user.maxGuests?.value ?? 1,
2726
smokingAllowed:
2827
user.smokingAllowed || SmokingLocation.SMOKING_LOCATION_UNKNOWN,
29-
aboutPlace: user.aboutPlace || DEFAULT_ABOUT_HOME_HEADINGS,
28+
aboutPlace: user.aboutPlace ?? "",
3029
sleepingArrangement:
3130
user.sleepingArrangement ||
3231
SleepingArrangement.SLEEPING_ARRANGEMENT_UNKNOWN,

app/web/features/profile/edit/EditHostingPreferenceForm.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import { theme } from "theme";
3232
import { useUnsavedChangesWarning } from "utils/hooks";
3333
import { useIsNativeEmbed } from "utils/nativeLink";
3434

35-
import { DEFAULT_ABOUT_HOME_HEADINGS } from "./constants";
36-
3735
interface HostingPreferenceCheckboxProps {
3836
className?: string;
3937
name: string;
@@ -315,12 +313,7 @@ export default function HostingPreferenceForm({
315313
resetUpdate();
316314
updateHostingPreferences(
317315
{
318-
preferenceData: {
319-
...data,
320-
aboutPlace: DEFAULT_ABOUT_HOME_HEADINGS.includes(data.aboutPlace)
321-
? ""
322-
: data.aboutPlace,
323-
},
316+
preferenceData: data,
324317
setMutationError: setErrorMessage,
325318
},
326319
{
@@ -437,7 +430,7 @@ export default function HostingPreferenceForm({
437430
label={t("profile:home_info_headings.about_home")}
438431
name="aboutPlace"
439432
control={control}
440-
defaultValue={user.aboutPlace || DEFAULT_ABOUT_HOME_HEADINGS}
433+
defaultValue={user.aboutPlace}
441434
/>
442435
</FieldGroup>
443436

app/web/features/profile/edit/EditProfile.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ import {
4949
nameMaxLength,
5050
nameMinLength,
5151
nameValidationPattern,
52+
profileAboutMeMinLength,
5253
} from "utils/validation";
5354

54-
import {
55-
ABOUT_ME_MIN_LENGTH,
56-
DEFAULT_ABOUT_ME_HEADINGS,
57-
DEFAULT_HOBBIES_HEADINGS,
58-
} from "./constants";
5955
import StatusCardGroup from "./StatusCard";
6056

6157
export type EditProfileFormValues = Omit<
@@ -297,7 +293,7 @@ export default function EditProfileForm() {
297293
regionsVisited: user.regionsVisitedList,
298294
regionsLived: user.regionsLivedList,
299295
aboutMe: user.aboutMe,
300-
thingsILike: user.thingsILike || DEFAULT_HOBBIES_HEADINGS,
296+
thingsILike: user.thingsILike,
301297
additionalInformation: user.additionalInformation,
302298
location: {
303299
city: user.city,
@@ -382,9 +378,6 @@ export default function EditProfileForm() {
382378
fluency: LanguageAbility.Fluency.FLUENCY_FLUENT,
383379
})),
384380
},
385-
thingsILike: DEFAULT_HOBBIES_HEADINGS.includes(data.thingsILike)
386-
? ""
387-
: data.thingsILike,
388381
},
389382
setMutationError: setErrorMessage,
390383
onSuccess: () => {
@@ -411,7 +404,7 @@ export default function EditProfileForm() {
411404
const handleSubmitButtonClick = (event: FormEvent<HTMLFormElement>) => {
412405
event.preventDefault();
413406

414-
if (aboutMeField.length < ABOUT_ME_MIN_LENGTH || !user?.avatarUrl) {
407+
if (aboutMeField.length < profileAboutMeMinLength || !user?.avatarUrl) {
415408
setShowIncompleteProfileDialog(true);
416409
} else {
417410
onSubmit();
@@ -915,15 +908,15 @@ export default function EditProfileForm() {
915908
id="aboutMe"
916909
label={t("profile:heading.about_me")}
917910
name="aboutMe"
918-
placeholder={DEFAULT_ABOUT_ME_HEADINGS}
911+
placeholder={t("profile:about_me_textbox_placeholder")}
919912
defaultValue={user.aboutMe}
920913
control={control}
921-
warning={aboutMeField.length < ABOUT_ME_MIN_LENGTH}
914+
warning={aboutMeField.length < profileAboutMeMinLength}
922915
helperText={
923916
<Trans
924917
i18nKey="profile:helper_text.characters_remaining"
925918
values={{
926-
count: ABOUT_ME_MIN_LENGTH - aboutMeField.length,
919+
count: profileAboutMeMinLength - aboutMeField.length,
927920
}}
928921
components={{ bold: <strong /> }}
929922
/>
@@ -956,7 +949,8 @@ export default function EditProfileForm() {
956949
id="thingsILike"
957950
label={t("profile:heading.hobbies_section")}
958951
name="thingsILike"
959-
defaultValue={user.thingsILike || DEFAULT_HOBBIES_HEADINGS}
952+
defaultValue={user.thingsILike}
953+
placeholder={t("profile:hobbies_textbox_placeholder")}
960954
control={control}
961955
/>
962956
</FieldGroup>
@@ -1070,7 +1064,7 @@ export default function EditProfileForm() {
10701064
>
10711065
{t("profile:incomplete_dialog.description")}
10721066
</Typography>
1073-
{aboutMeField.length < ABOUT_ME_MIN_LENGTH && (
1067+
{aboutMeField.length < profileAboutMeMinLength && (
10741068
<ListItem key={1} style={{ display: "list-item" }}>
10751069
{`• ${t("profile:incomplete_dialog.about_me_message")}`}
10761070
</ListItem>

app/web/features/profile/edit/EditProfilePage.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import wrapper from "test/hookWrapper";
55
import i18n from "test/i18n";
66
import { getLanguages, getRegions, getUser } from "test/serviceMockDefaults";
77
import { addDefaultUser } from "test/utils";
8+
import { profileAboutMeMinLength } from "utils/validation";
89

9-
import { ABOUT_ME_MIN_LENGTH } from "./constants";
1010
import EditProfilePage from "./EditProfilePage";
1111

1212
const { t } = i18n;
@@ -220,7 +220,7 @@ describe("Edit profile", () => {
220220
it("should reject names with invalid characters like !@#$", async () => {
221221
getUserMock.mockImplementation(async (user) => ({
222222
...(await getUser(user)),
223-
aboutMe: "a".repeat(ABOUT_ME_MIN_LENGTH),
223+
aboutMe: "a".repeat(profileAboutMeMinLength),
224224
}));
225225

226226
await renderPage();

app/web/features/profile/edit/constants.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/web/features/profile/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
"save_anyway": "Save anyway?",
5050
"continue_editing": "Continue editing"
5151
},
52+
"about_me_textbox_placeholder": "e.g. Current mission, why you use Couchers.org, favorite travel story...",
53+
"hobbies_textbox_placeholder": "e.g. Activities, books, movies, music...",
5254
"home_info_headings": {
5355
"about_home": "About my home",
5456
"general": "General",

app/web/utils/validation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const emailValidationPattern =
1111
/^[0-9a-z]([0-9a-z\-_+]|(\.[0-9a-z\-_+]))*@([0-9a-z-]+\.)*[0-9a-z-]+\.[a-z]{2,}$/i;
1212
export const timePattern = /\d{2}:\d{2}/;
1313

14+
export const profileAboutMeMinLength = 150;
15+
1416
export function validatePastDate(stringDate: string) {
1517
const date = new Date(stringDate);
1618
return !isNaN(date.getTime()) && date < new Date();

0 commit comments

Comments
 (0)