Skip to content

Commit 3408942

Browse files
authored
Merge pull request #471 from nyaruka/ticket-flow
Change how ticket workflow works when unmatched
2 parents 453d6c4 + 6266d9d commit 3408942

File tree

6 files changed

+67
-37
lines changed

6 files changed

+67
-37
lines changed

Diff for: src/contacts/ContactChat.ts

+30-20
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@ export class ContactChat extends ContactStoreElement {
519519
changedProperties.has('data') ||
520520
changedProperties.has('currentContact')
521521
) {
522+
// unschedule any previous refreshes
523+
if (this.refreshId) {
524+
clearTimeout(this.refreshId);
525+
this.refreshId = null;
526+
}
527+
522528
this.currentContact = this.data;
523529
}
524530

@@ -527,17 +533,6 @@ export class ContactChat extends ContactStoreElement {
527533
this.reset();
528534
this.fetchPreviousMessages();
529535
}
530-
531-
if (changedProperties.has('currentTicket')) {
532-
const users = this.shadowRoot.querySelector(
533-
'temba-user-select'
534-
) as UserSelect;
535-
if (users) {
536-
users.setValues(
537-
this.currentTicket?.assignee ? [this.currentTicket?.assignee] : []
538-
);
539-
}
540-
}
541536
}
542537

