Skip to content

Commit ecde374

Browse files
improving user frendly toast message (#635)
1 parent 8f45bdb commit ecde374

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+245
-158
lines changed

Diff for: public/locales/fr/translation.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@
464464
"Provide Professional_Skills range between 1-2": "Fournir une gamme de compétences professionnelles comprise entre 1-2",
465465
"Sprint Ratings": "Sprint Notations",
466466
"Please wait to be added to a program or cohort": "Veuillez attendre d'être ajouté à un programme ou à une cohorte",
467-
"Enter all the required information": "Entrez toutes les informations requises",
467+
"Select all the required information": "Entrez toutes les informations requises",
468468
"Are you sure you want to delete this user?": "Êtes-vous sûr de vouloir supprimer cet utilisateur ?",
469469
"Come shape the future together": "Venez former l'avenir ensemble",
470470
"Content1": "Je suis extrêmement impressionné par Pulse et leur plateforme de gestion de la performance. Depuis que nous utilisons leurs services, cela a été un véritable changement pour notre organisation. La plateforme est intuitive, facile à naviguer et riche en fonctionnalités puissantes",

Diff for: public/locales/kn/translation.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@
452452
"Provide Professional_Skills range between 1-2": "Tanga ubuhanga buri hagati ya 1-2",
453453
"Sprint Ratings": "Amanota ya Sprint",
454454
"Please wait to be added to a program or cohort": "Tegereza tukongere muri porogarame cyangwa itsinda",
455-
"Enter all the required information": "Shyiramo amakuru yose asabwa",
455+
"Select all the required information": "Shyiramo amakuru yose asabwa",
456456
"Are you sure you want to delete this user?": "urashaka kwemeza ikigikorwa cyo gusiba uyumuntu ?",
457457
"Come shape the future together": "Dufatanye kwubaka ejo Hazaza",
458458
"Content1": "Nshimishijwe cyane na Pulse n'ikoranabuhanga ryabo ryo gucunga imikorere. Kuva natangira gukoresha serivisi zabo, byabaye impinduka ikomeye mu kigo cyacu. iri koranabuhanga riroroshye kurikoresha, kandi ryubakanye ubuhanga n' ubushobozi buhanitse.",

Diff for: src/components/Calendar.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import moment from 'moment';
1616
import CalendarSkeleton from '../Skeletons/Calender.skeleton';
1717
import { toast } from 'react-toastify';
1818
import EventGuestList from './EventGuestList';
19+
import { handleError } from './ErrorHandle';
1920
/* istanbul ignore next */
2021

2122
const Calendar = () => {
@@ -48,7 +49,7 @@ const Calendar = () => {
4849
fetchPolicy: 'network-only',
4950
});
5051
} catch (error: any) {
51-
toast.error(error.message);
52+
toast.error(handleError(error));
5253
}
5354
};
5455

@@ -95,7 +96,7 @@ const Calendar = () => {
9596
})
9697
.then(() => {
9798
fetchData();
98-
toast.success('Event has been added!'); // {{ edit_1 }}
99+
toast.success('Event has been added!');
99100
setNewEvent({
100101
title: '',
101102
start: new Date(),
@@ -110,7 +111,7 @@ const Calendar = () => {
110111
}, 1000);
111112
})
112113
.catch((error) => {
113-
toast.error(error.message); // Handle error if needed
114+
toast.error(handleError(error));
114115
});
115116
};
116117

@@ -189,7 +190,7 @@ const Calendar = () => {
189190
}, 1000);
190191
})
191192
.catch((error) => {
192-
toast.error(error.message); // Handle error if needed
193+
toast.error(handleError(error));
193194
});
194195
};
195196

@@ -235,7 +236,7 @@ const Calendar = () => {
235236
}, 1000);
236237
})
237238
.catch((err) => {
238-
toast.error(err.message);
239+
toast.error(handleError(err));
239240
});
240241
};
241242

