refactor: use native form post instead if ajax
All checks were successful
/ Build (push) Successful in 34s

This commit is contained in:
log101 2024-08-05 12:17:26 +03:00
parent 37946d65b2
commit 8f61c0f99f
2 changed files with 9 additions and 19 deletions

View File

@ -4,6 +4,8 @@ import "../styles/locked-page.css"
import Layout from "../layouts/Layout.astro" import Layout from "../layouts/Layout.astro"
import { Loader2 } from "lucide-react" import { Loader2 } from "lucide-react"
const backendUrl = import.meta.env.PUBLIC_BACKEND_URL
--- ---
<Layout> <Layout>
@ -11,6 +13,8 @@ import { Loader2 } from "lucide-react"
<form <form
class='flex flex-col gap-12 md:gap-10' class='flex flex-col gap-12 md:gap-10'
id='sample-form' id='sample-form'
action={`${backendUrl}/api/location`}
method='post'
enctype='multipart/form-data'> enctype='multipart/form-data'>
<div> <div>
<h1 <h1

View File

@ -16,7 +16,6 @@ export function toggleMap() {
} }
const handleSubmit = async (e: SubmitEvent) => { const handleSubmit = async (e: SubmitEvent) => {
e.preventDefault()
toggleButton("submit-button", "submit-button-spinner") toggleButton("submit-button", "submit-button-spinner")
const locationSelected = document.getElementById( const locationSelected = document.getElementById(
"geolocation-input" "geolocation-input"
@ -41,27 +40,14 @@ const handleSubmit = async (e: SubmitEvent) => {
} }
validateFileInput(inputEl) 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("sample-form")!.onsubmit = handleSubmit
document.getElementById("photo-selector")!.oninput = (ev) => document.getElementById("photo-selector")!.oninput = (ev) =>
validateFileInput(ev.target as HTMLInputElement) 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.")