Refactor the calendar page appointment removal so that it also uses a request parameter called "cancellation_reason", just like the public booking page does.

This commit is contained in:
Alex Tselegidis 2023-06-01 14:25:02 +02:00
parent 64edc3e450
commit 8e37e54bdb
5 changed files with 16 additions and 22 deletions

View file

@ -95,7 +95,7 @@ class Booking_cancellation extends EA_Controller {
$this->synchronization->sync_appointment_deleted($appointment, $provider); $this->synchronization->sync_appointment_deleted($appointment, $provider);
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings); $this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings, $cancellation_reason);
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_DELETE, $appointment); $this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_DELETE, $appointment);

View file

@ -312,6 +312,7 @@ class Calendar extends EA_Controller {
} }
$appointment_id = request('appointment_id'); $appointment_id = request('appointment_id');
$cancellation_reason = request('cancellation_reason');
if (empty($appointment_id)) if (empty($appointment_id))
{ {
@ -335,7 +336,7 @@ class Calendar extends EA_Controller {
// Delete appointment record from the database. // Delete appointment record from the database.
$this->appointments_model->delete($appointment_id); $this->appointments_model->delete($appointment_id);
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings); $this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings, $cancellation_reason);
$this->synchronization->sync_appointment_deleted($appointment, $provider); $this->synchronization->sync_appointment_deleted($appointment, $provider);

View file

@ -201,17 +201,10 @@ class Notifications {
* @param array $customer Customer data. * @param array $customer Customer data.
* @param array $settings Required settings. * @param array $settings Required settings.
*/ */
public function notify_appointment_deleted(array $appointment, array $service, array $provider, array $customer, array $settings): void public function notify_appointment_deleted(array $appointment, array $service, array $provider, array $customer, array $settings, string $cancellation_reason = ''): void
{ {
try try
{ {
$delete_reason = (string)request('delete_reason');
if (empty($delete_reason))
{
$delete_reason = (string)request('cancellation_reason');
}
// Notify provider. // Notify provider.
$send_provider = filter_var( $send_provider = filter_var(
$this->CI->providers_model->get_setting($provider['id'], 'notifications'), $this->CI->providers_model->get_setting($provider['id'], 'notifications'),
@ -227,7 +220,7 @@ class Notifications {
$customer, $customer,
$settings, $settings,
$provider['email'], $provider['email'],
$delete_reason, $cancellation_reason,
$provider['timezone'] $provider['timezone']
); );
} }
@ -247,7 +240,7 @@ class Notifications {
$customer, $customer,
$settings, $settings,
$customer['email'], $customer['email'],
$delete_reason, $cancellation_reason,
$customer['timezone'] $customer['timezone']
); );
} }
@ -269,7 +262,7 @@ class Notifications {
$customer, $customer,
$settings, $settings,
$admin['email'], $admin['email'],
$delete_reason, $cancellation_reason,
$admin['timezone'] $admin['timezone']
); );
} }
@ -296,7 +289,7 @@ class Notifications {
$customer, $customer,
$settings, $settings,
$secretary['email'], $secretary['email'],
$delete_reason, $cancellation_reason,
$secretary['timezone'] $secretary['timezone']
); );
} }

View file

@ -59,17 +59,17 @@ App.Http.Calendar = (function () {
* Remove an appointment. * Remove an appointment.
* *
* @param {Number} appointmentId * @param {Number} appointmentId
* @param {String} deleteReason * @param {String} cancellationReason
* *
* @return {*|jQuery.jqXHR} * @return {*|jQuery.jqXHR}
*/ */
function deleteAppointment(appointmentId, deleteReason) { function deleteAppointment(appointmentId, cancellationReason) {
const url = App.Utils.Url.siteUrl('calendar/delete_appointment'); const url = App.Utils.Url.siteUrl('calendar/delete_appointment');
const data = { const data = {
csrf_token: vars('csrf_token'), csrf_token: vars('csrf_token'),
appointment_id: appointmentId, appointment_id: appointmentId,
delete_reason: deleteReason cancellation_reason: cancellationReason
}; };
return $.post(url, data); return $.post(url, data);

View file

@ -243,9 +243,9 @@ App.Utils.CalendarDefaultView = (function () {
click: (event, messageModal) => { click: (event, messageModal) => {
const appointmentId = lastFocusedEventData.extendedProps.data.id; const appointmentId = lastFocusedEventData.extendedProps.data.id;
const deleteReason = $('#delete-reason').val(); const cancellationReason = $('#cancellation-reason').val();
App.Http.Calendar.deleteAppointment(appointmentId, deleteReason).done(() => { App.Http.Calendar.deleteAppointment(appointmentId, cancellationReason).done(() => {
messageModal.dispose(); messageModal.dispose();
// Refresh calendar event items. // Refresh calendar event items.
@ -263,9 +263,9 @@ App.Utils.CalendarDefaultView = (function () {
$('<textarea/>', { $('<textarea/>', {
'class': 'form-control w-100', 'class': 'form-control w-100',
'id': 'delete-reason', 'id': 'cancellation-reason',
'rows': '3' 'rows': '3'
}).appendTo('#message-box'); }).appendTo('#message-modal .modal-body');
} else { } else {
// Do not display confirmation prompt. // Do not display confirmation prompt.