From a1a0da20c5b7033877c66016adda9855b3be4b41 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Tue, 16 Feb 2021 21:46:01 -0500 Subject: [PATCH] feat: migrate from slack to discord (#74) * feat: migrate from slack to discord * refactor: form to button --- _config.yml | 2 +- _includes/discord_invite.html | 9 +++ _includes/foot.html | 1 - _includes/join.html | 4 +- _includes/slack_invite.html | 16 ------ slack.html | 10 ++-- static/js/slack.js | 103 ---------------------------------- 7 files changed, 16 insertions(+), 129 deletions(-) create mode 100644 _includes/discord_invite.html delete mode 100644 _includes/slack_invite.html delete mode 100644 static/js/slack.js diff --git a/_config.yml b/_config.yml index a4d3408..23af758 100644 --- a/_config.yml +++ b/_config.yml @@ -2,4 +2,4 @@ title: Top Hat Open Source Portal description: >- # this means to ignore newlines Open Source at Top Hat: working to make education & technology open to the world url: https://opensource.tophat.com -exclude: [slack.html] +exclude: [discord.html] diff --git a/_includes/discord_invite.html b/_includes/discord_invite.html new file mode 100644 index 0000000..4f1cf7d --- /dev/null +++ b/_includes/discord_invite.html @@ -0,0 +1,9 @@ +

Join us on Discord

+
+

Come chat with us about open source, ask about projects or report issues on Discord!

+
+ + + + + diff --git a/_includes/foot.html b/_includes/foot.html index 170ac1a..5576c2a 100644 --- a/_includes/foot.html +++ b/_includes/foot.html @@ -1,5 +1,4 @@ - diff --git a/_includes/join.html b/_includes/join.html index 2e898ad..eb1b7c3 100644 --- a/_includes/join.html +++ b/_includes/join.html @@ -15,13 +15,11 @@

Work With Us

- {% comment %}
- {% include slack_invite.html %} + {% include discord_invite.html %}
- {% endcomment %} diff --git a/_includes/slack_invite.html b/_includes/slack_invite.html deleted file mode 100644 index f951921..0000000 --- a/_includes/slack_invite.html +++ /dev/null @@ -1,16 +0,0 @@ -

Join our Slack Workspace

-
-

Give us your email and we'll invite you to Top Hat's Open Source Slack community!

-
-
- - - Please check your email for an invite! - You have already been invited to Slack! Check your email. - Something went wrong.
Try going over to tophat-opensource.slack.com and sign-in.
- You're already on the workspace!
Head over to tophat-opensource.slack.com and sign-in.
- Please enter a valid email address -
-
-
- diff --git a/slack.html b/slack.html index aff12d6..121d11e 100644 --- a/slack.html +++ b/slack.html @@ -1,12 +1,12 @@ --- layout: default -id: slack +id: discord --- -
-
-
- {% include slack_invite.html %} +
+
+
+ {% include discord_invite.html %}
diff --git a/static/js/slack.js b/static/js/slack.js deleted file mode 100644 index 17054f5..0000000 --- a/static/js/slack.js +++ /dev/null @@ -1,103 +0,0 @@ -const validateEmail = (email) => { - var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - return re.test(String(email).toLowerCase()) -} - -const showCheckmark = () => { - const element = document.getElementsByClassName('slack-success')[0] - element.style.visibility = 'visible' -} - -const showFormValidation = messageType => { - let element - switch(messageType) { - case 'success' : - showCheckmark() - element = document.getElementsByClassName('form-submit-message success')[0] - break - case 'resubmit': - element = document.getElementsByClassName('form-submit-message resubmit')[0] - break - case 'exists': - element = document.getElementsByClassName('form-submit-message exists')[0] - break - case 'error': - default: - element = document.getElementsByClassName('form-submit-message error')[0] - } - element.style.visibility = 'visible'; -} - -const hideMessages = () => { - const elements = document.getElementsByClassName('form-submit-message') - for(let i = 0; i < elements.length; i++){ - element = elements[i] - element.style.visibility = 'hidden' - } - const check = document.getElementsByClassName('slack-success')[0] - check.style.visibility = 'hidden' -} - -const resubmittingRequest = (message) => { - return message.indexOf('You have already been invited to Slack') > -1 -} - -const existsRequest = (message) => { - return message.indexOf('Sending you to Slack...') > -1 -} - -const handleFormSubmit = (e) => { - e.preventDefault() - hideMessages() - const emailNode = document.getElementById('email') - const email = emailNode.value - - const isValid = email && validateEmail(email) - if(!isValid){ - const element = document.getElementsByClassName('form-submit-message invalid')[0] - element.style.visibility = 'visible'; - emailNode.focus() - return - } - - const buttonNode = document.getElementById('slack-submit-button') - buttonNode.classList.add('disabled') - buttonNode.disabled = true - - var http = new XMLHttpRequest(); - var url = 'https://slackinvite.dev.tophat.com/invite'; - var params = JSON.stringify({ email }) - - http.open('POST', url, true); - http.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); - http.onreadystatechange = function() { - if (http.readyState === 4) { - buttonNode.classList.remove('disabled') - buttonNode.disabled = false - const response = JSON.parse(http.response) - if(response.success) { - showFormValidation('success') - } else if(resubmittingRequest(response.message)) { - showFormValidation('resubmit') - emailNode.focus() - } else if(existsRequest(response.message)) { - showFormValidation('exists') - emailNode.focus() - } else { - showFormValidation('error') - emailNode.focus() - } - } - } - http.send(params); -} - - -const form = document.getElementById('slack-invite') -const submitButton = document.getElementById('slack-submit-button') -if (form) { - form.addEventListener('submit', handleFormSubmit) -} -if (submitButton) { - submitButton.addEventListener('click', handleFormSubmit) -}