User can add/edit flights
This commit is contained in:
@@ -28,9 +28,9 @@ class FlightController extends Controller
|
||||
'aircraft_id' => ['nullable', 'integer', 'exists:aircraft,id'],
|
||||
'aircraft_registration' => ['nullable', 'string', 'max:10'],
|
||||
'seat_number' => ['nullable', 'string', 'max:10'],
|
||||
'seat_type_id' => ['nullable', 'integer', 'exists:seat_types,id'],
|
||||
'flight_class_id' => ['nullable', 'integer', 'exists:flight_classes,id'],
|
||||
'flight_reason_id' => ['nullable', 'integer', 'exists:flight_reasons,id'],
|
||||
'seat_type_id' => ['integer', 'exists:seat_types,id'],
|
||||
'flight_class_id' => ['integer', 'exists:flight_classes,id'],
|
||||
'flight_reason_id' => ['integer', 'exists:flight_reasons,id'],
|
||||
'note' => ['nullable', 'string', 'max:5000'],
|
||||
'auto_update' => ['boolean'],
|
||||
];
|
||||
@@ -72,7 +72,6 @@ class FlightController extends Controller
|
||||
private function flightPayload(array $validated): array
|
||||
{
|
||||
[$departureUtc, $arrivalUtc] = $this->convertedDates($validated);
|
||||
|
||||
return [
|
||||
'departure_date' => $departureUtc,
|
||||
'arrival_date' => $arrivalUtc,
|
||||
@@ -115,9 +114,9 @@ class FlightController extends Controller
|
||||
|
||||
public function add(){
|
||||
return Inertia::render('AddFlight', [
|
||||
'seat_types' => SeatType::all()->map(fn ($s) => ['value' => $s->id, 'title' => $s->name]),
|
||||
'flight_reasons' => FlightReason::all()->map(fn ($f) => ['value' => $f->id, 'title' => $f->name]),
|
||||
'flight_classes' => FlightClass::all()->map(fn ($f) => ['value' => $f->id, 'title' => $f->name]),
|
||||
'seat_types' => SeatType::all()->toArray(),
|
||||
'flight_reasons' => FlightReason::all()->toArray(),
|
||||
'flight_classes' => FlightClass::all()->toArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -134,15 +133,9 @@ class FlightController extends Controller
|
||||
'seat_number' => $flight->seat_number,
|
||||
'note' => $flight->note,
|
||||
'auto_update' => $flight->auto_update,
|
||||
'seat_type' => $flight->seatType
|
||||
? ['value' => $flight->seatType->id, 'title' => $flight->seatType->name]
|
||||
: null,
|
||||
'flight_class' => $flight->flightClass
|
||||
? ['value' => $flight->flightClass->id, 'title' => $flight->flightClass->name]
|
||||
: null,
|
||||
'flight_reason' => $flight->flightReason
|
||||
? ['value' => $flight->flightReason->id, 'title' => $flight->flightReason->name]
|
||||
: null,
|
||||
'seat_type' => $flight->seatType->toArray(),
|
||||
'flight_class' => $flight->flightClass->toArray(),
|
||||
'flight_reason' => $flight->flightReason->toArray(),
|
||||
'airline_options' => $flight->airline
|
||||
? [['value' => $flight->airline->id, 'title' => $flight->airline->name]]
|
||||
: [],
|
||||
@@ -154,9 +147,9 @@ class FlightController extends Controller
|
||||
];
|
||||
return Inertia::render('AddFlight', [
|
||||
'flight' => $flightData,
|
||||
'seat_types' => SeatType::all()->map(fn($t) => ['value' => $t->id, 'title' => $t->name]),
|
||||
'flight_classes' => FlightClass::all()->map(fn($t) => ['value' => $t->id, 'title' => $t->name]),
|
||||
'flight_reasons' => FlightReason::all()->map(fn($t) => ['value' => $t->id, 'title' => $t->name]),
|
||||
'seat_types' => SeatType::all()->toArray(),
|
||||
'flight_classes' => FlightClass::all()->toArray(),
|
||||
'flight_reasons' => FlightReason::all()->toArray(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Head, useForm } from '@inertiajs/vue3'
|
||||
import AirlineSearchBox from '@/Components/FlightsGoneBy/AirlineSearchBox.vue'
|
||||
import AircraftSearchBox from '@/Components/FlightsGoneBy/AircraftSearchBox.vue'
|
||||
import AirportSearchBox from '@/Components/FlightsGoneBy/AirportSearchBox.vue'
|
||||
import type { SeatType, FlightReason, FlightClass} from '@/Types/types'
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineOptions({ layout: MainLayout })
|
||||
@@ -19,17 +20,17 @@ const props = defineProps<{
|
||||
seat_number: string
|
||||
note: string
|
||||
auto_update: boolean
|
||||
seat_type: { value: number; title: string } | null
|
||||
flight_class: { value: number; title: string } | null
|
||||
flight_reason: { value: number; title: string } | null
|
||||
seat_type: SeatType | null
|
||||
flight_class: FlightClass | null
|
||||
flight_reason: FlightReason | null
|
||||
airline_options: { value: number; title: string }[]
|
||||
from_options: { value: number; title: string; country_code: string }[]
|
||||
to_options: { value: number; title: string; country_code: string }[]
|
||||
aircraft_options: { value: number; title: string }[]
|
||||
}
|
||||
seat_types: { value: number; title: string }[]
|
||||
flight_classes: { value: number; title: string }[]
|
||||
flight_reasons: { value: number; title: string }[]
|
||||
seat_types: SeatType[]
|
||||
flight_classes: FlightClass[]
|
||||
flight_reasons: FlightReason[]
|
||||
}>()
|
||||
|
||||
const isEdit = !!props.flight
|
||||
@@ -50,6 +51,7 @@ interface LookupResult {
|
||||
|
||||
const lookupResult = ref<LookupResult | null>(null)
|
||||
const lookupKey = ref(0)
|
||||
|
||||
async function lookupFlight() {
|
||||
if (!flightNumber.value.trim()) return
|
||||
lookupLoading.value = true
|
||||
@@ -93,7 +95,7 @@ async function lookupFlight() {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Form ──────────────────────────────────────────────────────────────────────
|
||||
// ── Display form (drives the template) ───────────────────────────────────────
|
||||
|
||||
const form = useForm({
|
||||
flight_number: props.flight?.flight_number ?? '',
|
||||
@@ -105,13 +107,15 @@ const form = useForm({
|
||||
aircraft: props.flight?.aircraft_options[0] ?? null as { value: number; title: string } | null,
|
||||
aircraft_registration: props.flight?.aircraft_registration ?? '',
|
||||
seat_number: props.flight?.seat_number ?? '',
|
||||
seat_type: props.flight?.seat_type ?? props.seat_types[0],
|
||||
flight_class: props.flight?.flight_class ?? props.flight_classes[0],
|
||||
flight_reason: props.flight?.flight_reason ?? props.flight_reasons[0],
|
||||
seat_type: props.flight?.seat_type ?? props.seat_types[0] ?? null as SeatType | null,
|
||||
flight_class: props.flight?.flight_class ?? props.flight_classes[0] ?? null as FlightClass | null,
|
||||
flight_reason: props.flight?.flight_reason ?? props.flight_reasons[0] ?? null as FlightReason | null,
|
||||
note: props.flight?.note ?? '',
|
||||
auto_update: props.flight?.auto_update ?? false,
|
||||
})
|
||||
|
||||
// ── Submit form (ID-based, what actually gets sent) ───────────────────────────
|
||||
|
||||
const submitForm = useForm({
|
||||
flight_number: '' as string | null,
|
||||
departure_date: '' as string | null,
|
||||
@@ -139,9 +143,9 @@ function submit() {
|
||||
submitForm.aircraft_id = form.aircraft?.value ?? null
|
||||
submitForm.aircraft_registration = form.aircraft_registration
|
||||
submitForm.seat_number = form.seat_number
|
||||
submitForm.seat_type_id = form.seat_type?.value ?? null
|
||||
submitForm.flight_class_id = form.flight_class?.value ?? null
|
||||
submitForm.flight_reason_id = form.flight_reason?.value ?? null
|
||||
submitForm.seat_type_id = form.seat_type?.id
|
||||
submitForm.flight_class_id = form.flight_class?.id
|
||||
submitForm.flight_reason_id = form.flight_reason?.id
|
||||
submitForm.note = form.note
|
||||
submitForm.auto_update = form.auto_update
|
||||
|
||||
@@ -288,6 +292,9 @@ const aircraftOptionsData = ref<{ value: number; title: string }[]>(props.flight
|
||||
v-model="form.flight_class"
|
||||
label="Flight Class"
|
||||
:items="flight_classes"
|
||||
item-title="name"
|
||||
item-value="id"
|
||||
:return-object="true"
|
||||
:disabled="!lookupComplete"
|
||||
:error-messages="submitForm.errors.flight_class_id"
|
||||
/>
|
||||
@@ -310,6 +317,9 @@ const aircraftOptionsData = ref<{ value: number; title: string }[]>(props.flight
|
||||
v-model="form.seat_type"
|
||||
label="Seat Type"
|
||||
:items="seat_types"
|
||||
item-title="name"
|
||||
item-value="id"
|
||||
:return-object="true"
|
||||
:disabled="!lookupComplete"
|
||||
:error-messages="submitForm.errors.seat_type_id"
|
||||
/>
|
||||
@@ -323,6 +333,9 @@ const aircraftOptionsData = ref<{ value: number; title: string }[]>(props.flight
|
||||
v-model="form.flight_reason"
|
||||
label="Flight Reason"
|
||||
:items="flight_reasons"
|
||||
item-title="name"
|
||||
item-value="id"
|
||||
:return-object="true"
|
||||
:disabled="!lookupComplete"
|
||||
:error-messages="submitForm.errors.flight_reason_id"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user