Skip to content

Commit c2a4d90

Browse files
author
Andrew Nguyen
committed
Bobby Lobster Changes
1 parent c8c9aeb commit c2a4d90

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

app/globals.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
:root {
66
--error-color: #f87171;
7-
}
8-
:root {
97
--b1: #000000;
108
--n: 21% 0.003 296.813;
119
}

app/setup/page.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ type NametagData = {
1717
profilePhoto: string
1818
}
1919

20+
/** Same rules as the availability effect: empty, format, or not explicitly available. */
21+
function getHandleHasError(handle: string, handleAvailable: boolean | null): boolean {
22+
const trimmed = handle.trim()
23+
const handleRegex = /^(?:[a-z0-9_]|-)+$/
24+
const formatInvalid =
25+
!trimmed || !handleRegex.test(handle) || handle.length < 3 || handle.length > 30
26+
return formatInvalid || handleAvailable !== true
27+
}
28+
2029
export default function Setup() {
2130
const [loading, setLoading] = useState(true)
2231
const [saving, setSaving] = useState(false)
@@ -207,19 +216,27 @@ export default function Setup() {
207216

208217
const handleHandleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
209218
setHandle(e.target.value.toLowerCase())
210-
// Clear error when user starts typing
211-
if (hasAttemptedSubmit && validationErrors.handle) {
212-
setValidationErrors((prev) => ({ ...prev, handle: false }))
213-
}
214219
}
215220

221+
// After first submit, recompute handle error from current value + availability (not unconditional clear on keystroke)
222+
useEffect(() => {
223+
if (!hasAttemptedSubmit) return
224+
225+
const handleError = getHandleHasError(handle, handleAvailable)
226+
227+
setValidationErrors((prev) => {
228+
if (prev.handle === handleError) return prev
229+
return { ...prev, handle: handleError }
230+
})
231+
}, [handle, handleAvailable, hasAttemptedSubmit])
232+
216233
const handleFinishSetup = async (e: React.FormEvent) => {
217234
e.preventDefault()
218235
setHasAttemptedSubmit(true)
219236

220237
// Validate form and set error states
221238
const errors = {
222-
handle: !handle.trim() || !handleAvailable,
239+
handle: getHandleHasError(handle, handleAvailable),
223240
profilePhoto: !nametagData.profilePhoto,
224241
fullName: !nametagData.fullName.trim()
225242
}

0 commit comments

Comments
 (0)