-
Notifications
You must be signed in to change notification settings - Fork 178
/
customerList.js
64 lines (56 loc) · 1.78 KB
/
customerList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { LightningElement, api, wire } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import getCustomerList from '@salesforce/apex/reservationManagerController.getCustomerList';
import TILE_SELECTION_MC from '@salesforce/messageChannel/Tile_Selection__c';
import FLOW_STATUS_CHANGE_MC from '@salesforce/messageChannel/Flow_Status_Change__c';
import {
subscribe,
APPLICATION_SCOPE,
MessageContext,
publish
} from 'lightning/messageService';
export default class CustomerList extends LightningElement {
@api sobject;
customers = [];
errorMsg;
msgForUser;
wiredRecords;
@wire(MessageContext)
messageContext;
subscribeToMessageChannel() {
subscribe(
this.messageContext,
FLOW_STATUS_CHANGE_MC,
(message) => this.handleMessage(message),
{ scope: APPLICATION_SCOPE }
);
}
handleMessage(message) {
if (
message.flowName === 'createReservation' &&
message.status === 'FINISHED' &&
message.state
) {
if (message.state.sobjecttype === this.sobject) {
refreshApex(this.wiredRecords);
}
}
}
connectedCallback() {
this.subscribeToMessageChannel();
}
@wire(getCustomerList, { sObjectType: '$sobject' })
wiredCustomerData(value) {
this.wiredRecords = value;
if (value.error) {
this.errorMsg = value.error;
this.msgForUser = 'There was an issue loading customers.';
} else if (value.data) {
this.customers = value.data;
}
}
publishSelect(event) {
const payload = { tileType: 'customer', properties: event.detail };
publish(this.messageContext, TILE_SELECTION_MC, payload);
}
}