543538
private reset() {
@@ -609,7 +604,10 @@ export class ContactChat extends ContactStoreElement {
609604
}
610605

611606
private getEndpoint() {
612-
return `/contact/history/${this.contact}/?_format=json`;
607+
if (this.contact) {
608+
return `/contact/history/${this.contact}/?_format=json`;
609+
}
610+
return null;
613611
}
614612

615613
private scheduleRefresh() {
@@ -894,6 +892,9 @@ export class ContactChat extends ContactStoreElement {
894892
if (this.currentContact && this.newestEventTime) {
895893
this.polling = true;
896894
const endpoint = this.getEndpoint();
895+
if (!endpoint) {
896+
return;
897+
}
897898

898899
const fetchContact = this.currentContact.uuid;
899900

@@ -929,6 +930,10 @@ export class ContactChat extends ContactStoreElement {
929930
chat.fetching = true;
930931
if (this.currentContact) {
931932
const endpoint = this.getEndpoint();
933+
if (!endpoint) {
934+
return;
935+
}
936+
932937
fetchContactHistory(
933938
false,
934939
endpoint,
@@ -949,7 +954,9 @@ export class ContactChat extends ContactStoreElement {
949954
}
950955

951956
private fetchComplete() {
952-
this.chat.fetching = false;
957+
if (this.chat) {
958+
this.chat.fetching = false;
959+
}
953960
}
954961

955962
private getTembaCompose(): TemplateResult {
@@ -1003,6 +1010,7 @@ export class ContactChat extends ContactStoreElement {
10031010
private handleAssignmentChanged(evt: CustomEvent) {
10041011
const users = evt.currentTarget as UserSelect;
10051012
const assignee = users.values[0];
1013+
10061014
this.assignTicket(assignee ? assignee.email : null);
10071015
users.blur();
10081016
}
@@ -1054,13 +1062,15 @@ export class ContactChat extends ContactStoreElement {
10541062
if (this.currentTicket) {
10551063
fetchResults(`/api/v2/tickets.json?uuid=${this.currentTicket.uuid}`).then(
10561064
(values) => {
1057-
if (values.length > 0) {
1058-
this.fireCustomEvent(CustomEventType.TicketUpdated, {
1059-
ticket: values[0],
1060-
previous: this.currentTicket
1061-
});
1062-
this.currentTicket = values[0];
1063-
}
1065+
this.store.resolveUsers(values, ['assignee']).then(() => {
1066+
if (values.length > 0) {
1067+
this.fireCustomEvent(CustomEventType.TicketUpdated, {
1068+
ticket: values[0],
1069+
previous: this.currentTicket
1070+
});
1071+
this.currentTicket = values[0];
1072+
}
1073+
});
10641074
}
10651075
);
10661076
}

Diff for: src/list/TembaList.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,9 @@ export class TembaList extends RapidElement {
195195
const index = this.getItemIndex(value);
196196
this.items.splice(index, 1);
197197
this.items = [...this.items];
198-
199-
// if we were at the end, move us down
200-
this.cursorIndex = Math.max(
201-
0,
202-
Math.min(this.items.length - 1, this.cursorIndex - 1)
203-
);
198+
if (this.cursorIndex === index) {
199+
this.cursorIndex = -1;
200+
}
204201

205202
// request a change even if it is the same, the item is different
206203
this.requestUpdate('cursorIndex');

Diff for: src/options/Options.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export class Options extends RapidElement {
372372
(previousCount === 0 && newCount > 0 && !changed.has('cursorIndex'))
373373
) {
374374
if (!this.internalFocusDisabled) {
375-
if (!this.block || this.cursorIndex === -1) {
375+
if (!this.block) {
376376
this.cursorIndex = 0;
377377
} else {
378378
if (this.cursorIndex >= newCount) {
@@ -444,6 +444,10 @@ export class Options extends RapidElement {
444444
}
445445
}
446446

447+
if (index === -1) {
448+
return;
449+
}
450+
447451
const selected = this.options[index];
448452
this.fireCustomEvent(CustomEventType.Selection, {
449453
selected,

Diff for: src/store/Store.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ export class Store extends RapidElement {
519519
// we don't want to fetch all users at once so we can benefit from caching
520520
emails.forEach((email) => {
521521
promises.push(
522-
this.getUrl(`/api/v2/users.json?email=${encodeURIComponent(email)}`)
522+
this.getUrl(`/api/v2/users.json?email=${encodeURIComponent(email)}`, {
523+
force: true
524+
})
523525
);
524526
});
525527

Diff for: src/user/TembaUser.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export class TembaUser extends RapidElement {
4848
system: boolean;
4949

5050
@property({ type: String, attribute: false })
51-
background: string = '#e6e6e6';
51+
bgimage: string = null;
52+
53+
@property({ type: String, attribute: false })
54+
bgcolor: string = '#e6e6e6';
5255

5356
@property({ type: String, attribute: false })
5457
initials: string = '';
@@ -68,16 +71,25 @@ export class TembaUser extends RapidElement {
6871
super.updated(changed);
6972

7073
if (changed.has('system') && this.system) {
71-
this.background = `url('${DEFAULT_AVATAR}') center / contain no-repeat`;
74+
this.bgimage = `url('${DEFAULT_AVATAR}') center / contain no-repeat`;
7275
}
7376

74-
if (changed.has('name') && this.name) {
75-
this.background = colorHash.hex(this.name);
76-
this.initials = extractInitials(this.name);
77+
if (changed.has('name')) {
78+
if (this.name) {
79+
this.bgcolor = colorHash.hex(this.name);
80+
this.initials = extractInitials(this.name);
81+
} else {
82+
this.bgcolor = '#e6e6e6';
83+
this.initials = '';
84+
}
7785
}
7886

79-
if (changed.has('avatar') && this.avatar) {
80-
this.background = `url('${this.avatar}') center / contain no-repeat`;
87+
if (changed.has('avatar')) {
88+
if (this.avatar) {
89+
this.bgimage = `url('${this.avatar}') center / contain no-repeat`;
90+
} else if (!this.system) {
91+
this.bgimage = null;
92+
}
8193
}
8294
}
8395

@@ -98,9 +110,9 @@ export class TembaUser extends RapidElement {
98110
overflow: hidden;
99111
font-size: 12px;
100112
box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.1);
101-
background:${this.background}"
113+
background:${this.bgimage || this.bgcolor};"
102114
>
103-
${this.initials && !this.avatar
115+
${this.initials && !this.bgimage
104116
? html` <div
105117
style="border: 0px solid red; display:flex; flex-direction: column; align-items:center;flex-grow:1"
106118
>

Diff for: test/temba-contact-chat.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ describe('temba-contact-chat', () => {
6060
'/test-assets/contacts/history.json'
6161
);
6262

63+
mockGET(
64+
/\/api\/v2\/users\.json\?email=admin1%40nyaruka\.com/,
65+
'/test-assets/api/users/admin1.json'
66+
);
67+
6368
mockAPI();
6469
clock = useFakeTimers();
6570
});

0 commit comments

Comments
 (0)