create-review-modal.php
95 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tutor create review modal. |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | use Tutor\Components\Button; |
| 14 | use Tutor\Components\Constants\Size; |
| 15 | use Tutor\Components\Constants\Variant; |
| 16 | use Tutor\Components\InputField; |
| 17 | use Tutor\Components\StarRatingInput; |
| 18 | |
| 19 | // Get global variables. |
| 20 | global $current_user_id, |
| 21 | $tutor_course_id; |
| 22 | |
| 23 | $form_id = 'create-review-form'; |
| 24 | |
| 25 | ?> |
| 26 | <div |
| 27 | x-data="tutorReviewModal()" |
| 28 | <?php echo ! empty( $data['clear_review_popup_data'] ) ? 'x-on:tutor-modal-closed.document="if ($event.detail.id === \'create-review-modal\') clearReviewPopupData(' . esc_js( $tutor_course_id ) . ')"' : ''; ?> |
| 29 | > |
| 30 | <form |
| 31 | class="tutor-flex tutor-flex-column tutor-gap-6" |
| 32 | id="<?php echo esc_attr( $form_id ); ?>" |
| 33 | x-data='tutorForm({ |
| 34 | id: "<?php echo esc_attr( $form_id ); ?>", |
| 35 | mode: "onChange", |
| 36 | defaultValues: { |
| 37 | comment_post_ID: <?php echo esc_html( $tutor_course_id ); ?>, |
| 38 | clear_review_popup_data: <?php echo ! empty( $data['clear_review_popup_data'] ) ? 'true' : 'false'; ?> |
| 39 | }, |
| 40 | })' |
| 41 | x-bind="getFormBindings()" |
| 42 | @submit.prevent="handleSubmit( |
| 43 | (data) => handleReviewSubmit(data), |
| 44 | )($event)" |
| 45 | > |
| 46 | <div class="tutor-p-7"> |
| 47 | <?php |
| 48 | StarRatingInput::make() |
| 49 | ->field_name( 'rating' ) |
| 50 | ->current_rating( $review->rating ?? 0 ) |
| 51 | ->view( 'emoji' ) |
| 52 | ->attr( 'x-bind', "register('rating', { required: '" . esc_js( __( 'Rating is required', 'tutor' ) ) . "' })" ) |
| 53 | ->render(); |
| 54 | ?> |
| 55 | </div> |
| 56 | |
| 57 | <div class="tutor-pt-7 tutor-px-7 tutor-border-t"> |
| 58 | <?php |
| 59 | InputField::make() |
| 60 | ->type( 'textarea' ) |
| 61 | ->label( __( 'Write Your Review', 'tutor' ) ) |
| 62 | ->placeholder( __( 'Tell us about your experience. Was it a good match for you?', 'tutor' ) ) |
| 63 | ->name( 'comment_content' ) |
| 64 | ->required() |
| 65 | ->clearable() |
| 66 | ->attr( 'x-bind', "register('comment_content', { required: '" . esc_js( __( 'Review content is required', 'tutor' ) ) . "' })" ) |
| 67 | ->render(); |
| 68 | ?> |
| 69 | </div> |
| 70 | |
| 71 | <div class="tutor-flex tutor-justify-between tutor-gap-6 tutor-pb-6 tutor-px-7"> |
| 72 | <?php |
| 73 | Button::make() |
| 74 | ->label( __( 'Cancel', 'tutor' ) ) |
| 75 | ->variant( Variant::SECONDARY ) |
| 76 | ->size( Size::SMALL ) |
| 77 | ->attr( 'x-on:click', "TutorCore.modal.closeModal('create-review-modal')" ) |
| 78 | ->attr( 'type', 'button' ) |
| 79 | ->attr( 'class', 'tutor-w-full' ) |
| 80 | ->render(); |
| 81 | |
| 82 | Button::make() |
| 83 | ->label( __( 'Submit Review', 'tutor' ) ) |
| 84 | ->variant( Variant::PRIMARY ) |
| 85 | ->size( Size::SMALL ) |
| 86 | ->attr( 'type', 'submit' ) |
| 87 | ->attr( 'class', 'tutor-w-full' ) |
| 88 | ->attr( ':class', "{ 'tutor-btn-loading': saveRatingMutation?.isPending }" ) |
| 89 | ->attr( ':disabled', 'saveRatingMutation?.isPending' ) |
| 90 | ->render(); |
| 91 | ?> |
| 92 | </div> |
| 93 | </form> |
| 94 | </div> |
| 95 |