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