Skip to content

Commit

Permalink
Remove contact form and replace with link (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjamescompton authored Sep 11, 2023
1 parent 844d631 commit 2e6efcb
Showing 1 changed file with 1 addition and 89 deletions.
90 changes: 1 addition & 89 deletions website/layouts/devices/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1 class="device-single__title">{{ .Params.name }}</h1>
{{with .Params.producturl}}
<a href="{{ . }}" class="ttui-btn ttui-btn--primary">Partner Webpage</a>
{{ end }}
<button class="ttui-btn ttui-btn--primary" id="partner-toggle">Contact Partner</button>
<a href="https://thethingsindustries.com/contact/?message=Hi%2C%0D%0A%0D%0AI+found+{{.Params.Vendor.Name}}+on+the+LoRaWAN+device+repository+and+I%27m+interested+in+contacting+{{.Params.name}}." class="ttui-btn ttui-btn--primary" id="partner-toggle">Contact Partner</a>
</div>
</div>
<div class="item-12">
Expand Down Expand Up @@ -60,96 +60,8 @@ <h3>Specification</h3>
<div id="device-events"></div>
</div>
</div>

<div class="contact contact--hidden js-contact" >
<form id="contact" name="contact" >
<div class="grid">
<div class="item-10">
<h3>Contact Partner</h3>
<p class="contact__error"></p>
</div>
<div class="item-2 item-m" style="justify-self: end;">
<span id="partner-cross" type="button"><svg width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.233.43L7.929 5.732 2.626.43.86 2.197 6.16 7.5.86 12.803l1.767 1.767L7.93 9.267l5.304 5.303L15 12.802 9.698 7.5 15 2.197 13.233.43z" fill="#B7B6BC"/></svg></span>
</div>
<div class="item-6 item-xxs-12">
<label>Full Name*</label>
<input type="text" id="name" placeholder="Enter text" name="name" required/>
</div>
<div class="item-6 item-xxs-12">
<label>Company Name*</label>
<input type="text" id="company" placeholder="Enter text" name="company" required />
</div>
<div class="item-12">
<label>Email*</label>
<input type="email" id="email" placeholder="Enter text" name="email" required />
</div>
<div class="item-12">
<label>Message*</label>
<textarea id="message" placeholder="Enter text" name="message" required rows=10 maxlength=1000></textarea>
</div>
<div class="item-12">
<input type="hidden" id="url" name="url" value="{{ .Page.Permalink }}" />
<button class="ttui-btn ttui-btn--primary" type="submit">Send</button>
</div>
</div>
</form>
</div>

</section>

<script>
var config = {
device: JSON.parse("{{ .Params | jsonify }}")
}

document.getElementById('partner-toggle').addEventListener("click", handleContact, false)
document.getElementById('partner-cross').addEventListener("click", handleContact, false)
document.getElementById('contact').addEventListener("submit", handleSubmit);

function handleContact() {
clearError()
clearForm()
const form = document.getElementsByClassName('js-contact')[0].classList.toggle("contact--hidden")
}

var contactError = document.getElementsByClassName("contact__error")[0]

function setError(message) {
contactError.innerHTML = message
}

function clearError() {
contactError.innerHTML = ""
}

function clearForm() {
document.getElementById('contact').reset()
}

function handleSubmit(e) {
e.preventDefault()
clearError()

fetch('https://www.thethingsnetwork.org/api/partners/contact-partner/', {
method: 'POST',
body: JSON.stringify(Object.fromEntries(new FormData(e.target))),
headers: {
'Content-type': 'application/json; charset=UTF-8'
}
}).then(function (response) {
if (response.ok) {
clearForm()
handleContact()
} else {
setError("There was an error, please try again.")
}
}).catch(function() {
setError("There was an error, please try again.")
});
}

</script>

<script src="{{- (index .Site.Data.manifest `device_single.js`) | relURL -}}"></script>

{{ end }}

0 comments on commit 2e6efcb

Please sign in to comment.