refactor: use native form post instead if ajax
All checks were successful
/ Build (push) Successful in 34s
All checks were successful
/ Build (push) Successful in 34s
This commit is contained in:
parent
37946d65b2
commit
8f61c0f99f
|
@ -4,6 +4,8 @@ import "../styles/locked-page.css"
|
|||
|
||||
import Layout from "../layouts/Layout.astro"
|
||||
import { Loader2 } from "lucide-react"
|
||||
|
||||
const backendUrl = import.meta.env.PUBLIC_BACKEND_URL
|
||||
---
|
||||
|
||||
<Layout>
|
||||
|
@ -11,6 +13,8 @@ import { Loader2 } from "lucide-react"
|
|||
<form
|
||||
class='flex flex-col gap-12 md:gap-10'
|
||||
id='sample-form'
|
||||
action={`${backendUrl}/api/location`}
|
||||
method='post'
|
||||
enctype='multipart/form-data'>
|
||||
<div>
|
||||
<h1
|
||||
|
|
|
@ -16,7 +16,6 @@ export function toggleMap() {
|
|||
}
|
||||
|
||||
const handleSubmit = async (e: SubmitEvent) => {
|
||||
e.preventDefault()
|
||||
toggleButton("submit-button", "submit-button-spinner")
|
||||
const locationSelected = document.getElementById(
|
||||
"geolocation-input"
|
||||
|
@ -41,27 +40,14 @@ const handleSubmit = async (e: SubmitEvent) => {
|
|||
}
|
||||
|
||||
validateFileInput(inputEl)
|
||||
|
||||
const formData = new FormData(e.target as HTMLFormElement)
|
||||
|
||||
const res = await fetch(
|
||||
`${import.meta.env.PUBLIC_BACKEND_URL}/api/location`,
|
||||
{
|
||||
method: "POST",
|
||||
body: formData,
|
||||
}
|
||||
)
|
||||
|
||||
if (res.status === 200) {
|
||||
const data = await res.json()
|
||||
|
||||
if (data.url) location.assign(`/x?id=${data.url}`)
|
||||
} else {
|
||||
toast("Konulu konum oluşturulamadı, lütfen tekrar deneyin.")
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("sample-form")!.onsubmit = handleSubmit
|
||||
|
||||
document.getElementById("photo-selector")!.oninput = (ev) =>
|
||||
validateFileInput(ev.target as HTMLInputElement)
|
||||
|
||||
const url = new URL(document.URL)
|
||||
|
||||
if (url.searchParams.get("error"))
|
||||
toast("Konulu konum oluşturulamadı, lütfen tekrar deneyin.")
|
||||
|
|
Loading…
Reference in New Issue
Block a user