Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Last active August 14, 2020 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaidspaghetti/c93b717f981c6b637b3bce1aa4d31bf2 to your computer and use it in GitHub Desktop.
Save isaidspaghetti/c93b717f981c6b637b3bce1aa4d31bf2 to your computer and use it in GitHub Desktop.
//frontend/src/CustomerChat.js:6
useEffect(() => {
const handleUnload = (event) => {
event.preventDefault();
fetch('http://localhost:8080/email-transcript', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: channel.state.messages,
firstName: firstName,
lastName: lastName,
email: email,
createdAt: channel.data.config.created_at
})
});
event.returnValue = '';
};
window.addEventListener('beforeunload', handleUnload);
return () => {
window.removeEventListener('beforeunload', handleUnload);
};
}, [channel, firstName, lastName, email]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment