lbry.tech/.vuepress/components/EmailSubscribe.vue

70 lines
1.7 KiB
Vue
Raw Normal View History

2018-05-17 14:30:17 +02:00
<template>
<div id="email-subscribe">
<h3 class="title">Subscribe to our developer newsletter!</h3>
<input type="text" class="input" v-model="emailAddress" placeholder="your@email.com">
<a class="__button-black" href="#" v-on:click.prevent="subscribe">Subscribe</a>
<p v-if="message" class="message">{{ message }}</p>
</div>
</template>
<script>
export default {
data () {
return {
emailAddress: '',
message: ''
}
},
name: 'EmailSubscribe',
methods: {
subscribe () {
var component = this;
this.message = '';
if(!this.validateEmail(this.emailAddress)) {
this.message = 'Your email is not valid!';
} else {
2018-05-17 17:20:11 +02:00
this.$http.post('//api.lbry.io/list/subscribe', {
email: this.emailAddress,
tag: 'developer'
}, {
emulateJSON: true
}).then(function(response) {
2018-05-17 14:30:17 +02:00
component.email = '';
component.message = 'Thank you for subscribing!';
2018-05-25 08:58:48 +02:00
}, function(response) {
if(response.status == 409) {
component.message = 'You have already subscribed to our mailing list!';
}
2018-05-17 14:30:17 +02:00
});
}
},
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());
}
}
};
</script>
<style lang="scss">
#email-subscribe {
background: #ddd;
padding: 1rem 0;
text-align: center;
.title {
margin-bottom: 0.5rem;
}
.input {
border: 1px solid black;
padding: 0.65rem;
background: white;
margin-right: 1rem;
width: 18rem;
}
.message {
margin-top: 1rem;
}
}
</style>