gatsby-pingbot/src/pages/delete.js

91 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-08-19 21:13:03 +00:00
import React from 'react'
import AniLink from 'gatsby-plugin-transition-link/AniLink'
import { ToastContainer, toast } from 'react-toastify'
2021-08-04 19:17:51 +00:00
2021-08-19 21:13:03 +00:00
import Seo from '../components/seo'
import axios from '../axios'
2021-08-04 19:17:51 +00:00
2021-08-19 21:13:03 +00:00
import '../css/url.sass'
import '../css/notifications.sass'
2021-08-04 19:17:51 +00:00
const DeleteURLPage = () => {
2021-08-19 21:13:03 +00:00
const [url, setURL] = React.useState('')
2021-08-04 19:17:51 +00:00
2021-08-07 11:32:58 +00:00
const handleKeypress = e => {
if (e.charCode === 13 || e.keyCode === 13) {
deleteURL()
}
}
2021-08-04 19:17:51 +00:00
const changeURLHandler = event => {
const value = event.target.value
setURL(value)
}
const deleteURL = async () => {
2021-08-19 21:13:03 +00:00
setURL('')
2021-08-04 19:17:51 +00:00
2021-08-19 21:13:03 +00:00
if (url === '') {
2021-08-27 17:45:51 +00:00
return toast.warn('Empty input')
2021-08-04 19:17:51 +00:00
}
2021-08-27 17:45:51 +00:00
toast.promise(
axios.delete(`?url=${url}`),
{
pending: 'Sending request',
2021-08-27 17:52:56 +00:00
success: {
2021-08-30 19:53:33 +00:00
delay: 500,
2021-08-27 18:14:20 +00:00
render({ data: { data } }) {
2021-09-17 19:38:34 +00:00
return data.message
2021-08-27 17:52:56 +00:00
}
2021-08-27 17:45:51 +00:00
},
2021-08-27 17:52:56 +00:00
error: {
2021-08-30 19:53:33 +00:00
delay: 500,
2021-08-27 17:52:56 +00:00
render(err){
2021-08-27 18:05:12 +00:00
if (err.data.response && err.data.response.data.message) {
2021-09-19 13:59:45 +00:00
returnerr.data.response.data.message
2021-08-27 17:52:56 +00:00
} else {
2021-09-19 13:59:45 +00:00
return err.data.toString()
2021-08-27 17:52:56 +00:00
}
2021-08-27 17:45:51 +00:00
}
}
2021-08-04 19:17:51 +00:00
}
2021-08-27 17:45:51 +00:00
)
2021-08-04 19:17:51 +00:00
}
return (
<>
2021-09-19 13:59:45 +00:00
<Seo title="Delete URL" />
2021-08-04 19:17:51 +00:00
2021-09-19 13:59:45 +00:00
<ToastContainer theme="dark" />
2021-08-04 19:17:51 +00:00
<div className="field">
<input
type="url"
name="url"
inputMode="url"
className="input"
placeholder="URL"
value={url}
2021-08-07 11:32:58 +00:00
onChange={changeURLHandler}
onKeyPress={handleKeypress} />
2021-08-04 19:17:51 +00:00
</div>
<button
className="red-button"
onClick={() => deleteURL()}
2021-09-19 13:59:45 +00:00
>
Delete URL
</button>
2021-08-04 19:17:51 +00:00
<br />
2021-08-06 18:17:07 +00:00
<AniLink cover to="/">
<button className="blue-button">Go to home page</button>
2021-08-06 18:17:07 +00:00
</AniLink>
2021-08-04 19:17:51 +00:00
</>
)
}
export default DeleteURLPage