Skip to content

Commit

Permalink
Merge pull request #591 from themeum/harun
Browse files Browse the repository at this point in the history
Freezing popup dismiss fix and refactor code.
  • Loading branch information
shewa12 authored Oct 13, 2023
2 parents 1ffe764 + 4bc620f commit fa7391a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
30 changes: 15 additions & 15 deletions assets/react/lib/modules/instructor-review.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ window.jQuery(document).ready($ => {
course_id: course_id
}

$.ajax({
url: _tutorobject.ajaxurl,
type: 'POST',
dataType: 'json',
data: data,
success: function (res) {
if ( ! res.success ) {
console.warn('review pupup data clear error');
}
},
complete: function(){
modal.removeClass('tutor-is-active');
}
});
$.ajax({
url: _tutorobject.ajaxurl,
type: 'POST',
dataType: 'json',
data: data,
beforeSend: function () {
modal.removeClass('tutor-is-active');
},
success: function (res) {
if (!res.success) {
console.warn('review popup data clear error');
}
}
});
})

$(document).on('click', '.tutor_submit_review_btn', function (e) {
Expand Down Expand Up @@ -115,7 +115,7 @@ window.jQuery(document).ready($ => {
},
success: function (res) {
if ( ! res.success ) {
console.warn('review pupup data clear error');
console.warn('review popup data clear error');
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,8 @@ public static function set_review_popup_data( $user_id, $course_id ) {
if ( get_tutor_option( 'enable_course_review' ) ) {
$rating = tutor_utils()->get_course_rating_by_user( $course_id, $user_id );
if ( ! $rating || ( empty( $rating->rating ) && empty( $rating->review ) ) ) {
$meta_key = User::REVIEW_POPUP_META . '_' . $course_id;
add_user_meta( $user_id, $meta_key, $course_id );
$meta_key = User::get_review_popup_meta( $course_id );
add_user_meta( $user_id, $meta_key, $course_id, true );
}
}
}
Expand All @@ -873,7 +873,7 @@ public function popup_review_form() {
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$course_id = get_the_ID();
$meta_key = User::REVIEW_POPUP_META . '_' . $course_id;
$meta_key = User::get_review_popup_meta( $course_id );
$review_course_id = (int) get_user_meta( $user_id, $meta_key, true );

if ( is_single() && $course_id === $review_course_id ) {
Expand All @@ -897,7 +897,7 @@ public function clear_review_popup_data() {
$course_id = Input::post( 'course_id', 0, Input::TYPE_INT );

if ( $course_id ) {
$meta_key = User::REVIEW_POPUP_META . '_' . $course_id;
$meta_key = User::get_review_popup_meta( $course_id );
delete_user_meta( $user_id, $meta_key, $course_id );
}

Expand Down
13 changes: 13 additions & 0 deletions classes/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public function __construct( $register_hooks = true ) {
add_action( 'admin_init', array( $this, 'hide_notices' ) );
}

/**
* Get meta key name for review popup.
*
* @since 2.4.0
*
* @param int $course_id course id.
*
* @return string user meta key name.
*/
public static function get_review_popup_meta( $course_id ) {
return self::REVIEW_POPUP_META . '_' . $course_id;
}

/**
* Check user has provided role.
*
Expand Down

0 comments on commit fa7391a

Please sign in to comment.