-
Notifications
You must be signed in to change notification settings - Fork 27
/
ui-pagerbeauty.jsx
54 lines (44 loc) · 1.77 KB
/
ui-pagerbeauty.jsx
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
// ------- Imports -------------------------------------------------------------
import React from 'react';
import ReactDOM from 'react-dom';
// ------- Internal imports ----------------------------------------------------
import { SchedulesListView } from './views/ScheduleViews';
import { OnCallView } from './views/OnCallViews';
import { withAjaxBackend } from './ui-backend-drivers';
// ------- Program -------------------------------------------------------------
// Pass authentication
const url = new URL(document.URL);
const accessToken = url.searchParams.get('access_token');
function authenticateBearerOrBasic(requestInit) {
const options = requestInit;
if (accessToken) {
options.headers.set('Authorization', `Bearer ${accessToken}`);
options.credentials = 'omit';
} else {
options.credentials = 'same-origin';
}
}
// Render schedules list
const schedulesListRoot = document.getElementById('schedules_list_root');
if (schedulesListRoot) {
const SchedulesListWithBackend = withAjaxBackend({
WrappedComponent: SchedulesListView,
endpoint: '/v1/schedules.json',
authenticationStrategy: authenticateBearerOrBasic,
});
ReactDOM.render(<SchedulesListWithBackend />, schedulesListRoot);
}
// Render individual schedules
document.querySelectorAll('.on_call_root').forEach((schedule) => {
const OnCallWithBackend = withAjaxBackend({
WrappedComponent: OnCallView,
endpoint: `/v1/schedules/${schedule.dataset.id}.json`,
authenticationStrategy: authenticateBearerOrBasic,
});
ReactDOM.render(<OnCallWithBackend />, schedule);
});
// Hard page refresh every day to prevent memory leaks.
window.setTimeout(() => {
window.location.reload();
}, 3600 * 24 * 1000); // 1 day
// ------- End -----------------------------------------------------------------