Diff for: src/components/CreateOrganizationModal.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TFunction, useTranslation } from 'react-i18next';
55
import { toast } from 'react-toastify';
66
import Button from './Buttons';
77
import { AddOrganization } from '../Mutations/OrganisationMutations';
8+
import { handleError } from './ErrorHandle';
89

910
export default function CreateOrganizationModal({
1011
createOrganizationModel,
@@ -24,7 +25,7 @@ export default function CreateOrganizationModal({
2425
} = useForm();
2526
const [addOrganizationMutation, { loading }] = useMutation(AddOrganization, {
2627
onError(error) {
27-
toast.error(error.message.toString());
28+
toast.error(handleError(error).toString());
2829
},
2930
onCompleted() {
3031
toast.success(t('Organization added successfully') as TFunction);

Diff for: src/components/DashHeader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function DashHeader({minimize}: any) {
9696
const { data } = await getProfile();
9797
setProfileData(data);
9898
} catch (error: any) {
99-
toast.error(error?.message || 'Something went wrong');
99+
toast.error('Something went wrong');
100100
}
101101
};
102102
/* istanbul ignore next */

Diff for: src/components/Docs/AdminDocs.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
UPDATE_DOCUMENTATION,
1919
} from '../../Mutations/manageStudentMutations';
2020
import { GET_DOCUMENTATION } from '../../queries/manageStudent.queries';
21+
import { handleError } from '../ErrorHandle';
2122

2223
function AdminDocs() {
2324
useDocumentTitle('Documentation');
@@ -68,7 +69,7 @@ function AdminDocs() {
6869
});
6970
},
7071
onError: (error) => {
71-
toast.error(error.message);
72+
toast.error(handleError(error));
7273
},
7374
});
7475

@@ -87,7 +88,7 @@ function AdminDocs() {
8788
});
8889
},
8990
onError: (error) => {
90-
toast.error(error.message);
91+
toast.error(handleError(error));
9192
},
9293
});
9394

@@ -104,7 +105,7 @@ function AdminDocs() {
104105
setIsUpdate(false);
105106
},
106107
onError: (error) => {
107-
toast.error(error.message);
108+
toast.error(handleError(error));
108109
},
109110
});
110111

@@ -127,7 +128,7 @@ function AdminDocs() {
127128
getDocumentations();
128129
},
129130
onError: (error) => {
130-
toast.error(error.message);
131+
toast.error(handleError(error));
131132
},
132133
});
133134

@@ -138,7 +139,7 @@ function AdminDocs() {
138139
getDocumentations();
139140
},
140141
onError: (error) => {
141-
toast.error(error.message);
142+
toast.error(handleError(error));
142143
},
143144
});
144145

Diff for: src/components/EditTicketModal.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
22
import { useMutation } from '@apollo/client';
33
import { toast } from 'react-toastify';
44
import { UPDATE_TICKET } from '../queries/tickets.queries';
5+
import { handleError } from './ErrorHandle';
56

67
interface EditTicketModalProps {
78
isOpen: boolean;
@@ -54,7 +55,7 @@ function EditTicketModal({
5455
},
5556
onError: (error) => {
5657
setLoading(false);
57-
toast.error(`Error updating ticket: ${error.message}`);
58+
toast.error(`Error updating ticket: ${handleError(error)}`);
5859
},
5960
});
6061

@@ -95,7 +96,7 @@ function EditTicketModal({
9596
},
9697
});
9798
} catch (error: any) {
98-
toast.error(`Error updating ticket: ${error.message}`);
99+
toast.error(`Error updating ticket: ${handleError(error)}`);
99100
setLoading(false);
100101
}
101102
};

