Page 1 of 1

Add a spinner when sending a ticket

Posted: Tue Mar 05, 2024 12:44 pm
by mbory
Hi, there,

I noticed that when a ticket was being sent, we had no notification to wait. So I added a modal with a spinner. If you're interested, here's how to do it:

Open theme/hesk3/customer/create-ticket/create-ticket.php

Add this code (for example, just before the <div class="form-footer"> tag), and change the display text as you wish:

Code: Select all

<div id="loading-overlay" class="loading-overlay">
	<div id="loading-message" class="loading-message">
		<div class="spinner"></div>
		<p>Envoi en cours, merci de patienter...</p>
	</div>
</div>
Then, still in the same file, add this script after the others (just before the RECAPTCHA logic):

Code: Select all

    <script>
        function showLoadingMessage() {
            // Show loading message
            document.getElementById('loading-overlay').style.display = 'block';
            // You may also want to disable the submit button to prevent multiple submissions
            document.getElementById('recaptcha-submit').disabled = true;
        }
    </script>
Now you need to pass the showLoadingMessage function to the form's onSubmit :

Code: Select all

<form class="form form-submit-ticket ticket-create <?php echo count($_SESSION['iserror']) ? 'invalid' : ''; ?>" method="post" action="submit_ticket.php?submit=1" name="form1" id="form1" enctype="multipart/form-data" onsubmit="showLoadingMessage()">
Now go to the app.css file in theme/hesk3/customer/css and add this code:

Code: Select all

.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* Fond grisant semi-transparent */
  z-index: 9999; /* Assure que la modal est au-dessus de tout le reste */
}

.loading-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.spinner {
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top: 4px solid #156cc8; /* Couleur du spinner */
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
If you're not using debug mode, I think you'll have to minify it and then replace app.min.css

If you've followed this correctly, you should normally have a popup with a spinner while the ticket is being sent, and once it's been sent, the popup closes.

Result :
Image

Don't hesitate if you need help! Thank you

Re: Add a spinner when sending a ticket

Posted: Tue Mar 05, 2024 3:37 pm
by Klemen
Thank you for sharing this, I hope others find it useful!

Re: Add a spinner when sending a ticket

Posted: Sun Mar 10, 2024 4:28 am
by cwshubby
Will something like this be implemented in future version?

Re: Add a spinner when sending a ticket

Posted: Tue Mar 12, 2024 8:10 am
by Klemen
It just might be :D

Re: Add a spinner when sending a ticket

Posted: Tue Mar 12, 2024 8:22 am
by Klemen
P.s.: to make this work, you also need to add

Code: Select all

onsubmit="showLoadingMessage()"
to the

Code: Select all

<form class="form form-submit-ticket ticket-create <?php echo count($_SESSION['iserror']) ? 'invalid' : ''; ?>" method="post" action="submit_ticket.php?submit=1" name="form1" id="form1" enctype="multipart/form-data">
line, for example:

Code: Select all

<form class="form form-submit-ticket ticket-create <?php echo count($_SESSION['iserror']) ? 'invalid' : ''; ?>" method="post" action="submit_ticket.php?submit=1" name="form1" id="form1" enctype="multipart/form-data" onsubmit="showLoadingMessage()">

Re: Add a spinner when sending a ticket

Posted: Tue Mar 12, 2024 10:59 am
by mbory
Klemen wrote: Tue Mar 12, 2024 8:22 am P.s.: to make this work, you also need to add

Code: Select all

onsubmit="showLoadingMessage()"
to the

Code: Select all

<form class="form form-submit-ticket ticket-create <?php echo count($_SESSION['iserror']) ? 'invalid' : ''; ?>" method="post" action="submit_ticket.php?submit=1" name="form1" id="form1" enctype="multipart/form-data">
line, for example:

Code: Select all

<form class="form form-submit-ticket ticket-create <?php echo count($_SESSION['iserror']) ? 'invalid' : ''; ?>" method="post" action="submit_ticket.php?submit=1" name="form1" id="form1" enctype="multipart/form-data" onsubmit="showLoadingMessage()">
Oh yeah ! Sorry for the oversight! You do need to add the function to onSubmit!

Re: Add a spinner when sending a ticket

Posted: Wed Apr 10, 2024 12:28 pm
by Rapthorne
Would love to see this in a future version

Re: Add a spinner when sending a ticket

Posted: Thu Apr 11, 2024 3:59 pm
by Klemen
It has already been included in the development version.