You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.8 KiB
JavaScript
98 lines
2.8 KiB
JavaScript
import React, { Component } from 'react';
|
|
import Link from 'next/link'
|
|
|
|
class AddRecordForm extends Component {
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
status : "",
|
|
message: "",
|
|
subdomain: "",
|
|
pointsto: "",
|
|
redirectmode: false
|
|
}
|
|
}
|
|
|
|
render() {
|
|
|
|
return ( <div>
|
|
<form onSubmit={async (e) => {
|
|
e.preventDefault();
|
|
if (this.state.subdomain.length === 0 || this.state.pointsto.length === 0) {
|
|
this.setState({ status: "error", message: "You have some blank fields!" });
|
|
}else{
|
|
|
|
let resp, data;
|
|
try {
|
|
resp = await fetch(
|
|
`/api/addrecord`,
|
|
{
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ subdomain: this.state.subdomain, pointsto: this.state.pointsto, redirect: this.state.redirectmode }),
|
|
}
|
|
);
|
|
data = await resp.json();
|
|
} catch (error) {
|
|
console.log(error);
|
|
this.setState({ status: "error", message: "Internal error" });
|
|
return;
|
|
}
|
|
|
|
if(data.ok) {
|
|
this.setState({ status: "success", message: `<b>Success!</b> Your domain is now registred.<br />
|
|
Ping this URL at least once a week to keep your domain active: <code>http://on.loki/api/renew?uuid=${data.uuid}</code><br />
|
|
Ping this URL to delete your domain: <code>http://on.loki/api/delete?uuid=${data.uuid}</code>` });
|
|
}else{
|
|
this.setState({ status: "error", message: data.error });
|
|
}
|
|
|
|
}
|
|
}}
|
|
>
|
|
<div>
|
|
|
|
<input
|
|
value={this.state.subdomain}
|
|
onChange={(e) => this.setState({subdomain: e.target.value})}
|
|
type="name"
|
|
placeholder="Name of your choice"
|
|
/>.on.loki
|
|
<br />
|
|
|
|
<input
|
|
value={this.state.pointsto}
|
|
onChange={(e) => this.setState({pointsto: e.target.value})}
|
|
type="name"
|
|
placeholder="SNApp's current address"
|
|
/>.loki
|
|
<br />
|
|
|
|
<input
|
|
value={this.state.redirectmode}
|
|
onChange={(e) => this.setState({redirectmode: !this.state.redirectmode})}
|
|
type="checkbox"
|
|
/>Redirect Mode <Link href="/faq#redirect">(?)</Link>
|
|
<br />
|
|
|
|
<button type="submit">
|
|
Register
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<div className={ this.state.status } dangerouslySetInnerHTML={{__html: this.state.message}}>
|
|
</div>
|
|
|
|
</div>)
|
|
}
|
|
|
|
}
|
|
|
|
export default AddRecordForm; |