Diff for: src/components/ErrorHandle.tsx

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
interface ErrorMessages {
2+
[key: string]: string;
3+
}
4+
5+
const DEFAULT_MESSAGE = "Something went wrong. Please try again.";
6+
7+
const ERROR_MESSAGES: ErrorMessages = {
8+
JWT_MISSING: "Please sign in to continue",
9+
JWT_EXPIRED: "Please sign in to continue",
10+
AUTHENTICATION_ERROR: "Please sign in to continue",
11+
ORG_JWT_EXPIRED: "Please sign in to continue",
12+
UNAUTHENTICATED: "Please sign in to continue",
13+
INVALID_EVENT_TOKEN: "Please sign in to continue",
14+
AccountNotFound: "Please sign in to continue",
15+
16+
FORBIDDEN: "You don't have permission for this action",
17+
USER_NOT_ACTIVE: "You don't have permission for this action",
18+
19+
NOT_FOUND: DEFAULT_MESSAGE,
20+
USER_NOT_FOUND: DEFAULT_MESSAGE,
21+
ORG_NOT_FOUND: DEFAULT_MESSAGE,
22+
EVENT_NOT_FOUND: DEFAULT_MESSAGE,
23+
24+
UserInputError: "Please check your input and try again",
25+
INVALID_INPUT: "Please check your input and try again",
26+
BAD_REQUEST: "Please check your input and try again",
27+
VALIDATION_ERROR: "Please check your input and try again",
28+
INVALID_TRAINEE_SCORE: "Please check your input and try again",
29+
30+
ATTENDANCE_WEEK_COMPLETE: "Attendance for this week is complete",
31+
ATTENDANCE_ALREADY_RECORDED: "Attendance already recorded",
32+
INCONSISTENT_TRAINEE_ATTENDANCE: "Please complete attendance for all trainees",
33+
UPDATE_ATTENDANCE_ERROR: DEFAULT_MESSAGE,
34+
35+
INTERNAL_SERVER_ERROR: DEFAULT_MESSAGE,
36+
SERVER_ERROR: DEFAULT_MESSAGE
37+
};
38+
39+
export const handleError = (error: any): string => {
40+
if (error?.graphQLErrors?.length > 0) {
41+
const gqlError = error.graphQLErrors[0];
42+
const errorCode = gqlError?.extensions?.code;
43+
44+
return ERROR_MESSAGES[errorCode] || DEFAULT_MESSAGE;
45+
}
46+
47+
if (error?.networkError) {
48+
return "Please check your internet connection and try again";
49+
}
50+
51+
return DEFAULT_MESSAGE;
52+
};

Diff for: src/components/EventGuestList.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import { useQuery } from "@apollo/client";
33
import { toast } from "react-toastify";
44
import { GET_ALL_USERS_QUERY } from "../queries/manageStudent.queries";
5+
import { handleError } from "./ErrorHandle";
56

67
export const getRoleColor = (role: string) => {
78
switch (role) {
@@ -46,7 +47,7 @@ function EventGuestList({ selectedGuests, handleAddGuest }: { selectedGuests: st
4647
},
4748
fetchPolicy: 'network-only',
4849
onError: (error) => {
49-
toast.error(error.message);
50+
toast.error(handleError(error));
5051
},
5152
},
5253
);

Diff for: src/components/ModalAttendance.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ function ModalAttendance({
7777
onClose();
7878
},
7979
onError: (error) => {
80-
const errorMessage =
81-
error.graphQLErrors?.[0]?.message || 'An unexpected error occurred';
82-
toast.error(errorMessage);
80+
toast.error("Something went wrong!");
8381
},
8482
});
8583

Diff for: src/components/NewTicketModal.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useMemo } from 'react';
22
import { useMutation } from '@apollo/client';
33
import { toast } from 'react-toastify';
44
import CREATE_TICKET from '../Mutations/help.mutation';
5+
import { handleError } from './ErrorHandle';
56

67
interface NewTicketModalProps {
78
isOpen: boolean;
@@ -37,7 +38,7 @@ function NewTicketModal({
3738
},
3839
onError: (error) => {
3940
setLoading(false);
40-
toast.error(`Error creating ticket: ${error.message}`);
41+
toast.error(handleError(error));
4142
},
4243
});
4344

