83 lines
2.8 KiB
JavaScript
83 lines
2.8 KiB
JavaScript
import { track, api } from 'lwc';
|
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
|
import Botimage from '@salesforce/resourceUrl/Botimage';
|
|
import ChatMessage from 'lightningsnapin/baseChatMessage';
|
|
|
|
const CHAT_CONTENT_CLASS = 'chat-content';
|
|
const AGENT_USER_TYPE = 'agent';
|
|
const CHASITOR_USER_TYPE = 'chasitor';
|
|
const SUPPORTED_USER_TYPES = [AGENT_USER_TYPE, CHASITOR_USER_TYPE];
|
|
|
|
export default class calllwc extends ChatMessage {
|
|
@track messageStyle = '';
|
|
@track imageURL = Botimage;
|
|
@track name = 'Order Product Image';
|
|
@track showImage = false;
|
|
@track fileUpload = false; // Initialize to false
|
|
@track mapMarkers = []; // Initialize to empty array
|
|
@track showMap = false;
|
|
|
|
handleGeolocationSuccess(position) {
|
|
const { latitude, longitude } = position.coords;
|
|
this.mapMarkers = [{
|
|
location: {
|
|
Street: '',
|
|
City: '',
|
|
Country: '',
|
|
Latitude: latitude,
|
|
Longitude: longitude
|
|
},
|
|
title: 'You are here',
|
|
description: 'Your current location'
|
|
}];
|
|
}
|
|
|
|
handleClick(){
|
|
if(navigator.geolocation){
|
|
navigator.geolocation.getCurrentPosition(
|
|
this.handleGeolocationSuccess.bind(this),
|
|
error => console.error('Geolocation error:', error)
|
|
);
|
|
}
|
|
}
|
|
|
|
@api
|
|
handleUploadFinished(event) {
|
|
console.log('Upload finished');
|
|
// Get the list of uploaded files
|
|
const uploadedFiles = event.detail.files;
|
|
console.log('No. of files uploaded : ' + uploadedFiles.length);
|
|
console.log('file : ', event.detail.files);
|
|
|
|
// Show success message
|
|
const toastEvent = new ShowToastEvent({
|
|
title: 'Success!',
|
|
message: 'Upload completed successfully',
|
|
variant: 'success',
|
|
});
|
|
this.dispatchEvent(toastEvent);
|
|
}
|
|
|
|
isSupportedUserType(userType) {
|
|
return SUPPORTED_USER_TYPES.includes(userType);
|
|
}
|
|
|
|
connectedCallback() {
|
|
if (this.isSupportedUserType(this.userType)) {
|
|
this.messageStyle = `${CHAT_CONTENT_CLASS} ${this.userType}`;
|
|
} else {
|
|
throw new Error(`Unsupported user type: ${this.userType}`);
|
|
}
|
|
if (this.messageContent.value === 'Einstein Chatbot') {
|
|
this.showImage = true;
|
|
} else if (this.messageContent.value === 'File Upload') {
|
|
this.fileUpload = true;
|
|
} else if (this.messageContent.value === 'Current Location') {
|
|
this.handleClick(); // Call the handleClick method to get the current location
|
|
this.showMap = true;
|
|
console.log('Map ' ,this.showMap );
|
|
} else {
|
|
this.showImage = false;
|
|
}
|
|
}
|
|
} |