Resolved multiple popups on Share
This commit is contained in:
@@ -65,7 +65,7 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule {
|
||||
@Override
|
||||
public void onActivityResult(Activity activity, int i, int i1, @Nullable Intent intent) {
|
||||
if(i1 != RESULT_CANCELED) {
|
||||
if (i == WHATSAPP_SHARE_REQUEST_CODE) {
|
||||
if ((i == WHATSAPP_SHARE_REQUEST_CODE) && (imageFile!=null)) {
|
||||
new File(Uri.fromFile(imageFile).getPath()).delete();
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,9 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule {
|
||||
else if(numberOfAppsInstalled == 1) {
|
||||
String packageName = appsInstalled.get(0);
|
||||
Intent sendIntent = getWhatsappShareIntent(message, imageUrl, mimeType, packageName);
|
||||
getCurrentActivity().startActivityForResult(sendIntent, WHATSAPP_SHARE_REQUEST_CODE);
|
||||
if(getCurrentActivity()!=null) {
|
||||
getCurrentActivity().startActivityForResult(sendIntent, WHATSAPP_SHARE_REQUEST_CODE);
|
||||
}
|
||||
promise.resolve(true);
|
||||
return;
|
||||
}
|
||||
@@ -187,6 +189,7 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule {
|
||||
else {
|
||||
String packageName1 = appsInstalled.get(0);
|
||||
String packageName2 = appsInstalled.get(1);
|
||||
//Firing two intents, one for WhatsApp, another for WhatsApp business
|
||||
Intent sendIntent1 = getWhatsappShareIntent(message, imageUrl, mimeType, packageName1);
|
||||
Intent sendIntent2 = getWhatsappShareIntent(message, imageUrl, mimeType, packageName2);
|
||||
ArrayList<Intent> appIntents = new ArrayList<>();
|
||||
@@ -195,12 +198,13 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule {
|
||||
|
||||
Intent defaultIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||
defaultIntent.setType("text/plain");
|
||||
defaultIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Default text to share");
|
||||
defaultIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Sharing to WhatsApp");
|
||||
|
||||
Intent chooserIntent = Intent.createChooser(defaultIntent, "Share via");
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, appIntents.toArray(new Parcelable[appIntents.size()]));
|
||||
getCurrentActivity().startActivityForResult(chooserIntent, WHATSAPP_SHARE_REQUEST_CODE);
|
||||
|
||||
if(getCurrentActivity()!=null) {
|
||||
getCurrentActivity().startActivityForResult(chooserIntent, WHATSAPP_SHARE_REQUEST_CODE);
|
||||
}
|
||||
promise.resolve(true);
|
||||
return;
|
||||
|
||||
|
||||
@@ -368,10 +368,3 @@ export function getDistanceFromLatLonInKm(
|
||||
const distance = 2 * Math.atan2(Math.sqrt(intermediateResult), Math.sqrt(1 - intermediateResult));
|
||||
return EARTH_RADIUS * distance;
|
||||
}
|
||||
|
||||
export function insertCommasinAmount(amount: number | undefined) {
|
||||
const reversedAmount = amount?.toString().split('').reverse().join('');
|
||||
const groups = reversedAmount?.match(/.{1,3}/g);
|
||||
const result = groups?.join(',').split('').reverse().join('');
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
dateFormat,
|
||||
} from '../../../../RN-UI-LIB/src/utlis/dates';
|
||||
import {
|
||||
debounce,
|
||||
getGoogleMapUrl,
|
||||
insertCommasinAmount,
|
||||
sanitizeString,
|
||||
@@ -32,6 +33,7 @@ import { useAppSelector } from '../../../hooks';
|
||||
import { toast } from '../../../../RN-UI-LIB/src/components/toast';
|
||||
import { ToastMessages } from '../../allCases/constants';
|
||||
import { sendFeedbackToWhatsapp } from '../../../components/utlis/DeviceUtils';
|
||||
import { getSanitizedCommaAmount } from '@rn-ui-lib/utils/amount';
|
||||
|
||||
interface IFeedbackDetailItem {
|
||||
feedbackItem: IFeedback;
|
||||
@@ -69,116 +71,127 @@ function getLocationLink(latitude: string, longitude: string): string {
|
||||
return link;
|
||||
}
|
||||
|
||||
const sendToWhatsappNative = (
|
||||
message: string,
|
||||
imageUrl: string,
|
||||
mimeType: string,
|
||||
caseDetails: CaseDetail,
|
||||
agentId: string
|
||||
) => {
|
||||
sendFeedbackToWhatsapp(message, imageUrl, mimeType)
|
||||
.then((res: boolean) => {
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_SHARE_SUCCESSFUL, {
|
||||
caseId: caseDetails?.id,
|
||||
agentId: agentId,
|
||||
});
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
if (err.message === '1') {
|
||||
toast({
|
||||
text1: ToastMessages.WHATSAPP_NOT_INSTALLED,
|
||||
type: 'error',
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
text1: ToastMessages.WHATSAPP_FEEDBACK_SHARE_FAILURE,
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const sendToWhatsapp = (feedbackItem: IFeedback, caseDetails: CaseDetail, agentId: string) => {
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_SHARE_FEEDBACK_CLICKED, {
|
||||
caseId: caseDetails?.id,
|
||||
agentId: agentId,
|
||||
});
|
||||
|
||||
var message = `*Visit Feedback* for ${sanitizeString(caseDetails?.customerName)}
|
||||
_${sanitizeString(dateFormat(new Date(feedbackItem?.createdAt), 'DD MMM, YYYY | HH:mm a.'))}_\n
|
||||
*LAN*: ${sanitizeString(caseDetails?.loanAccountNumber)}
|
||||
*DPD Bucket*: ${sanitizeString(caseDetails?.dpdBucket)}
|
||||
*EMI Amount*: ₹${insertCommasinAmount(caseDetails?.outstandingEmiDetails?.[0]?.emiAmount)}\n
|
||||
*Disposition*: ${sanitizeString(feedbackItem?.interactionStatus)}`;
|
||||
|
||||
const ptpDate = feedbackItem?.answerViews.filter((answer) => answer.questionName === 'PTP Date');
|
||||
if (ptpDate.length > 0) {
|
||||
message +=
|
||||
' for ' + sanitizeString(dateFormat(new Date(ptpDate[0].inputDate), 'DD MMM, YYYY')) + '\n\n';
|
||||
} else {
|
||||
message += '\n\n';
|
||||
}
|
||||
|
||||
message += '*Remarks*: ';
|
||||
const answerList = feedbackItem?.answerViews?.filter(
|
||||
(answer) => answer.questionName === 'Comments'
|
||||
);
|
||||
if (answerList.length > 0) {
|
||||
message += sanitizeString(answerList[0]?.inputText) + '\n\n';
|
||||
} else {
|
||||
message += 'N.A.\n\n';
|
||||
}
|
||||
|
||||
{
|
||||
feedbackItem?.metadata?.interactionLatitude &&
|
||||
feedbackItem?.metadata?.interactionLongitude &&
|
||||
FIELD_FEEDBACKS.includes(feedbackItem?.type)
|
||||
? (message +=
|
||||
'*Location of feedback*: ' +
|
||||
sanitizeString(
|
||||
getLocationLink(
|
||||
feedbackItem?.metadata?.interactionLatitude,
|
||||
feedbackItem?.metadata?.interactionLongitude
|
||||
)
|
||||
) +
|
||||
'\n\n')
|
||||
: null;
|
||||
}
|
||||
|
||||
const imagesList = feedbackItem?.answerViews.filter(
|
||||
(answer) => answer.questionTag === OPTION_TAG.IMAGE_UPLOAD
|
||||
);
|
||||
var imageUrl = '';
|
||||
const mimeType = 'image/*';
|
||||
if (imagesList.length > 0) {
|
||||
var imageUri = '';
|
||||
imageUri = imagesList[0]?.inputText ? imagesList[0].inputText : '';
|
||||
let imagePath = '';
|
||||
ReactNativeBlobUtil.config({
|
||||
fileCache: true,
|
||||
})
|
||||
.fetch('GET', imageUri)
|
||||
.then((resp: any) => {
|
||||
if (resp.info().status !== 200) {
|
||||
return '';
|
||||
} else {
|
||||
imagePath = resp.path();
|
||||
return resp.readFile('base64');
|
||||
}
|
||||
})
|
||||
.then((base64Data: any) => {
|
||||
imageUrl = base64Data;
|
||||
sendToWhatsappNative(message, imageUrl, mimeType, caseDetails, agentId);
|
||||
ReactNativeBlobUtil.fs.unlink(imagePath);
|
||||
});
|
||||
} else {
|
||||
sendToWhatsappNative(message, imageUrl, mimeType, caseDetails, agentId);
|
||||
}
|
||||
};
|
||||
|
||||
const FeedbackDetailItem = ({ feedbackItem, isExpanded, caseId }: IFeedbackDetailItem) => {
|
||||
const caseDetails = useAppSelector((state) => state.allCases.caseDetails[caseId]);
|
||||
const { agentId } = useAppSelector((state) => ({ agentId: state.user.user?.referenceId!! }));
|
||||
const [isWhastappSendLoading, setIsWhatsappSendLoading] = useState(false);
|
||||
|
||||
const sendToWhatsappNative = (
|
||||
message: string,
|
||||
imageUrl: string,
|
||||
mimeType: string,
|
||||
caseDetails: CaseDetail,
|
||||
agentId: string
|
||||
) => {
|
||||
setIsWhatsappSendLoading(true);
|
||||
sendFeedbackToWhatsapp(message, imageUrl, mimeType)
|
||||
.then((res: boolean) => {
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_SHARE_SUCCESSFUL, {
|
||||
caseId: caseDetails?.id,
|
||||
agentId: agentId,
|
||||
});
|
||||
setIsWhatsappSendLoading(false);
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
setIsWhatsappSendLoading(false);
|
||||
if (err.message === '1') {
|
||||
toast({
|
||||
text1: ToastMessages.WHATSAPP_NOT_INSTALLED,
|
||||
type: 'error',
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
text1: ToastMessages.WHATSAPP_FEEDBACK_SHARE_FAILURE,
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const sendToWhatsapp = (feedbackItem: IFeedback, caseDetails: CaseDetail, agentId: string) => {
|
||||
setIsWhatsappSendLoading(true);
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_SHARE_FEEDBACK_CLICKED, {
|
||||
caseId: caseDetails?.id,
|
||||
agentId: agentId,
|
||||
});
|
||||
|
||||
var message = `*Visit Feedback* for ${sanitizeString(caseDetails?.customerName)}
|
||||
_${sanitizeString(dateFormat(new Date(feedbackItem?.createdAt), 'DD MMM, YYYY | HH:mm a.'))}_\n
|
||||
*LAN*: ${sanitizeString(caseDetails?.loanAccountNumber)}
|
||||
*DPD Bucket*: ${sanitizeString(caseDetails?.dpdBucket)}
|
||||
*EMI Amount*: ₹${getSanitizedCommaAmount(caseDetails?.currentOutstandingEmi)}\n
|
||||
*Disposition*: ${sanitizeString(feedbackItem?.interactionStatus)}`;
|
||||
|
||||
const ptpDate = feedbackItem?.answerViews.filter(
|
||||
(answer) => answer.questionName === 'PTP Date'
|
||||
);
|
||||
if (ptpDate.length > 0) {
|
||||
message +=
|
||||
' for ' +
|
||||
sanitizeString(dateFormat(new Date(ptpDate[0].inputDate), 'DD MMM, YYYY')) +
|
||||
'\n\n';
|
||||
} else {
|
||||
message += '\n\n';
|
||||
}
|
||||
|
||||
message += '*Remarks*: ';
|
||||
const answerList = feedbackItem?.answerViews?.filter(
|
||||
(answer) => answer.questionName === 'Comments'
|
||||
);
|
||||
if (answerList.length > 0) {
|
||||
message += sanitizeString(answerList[0]?.inputText) + '\n\n';
|
||||
} else {
|
||||
message += 'N.A.\n\n';
|
||||
}
|
||||
|
||||
{
|
||||
feedbackItem?.metadata?.interactionLatitude &&
|
||||
feedbackItem?.metadata?.interactionLongitude &&
|
||||
FIELD_FEEDBACKS.includes(feedbackItem?.type)
|
||||
? (message +=
|
||||
'*Location of feedback*: ' +
|
||||
sanitizeString(
|
||||
getLocationLink(
|
||||
feedbackItem?.metadata?.interactionLatitude,
|
||||
feedbackItem?.metadata?.interactionLongitude
|
||||
)
|
||||
) +
|
||||
'\n\n')
|
||||
: null;
|
||||
}
|
||||
|
||||
const imagesList = feedbackItem?.answerViews.filter(
|
||||
(answer) => answer.questionTag === OPTION_TAG.IMAGE_UPLOAD
|
||||
);
|
||||
var imageUrl = '';
|
||||
const mimeType = 'image/*';
|
||||
if (imagesList.length > 0) {
|
||||
var imageUri = '';
|
||||
imageUri = imagesList[0]?.inputText ? imagesList[0].inputText : '';
|
||||
let imagePath = '';
|
||||
ReactNativeBlobUtil.config({
|
||||
fileCache: true,
|
||||
})
|
||||
.fetch('GET', imageUri)
|
||||
.then((resp: any) => {
|
||||
if (resp.info().status !== 200) {
|
||||
return '';
|
||||
} else {
|
||||
imagePath = resp.path();
|
||||
return resp.readFile('base64');
|
||||
}
|
||||
})
|
||||
.then((base64Data: any) => {
|
||||
imageUrl = base64Data;
|
||||
sendToWhatsappNative(message, imageUrl, mimeType, caseDetails, agentId);
|
||||
ReactNativeBlobUtil.fs.unlink(imagePath);
|
||||
});
|
||||
} else {
|
||||
sendToWhatsappNative(message, imageUrl, mimeType, caseDetails, agentId);
|
||||
}
|
||||
};
|
||||
|
||||
const throttledSendToWhatsapp = React.useRef(debounce(sendToWhatsapp, 500));
|
||||
return (
|
||||
<View style={[styles.addressItem]}>
|
||||
<View style={[GenericStyles.row, GenericStyles.alignCenter]}>
|
||||
@@ -244,8 +257,11 @@ const FeedbackDetailItem = ({ feedbackItem, isExpanded, caseId }: IFeedbackDetai
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
activeOpacity={0.7}
|
||||
onPress={() => sendToWhatsapp(feedbackItem, caseDetails, agentId)}
|
||||
onPress={() => {
|
||||
throttledSendToWhatsapp.current(feedbackItem, caseDetails, agentId);
|
||||
}}
|
||||
style={[GenericStyles.row, styles.BtnPadding]}
|
||||
disabled={isWhastappSendLoading}
|
||||
>
|
||||
<IconLabel
|
||||
text="Share"
|
||||
|
||||
Reference in New Issue
Block a user