From 49444647953c4de05cc1f06f924f027364fb03d5 Mon Sep 17 00:00:00 2001 From: vivek kasture Date: Fri, 14 Jun 2024 19:22:23 +0530 Subject: [PATCH 1/3] Issue #PS-390 fix: Fixed toast message --- src/components/MarkBulkAttendance.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/MarkBulkAttendance.tsx b/src/components/MarkBulkAttendance.tsx index 6890a3f4..7f39f8ec 100644 --- a/src/components/MarkBulkAttendance.tsx +++ b/src/components/MarkBulkAttendance.tsx @@ -269,15 +269,17 @@ const MarkBulkAttendance: React.FC = ({ if (resp) { setShowUpdateButton(true); setLoading(false); - } - if (onSaveSuccess) { - if (presentCount === 0 && absentCount === 0) { - onSaveSuccess(false); - } else { - onSaveSuccess(true); + if (onSaveSuccess) { + if (presentCount === 0 && absentCount === 0) { + onSaveSuccess(false); + } else { + onSaveSuccess(true); + } + + onClose(); } - - onClose(); + } else { + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); } } catch (error) { console.error('Error fetching cohort list:', error); From ab14c48ffdd11a015b5d85bc10734cbca7422baa Mon Sep 17 00:00:00 2001 From: Rushikesh-Sonawane99 Date: Fri, 14 Jun 2024 19:40:07 +0530 Subject: [PATCH 2/3] Issue #PS-000 chore: Modified toast messages for something went wrong --- src/pages/attendance-history.tsx | 8 +++----- src/pages/attendance-overview.tsx | 9 +++------ src/pages/dashboard.tsx | 19 +++---------------- src/pages/learner-attendance-history.tsx | 9 ++------- src/pages/learner/[userId].tsx | 5 ++++- src/pages/profile.tsx | 5 +++-- 6 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/pages/attendance-history.tsx b/src/pages/attendance-history.tsx index aed666cd..ad4d67c8 100644 --- a/src/pages/attendance-history.tsx +++ b/src/pages/attendance-history.tsx @@ -49,8 +49,8 @@ import { usePathname } from 'next/navigation'; import { useRouter } from 'next/router'; import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; -import ToastMessage from '@/components/ToastMessage'; import { logEvent } from '@/utils/googleAnalytics'; +import { showToastMessage } from '@/components/Toastify'; interface user { userId: string; @@ -86,7 +86,6 @@ const UserAttendanceHistory = () => { const [open, setOpen] = useState(false); const [handleSaveHasRun, setHandleSaveHasRun] = React.useState(false); const searchRef = useRef(null); - const [isError, setIsError] = React.useState(false); const pathname = usePathname(); let userId: string; @@ -168,7 +167,7 @@ const UserAttendanceHistory = () => { } } catch (error) { console.error('Error fetching cohort list:', error); - setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); setLoading(false); } }; @@ -337,7 +336,7 @@ const UserAttendanceHistory = () => { } } catch (error) { console.error('Error fetching cohort list:', error); - setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); setLoading(false); } finally { setLoading(false); @@ -884,7 +883,6 @@ const UserAttendanceHistory = () => { {displayStudentList.length >= 1 ? : null} - {isError && } ); }; diff --git a/src/pages/attendance-overview.tsx b/src/pages/attendance-overview.tsx index 261395b4..1d6bc2ca 100644 --- a/src/pages/attendance-overview.tsx +++ b/src/pages/attendance-overview.tsx @@ -41,7 +41,6 @@ import OverviewCard from '@/components/OverviewCard'; import SearchIcon from '@mui/icons-material/Search'; import SortingModal from '@/components/SortingModal'; import StudentsStatsList from '@/components/LearnerAttendanceStatsListView'; -import ToastMessage from '@/components/ToastMessage'; import UpDownButton from '@/components/UpDownButton'; import { cohortList } from '@/services/CohortServices'; import { getMyCohortMemberList } from '@/services/MyClassDetailsService'; @@ -52,6 +51,7 @@ import { useRouter } from 'next/router'; import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; import { logEvent } from '@/utils/googleAnalytics'; +import { showToastMessage } from '@/components/Toastify'; interface AttendanceOverviewProps { // buttonText: string; @@ -91,7 +91,6 @@ const AttendanceOverview: React.FC = () => { const [numberOfDaysAttendanceMarked, setNumberOfDaysAttendanceMarked] = useState(0); const [dateRange, setDateRange] = React.useState(''); - const [isError, setIsError] = React.useState(false); const theme = useTheme(); const pathname = usePathname(); @@ -238,10 +237,9 @@ const AttendanceOverview: React.FC = () => { } } setLoading(false); - setIsError(false); } catch (error) { console.error('Error fetching cohort list:', error); - setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); setLoading(false); } }; @@ -439,7 +437,7 @@ const AttendanceOverview: React.FC = () => { } } catch (error) { console.error('Error fetching cohort list:', error); - setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); setLoading(false); } finally { setLoading(false); @@ -918,7 +916,6 @@ const AttendanceOverview: React.FC = () => { {t('COMMON.NO_DATA_FOUND')} )} - {isError && } ); }; diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index ec956803..6f2ea19b 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -36,7 +36,6 @@ import { import MarkBulkAttendance from '@/components/MarkBulkAttendance'; import OverviewCard from '@/components/OverviewCard'; -import ToastMessage from '@/components/ToastMessage'; import { showToastMessage } from '@/components/Toastify'; import WeekCalender from '@/components/WeekCalender'; import { getMyCohortMemberList } from '@/services/MyClassDetailsService'; @@ -87,13 +86,6 @@ const Dashboard: React.FC = () => { const [dateRange, setDateRange] = React.useState(''); const [allCenterAttendanceData, setAllCenterAttendanceData] = React.useState(cohortsData); - const [isError, setIsError] = React.useState(false); - // const [state, setState] = React.useState({ - // openModal: false, - // vertical: 'top', - // horizontal: 'center', - // }); - // const { vertical, horizontal, openModal } = state; const router = useRouter(); const theme = useTheme(); @@ -187,7 +179,7 @@ const Dashboard: React.FC = () => { } } catch (error) { console.error('Error fetching cohort list:', error); - setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); setLoading(false); } }; @@ -322,14 +314,13 @@ const Dashboard: React.FC = () => { filters, facets, }); - setIsError(false); return { cohortId, data: response?.data?.result }; } catch (error) { console.error( `Error fetching data for cohortId ${cohortId}:`, error ); - setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); return { cohortId, error }; } }); @@ -366,11 +357,10 @@ const Dashboard: React.FC = () => { .filter((item) => item.presentPercentage !== null); // Filter out items with no valid percentage // console.log('Filtered and merged data:', nameIDAttendanceArray); - setIsError(false); setAllCenterAttendanceData(nameIDAttendanceArray); } catch (error) { console.error('Error fetching attendance data:', error); - setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); } }; @@ -931,9 +921,6 @@ const Dashboard: React.FC = () => { - {isError && ( - - )} {/* { const [learnerAttendance, setLearnerAttendance] = useState< LearnerAttendanceData | undefined >(undefined); - const [isError, setIsError] = React.useState(false); useEffect(() => { if (typeof window !== 'undefined' && window.localStorage) { @@ -140,11 +139,10 @@ const LearnerAttendanceHistory = () => { {} ); setLearnerAttendance(attendanceData); - setIsError(false) setLoading(false); } } catch (err) { - setIsError(true) + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); setLoading(false); } finally { setLoading(false); @@ -240,9 +238,6 @@ const LearnerAttendanceHistory = () => { handleClose={handleModalClose} onAttendanceUpdate={() => setAttendanceUpdated(!attendanceUpdated)} /> - { isError && - - } ); }; diff --git a/src/pages/learner/[userId].tsx b/src/pages/learner/[userId].tsx index 08b1b723..9da9c8aa 100644 --- a/src/pages/learner/[userId].tsx +++ b/src/pages/learner/[userId].tsx @@ -64,6 +64,7 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { useRouter } from 'next/router'; import { useTranslation } from 'next-i18next'; import { logEvent } from '@/utils/googleAnalytics'; +import { showToastMessage } from '@/components/Toastify'; // import { UserData, updateCustomField } from '../utils/Interfaces'; @@ -285,6 +286,7 @@ const LearnerProfile: React.FC = () => { setIsError(false); } catch (error) { setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); setLoading(false); console.error('Error fetching user details:', error); } @@ -377,6 +379,7 @@ const LearnerProfile: React.FC = () => { setIsError(false); } catch (error) { setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); console.error( 'Error fetching getDoIdForAssesmentDetails results:', error @@ -676,6 +679,7 @@ const LearnerProfile: React.FC = () => { } } catch (error) { setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); console.error('Error:', error); } }; @@ -1599,7 +1603,6 @@ const LearnerProfile: React.FC = () => { - {isError && } ); }; diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx index b5dedf18..ba5408c3 100644 --- a/src/pages/profile.tsx +++ b/src/pages/profile.tsx @@ -33,7 +33,6 @@ import Image from 'next/image'; import Loader from '@/components/Loader'; import Modal from '@mui/material/Modal'; import PlaceOutlinedIcon from '@mui/icons-material/PlaceOutlined'; -import ToastMessage from '@/components/ToastMessage'; import { getLabelForValue } from '@/utils/Helper'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { useRouter } from 'next/router'; @@ -41,6 +40,7 @@ import { useTranslation } from 'next-i18next'; import userPicture from '@/assets/images/imageOne.jpg'; import user_placeholder from '../assets/images/user_placeholder.png'; import { logEvent } from '@/utils/googleAnalytics'; +import { showToastMessage } from '@/components/Toastify'; interface FieldOption { name: string; @@ -182,6 +182,7 @@ const TeacherProfile = () => { } catch (error) { setLoading(false); setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); console.error('Error fetching user details:', error); } } @@ -459,6 +460,7 @@ const TeacherProfile = () => { } } catch (error) { setIsError(true); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); console.error('Error:', error); } @@ -1145,7 +1147,6 @@ const TeacherProfile = () => { )}{' '} - {isError && } ); }; From e0ccaa5e67d728bf210f19d7d01f2baa14ffb95a Mon Sep 17 00:00:00 2001 From: vivek kasture Date: Fri, 14 Jun 2024 19:42:36 +0530 Subject: [PATCH 3/3] Issue #PS-390 fix: Fixed toast message for login --- src/pages/login.tsx | 49 ++++----------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/src/pages/login.tsx b/src/pages/login.tsx index a474e1d3..249e0790 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -8,17 +8,13 @@ import { } from '@mui/material'; import React, { useEffect, useRef, useState } from 'react'; import Select, { SelectChangeEvent } from '@mui/material/Select'; -import Snackbar, { SnackbarOrigin } from '@mui/material/Snackbar'; import { Visibility, VisibilityOff } from '@mui/icons-material'; import ReactGA from 'react-ga4'; import Checkbox from '@mui/material/Checkbox'; -import CloseIcon from '@mui/icons-material/Close'; import Image from 'next/image'; -import Link from '@mui/material/Link'; import Loader from '../components/Loader'; import MenuItem from '@mui/material/MenuItem'; -import ToastMessage from '@/components/ToastMessage'; import appLogo from '../../public/images/appLogo.png'; import config from '../../config.json'; import { getUserId } from '../services/ProfileService'; @@ -29,10 +25,7 @@ import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; import { telemetryFactory } from '@/utils/telemetry'; import { logEvent } from '@/utils/googleAnalytics'; - -interface State extends SnackbarOrigin { - openModal: boolean; -} +import { showToastMessage } from '@/components/Toastify'; const LoginPage = () => { const { t } = useTranslation(); @@ -40,7 +33,6 @@ const LoginPage = () => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [rememberMe, setRememberMe] = useState(false); - const [showToastMessage, setShowToastMessage] = useState(false); const [usernameError, setUsernameError] = useState(false); const [passwordError, setPasswordError] = useState(false); const [loading, setLoading] = useState(false); @@ -55,16 +47,6 @@ const LoginPage = () => { const passwordRef = useRef(null); const loginButtonRef = useRef(null); - const DEFAULT_POSITION: Pick = { - vertical: 'bottom', - horizontal: 'center', - }; - const [state, setState] = React.useState({ - openModal: false, - ...DEFAULT_POSITION, - }); - const { vertical, horizontal, openModal } = state; - useEffect(() => { if (typeof window !== 'undefined' && window.localStorage) { if (localStorage.getItem('preferredLanguage')) { @@ -124,13 +106,6 @@ const LoginPage = () => { password: password, }); if (response) { - setTimeout(() => { - setState({ - openModal: false, - ...DEFAULT_POSITION, - }); - }); - if (typeof window !== 'undefined' && window.localStorage) { const token = response?.result?.access_token; const refreshToken = response?.result?.refresh_token; @@ -144,7 +119,6 @@ const LoginPage = () => { } } setLoading(false); - setShowToastMessage(false); const telemetryInteract = { context: { env: 'sign-in', @@ -156,8 +130,6 @@ const LoginPage = () => { subtype: '', pageid: 'sign-in', uid: localStorage.getItem('userId') || 'Anonymous', - - }, }; telemetryFactory.interact(telemetryInteract); @@ -165,11 +137,11 @@ const LoginPage = () => { } catch (error: any) { setLoading(false); if (error.response && error.response.status === 404) { - handleClick({ ...DEFAULT_POSITION })(); - setShowToastMessage(true); + showToastMessage(t('LOGIN_PAGE.USERNAME_PASSWORD_NOT_CORRECT'), 'error'); + } else { console.error('Error:', error); - setShowToastMessage(true); + showToastMessage(t('LOGIN_PAGE.USERNAME_PASSWORD_NOT_CORRECT'), 'error'); } } } @@ -190,14 +162,6 @@ const LoginPage = () => { } }; - const handleClick = (newState: SnackbarOrigin) => () => { - setState({ ...newState, openModal: true }); - }; - - const handleClose = () => { - setState({ ...state, openModal: false }); - }; - useEffect(() => { const handlePasswordFocus = () => { if (loginButtonRef.current) { @@ -408,11 +372,6 @@ const LoginPage = () => { - {showToastMessage && ( - - )} );