blob: c7123edcdd28bca48665a24508e0f05e7fab38cf (
plain)
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
|
import 'typeface-roboto';
import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import App from './App';
import * as serviceWorker from './serviceWorker';
import store from './store';
ReactDOM.render((
<Provider store={store}>
<HashRouter>
<App />
</HashRouter>
</Provider>
), document.getElementById('root'));
window.updateNotificationToken = async (token) => {
// Get user attributes
const response = await fetch('/api/session', {
headers: { Accept: 'application/json' }
});
if (response.ok) {
let user = await response.json();
if (user.attributes) {
if (!user.attributes.notificationTokens || user.attributes.notificationTokens.indexOf(token) < 0) {
if (!user.attributes.notificationTokens) {
user.attributes.notificationTokens = token;
} else {
user.attributes.notificationTokens += ',' + token;
}
// Set user attributes
const response2 = await fetch(`/api/users/${user.id}`, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(user),
});
console.log ('Set token: ', await response2.json());
}
}
}
}
serviceWorker.unregister();
|