From e116f6ce66ec9291c953a8a70f7ed2b9f4c67968 Mon Sep 17 00:00:00 2001 From: MRoyhanF Date: Sun, 22 Dec 2024 02:41:35 +0700 Subject: [PATCH] fix : ticket | validation create ticket --- public/css/app.css | 4 + src/resources/views/pages/ticket/create.edge | 78 +++++++++++++++----- src/resources/views/pages/ticket/index.edge | 1 + 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/public/css/app.css b/public/css/app.css index 82025a0..a054e68 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -1043,6 +1043,10 @@ video { border-radius: 0.75rem; } +.rounded-sm { + border-radius: 0.125rem; +} + .rounded-r-xl { border-top-right-radius: 0.75rem; border-bottom-right-radius: 0.75rem; diff --git a/src/resources/views/pages/ticket/create.edge b/src/resources/views/pages/ticket/create.edge index 83dc820..72edffa 100644 --- a/src/resources/views/pages/ticket/create.edge +++ b/src/resources/views/pages/ticket/create.edge @@ -57,8 +57,22 @@ @@ -131,7 +148,10 @@ {{ data.airline.name }}
- {{ data.airline.name }} ( {{ data.departure.city.name }} - {{ data.arrival.city.name }} ) + {{ data.airline.name }} ( + {{ data.departure.city.name }} + - + {{ data.arrival.city.name }} )
{{ new Date(data.departure.time).toISOString().split('T')[1].slice(0, 8) }} - {{ new Date(data.arrival.time).toISOString().split('T')[1].slice(0, 8) }} @@ -151,7 +171,7 @@

{{ data.id }}

- +
@@ -182,57 +202,76 @@ const token = '{{ token }}'; let firstFlightId = null; let secondFlightId = null; + let departureFirstFlight = null; + let arrivalFirstFlight = null; + let departureSecondFlight = null; + let arrivalSecondFlight = null; + // Update selection in real-time - function updateSelection(type, id) { + function updateSelection(type, id, departure, arrival) { if (type === 'first') { firstFlightId = id; + firstFlightDeparture = departure; + firstFlightArrival = arrival; + document.getElementById('firstFlightDisplay').innerText = `First Flight ID: ${firstFlightId}`; + document.getElementById('departureFirstFlightDisplay').innerText = firstFlightDeparture; + document.getElementById('arrivalFirstFlightDisplay').innerText = firstFlightArrival; + } else if (type === 'second') { secondFlightId = id; + secondFlightDeparture = departure; + secondFlightArrival = arrival; + document.getElementById('secondFlightDisplay').innerText = `Second Flight ID: ${secondFlightId}`; + document.getElementById('departureSecondFlightDisplay').innerText = secondFlightDeparture; + document.getElementById('arrivalSecondFlightDisplay').innerText = secondFlightArrival; + } } // Lock selection function lockSelection() { if (!firstFlightId || !secondFlightId) { - alert('Please select one flight for both First and Second.'); + showToast("error", "Validation Error", "Please select both First and Second flights."); + return; + } + + if(firstFlightArrival != secondFlightDeparture) { + showToast("error", "Validation Error", "Departure for First Flight and Arrival for Second Flight must be the same."); return; } - // Show Selected Flights Section document.getElementById('selectedFlights').classList.remove('hidden'); - // Show Discount Dropdown and Create Button document.getElementById('discountDropdown').classList.remove('hidden'); document.getElementById('createButton').classList.remove('hidden'); } // Create Ticket function createTicket() { - // Ambil nilai flight ID dari radio button yang dipilih const firstFlightId = document.querySelector('input[name="firstFlight"]:checked')?.value; const secondFlightId = document.querySelector('input[name="secondFlight"]:checked')?.value; if (!firstFlightId || !secondFlightId) { - alert('Please select one flight for both First and Second.'); + showToast("error", "Validation Error", "Please select both First and Second flights."); + return; + } + + if(firstFlightArrival != secondFlightDeparture) { + showToast("error", "Validation Error", "Departure for First Flight and Arrival for Second Flight must be the same."); return; } - // Ambil nilai discount ID dari dropdown const discountIdValue = document.getElementById('discountId')?.value; - // Siapkan payload data const formData = { - routeId: routeId, // Ganti dengan routeId yang sesuai + routeId: routeId, flightIds: [parseInt(firstFlightId), parseInt(secondFlightId)], - ...(discountIdValue ? { discountId: parseInt(discountIdValue) } : {}) // Opsional + ...(discountIdValue ? { discountId: parseInt(discountIdValue) } : {}) }; - console.log(token); - console.log('Payload Data:', formData); // Debug log untuk memastikan format data benar - $.ajax({ url: '{{ api }}/api/v1/tickets', method: 'POST', @@ -258,7 +297,6 @@ } }, error: function (xhr) { - // Tangani kesalahan respons lainnya const errorMessage = xhr.responseJSON?.message || `Error ${xhr.status}: ${xhr.statusText}`; showToast("error", "Error", errorMessage); } diff --git a/src/resources/views/pages/ticket/index.edge b/src/resources/views/pages/ticket/index.edge index 7d3a066..6fab5bb 100644 --- a/src/resources/views/pages/ticket/index.edge +++ b/src/resources/views/pages/ticket/index.edge @@ -151,6 +151,7 @@