WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9f5bba2

Browse files
authored
feat: show error message if organization of same name already exists while editing organization (#4939)
* feat: display error message if the given organization name already exists while editing * chore: fix tests * chore: fix tests * feat: revert changes to OrgUpdate.tsx and add the check in errorHandler.tsx * chore: revert changes to OrgUpdate.spec.tsx * chore: update errorHandler.spec.tsx
1 parent 5f61fbf commit 9f5bba2

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

public/locales/en/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"invalidEducationGrade": "Please select a valid education grade",
1313
"invalidEmploymentStatus": "Please select a valid employment status",
1414
"invalidMaritalStatus": "Please select a valid marital status",
15-
"error400": "The submitted information is invalid. Please check your inputs and try again"
15+
"error400": "The submitted information is invalid. Please check your inputs and try again",
16+
"organizationNameAlreadyExists": "An organization with this name already exists"
1617
}

public/locales/es/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"invalidEducationGrade": "Por favor seleccione un grado de educación válido",
1313
"invalidEmploymentStatus": "Por favor seleccione un estado de empleo válido",
1414
"invalidMaritalStatus": "Por favor seleccione un estado civil válido",
15-
"error400": "Respuesta no exitosa. Se recibió el código de estado 400 del servidor"
15+
"error400": "Respuesta no exitosa. Se recibió el código de estado 400 del servidor",
16+
"organizationNameAlreadyExists": "Una organización con este nombre ya existe"
1617
}

public/locales/fr/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"invalidEducationGrade": "Veuillez sélectionner un niveau d'études valide",
1313
"invalidEmploymentStatus": "Veuillez sélectionner un statut d'emploi valide",
1414
"invalidMaritalStatus": "Veuillez sélectionner un état matrimonial valide",
15-
"error400": "Réponse non réussie. Code d'état 400 reçu du serveur"
15+
"error400": "Réponse non réussie. Code d'état 400 reçu du serveur",
16+
"organizationNameAlreadyExists": "Une organisation avec ce nom existe déjà"
1617
}

public/locales/hi/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"invalidEducationGrade": "कृपया एक शिक्षा ग्रेड चुनें",
1313
"invalidEmploymentStatus": "कृपया वैध रोजगार स्थिति चुनें",
1414
"invalidMaritalStatus": "कृपया वैध वैवाहिक स्थिति चुनें",
15-
"error400": "आपकी जानकारी सहेजी नहीं जा सकी। कृपया अपनी प्रविष्टियों की जांच करें और पुनः प्रयास करें।"
15+
"error400": "आपकी जानकारी सहेजी नहीं जा सकी। कृपया अपनी प्रविष्टियों की जांच करें और पुनः प्रयास करें।",
16+
"organizationNameAlreadyExists": "इस नाम का एक संगठन पहले से मौजूद है"
1617
}

public/locales/zh/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"invalidEducationGrade": "请选择教育年级",
1313
"invalidEmploymentStatus": "请选择有效的就业状况",
1414
"invalidMaritalStatus": "请选择有效的婚姻状况",
15-
"error400": "响应不成功. 从服务器收到状态代码 400"
15+
"error400": "响应不成功. 从服务器收到状态代码 400",
16+
"organizationNameAlreadyExists": "具有此名称的组织已存在"
1617
}

src/utils/errorHandler.spec.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ describe('Test if errorHandler is working properly', () => {
6060
expect(toast.error).toHaveBeenCalledWith(tErrors('error400'));
6161
});
6262

63+
it('should call toast.error with the correct message if error message contains this substring "organization name already exists"', () => {
64+
const error = new Error('organization name already exists');
65+
errorHandler(t, error);
66+
67+
expect(toast.error).toHaveBeenCalledWith(
68+
tErrors('organizationNameAlreadyExists'),
69+
);
70+
});
71+
6372
it('should handle error messages with different cases', () => {
6473
errorHandler(t, new Error('VALUE IS NOT A VALID PHONE NUMBER'));
6574
expect(toast.error).toHaveBeenCalledWith(tErrors('invalidPhoneNumber'));

src/utils/errorHandler.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const errorHandler = (a: unknown, error: unknown): void => {
2323
toast.error(tErrors('invalidMaritalStatus'));
2424
} else if (errorMessage.match(/status code 400/i)) {
2525
toast.error(tErrors('error400'));
26+
} else if (errorMessage.match(/organization name already exists/i)) {
27+
toast.error(tErrors('organizationNameAlreadyExists'));
2628
} else {
2729
toast.error(errorMessage);
2830
}

0 commit comments

Comments
 (0)