1
|
|
|
import {chat_v1 as chatV1} from '@googleapis/chat'; |
2
|
|
|
import {offsetToTimezone} from '../helpers/time'; |
3
|
|
|
import ClosePollFormCard from './ClosePollFormCard'; |
4
|
|
|
import {createButton} from '../helpers/cards'; |
5
|
|
|
|
6
|
|
|
export default class ScheduleClosePollFormCard extends ClosePollFormCard { |
7
|
|
|
create(): chatV1.Schema$GoogleAppsCardV1Card { |
8
|
|
|
this.buildHeader(); |
9
|
|
|
if (this.state.closedTime) { |
10
|
|
|
this.buildCurrentScheduleInfo(); |
11
|
|
|
} |
12
|
|
|
this.buildAutoCloseSection(); |
13
|
|
|
this.buildButtons(); |
14
|
|
|
this.buildSections(); |
15
|
|
|
return this.card; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
buildHeader() { |
19
|
|
|
this.card.header = { |
20
|
|
|
'title': 'Schedule Close Poll', |
21
|
|
|
'subtitle': 'You can schedule the poll to close here.', |
22
|
|
|
'imageUrl': '', |
23
|
|
|
'imageType': 'CIRCLE', |
24
|
|
|
}; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
buildButtons() { |
28
|
|
|
let scheduleButtonText = 'Create Schedule Close'; |
29
|
|
|
if (this.state.closedTime) { |
30
|
|
|
scheduleButtonText = 'Edit Schedule Close'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
this.addSectionWidget({ |
34
|
|
|
'buttonList': { |
35
|
|
|
'buttons': [createButton(scheduleButtonText, 'schedule_close_poll')], |
36
|
|
|
}, |
37
|
|
|
}); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
buildAutoCloseSection() { |
41
|
|
|
const widgets: chatV1.Schema$GoogleAppsCardV1Widget[] = []; |
42
|
|
|
const timezone = offsetToTimezone(this.timezone.offset); |
43
|
|
|
let scheduleTime = Date.now() + 18000000; |
44
|
|
|
if (this.state.closedTime) { |
45
|
|
|
scheduleTime = this.state.closedTime; |
46
|
|
|
} |
47
|
|
|
scheduleTime += this.timezone.offset; |
48
|
|
|
widgets.push( |
49
|
|
|
{ |
50
|
|
|
'dateTimePicker': { |
51
|
|
|
'label': 'Close schedule time ' + timezone, |
52
|
|
|
'name': 'close_schedule_time', |
53
|
|
|
'type': 'DATE_AND_TIME', |
54
|
|
|
'valueMsEpoch': scheduleTime.toString(), |
55
|
|
|
}, |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
widgets.push( |
59
|
|
|
{ |
60
|
|
|
'decoratedText': { |
61
|
|
|
'text': 'Auto mention <b>@all</b> on 5 minutes before poll closed', |
62
|
|
|
'bottomLabel': 'This is to ensure that other users do not forget to vote before the poll is closed.', |
63
|
|
|
'switchControl': { |
64
|
|
|
'controlType': 'SWITCH', |
65
|
|
|
'name': 'auto_mention', |
66
|
|
|
'value': '1', |
67
|
|
|
'selected': true, |
68
|
|
|
}, |
69
|
|
|
}, |
70
|
|
|
}); |
71
|
|
|
this.card.sections!.push({ |
72
|
|
|
widgets, |
73
|
|
|
}); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|