mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
use error notification and disable button
This commit is contained in:
@@ -65,6 +65,8 @@ export default function ShowBooking({
|
|||||||
booking: BookingDocument
|
booking: BookingDocument
|
||||||
}) {
|
}) {
|
||||||
const [booking, setBooking] = useState(bookingProp)
|
const [booking, setBooking] = useState(bookingProp)
|
||||||
|
const [storingBooking, setStoringBooking] = useState(false)
|
||||||
|
const [storingBookingError, setStoringBookingError] = useState(null)
|
||||||
|
|
||||||
// in case the props change, update the internal state
|
// in case the props change, update the internal state
|
||||||
useEffect(() => setBooking(bookingProp), [bookingProp])
|
useEffect(() => setBooking(bookingProp), [bookingProp])
|
||||||
@@ -73,14 +75,19 @@ export default function ShowBooking({
|
|||||||
if (!confirm('Soll die Buchung wirklich storniert werden?')) {
|
if (!confirm('Soll die Buchung wirklich storniert werden?')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setStoringBookingError(null)
|
||||||
|
setStoringBooking(true)
|
||||||
const updatedBooking = await cancelBooking(booking)
|
const updatedBooking = await cancelBooking(booking)
|
||||||
setBooking(updatedBooking)
|
setBooking(updatedBooking)
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
alert(
|
setStoringBookingError(
|
||||||
'Die Buchung konnte nicht storniert werden. Schreiben Sie uns eine E-Mail'
|
'Buchung konnte nicht storniert werden. Schreiben Sie uns eine E-Mail!'
|
||||||
)
|
)
|
||||||
|
console.error('Failed to store booking', error)
|
||||||
}
|
}
|
||||||
|
setStoringBooking(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -96,11 +103,18 @@ export default function ShowBooking({
|
|||||||
{dateFormatFrontend(new Date(booking.startDate))} -{' '}
|
{dateFormatFrontend(new Date(booking.startDate))} -{' '}
|
||||||
{dateFormatFrontend(new Date(booking.endDate))}
|
{dateFormatFrontend(new Date(booking.endDate))}
|
||||||
</div>
|
</div>
|
||||||
|
{storingBookingError && (
|
||||||
|
<div className="error-message flex-grow">{storingBookingError}</div>
|
||||||
|
)}
|
||||||
{[BOOKING_STATUS.CONFIRMED, BOOKING_STATUS.REQUESTED].includes(
|
{[BOOKING_STATUS.CONFIRMED, BOOKING_STATUS.REQUESTED].includes(
|
||||||
booking.status
|
booking.status
|
||||||
) && (
|
) && (
|
||||||
<div className="my-6">
|
<div className="my-6">
|
||||||
<button onClick={onCancelBooking} className="btn btn-red">
|
<button
|
||||||
|
onClick={onCancelBooking}
|
||||||
|
className="btn btn-red"
|
||||||
|
disabled={storingBooking}
|
||||||
|
>
|
||||||
Buchung Stornieren
|
Buchung Stornieren
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user