Skip to content

Commit 5deeebe

Browse files
committed
Add char limit for goal title
1 parent 48becf6 commit 5deeebe

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/components/goals/EditGoal.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,18 @@ export default function EditGoal({
7676
<div className="min-w-0 flex-1">
7777
<form onSubmit={handleSubmit(onSubmit)}>
7878
<Input
79-
ref={register({ required: true })}
79+
ref={register({ required: true, maxLength: 50 })}
8080
defaultValue={goal.title}
8181
name="title"
8282
label="Goal Title"
8383
type="text"
8484
placeholder="Participate in #100DaysOfCode"
8585
hasError={Boolean(errors.title)}
86-
errorMessage="Title is required"
86+
errorMessage={
87+
errors.title?.type === 'maxLength'
88+
? 'Title should have less than 50 chars'
89+
: 'Title is required'
90+
}
8791
/>
8892

8993
<TextArea

src/components/goals/NewGoal.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default function NewGoal() {
5757
toastId.current = id
5858
mutate(data)
5959
}
60+
6061
return (
6162
<>
6263
<Toaster />
@@ -65,13 +66,17 @@ export default function NewGoal() {
6566
<div className="min-w-0 flex-1">
6667
<form onSubmit={handleSubmit(onSubmit)}>
6768
<Input
68-
ref={register({ required: true })}
69+
ref={register({ required: true, maxLength: 50 })}
6970
name="title"
7071
label="Goal Title"
7172
type="text"
7273
placeholder="Participate in #100DaysOfCode"
7374
hasError={Boolean(errors.title)}
74-
errorMessage="Title is required"
75+
errorMessage={
76+
errors.title?.type === 'maxLength'
77+
? 'Title should have less than 50 chars'
78+
: 'Title is required'
79+
}
7580
/>
7681

7782
<TextArea

src/components/settings/ProfileSettings.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export default function ProfileSettings() {
107107
defaultValue={user.username}
108108
ref={register({
109109
required: true,
110+
maxLength: 50,
110111
validate: (username: string) => {
111112
if (username === user.username) {
112113
return true
@@ -126,7 +127,9 @@ export default function ProfileSettings() {
126127
errorMessage={
127128
errors.username?.type === 'validate'
128129
? 'Username is already taken'
129-
: 'This field is required'
130+
: errors.username?.type === 'maxLength'
131+
? 'Username should have less than 50 chars'
132+
: 'Username is required'
130133
}
131134
/>
132135
<Input
@@ -136,7 +139,7 @@ export default function ProfileSettings() {
136139
defaultValue={user.image ?? ''}
137140
ref={register({ required: true })}
138141
hasError={Boolean(errors.image)}
139-
errorMessage="This field is required"
142+
errorMessage="Profile picture is required"
140143
/>
141144
</div>
142145
<div className="md:col-span-1 grid place-items-center">
@@ -163,19 +166,23 @@ export default function ProfileSettings() {
163166
name="firstName"
164167
className="col-span-4 sm:col-span-2"
165168
defaultValue={user.account?.firstName}
166-
ref={register({ required: true })}
169+
ref={register({ required: true, maxLength: 50 })}
167170
hasError={Boolean(errors.firstName)}
168-
errorMessage="This field is required"
171+
errorMessage={
172+
errors.firstName?.type === 'maxLength'
173+
? 'Firstname should have less than 50 chars'
174+
: 'Firstname is required'
175+
}
169176
/>
170177

171178
<Input
172179
label="Last name"
173180
type="text"
174181
name="lastName"
175182
className="col-span-4 sm:col-span-2"
176-
ref={register}
183+
ref={register({ maxLength: 50 })}
177184
hasError={Boolean(errors.lastName)}
178-
errorMessage="Something went wrong!!"
185+
errorMessage="Lastname should have less than 50 chars"
179186
defaultValue={user.account?.lastName ?? ''}
180187
/>
181188
</div>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy