Skip to content

Commit fe75979

Browse files
authored
fix: allow attendee multiple day checkin (#7623)
1 parent 20cd2c7 commit fe75979

File tree

4 files changed

+88
-20
lines changed

4 files changed

+88
-20
lines changed
Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
import classic from 'ember-classic-decorator';
22
import Component from '@ember/component';
3-
3+
import moment from 'moment';
44
@classic
5-
export default class CellAction extends Component {}
5+
export default class CellAction extends Component {
6+
currentlyCheckedin = [];
7+
eventdates = [];
8+
get allDates() {
9+
const dates = [];
10+
const date1 = moment(this.extraRecords.event.get('endsAtDate'));
11+
const date2 = moment(this.extraRecords.event.get('startsAtDate'));
12+
const diff = date1.diff(date2, 'days');
13+
for (let i = 0; i < diff; i++) {
14+
dates.push((moment(this.extraRecords.event.get('startsAtDate'), 'MM-DD-YYYY').add(i, 'days').format('MM-DD-YYYY')));
15+
this.eventdates.push(moment(this.extraRecords.event.get('startsAtDate'), 'MM-DD-YYYY').add(i, 'days').format('MM-DD-YYYY'));
16+
}
17+
return dates;
18+
}
19+
20+
get checkinTimes() {
21+
if (this.extraRecords.checkinTimes) {
22+
const x = this.extraRecords.checkinTimes?.split(',');
23+
const checkinDates = [];
24+
for (const i of x) {
25+
checkinDates.push(moment(i).format('MM-DD-YYYY'));
26+
}
27+
return checkinDates;
28+
}
29+
return [];
30+
}
31+
32+
get checkoutTimes() {
33+
if (this.extraRecords.checkoutTimes) {
34+
const x = this.extraRecords.checkoutTimes?.split(',');
35+
const checkoutDates = [];
36+
for (const i of x) {
37+
checkoutDates.push(moment(i).format('MM-DD-YYYY'));
38+
}
39+
return checkoutDates;
40+
}
41+
return [];
42+
}
43+
44+
get currentlyChecked() {
45+
for (const i of this.eventdates) {
46+
const checkinCount = this.checkinTimes?.filter(x => x === i).length || 0;
47+
const checkoutCount = this.checkoutTimes?.filter(x => x === i).length || 0;
48+
if (checkinCount > checkoutCount && !this.currentlyCheckedin.includes(i)) {
49+
this.currentlyCheckedin.push(i);
50+
}
51+
}
52+
return this.currentlyCheckedin;
53+
}
54+
}

app/controllers/events/view/tickets/attendees/list.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
2525
},
2626
{
2727
name : 'Date and Time',
28-
width : 140,
28+
width : 120,
2929
valuePath : 'order.completed_at',
3030
extraValuePaths : ['order'],
3131
cellComponent : 'ui-table/cell/events/view/tickets/attendees/cell-date',
@@ -34,7 +34,7 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
3434
},
3535
{
3636
name : 'Ticket Price',
37-
width : 90,
37+
width : 50,
3838
valuePath : 'ticket.price',
3939
extraValuePaths : ['event', 'discountCode'],
4040
cellComponent : 'ui-table/cell/events/view/tickets/attendees/cell-price',
@@ -44,23 +44,23 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
4444
{
4545
name : 'First Name',
4646
valuePath : 'firstname',
47-
width : 100
47+
width : 60
4848
},
4949
{
5050
name : 'Last Name',
5151
valuePath : 'lastname',
52-
width : 90
52+
width : 60
5353
},
5454
{
5555
name : 'Email',
5656
valuePath : 'email',
57-
width : 120
57+
width : 130
5858
},
5959
{
6060
name : 'Actions',
6161
valuePath : 'id',
62-
width : 90,
63-
extraValuePaths : ['order', 'isCheckedIn'],
62+
width : 130,
63+
extraValuePaths : ['order', 'isCheckedIn', 'event', 'checkinTimes', 'checkoutTimes'],
6464
cellComponent : 'ui-table/cell/events/view/tickets/attendees/cell-action',
6565
actions : {
6666
toggleCheckIn: this.toggleCheckIn.bind(this)
@@ -70,16 +70,23 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
7070
}
7171

7272
@action
73-
toggleCheckIn(attendee_id) {
73+
toggleCheckIn(attendee_id, date, isCheckedInCurrently) {
7474
const attendee = this.store.peekRecord('attendee', attendee_id, { backgroundReload: false });
75-
attendee.toggleProperty('isCheckedIn');
76-
if (attendee.isCheckedIn) {
77-
const newCheckinTimes = attendee.get('checkinTimes') === null ? `${moment().toISOString()}` : `${attendee.get('checkinTimes')},${moment().toISOString()}`;
75+
let myTime = moment().toISOString();
76+
if (moment(date, 'MM-DD-YYYY').format('MM-DD-YYYY') !== moment().format('MM-DD-YYYY')) {
77+
myTime = moment(date, 'MM-DD-YYYY');
78+
myTime = myTime.format('YYYY-MM-DD') + 'T13:00:00.000Z';
79+
}
80+
if (!isCheckedInCurrently) {
81+
const newCheckinTimes = attendee.get('checkinTimes') === null ? `${myTime}` : `${attendee.get('checkinTimes')},${myTime}`;
7882
attendee.set('checkinTimes', newCheckinTimes);
83+
} else {
84+
const newCheckoutTimes = attendee.get('checkoutTimes') === null ? `${myTime}` : `${attendee.get('checkoutTimes')},${myTime}`;
85+
attendee.set('checkoutTimes', newCheckoutTimes);
7986
}
8087
attendee.save()
81-
.then(savedAttendee => {
82-
const message = savedAttendee.isCheckedIn ? this.l10n.t('Attendee Checked-In Successfully') : this.l10n.t('Attendee Checked-Out Successfully');
88+
.then(() => {
89+
const message = !isCheckedInCurrently ? this.l10n.t('Attendee Checked-In Successfully') : this.l10n.t('Attendee Checked-Out Successfully');
8390
this.notify.success(message);
8491
this.refreshModel.bind(this)();
8592
})

app/models/attendee.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default ModelBase.extend({
1212
lastname : attr('string'),
1313
isCheckedIn : attr('boolean', { defaultValue: false }),
1414
checkinTimes : attr('string'),
15+
checkoutTimes : attr('string'),
1516
state : attr('string'),
1617
address : attr('string'),
1718
pdfUrl : attr('string'),
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
{{#if (eq this.extraRecords.order.status 'completed')}}
2-
{{#if this.extraRecords.isCheckedIn}}
3-
<button class="tiny ui labeled icon negative button" {{action this.props.actions.toggleCheckIn this.record}}><i class="remove icon"></i>{{t 'Check-Out'}}</button>
4-
{{else}}
5-
<button class="tiny ui labeled icon positive button" {{action this.props.actions.toggleCheckIn this.record}}><i class="checkmark icon"></i>{{t 'Check‑In'}}</button>
6-
{{/if}}
2+
<UiDropdown @class="d-flex items-center pl-4 fluid multiple selection">
3+
<div class="default">
4+
{{t 'Checkin'}}
5+
</div>
6+
<i class="dropdown icon"></i>
7+
<div class="menu">
8+
{{#each this.allDates as |date|}}
9+
<UiCheckbox
10+
@class="item"
11+
@label={{date}}
12+
@checked={{if (includes this.currentlyChecked date) true}}
13+
@onChange={{action this.props.actions.toggleCheckIn this.record date (includes this.currentlyChecked date)}}
14+
/>
15+
{{/each}}
16+
</div>
17+
</UiDropdown>
718
{{/if}}

0 commit comments

Comments
 (0)