Fix the booking cancellation flow and make sure analytics are loaded in both confirmation and cancellation (#1200)

This commit is contained in:
Alex Tselegidis 2022-05-26 15:32:21 +02:00
parent 72e84bd4f3
commit e09647d01f
7 changed files with 46 additions and 42 deletions

View file

@ -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/.*'
];
/*

View file

@ -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');
}
}

View file

@ -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';

View file

@ -17,9 +17,7 @@
<form id="cancel-appointment-form" method="post"
action="<?= site_url('booking_cancellation/of/' . $appointment_data['hash']) ?>">
<input type="hidden" name="csrfToken" value="<?= $this->security->get_csrf_hash() ?>"/>
<input id="cancel-reason" name="cancellation_reason" type="hidden">
<input id="hidden-cancellation-reason" name="cancellation_reason" type="hidden">
<button id="cancel-appointment" class="btn btn-warning btn-sm">
<i class="fas fa-trash me-2"></i>

View file

@ -3,34 +3,28 @@
<?php section('content') ?>
<div>
<img id="success-icon" class="mt-0 mb-2" src="<?= base_url('assets/img/success.png') ?>" alt="success"/>
<img id="success-icon" class="mt-0 mb-5" src="<?= base_url('assets/img/success.png') ?>" alt="success"/>
</div>
<div>
<h3><?= lang('appointment_registered') ?></h3>
<div class="mb-5">
<h4 class="mb-5"><?= lang('appointment_cancelled_title') ?></h4>
<p>
<?= lang('appointment_details_was_sent_to_you') ?>
</p>
<p>
<strong>
<?= lang('check_spam_folder') ?>
</strong>
<p class="mb-5">
<?= lang('appointment_cancelled') ?>
</p>
<a href="<?= site_url() ?>" class="btn btn-primary btn-large">
<i class="fas fa-calendar-alt"></i>
<i class="fas fa-calendar-alt me-2"></i>
<?= lang('go_to_booking_page') ?>
</a>
<?php if (config('google_sync_feature')): ?>
<button id="add-to-google-calendar" class="btn btn-outline-secondary">
<i class="fas fa-plus"></i>
<?= lang('add_to_google_calendar') ?>
</button>
<?php endif ?>
</div>
<?php section('content') ?>
<?php section('scripts') ?>
<?php component('google_analytics_script', ['google_analytics_code' => vars('google_analytics_code')]) ?>
<?php component('matomo_analytics_script', ['matomo_analytics_url' => vars('matomo_analytics_url')]) ?>
<?php section('scripts') ?>

View file

@ -31,3 +31,10 @@
</div>
<?php section('content') ?>
<?php section('scripts') ?>
<?php component('google_analytics_script', ['google_analytics_code' => vars('google_analytics_code')]) ?>
<?php component('matomo_analytics_script', ['matomo_analytics_url' => vars('matomo_analytics_url')]) ?>
<?php section('scripts') ?>

View file

@ -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 = $('<textarea/>', {
$cancellationReason = $('<textarea/>', {
'class': 'form-control',
'id': 'cancel-reason',
'id': 'cancellation-reason',
'rows': '3',
'css': {
'width': '100%'
@ -723,7 +723,6 @@ App.Pages.Booking = (function () {
data.appointment.id = vars('appointment_data').id;
data.customer.id = vars('customer_data').id;
}
$('input[name="csrfToken"]').val(vars('csrf_token'));
$('input[name="post_data"]').val(JSON.stringify(data));
}