NTP-12177 | fix addresses api

This commit is contained in:
Aman Chaturvedi
2024-11-15 19:08:35 +05:30
parent ca1b83b234
commit d1eea72568
7 changed files with 43 additions and 12 deletions

View File

@@ -75,12 +75,15 @@ export const getUngroupedAddress =
.get(url)
.then((response) => {
if (response.status === API_STATUS_CODE.OK) {
const ungroupedAddressesWithFeedbacks = {
ungroupedAddresses: response?.data?.ungroupedAddresses || [],
ungroupedAddressFeedbacks: response?.data?.addressFeedbacks || [],
const data = {
loanAccountNumber,
ungroupedAddresses: response.data?.ungroupedAddresses,
ungroupedAddressFeedbacks: response.data?.addressFeedbacks || [],
};
dispatch(setUngroupedAddresses(ungroupedAddressesWithFeedbacks));
if (!includeFeedbacks) {
delete response.data?.addressFeedbacks;
}
dispatch(setUngroupedAddresses(data));
}
})
.catch((err) => {

View File

@@ -52,7 +52,16 @@ export const getAddressesAndGeolocations =
axiosInstance
.get(url)
.then((res) => {
dispatch(setAddresses({ loanAccountNumber, groupedAddressesAndGeoLocations: res.data }));
const { groupedAddressesAndGeoLocations, addressFeedbacks } = res.data;
const data = {
loanAccountNumber,
groupedAddressesAndGeoLocations,
addressFeedbacks: addressFeedbacks || [],
};
if (!includeFeedbacks) {
delete data.addressFeedbacks;
}
dispatch(setAddresses(data));
})
.catch((err) => {
logError(err as Error, 'Error fetching addresses and geolocations data');

View File

@@ -59,7 +59,7 @@ const CollectionCaseDetails: React.FC<ICaseDetails> = (props) => {
useEffect(() => {
if (caseId) dispatch(setSelectedCaseId(caseId));
dispatch(getFeedbackHistory(loanAccountNumber));
return () => {
dispatch(setSelectedCaseId(''));
};
@@ -69,7 +69,6 @@ const CollectionCaseDetails: React.FC<ICaseDetails> = (props) => {
React.useCallback(() => {
if (loanAccountNumber) {
dispatch(getAddressesAndGeolocations(loanAccountNumber));
dispatch(getFeedbackHistory(loanAccountNumber));
dispatch(getUngroupedAddress(loanAccountNumber));
}
}, [loanAccountNumber])

View File

@@ -24,6 +24,9 @@ const FeedbackDetailsSection = ({ caseId }: IFeedbackDetailsSection) => {
const feedbackList = useAppSelector(
(state: RootState) => state.feedbackHistory?.[loanAccountNumber as string]?.data || []
);
const feedbackListLoading = useAppSelector(
(state: RootState) => state.feedbackHistory?.[loanAccountNumber as string]?.isLoading
);
const allCasesDetails = useAppSelector((state: RootState) => state.allCases.caseDetails);
const openAllFeedbacksHandler = () => {
@@ -85,6 +88,7 @@ const FeedbackDetailsSection = ({ caseId }: IFeedbackDetailsSection) => {
feedbackList={[...getUnSyncedFeedback(), ...feedbackList]?.splice(0, 5)}
loanAccountNumber={loanAccountNumber}
caseId={caseId}
loading={feedbackListLoading}
/>
</View>
</View>

View File

@@ -20,6 +20,7 @@ interface IFeedbackListContainer {
loanAccountNumber: string;
feedbackList: (IFeedback | IUnSyncedFeedbackItem)[];
caseId: string;
loading: boolean;
}
interface IOfflineFeedbackListContainer {
@@ -69,6 +70,7 @@ const FeedbackListContainer: React.FC<IFeedbackListContainer> = ({
loanAccountNumber,
feedbackList,
caseId,
loading,
}) => {
const [retryBtnCount, setRetryBtnCount] = useState(0);
@@ -94,7 +96,7 @@ const FeedbackListContainer: React.FC<IFeedbackListContainer> = ({
}
return (
<SuspenseLoader loading={false} fallBack={<FeedbackLoading />}>
<SuspenseLoader loading={loading} fallBack={<FeedbackLoading />}>
<View>
{feedbackList.map((feedbackItem: IFeedback | IUnSyncedFeedbackItem, idx: number) => (
<FeedbackListItem

View File

@@ -10,7 +10,7 @@ const FeedbackLoading = (props: IFeedbackLoading) => {
return (
<View>
{Array.from({ length: arrayLength }).map((_, idx) => (
<View style={[!isTopFeedbackItem ? GenericStyles.ph16 : {}]}>
<View key={idx} style={[!isTopFeedbackItem ? GenericStyles.ph16 : {}]}>
<View
style={[
GenericStyles.pv16,

View File

@@ -8,7 +8,7 @@ import { getTransformedCollectionCaseItem } from '../../services/casePayload.tra
import { addClickstreamEvent } from '../../services/clickstreamEventService';
import { CaseAllocationType } from '../allCases/interface';
import { CaseDetail } from './interface';
import { uploadImages } from '../../action/caseApiActions';
import { getFeedbackHistory, uploadImages } from '../../action/caseApiActions';
import { setDocumentInteractionId } from '../../reducer/feedbackImagesSlice';
export const getUnSyncedCase = (updatedCaseDetail: CaseDetail | undefined): any => {
@@ -33,13 +33,21 @@ const interactionsHandler = () => {
const inProgressCaseIds = useRef<string[]>([]);
const handleSuccessSubmit = (caseKey: string, interactionId: string, caseId: string) => {
const handleSuccessSubmit = (
caseKey: string,
interactionId: string,
caseId: string,
loanAccountNumber: string
) => {
const docs = docsToBeUploaded?.[caseKey]?.documents;
if (!docs) {
return;
}
dispatch(setDocumentInteractionId({ caseKey, interactionId, caseId }));
dispatch(uploadImages(caseKey, docs, interactionId));
if (loanAccountNumber) {
dispatch(getFeedbackHistory(loanAccountNumber));
}
};
useEffect(() => {
@@ -74,7 +82,13 @@ const interactionsHandler = () => {
}
dispatch(
syncCaseDetail(modifiedCaseItem, {
onSuccessCB: (_, interactionId) => handleSuccessSubmit(caseKey, interactionId, caseItem.caseId),
onSuccessCB: (_, interactionId) =>
handleSuccessSubmit(
caseKey,
interactionId,
caseItem.caseId,
caseItem.loanAccountNumber
),
})
);
}