diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-03 13:56:55 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-03 13:56:55 -0600 |
commit | 79a6c4f12df873c4087b143bdee3fb0a0bb801f4 (patch) | |
tree | d93a635cf2ba0746f008cc49acb92354ed76fddd /modern/src | |
parent | e2ae92ef37d0f5016b8e8375d8657ea125571634 (diff) | |
download | etbsa-traccar-web-79a6c4f12df873c4087b143bdee3fb0a0bb801f4.tar.gz etbsa-traccar-web-79a6c4f12df873c4087b143bdee3fb0a0bb801f4.tar.bz2 etbsa-traccar-web-79a6c4f12df873c4087b143bdee3fb0a0bb801f4.zip |
Reworded Spanish translations and added updateNotificationToken() method to window
Diffstat (limited to 'modern/src')
-rw-r--r-- | modern/src/index.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/modern/src/index.js b/modern/src/index.js index 32cf990..c7123ed 100644 --- a/modern/src/index.js +++ b/modern/src/index.js @@ -16,4 +16,34 @@ ReactDOM.render(( </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(); |