mirror of
https://github.com/MedzikUser/gatsby-pingbot
synced 2024-08-15 03:20:27 +00:00
97 lines
1.8 KiB
JavaScript
97 lines
1.8 KiB
JavaScript
import React from 'react'
|
|
import AniLink from 'gatsby-plugin-transition-link/AniLink'
|
|
import { ToastContainer, toast } from 'react-toastify'
|
|
|
|
import Seo from '../components/seo'
|
|
import axios from '../axios'
|
|
|
|
import '../css/url.sass'
|
|
import '../css/notifications.sass'
|
|
|
|
const AddURLPage = () => {
|
|
const [url, setURL] = React.useState('')
|
|
|
|
const handleKeypress = e => {
|
|
if (e.charCode === 13 || e.keyCode === 13) {
|
|
addURL()
|
|
}
|
|
}
|
|
|
|
const changeURLHandler = event => {
|
|
const value = event.target.value
|
|
setURL(value)
|
|
}
|
|
|
|
const addURL = async () => {
|
|
setURL('')
|
|
|
|
if (url === '') {
|
|
return toast.warn('Empty input')
|
|
}
|
|
|
|
toast.promise(
|
|
axios.post('', {
|
|
url: url,
|
|
cluster: 1
|
|
}),
|
|
{
|
|
pending: 'Sending request',
|
|
success: {
|
|
render({ data }) {
|
|
return `Added ${data.url}!`
|
|
}
|
|
},
|
|
error: {
|
|
render(err) {
|
|
let e = ''
|
|
|
|
if (err.response && err.response.data.message) {
|
|
e = err.response.data.message
|
|
} else {
|
|
e = err.toString()
|
|
}
|
|
|
|
return `${e}`
|
|
}
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Seo
|
|
title="Add URL"
|
|
/>
|
|
|
|
<ToastContainer
|
|
theme="dark"
|
|
/>
|
|
|
|
<div className="field">
|
|
<input
|
|
type="url"
|
|
name="url"
|
|
inputMode="url"
|
|
className="input"
|
|
placeholder="URL"
|
|
value={url}
|
|
onChange={changeURLHandler}
|
|
onKeyPress={handleKeypress} />
|
|
</div>
|
|
|
|
<button
|
|
className="yellow-button"
|
|
onClick={() => addURL()}
|
|
>Add URL</button>
|
|
|
|
<br />
|
|
|
|
<AniLink cover to="/">
|
|
<button className="blue-button">Go to home page</button>
|
|
</AniLink>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default AddURLPage
|