PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.6
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.6
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / js / frontend / profile / order-recover.js

order-recover.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.6, at assets/src/js/frontend/profile/order-recover.js

73 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { lpSetLoadingEl } from '../../utils.js';
2 import Toastify from 'toastify-js';
3
4 /**
5 * JS Recover order
6 *
7 * @since 4.0.0
8 * @version 1.0.1
9 */
10 const recoverOrder = () => {
11 const toastify = Toastify( {
12 gravity: lpData.toast.gravity, // `top` or `bottom`
13 position: lpData.toast.position, // `left`, `center` or `right`
14 close: lpData.toast.close == 1,
15 className: `${ lpData.toast.classPrefix }`,
16 stopOnFocus: lpData.toast.stopOnFocus == 1,
17 duration: lpData.toast.duration,
18 } );
19
20 // Events
21 document.addEventListener( 'submit', ( e ) => {
22 const target = e.target;
23 if ( target.classList.contains( 'lp-order-recover' ) ) {
24 e.preventDefault();
25 ajaxRecover( target );
26 }
27 } );
28
29 const ajaxRecover = ( form ) => {
30 const status = 'error';
31 const btnSubmit = form.querySelector( '.button-recover-order' );
32 if ( ! btnSubmit ) {
33 return;
34 }
35
36 lpSetLoadingEl( btnSubmit, 1 );
37
38 const url = new URL( window.location.href );
39 fetch( url, {
40 method: 'POST',
41 body: new FormData( form ),
42 } )
43 .then( ( response ) => {
44 return response.json();
45 } )
46 .then( ( res ) => {
47 const { status, data: { redirect }, message } = res;
48
49 if ( status === 'success' ) {
50 toastify.options.text = message;
51 toastify.options.className += ` ${ status }`;
52 toastify.showToast();
53 if ( redirect ) {
54 window.location.href = redirect;
55 }
56 btnSubmit.remove();
57 } else {
58 lpSetLoadingEl( btnSubmit, 0 );
59 throw new Error( message );
60 }
61 } ).finally( () => {
62
63 } ).catch( ( err ) => {
64 toastify.options.text = err.message;
65 toastify.options.className += ` ${ status }`;
66 toastify.showToast();
67 } );
68 };
69 };
70
71 export default recoverOrder;
72
73