Skip to content

Commit 60273f5

Browse files
committed
fix: refinning pseudo validation logic commit issues
1 parent a397cef commit 60273f5

5 files changed

Lines changed: 12 additions & 27 deletions

File tree

src/assets/js/pseudoValidation.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ const PROFANITY_WORDS = [
308308
/**
309309
* Validates a pseudo (username) and returns an error code or null if valid
310310
* @param {string} pseudo - The username to validate
311-
* @returns {string|null} - Error code ('tooShort', 'tooLong', 'profanity') or null if valid
311+
* @returns {string|null} - Error code ('tooShort', 'profanity') or null if valid
312312
*/
313313
function validatePseudo(pseudo) {
314314
const trimmed = pseudo.trim();
@@ -318,11 +318,6 @@ function validatePseudo(pseudo) {
318318
return 'tooShort';
319319
}
320320

321-
// Check maximum length
322-
if (trimmed.length > PSEUDO_MAX_LENGTH) {
323-
return 'tooLong';
324-
}
325-
326321
// Check for profanity - convert to lowercase for comparison
327322
const pseudoLower = trimmed.toLowerCase();
328323

@@ -359,20 +354,16 @@ function validatePseudo(pseudo) {
359354
}
360355

361356
/**
362-
* Gets the error message for a given error code
363-
* @param {string} errorCode - The error code ('tooShort', 'tooLong', 'profanity')
364-
* @returns {string} - The localized error message
357+
* Returns the translation key for a given error code
358+
* @param {string} errorCode - The error code ('tooShort', 'profanity')
359+
* @returns {string} - The translation key
365360
*/
366361
function getPseudoErrorMessage(errorCode) {
367-
if (!errorCode) return '';
368-
369362
switch (errorCode) {
370363
case 'tooShort':
371-
return i18next.t('welcome.errorPseudoTooShort', { min: PSEUDO_MIN_LENGTH });
372-
case 'tooLong':
373-
return i18next.t('welcome.errorPseudoTooLong', { max: PSEUDO_MAX_LENGTH });
364+
return 'welcome.errorPseudoTooShort';
374365
case 'profanity':
375-
return i18next.t('welcome.errorPseudoProfanity');
366+
return 'welcome.errorPseudoProfanity';
376367
default:
377368
return '';
378369
}
@@ -389,16 +380,13 @@ function displayPseudoError(errorCode, errorContainer) {
389380
if (errorCode) {
390381
const errorMessage = getPseudoErrorMessage(errorCode);
391382
errorContainer.innerHTML = `
392-
<div class="alert alert-danger fade show mt-2" role="alert">
393-
<span class="alert-icon" aria-hidden="true"></span>
394-
<div class="alert-container">
395-
<div class="alert-text-container">
396-
<p class="alert-label m-0">${errorMessage}</p>
397-
</div>
398-
</div>
383+
<div class="alert alert-danger alert-sm mt-2" role="alert">
384+
<span class="alert-icon"><span class="visually-hidden">Error</span></span>
385+
<p data-i18n="${errorMessage}"></p>
399386
</div>
400387
`;
401388
errorContainer.classList.remove('d-none');
389+
updateTranslations();
402390
} else {
403391
errorContainer.innerHTML = '';
404392
errorContainer.classList.add('d-none');

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ <h4 class="mt-3" id="pseudoLabel" data-i18n="welcome.pseudo"></h4>
102102
</form>
103103
</div>
104104
<div class="ms-5 col-4">
105-
<img src="assets/img/Start.svg" alt="" role="presentation">
105+
<img src="assets/img/Start.svg" alt="">
106106
</div>
107107
</main>
108108

src/locales/en.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
"placeholder_enterPseudo": "Enter your nickname",
5050
"oninvalid_errorMessageEmptyPseudo": "this.setCustomValidity(\"Please enter a nickname\")",
5151
"buttonStartAdventure": "Start the adventure",
52-
"errorPseudoTooShort": "Nickname must be at least {min} characters.",
53-
"errorPseudoTooLong": "Nickname must not exceed {max} characters.",
52+
"errorPseudoTooShort": "Nickname must be at least 3 characters.",
5453
"errorPseudoProfanity": "This nickname contains inappropriate terms. Please choose another one."
5554
},
5655
"intro": {

src/locales/es.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"oninvalid_errorMessageEmptyPseudo": "this.setCustomValidity(\"Por favor, indica un apodo\")",
5151
"buttonStartAdventure": "Iniciar la aventura",
5252
"errorPseudoTooShort": "El apodo debe tener al menos 3 caracteres.",
53-
"errorPseudoTooLong": "El apodo no debe superar los 20 caracteres.",
5453
"errorPseudoProfanity": "Este apodo contiene términos inapropiados. Por favor, elige otro."
5554
},
5655
"intro": {

src/locales/fr.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"oninvalid_errorMessageEmptyPseudo": "this.setCustomValidity(\"Merci d'entrer un pseudo\")",
5151
"buttonStartAdventure": "Démarrer l'aventure",
5252
"errorPseudoTooShort": "Le pseudo doit contenir au moins 3 caractères.",
53-
"errorPseudoTooLong": "Le pseudo ne doit pas dépasser 20 caractères.",
5453
"errorPseudoProfanity": "Ce pseudo contient des termes inappropriés. Veuillez en choisir un autre."
5554
},
5655
"intro": {

0 commit comments

Comments
 (0)