From e09647d01fe0a3ee0818777c388c551dff766d20 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Thu, 26 May 2022 15:32:21 +0200 Subject: [PATCH] Fix the booking cancellation flow and make sure analytics are loaded in both confirmation and cancellation (#1200) --- application/config/config.php | 4 ++- .../controllers/Booking_cancellation.php | 26 ++++++++------- .../language/english/translations_lang.php | 2 +- .../components/booking_cancellation_frame.php | 4 +-- .../views/pages/booking_cancellation.php | 32 ++++++++----------- .../views/pages/booking_confirmation.php | 7 ++++ assets/js/pages/booking.js | 13 ++++---- 7 files changed, 46 insertions(+), 42 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index dbac9753..1b7e624d 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -389,7 +389,9 @@ $config['csrf_cookie_name'] = 'csrf_cookie'; $config['csrf_expire'] = 7200; $config['csrf_exclude_uris'] = [ 'api/v1/.*', - 'booking/.*' + 'booking/.*', + 'booking_cancellation/.*', + 'booking_confirmation/.*' ]; /* diff --git a/application/controllers/Booking_cancellation.php b/application/controllers/Booking_cancellation.php index 7b8c987d..f5019948 100755 --- a/application/controllers/Booking_cancellation.php +++ b/application/controllers/Booking_cancellation.php @@ -55,13 +55,22 @@ class Booking_cancellation extends EA_Controller { abort(403, 'Forbidden'); } - $exceptions = []; - $occurrences = $this->appointments_model->get(['hash' => $appointment_hash]); if (empty($occurrences)) { - throw new Exception('No record matches the provided hash.'); + html_vars([ + 'page_title' => lang('appointment_not_found'), + 'message_title' => lang('appointment_not_found'), + 'message_text' => lang('appointment_does_not_exist_in_db'), + 'message_icon' => base_url('assets/img/error.png'), + 'google_analytics_code' => setting('google_analytics_code'), + 'matomo_analytics_url' => setting('matomo_analytics_url'), + ]); + + $this->load->view('pages/booking_message'); + + return; } $appointment = $occurrences[0]; @@ -88,18 +97,13 @@ class Booking_cancellation extends EA_Controller { } catch (Throwable $e) { - $exceptions[] = $e; + log_message('error', 'Booking Cancellation Exception: ' . $e->getMessage()); } html_vars([ - 'message_title' => lang('appointment_cancelled_title'), - 'message_text' => lang('appointment_cancelled'), - 'message_icon' => base_url('assets/img/success.png'), - 'google_analytics_code' => setting('google_analytics_code'), - 'matomo_analytics_url' => setting('matomo_analytics_url'), - 'exceptions' => $exceptions + 'page_title' => lang('appointment_cancelled_title'), ]); - $this->load->view('pages/booking_message'); + $this->load->view('pages/booking_cancellation'); } } diff --git a/application/language/english/translations_lang.php b/application/language/english/translations_lang.php index 9c41e48e..26ea0e94 100755 --- a/application/language/english/translations_lang.php +++ b/application/language/english/translations_lang.php @@ -55,7 +55,7 @@ $lang['appointment_added_to_your_plan'] = 'A new appointment has been added to y $lang['appointment_link_description'] = 'You can make changes by clicking the appointment link below.'; $lang['appointment_locked'] = 'Modification impossible!'; $lang['appointment_locked_message'] = 'The appointment cannot be changed less than {$limit} hours in advance.'; -$lang['appointment_not_found'] = 'Appointment Not Found.'; +$lang['appointment_not_found'] = 'Appointment Not Found'; $lang['appointment_does_not_exist_in_db'] = 'The appointment you requested does not exist in the system database anymore.'; $lang['display_calendar'] = 'Display Calendar'; $lang['calendar'] = 'Calendar'; diff --git a/application/views/components/booking_cancellation_frame.php b/application/views/components/booking_cancellation_frame.php index 71a31f43..c7f8aa8b 100644 --- a/application/views/components/booking_cancellation_frame.php +++ b/application/views/components/booking_cancellation_frame.php @@ -17,9 +17,7 @@
- - - + - + + + vars('google_analytics_code')]) ?> + vars('matomo_analytics_url')]) ?> + + + diff --git a/application/views/pages/booking_confirmation.php b/application/views/pages/booking_confirmation.php index b246366e..3ebf2d1e 100755 --- a/application/views/pages/booking_confirmation.php +++ b/application/views/pages/booking_confirmation.php @@ -31,3 +31,10 @@ + + + + vars('google_analytics_code')]) ?> + vars('matomo_analytics_url')]) ?> + + diff --git a/assets/js/pages/booking.js b/assets/js/pages/booking.js index dc8fc5d9..c00ce45c 100644 --- a/assets/js/pages/booking.js +++ b/assets/js/pages/booking.js @@ -410,7 +410,7 @@ App.Pages.Booking = (function () { $('#cancel-appointment').on('click', () => { const $cancelAppointmentForm = $('#cancel-appointment-form'); - let $cancelReason; + let $cancellationReason; const buttons = [ { @@ -422,11 +422,11 @@ App.Pages.Booking = (function () { { text: 'OK', click: () => { - if ($cancelReason.val() === '') { - $cancelReason.css('border', '2px solid #DC3545'); + if ($cancellationReason.val() === '') { + $cancellationReason.css('border', '2px solid #DC3545'); return; } - $cancelAppointmentForm.find('textarea').val($cancelReason.val()); + $cancelAppointmentForm.find('#hidden-cancellation-reason').val($cancellationReason.val()); $cancelAppointmentForm.submit(); } } @@ -438,9 +438,9 @@ App.Pages.Booking = (function () { buttons ); - $cancelReason = $('