forked from magonysandormate/PeePal
Működik a form a módosított adatbázissal
This commit is contained in:
@@ -56,7 +56,7 @@ class WcController extends Controller
|
|||||||
'utvonal' => $validatedData['utvonal'],
|
'utvonal' => $validatedData['utvonal'],
|
||||||
'szel_koord' => $szelesseg,
|
'szel_koord' => $szelesseg,
|
||||||
'hossz_koord' => $hosszusag,
|
'hossz_koord' => $hosszusag,
|
||||||
'felhasznalo_id' => $validatedData['felhasznalo_id']
|
'felhasznalo_id' => $validatedData['felhasznalo_id'] ?? null
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ class WcAdatok extends Model
|
|||||||
return $this->belongsTo(Keruletek::class);
|
return $this->belongsTo(Keruletek::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function felhasznalo(){
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
protected $table = 'wc_adatok';
|
protected $table = 'wc_adatok';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ return new class extends Migration
|
|||||||
$table->double('hossz_koord');
|
$table->double('hossz_koord');
|
||||||
$table->double('szel_koord');
|
$table->double('szel_koord');
|
||||||
$table->string('utvonal', 1000);
|
$table->string('utvonal', 1000);
|
||||||
$table->foreignId('felhasznalo_id')->references('id')->on('felhasznalok');
|
$table->foreignId('felhasznalo_id')->nullable()->references('id')->on('felhasznalok');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, {useState} from "react";
|
import React, { useState} from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export default function HozzaadForm() {
|
export default function HozzaadForm() {
|
||||||
@@ -23,7 +23,8 @@ export default function HozzaadForm() {
|
|||||||
ar: ar,
|
ar: ar,
|
||||||
nyitva: nyitva,
|
nyitva: nyitva,
|
||||||
utvonal: utvonal,
|
utvonal: utvonal,
|
||||||
koordinatak: koordinatak
|
koordinatak: koordinatak,
|
||||||
|
felhasznalo_id: null
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch("http://localhost:8000/api/hozzaadas", {
|
fetch("http://localhost:8000/api/hozzaadas", {
|
||||||
@@ -33,21 +34,33 @@ export default function HozzaadForm() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(wcInfo)
|
body: JSON.stringify(wcInfo)
|
||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then(async (response) => {
|
||||||
.then((newWC) => {
|
if (!response.ok) {
|
||||||
setNev("");
|
const errorData = await response.json();
|
||||||
setKeruletId("");
|
console.error("Hiba a POST kérésnél:", errorData);
|
||||||
setKozeli("");
|
alert("Hiba történt az adatok mentésekor.");
|
||||||
setAkadalym(false);
|
return;
|
||||||
setAr("");
|
}
|
||||||
setNyitva("");
|
|
||||||
setUtvonal("");
|
const newWC = await response.json();
|
||||||
setKoordinatak("");
|
|
||||||
navigate("/");
|
console.log("Sikeres mentés:", newWC);
|
||||||
})
|
|
||||||
.catch((error) => {
|
// csak siker után törlünk mindent és navigálunk
|
||||||
console.log(error);
|
setNev("");
|
||||||
})
|
setKeruletId("");
|
||||||
|
setKozeli("");
|
||||||
|
setAkadalym(false);
|
||||||
|
setAr("");
|
||||||
|
setNyitva("");
|
||||||
|
setUtvonal("");
|
||||||
|
setKoordinatak("");
|
||||||
|
navigate("/");
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("Hálózati hiba:", error);
|
||||||
|
alert("Nem sikerült csatlakozni a szerverhez.");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const ToolTip = ({children, text}) => {
|
const ToolTip = ({children, text}) => {
|
||||||
@@ -83,10 +96,21 @@ export default function HozzaadForm() {
|
|||||||
|
|
||||||
<label className="block text-gray-700">Kerület:</label>
|
<label className="block text-gray-700">Kerület:</label>
|
||||||
|
|
||||||
<select name="kerulet_id">
|
<select
|
||||||
|
id="kerulet"
|
||||||
|
name="kerulet_id"
|
||||||
|
value={kerulet_id}
|
||||||
|
onChange={(event) => setKeruletId(event.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">Válassz kerületet</option>
|
||||||
|
{Array.from({ length: 23 }, (_, i) => (
|
||||||
|
<option key={i + 1} value={i + 1}>
|
||||||
|
{i + 1}. kerület
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
{/*
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="kerulet"
|
name="kerulet"
|
||||||
@@ -95,6 +119,7 @@ export default function HozzaadForm() {
|
|||||||
placeholder="Kerület"
|
placeholder="Kerület"
|
||||||
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
/>
|
/>
|
||||||
|
*/}
|
||||||
|
|
||||||
<label className="block text-gray-700">Legközelebbi megálló:</label>
|
<label className="block text-gray-700">Legközelebbi megálló:</label>
|
||||||
<input
|
<input
|
||||||
|
|||||||
Reference in New Issue
Block a user