@@ -85,7 +86,7 @@ function NewTicketModal({
8586
},
8687
});
8788
} catch (error: any) {
88-
toast.error(`Error submitting ticket: ${error.message}`);
89+
toast.error(handleError(error));
8990
}
9091
};
9192

Diff for: src/components/Organizations.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { AddOrganization } from '../Mutations/OrganisationMutations';
1717
import { GET_ORGANIZATIONS } from '../queries/organization.queries';
1818
import jwtDecode from 'jwt-decode';
1919
import { useSearchParams,useNavigate } from 'react-router-dom';
20+
import { handleError } from './ErrorHandle';
2021

2122
export interface Admin {
2223
id: string;
@@ -151,7 +152,7 @@ const ApproveNewOrganization= async (token:string)=>{
151152
toast.error(`${name} organization approval failed.`);
152153
}
153154
} catch (error:any) {
154-
toast.error(`An error occurred, Try again`);
155+
toast.error(handleError(error));
155156
}
156157
}
157158

@@ -216,7 +217,7 @@ useEffect(() => {
216217

217218
const [addOrganizationMutation, { loading }] = useMutation(AddOrganization, {
218219
onError(error) {
219-
toast.error(error.message.toString());
220+
toast.error(handleError(error).toString());
220221
},
221222
onCompleted() {
222223
toast.success('Email Sent Successfully');
@@ -227,7 +228,7 @@ useEffect(() => {
227228
const [RegisterOrganizationMutation] = useMutation(RegisterNewOrganization, {
228229
onError(error) {
229230
setIsLoad(false);
230-
toast.error(error.message.toString());
231+
toast.error(handleError(error).toString());
231232
},
232233
onCompleted() {
233234
setIsLoad(false);
@@ -238,11 +239,11 @@ useEffect(() => {
238239

239240
const [deleteOrganizationMutation] = useMutation(DeleteOrganization, {
240241
onError(error) {
241-
toast.error(error.message.toString());
242+
toast.error(handleError(error).toString());
242243
},
243244
onCompleted() {
244245
setIsLoad(false);
245-
toast.success('Organisation Deleted.');
246+
toast.success('Organization Deleted Successfully');
246247
getRefetch();
247248
},
248249
});
@@ -265,7 +266,7 @@ useEffect(() => {
265266
return { success: false};
266267
}
267268
} catch (error:any) {
268-
toast.error(`An error occurred, Try again`);
269+
toast.error(handleError(error));
269270
}
270271
}
271272

Diff for: src/components/ProfileCoverpage.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Avatar from '../assets/avatar.png';
1919
import Spinner from '../components/ButtonLoading';
2020
import { UserContext } from '../hook/useAuth';
2121
import { UPDATE_AVATAR, UPDATE_COVER } from '../Mutations/coverMutations';
22+
import { handleError } from './ErrorHandle';
2223

2324
export default function ProfileCoverpage({
2425
currentPage,
@@ -63,7 +64,7 @@ export default function ProfileCoverpage({
6364
if (updated) {
6465
setSpinner(false);
6566
setProfileImage(updated?.data?.updateAvatar?.avatar);
66-
toast.success('updated');
67+
toast.success('Updated successfully');
6768
}
6869
/* istanbul ignore next */
6970
if (updated?.data?.updateAvatar?.avatar) {
@@ -95,7 +96,7 @@ export default function ProfileCoverpage({
9596
setSpinnerCover(true);
9697
if (updated) {
9798
setSpinnerCover(false);
98-
toast.success('updated');
99+
toast.success('updated successfully');
99100
}
100101
/* istanbul ignore next */
101102
if (updated?.data?.updateCoverImage?.cover) {
@@ -117,7 +118,7 @@ export default function ProfileCoverpage({
117118
setProfileData(data);
118119
} catch (error: any) {
119120
/* istanbul ignore next */
120-
toast.error(error?.message || 'Something went wrong');
121+
toast.error(handleError(error));
121122
}
122123
};
123124
fetchData();

0 commit comments

Comments
 (0)