From 2fed05d25f9683d534c23f34ea6b6502dbb04ddd Mon Sep 17 00:00:00 2001 From: yashmantri Date: Thu, 17 Aug 2023 16:47:30 +0530 Subject: [PATCH] TP-36903 | PR comments Resolved --- src/action/agentPerformanceAction.ts | 144 ++++++++++++++++------ src/screens/Dashboard/DashboardHeader.tsx | 41 +++--- src/screens/Dashboard/PerformanceCard.tsx | 45 ++++--- src/screens/Dashboard/index.tsx | 47 +------ src/screens/Dashboard/interface.ts | 20 +++ src/screens/auth/ProtectedRouter.tsx | 10 +- src/screens/cashCollected/index.tsx | 31 ++--- src/store/store.ts | 2 +- 8 files changed, 185 insertions(+), 155 deletions(-) diff --git a/src/action/agentPerformanceAction.ts b/src/action/agentPerformanceAction.ts index 752749f3..adafdd32 100644 --- a/src/action/agentPerformanceAction.ts +++ b/src/action/agentPerformanceAction.ts @@ -1,52 +1,122 @@ import axiosInstance, { ApiKeys, API_STATUS_CODE, getApiUrl } from '../components/utlis/apiHelper'; import { logError } from '../components/utlis/errorUtils'; +import { + setCashCollectedData, + setIsloading, + setPerformanceData, +} from '../reducer/agentPerformanceSlice'; +import { setIsExternalAgent } from '../reducer/userSlice'; +import { + CashCollectedData, + CashCollectedSplitPayload, + PaginationDetails, +} from '../screens/Dashboard/interface'; +import { getCashCollectedData, getFiltersCount } from '../screens/Dashboard/utils'; +import { AppDispatch } from '../store/store'; -export const getAgentDetail = () => { +export const getAgentDetail = (callbackFn: () => void) => (dispatch: AppDispatch) => { const url = getApiUrl(ApiKeys.GET_AGENT_DETAIL); return axiosInstance .get(url) .then((response) => { if (response.status === API_STATUS_CODE.OK) { - return response.data; + dispatch(setIsExternalAgent(response?.data?.isExternalAgent)); } - throw response; }) .catch((err) => { logError(err); - throw new Error(err); - }); + }) + .finally(() => callbackFn()); }; -export const getPerformanceMetrics = () => { - const url = getApiUrl(ApiKeys.GET_PERFORMANCE_METRICS); - return axiosInstance - .get(url) - .then((response) => { - if (response.status === API_STATUS_CODE.OK) { - return response.data; - } - throw response; - }) - .catch((err) => { - logError(err); - throw new Error(err); - }); -}; +export const getPerformanceMetrics = + ( + caseDetailsIds: Array, + setIsLoading: (isLoading: boolean) => void, + callbackFn?: () => void + ) => + (dispatch: AppDispatch) => { + const url = getApiUrl(ApiKeys.GET_PERFORMANCE_METRICS); + return axiosInstance + .get(url) + .then((response) => { + if (response.status === API_STATUS_CODE.OK) { + const { + visitedCases, + contactableCases, + ptpCases, + convertedPtpCases, + atLeastOneEmiCollectedCases, + } = response?.data?.casesSplit; + const { totalLevel, currentLevel } = response?.data?.performanceLevel; + const { unVisitedCount, nonContactableCount, nonPtpCount, brokenPtpCount } = + getFiltersCount(caseDetailsIds, response?.data?.casesSplit); -export const getCashCollectedSplit = (payload: any) => { - const url = getApiUrl(ApiKeys.GET_CASH_COLLECTED); - return axiosInstance - .get(url, { - params: payload, - }) - .then((response) => { - if (response.status === API_STATUS_CODE.OK) { - return response.data; - } - throw response; - }) - .catch((err) => { - logError(err); - throw new Error(err); - }); -}; + dispatch( + setPerformanceData({ + cases: { + visitedCases, + unvisitedCases: unVisitedCount, + contactableCases, + nonContactableCases: nonContactableCount, + totalPtp: ptpCases, + nonPtp: nonPtpCount, + convertedPtp: convertedPtpCases, + brokenPtp: brokenPtpCount, + totalEmi: response?.data?.allCases, + atleastOneEmiCollected: atLeastOneEmiCollectedCases, + }, + performanceLevel: { + totalLevel, + currentLevel, + }, + totalCashCollected: response?.data?.totalCashCollected, + lastUpdatedAt: response?.data?.lastUpdatedAt, + }) + ); + } + return; + }) + .catch((err) => { + logError(err); + }) + .finally(() => { + callbackFn && callbackFn(); + setIsLoading(false); + }); + }; + +export const getCashCollectedSplit = + ( + payload: CashCollectedSplitPayload, + caseDetailsIds: Array, + cashCollectedData: CashCollectedData, + setPaginationDetails: (data: PaginationDetails) => void, + callbackFn?: () => void + ) => + (dispatch: AppDispatch) => { + const url = getApiUrl(ApiKeys.GET_CASH_COLLECTED); + return axiosInstance + .get(url, { + params: payload, + }) + .then((response) => { + if (response.status === API_STATUS_CODE.OK) { + const cashData = response?.data?.data; + setPaginationDetails(response?.data?.pages); + const cashCollected = getCashCollectedData(cashData, caseDetailsIds); + if (response?.data?.pages?.pageNo === 0) { + dispatch(setCashCollectedData(cashCollected)); + return; + } + dispatch(setCashCollectedData([...cashCollectedData.data, ...cashCollected])); + } + }) + .catch((err) => { + logError(err); + }) + .finally(() => { + dispatch(setIsloading(false)); + callbackFn && callbackFn(); + }); + }; diff --git a/src/screens/Dashboard/DashboardHeader.tsx b/src/screens/Dashboard/DashboardHeader.tsx index 0d232dbd..3027169a 100644 --- a/src/screens/Dashboard/DashboardHeader.tsx +++ b/src/screens/Dashboard/DashboardHeader.tsx @@ -14,28 +14,27 @@ const DashboardHeader = () => { const performanceData = useAppSelector((state) => state.agentPerformance.performanceData); const { lastUpdatedAt } = performanceData; return ( - - - - - {PerfomanceHeaderTitle} - - - Last updated at{' '} - {sanitizeString(`${dateFormat(new Date(lastUpdatedAt ?? 0), BUSINESS_TIME_FORMAT)}`)} - - - + + + + {PerfomanceHeaderTitle} + + + Last updated at{' '} + {sanitizeString(`${dateFormat(new Date(lastUpdatedAt ?? 0), BUSINESS_TIME_FORMAT)}`)} + - + + ); }; diff --git a/src/screens/Dashboard/PerformanceCard.tsx b/src/screens/Dashboard/PerformanceCard.tsx index a67a9588..ba62a2ce 100644 --- a/src/screens/Dashboard/PerformanceCard.tsx +++ b/src/screens/Dashboard/PerformanceCard.tsx @@ -10,7 +10,11 @@ import { useAppDispatch, useAppSelector } from '../../hooks'; import { setFilteredListToast } from '../../reducer/allCasesSlice'; import { setSelectedFilters } from '../../reducer/filtersSlice'; import { BOTTOM_TAB_ROUTES } from '../allCases/constants'; -import { CurrentAllocationStatsFilterMap, CurrentAllocationStatsMap } from './interface'; +import { + CurrentAllocationStatsFilterMap, + CurrentAllocationStatsMap, + PerformanceDetailsType, +} from './interface'; import { getPerformanceDetailFilter, getPerformanceDetails } from './utils'; const PerformanceCard = () => { @@ -23,30 +27,31 @@ const PerformanceCard = () => { const dispatch = useAppDispatch(); + const handlePress = (item: PerformanceDetailsType) => { + dispatch( + setSelectedFilters( + getPerformanceDetailFilter( + item.redirectionType, + Object.keys(filters['COMMON']?.filters)?.includes( + CurrentAllocationStatsFilterMap[item.redirectionType] + ) + ) + ) + ); + dispatch( + setFilteredListToast({ + showToast: true, + caseType: CurrentAllocationStatsMap[item.redirectionType], + }) + ); + navigateToScreen(BOTTOM_TAB_ROUTES.Cases); + }; return ( {performanceDetails.map((item) => ( { - dispatch( - setSelectedFilters( - getPerformanceDetailFilter( - item.redirectionType, - Object.keys(filters['COMMON']?.filters)?.includes( - CurrentAllocationStatsFilterMap[item.redirectionType] - ) - ) - ) - ); - dispatch( - setFilteredListToast({ - showToast: true, - caseType: CurrentAllocationStatsMap[item.redirectionType], - }) - ); - navigateToScreen(BOTTOM_TAB_ROUTES.Cases); - }} + onPress={() => handlePress(item)} style={[ getShadowStyle(2), GenericStyles.br6, diff --git a/src/screens/Dashboard/index.tsx b/src/screens/Dashboard/index.tsx index e157fa3a..8e06cffa 100644 --- a/src/screens/Dashboard/index.tsx +++ b/src/screens/Dashboard/index.tsx @@ -10,13 +10,10 @@ import { import { GenericStyles } from '../../../RN-UI-LIB/src/styles'; import { COLORS } from '../../../RN-UI-LIB/src/styles/colors'; import { getPerformanceMetrics } from '../../action/agentPerformanceAction'; -import { logError } from '../../components/utlis/errorUtils'; import { useAppDispatch, useAppSelector } from '../../hooks'; -import { setPerformanceData } from '../../reducer/agentPerformanceSlice'; import DashboardHeader from './DashboardHeader'; import PerformanceCard from './PerformanceCard'; import PerformanceOverview from './PerformanceOverview'; -import { getFiltersCount } from './utils'; const Dashboard = () => { const [refreshing, setRefreshing] = React.useState(false); @@ -27,49 +24,7 @@ const Dashboard = () => { const fetchAgentPerformanceMetrics = (callbackFn?: () => void) => { setIsLoading(true); - getPerformanceMetrics() - .then((res) => { - const { - visitedCases, - contactableCases, - ptpCases, - convertedPtpCases, - atLeastOneEmiCollectedCases, - } = res?.casesSplit; - const { totalLevel, currentLevel } = res?.performanceLevel; - const { unVisitedCount, nonContactableCount, nonPtpCount, brokenPtpCount } = - getFiltersCount(caseDetailsIds, res?.casesSplit); - - dispatch( - setPerformanceData({ - cases: { - visitedCases, - unvisitedCases: unVisitedCount, - contactableCases, - nonContactableCases: nonContactableCount, - totalPtp: ptpCases, - nonPtp: nonPtpCount, - convertedPtp: convertedPtpCases, - brokenPtp: brokenPtpCount, - totalEmi: res?.allCases, - atleastOneEmiCollected: atLeastOneEmiCollectedCases, - }, - performanceLevel: { - totalLevel, - currentLevel, - }, - totalCashCollected: res?.totalCashCollected, - lastUpdatedAt: res?.lastUpdatedAt, - }) - ); - }) - .catch((err) => { - logError(err); - }) - .finally(() => { - callbackFn && callbackFn(); - setIsLoading(false); - }); + dispatch(getPerformanceMetrics(caseDetailsIds, setIsLoading, callbackFn)); }; useEffect(() => { diff --git a/src/screens/Dashboard/interface.ts b/src/screens/Dashboard/interface.ts index 760c6d04..3dc927a7 100644 --- a/src/screens/Dashboard/interface.ts +++ b/src/screens/Dashboard/interface.ts @@ -79,3 +79,23 @@ export const CurrentAllocationStatsFilterMap = { [CurrentAllocationStats.NON_PTP]: CurrentAllocationStatsFilter.PTP_STATUS, [CurrentAllocationStats.BROKEN_PTP]: CurrentAllocationStatsFilter.PTP_BREAKAGE, }; + +export interface PerformanceDetailsType { + totalConverted: number; + convertedText: string; + totalNotConverted: number; + notConvertedText: string; + redirectionType: CurrentAllocationStats; +} + +export interface PaginationDetails { + pageNo: number; + totalPages: number; + pageSize: number; + totalElements: number; +} + +export interface CashCollectedSplitPayload { + pageNo: number; + pageSize: number; +} diff --git a/src/screens/auth/ProtectedRouter.tsx b/src/screens/auth/ProtectedRouter.tsx index c5f820de..17f09e17 100644 --- a/src/screens/auth/ProtectedRouter.tsx +++ b/src/screens/auth/ProtectedRouter.tsx @@ -34,7 +34,6 @@ import TodoList from '../todoList/TodoList'; import UngroupedAddressContainer from '../addressGeolocation/UngroupedAddressContainer'; import CashCollected from '../cashCollected'; import { getAgentDetail } from '../../action/agentPerformanceAction'; -import { setIsExternalAgent } from '../../reducer/userSlice'; import FullScreenLoader from '../../../RN-UI-LIB/src/components/FullScreenLoader'; const Stack = createNativeStackNavigator(); @@ -115,14 +114,7 @@ const ProtectedRouter = () => { useEffect(() => { if (isOnline) { setIsLoading(true); - getAgentDetail() - .then((res) => { - dispatch(setIsExternalAgent(res?.isExternalAgent)); - }) - .catch(() => { - dispatch(setIsExternalAgent(false)); - }) - .finally(() => setIsLoading(false)); + dispatch(getAgentDetail(() => setIsLoading(false))); } }, [isOnline]); diff --git a/src/screens/cashCollected/index.tsx b/src/screens/cashCollected/index.tsx index b57965bf..ce51f4b7 100644 --- a/src/screens/cashCollected/index.tsx +++ b/src/screens/cashCollected/index.tsx @@ -16,13 +16,11 @@ import { _map } from '../../../RN-UI-LIB/src/utlis/common'; import { getCashCollectedSplit } from '../../action/agentPerformanceAction'; import NoRepaymentsFoundIcon from '../../assets/icons/NoRepaymentsFoundIcon'; import NotificationMenu from '../../components/notificationMenu'; -import { logError } from '../../components/utlis/errorUtils'; import { goBack } from '../../components/utlis/navigationUtlis'; import { useAppDispatch, useAppSelector } from '../../hooks'; -import { setCashCollectedData, setIsloading } from '../../reducer/agentPerformanceSlice'; +import { setIsloading } from '../../reducer/agentPerformanceSlice'; import { RootState } from '../../store/store'; import { NO_CASH_COLLECTED_FOUND } from '../Dashboard/constants'; -import { getCashCollectedData } from '../Dashboard/utils'; import Layout from '../layout/Layout'; import CashCollectedItem from './CashCollectedItem'; @@ -48,24 +46,15 @@ const CashCollected = () => { const fetchCashCollectedData = (pageNo: number, callbackFn?: () => void) => { dispatch(setIsloading(true)); - getCashCollectedSplit({ pageNo, pageSize: 10 }) - .then((res) => { - const cashData = res?.data; - setPaginationDetails(res?.pages); - const cashCollected = getCashCollectedData(cashData, caseDetailsIds); - if (res?.pages?.pageNo === 0) { - dispatch(setCashCollectedData(cashCollected)); - return; - } - dispatch(setCashCollectedData([...cashCollectedData.data, ...cashCollected])); - }) - .catch((err) => { - logError(err); - }) - .finally(() => { - dispatch(setIsloading(true)); - callbackFn && callbackFn(); - }); + dispatch( + getCashCollectedSplit( + { pageNo, pageSize: 10 }, + caseDetailsIds, + cashCollectedData, + setPaginationDetails, + callbackFn + ) + ); }; const fetchMoreData = () => { diff --git a/src/store/store.ts b/src/store/store.ts index d81087f1..d114c427 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -74,7 +74,7 @@ const persistConfig = { 'profile', 'foregroundService', ], - blackList: ['case', 'filters'], + blackList: ['case', 'filters', 'agentPerformance'], }; const persistedReducer = persistReducer(persistConfig, rootReducer);