From 79a6c4f12df873c4087b143bdee3fb0a0bb801f4 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 3 Jan 2022 13:56:55 -0600 Subject: Reworded Spanish translations and added updateNotificationToken() method to window --- modern/src/index.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'modern') 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(( ), 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(); -- cgit v1.2.3