Skip to content

Commit b53d66b

Browse files
committed
Address QnA PR review comments
1 parent 491846c commit b53d66b

10 files changed

Lines changed: 77 additions & 75 deletions

File tree

assets/src/js/frontend/dashboard/pages/discussions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ const discussionsPage = () => {
198198
onSuccess: (_, payload) => {
199199
toast.success(__('Reply saved successfully', 'tutor'));
200200
this.reloadReplies();
201-
const formId = `qna-reply-form-${payload.question_id}`;
201+
const formId = `${FORM_ID_PREFIXES.QNA_REPLY}${payload.question_id}`;
202202
if (form.hasForm(formId)) {
203203
form.reset(formId);
204204
}

assets/src/js/frontend/learning-area/pages/qna.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const qnaPage = () => {
9999
}
100100
},
101101
onError: (error: Error) => {
102-
toast.error(error.message || __('Failed to update', 'tutor'));
102+
toast.error(convertToErrorMessage(error));
103103
},
104104
});
105105

classes/Q_And_A.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct( $register_hooks = true ) {
5353
add_filter( 'tutor_learning_area_sub_page_nav_item', array( $this, 'add_learning_area_menu' ), 10, 2 );
5454

5555
add_action( 'wp_ajax_tutor_qna_create_update', array( $this, 'tutor_qna_create_update' ) );
56-
add_action( 'wp_ajax_tutor_qna_update', array( $this, 'tutor_qna_update' ) );
56+
add_action( 'wp_ajax_tutor_qna_update', array( $this, 'ajax_qna_update' ) );
5757
add_action( 'wp_ajax_tutor_delete_dashboard_question', array( $this, 'tutor_delete_dashboard_question' ) );
5858
add_action( 'wp_ajax_tutor_qna_single_action', array( $this, 'tutor_qna_single_action' ) );
5959
add_action( 'wp_ajax_tutor_qna_bulk_action', array( $this, 'process_bulk_action' ) );
@@ -235,9 +235,9 @@ public function inset_qna( $qna_object ) {
235235
/**
236236
* Update question [frontend dashboard]
237237
*
238-
* @since v.4.0.0
238+
* @since 4.0.0
239239
*/
240-
public function tutor_qna_update() {
240+
public function ajax_qna_update() {
241241
tutor_utils()->checking_nonce();
242242

243243
$question_id = Input::post( 'question_id', 0, Input::TYPE_INT );
@@ -257,13 +257,13 @@ public function tutor_qna_update() {
257257
global $wpdb;
258258
$wpdb->update( $wpdb->comments, $data, array( 'comment_ID' => $question_id ) );
259259

260-
wp_send_json_success( array( 'message' => __( 'Comment edited successfully', 'tutor' ) ) );
260+
$this->json_response( __( 'Comment edited successfully', 'tutor' ) );
261261
}
262262

263263
/**
264264
* Delete question [frontend dashboard]
265265
*
266-
* @since v.1.6.4
266+
* @since 1.6.4
267267
*/
268268
public function tutor_delete_dashboard_question() {
269269
tutor_utils()->checking_nonce();
@@ -490,15 +490,15 @@ public static function load_more() {
490490
/**
491491
* Load replies
492492
*
493-
* @since v4.0.0
493+
* @since 4.0.0
494494
*
495495
* @return void send wp_json response
496496
*/
497497
public function load_replies() {
498498
tutor_utils()->checking_nonce();
499499

500500
$comment_id = Input::post( 'comment_id', 0, Input::TYPE_INT );
501-
$replies_order = Input::post( 'order', 'DESC' );
501+
$replies_order = QueryHelper::get_valid_sort_order( Input::post( 'order', 'DESC' ) );
502502
$context = Input::post( 'context', 'dashboard' );
503503

504504
if ( ! $comment_id ) {
@@ -524,6 +524,6 @@ public function load_replies() {
524524
);
525525
$html = ob_get_clean();
526526

527-
wp_send_json_success( array( 'html' => $html ) );
527+
$this->json_response( '', array( 'html' => $html ) );
528528
}
529529
}

templates/dashboard/discussions/qna-form.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
* @since 4.0.0
1010
*/
1111

12+
defined( 'ABSPATH' ) || exit;
13+
1214
use Tutor\Components\Button;
15+
use Tutor\Components\Constants\InputType;
1316
use Tutor\Components\Constants\Size;
1417
use Tutor\Components\Constants\Variant;
1518
use Tutor\Components\InputField;
16-
use Tutor\Components\Constants\InputType;
17-
18-
defined( 'ABSPATH' ) || exit;
19+
use TUTOR\Icon;
1920

2021
$form_id = isset( $form_id ) ? $form_id : '';
2122
$label = isset( $label ) ? $label : '';
@@ -29,7 +30,7 @@
2930

3031
?>
3132

32-
<form
33+
<form
3334
class="<?php echo esc_attr( $form_class ); ?>"
3435
x-data="{ ...tutorForm({ id: '<?php echo esc_attr( $form_id ); ?>', mode: 'onSubmit', defaultValues: { answer: '<?php echo esc_js( $default_value ); ?>' } }), focused: false }"
3536
x-bind="getFormBindings()"
@@ -51,15 +52,15 @@ class="<?php echo esc_attr( $form_class ); ?>"
5152
$input->render();
5253
?>
5354

54-
<div
55-
class="tutor-flex tutor-items-center tutor-mt-5 tutor-justify-between tutor-sm-justify-end"
56-
x-cloak
55+
<div
56+
class="tutor-flex tutor-items-center tutor-mt-5 tutor-justify-between tutor-sm-justify-end"
57+
x-cloak
5758
:class="{ 'tutor-hidden': !focused }"
5859
>
5960
<div class="tutor-tiny tutor-text-subdued tutor-flex tutor-items-center tutor-gap-2 tutor-sm-hidden">
60-
<?php tutor_utils()->render_svg_icon( \TUTOR\Icon::COMMAND, 12, 12 ); ?>
61+
<?php tutor_utils()->render_svg_icon( Icon::COMMAND, 12, 12 ); ?>
6162
<?php esc_html_e( 'Cmd/Ctrl +', 'tutor' ); ?>
62-
<?php tutor_utils()->render_svg_icon( \TUTOR\Icon::ENTER, 12, 12 ); ?>
63+
<?php tutor_utils()->render_svg_icon( Icon::ENTER, 12, 12 ); ?>
6364
<?php esc_html_e( 'Enter to Save', 'tutor' ); ?>
6465
</div>
6566
<div class="tutor-flex tutor-items-center tutor-gap-2">
@@ -75,7 +76,6 @@ class="tutor-flex tutor-items-center tutor-mt-5 tutor-justify-between tutor-sm-j
7576

7677
Button::make()
7778
->label( $submit_label )
78-
->variant( Variant::PRIMARY )
7979
->size( Size::X_SMALL )
8080
->attr( 'type', 'submit' )
8181
->attr( ':disabled', $is_pending )

templates/dashboard/discussions/qna-replies.php

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="tutor-flex tutor-items-center tutor-justify-between tutor-px-6 tutor-py-5 tutor-border-t" :class="{ 'tutor-loading-spinner': loadingReplies }">
2323
<div class="tutor-small tutor-text-secondary">
2424
<?php esc_html_e( 'Replies', 'tutor' ); ?>
25-
<span class="tutor-text-primary tutor-font-medium">(<?php echo (int) count( $replies ); ?>)</span>
25+
<span class="tutor-text-primary tutor-font-medium">(<?php echo esc_html( count( $replies ) ); ?>)</span>
2626
</div>
2727
<?php
2828
Sorting::make()
@@ -36,7 +36,7 @@
3636
<div class="tutor-discussion-single-reply-list tutor-border-t">
3737
<?php foreach ( $replies as $reply ) : ?>
3838
<div class="tutor-discussion-reply-list-item">
39-
<div class="tutor-flex tutor-gap-5 tutor-w-full" x-show="editingId !== <?php echo (int) $reply->comment_ID; ?>">
39+
<div class="tutor-flex tutor-gap-5 tutor-w-full" x-show="editingId !== <?php echo esc_attr( $reply->comment_ID ); ?>">
4040
<?php Avatar::make()->user( $reply->user_id )->size( Size::SIZE_40 )->render(); ?>
4141
<div class="tutor-flex-1">
4242
<div class="tutor-flex tutor-items-center tutor-gap-5 tutor-mb-2 tutor-small">
@@ -45,12 +45,12 @@
4545
</span>
4646
<span class="tutor-text-secondary">
4747
<?php
48-
// Translators: %s is the time of comment.
49-
echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $reply->comment_date_gmt ) ) ) );
48+
// translators: %s is the time of comment.
49+
echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $reply->comment_date_gmt ) ) ) );
5050
?>
5151
</span>
5252
</div>
53-
<div class="tutor-p2 tutor-text-secondary" id="tutor-qna-text-<?php echo (int) $reply->comment_ID; ?>">
53+
<div class="tutor-p2 tutor-text-secondary" id="tutor-qna-text-<?php echo esc_attr( $reply->comment_ID ); ?>">
5454
<?php echo wp_kses_post( $reply->comment_content ); ?>
5555
</div>
5656
</div>
@@ -60,34 +60,35 @@
6060
$has_menu = $can_edit || $can_delete;
6161
?>
6262
<?php if ( $has_menu ) : ?>
63-
<div x-data="tutorPopover({ placement: 'bottom-end' })" class="tutor-ml-auto">
64-
<button x-ref="trigger" @click="toggle()" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon">
65-
<?php tutor_utils()->render_svg_icon( Icon::ELLIPSES, 16, 16, array( 'class' => 'tutor-icon-secondary' ) ); ?>
66-
</button>
67-
<div x-ref="content" x-show="open" x-cloak @click.outside="handleClickOutside()" class="tutor-popover">
68-
<div class="tutor-popover-menu" style="min-width: 110px;">
69-
<?php if ( $user_id === (int) $reply->user_id ) : ?>
70-
<button class="tutor-popover-menu-item tutor-gap-5" @click="setEditing(<?php echo (int) $reply->comment_ID; ?>, 'qna'); hide()">
71-
<?php tutor_utils()->render_svg_icon( Icon::EDIT_2, 20, 20 ); ?>
72-
<?php esc_html_e( 'Edit', 'tutor' ); ?>
73-
</button>
74-
<?php endif; ?>
75-
<?php if ( User::is_instructor_view() || $user_id === (int) $reply->user_id ) : ?>
76-
<button
77-
class="tutor-popover-menu-item tutor-gap-5"
78-
@click="TutorCore.modal.showModal('tutor-qna-delete-modal', { question_id: <?php echo esc_html( $reply->comment_ID ); ?>, context: 'reply' }); hide()">
79-
<?php tutor_utils()->render_svg_icon( Icon::DELETE_2, 20, 20 ); ?>
80-
<?php esc_html_e( 'Delete', 'tutor' ); ?>
81-
</button>
82-
<?php endif; ?>
63+
<div x-data="tutorPopover({ placement: 'bottom-end' })" class="tutor-ml-auto">
64+
<button x-ref="trigger" @click="toggle()" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon">
65+
<?php tutor_utils()->render_svg_icon( Icon::ELLIPSES, 16, 16, array( 'class' => 'tutor-icon-secondary' ) ); ?>
66+
</button>
67+
<div x-ref="content" x-show="open" x-cloak @click.outside="handleClickOutside()" class="tutor-popover">
68+
<div class="tutor-popover-menu" style="min-width: 110px;">
69+
<?php if ( $can_edit ) : ?>
70+
<button class="tutor-popover-menu-item tutor-gap-5" @click="setEditing(<?php echo esc_attr( $reply->comment_ID ); ?>, 'qna'); hide()">
71+
<?php tutor_utils()->render_svg_icon( Icon::EDIT_2, 20, 20 ); ?>
72+
<?php esc_html_e( 'Edit', 'tutor' ); ?>
73+
</button>
74+
<?php endif; ?>
75+
<?php if ( $can_delete ) : ?>
76+
<button
77+
class="tutor-popover-menu-item tutor-gap-5"
78+
@click="TutorCore.modal.showModal('tutor-qna-delete-modal', { question_id: <?php echo esc_attr( $reply->comment_ID ); ?>, context: 'reply' }); hide()"
79+
>
80+
<?php tutor_utils()->render_svg_icon( Icon::DELETE_2, 20, 20 ); ?>
81+
<?php esc_html_e( 'Delete', 'tutor' ); ?>
82+
</button>
83+
<?php endif; ?>
84+
</div>
8385
</div>
8486
</div>
85-
</div>
8687
<?php endif; ?>
8788
</div>
8889

89-
<?php if ( $user_id === (int) $reply->user_id ) : ?>
90-
<div x-show="editingId === <?php echo (int) $reply->comment_ID; ?>" x-cloak class="tutor-mt-5 tutor-w-full">
90+
<?php if ( $can_edit ) : ?>
91+
<div x-show="editingId === <?php echo esc_attr( $reply->comment_ID ); ?>" x-cloak class="tutor-mt-5 tutor-w-full">
9192
<?php
9293
tutor_load_template(
9394
'dashboard.discussions.qna-form',

templates/dashboard/discussions/qna-single.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
return;
2626
}
2727

28-
$user_id = get_current_user_id();
29-
$is_user_asker = $user_id === (int) $question->user_id;
28+
$user_id = get_current_user_id();
29+
$is_user_asker = $user_id === (int) $question->user_id;
30+
$qna_delete_modal_id = 'tutor-qna-delete-modal';
3031

3132
$replies_order = Input::get( 'order', '' );
3233
$replies = tutor_utils()->get_qa_answer_by_question( $discussion_id, $replies_order, 'frontend' );
@@ -143,7 +144,7 @@ class="tutor-popover-menu-item tutor-gap-5"
143144
<?php endif; ?>
144145
<button
145146
class="tutor-popover-menu-item tutor-gap-5"
146-
@click="TutorCore.modal.showModal('tutor-qna-delete-modal', { question_id: <?php echo esc_html( $question->comment_ID ); ?> }); hide();"
147+
@click="TutorCore.modal.showModal('<?php echo esc_js( $qna_delete_modal_id ); ?>', { question_id: <?php echo esc_html( $question->comment_ID ); ?> }); hide();"
147148
>
148149
<?php tutor_utils()->render_svg_icon( Icon::DELETE_2, 20, 20 ); ?> <?php esc_html_e( 'Delete', 'tutor' ); ?>
149150
</button>
@@ -206,7 +207,7 @@ class="tutor-popover-menu-item tutor-gap-5"
206207

207208
<?php
208209
ConfirmationModal::make()
209-
->id( 'tutor-qna-delete-modal' )
210+
->id( $qna_delete_modal_id )
210211
->title( __( 'Delete This Question?', 'tutor' ) )
211212
->message( __( 'Are you sure you want to delete this question permanently? Please confirm your choice.', 'tutor' ) )
212213
->confirm_text( __( 'Yes, Delete This', 'tutor' ) )
@@ -215,4 +216,3 @@ class="tutor-popover-menu-item tutor-gap-5"
215216
->render();
216217
?>
217218
</div>
218-

templates/learning-area/subpages/qna.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@
7676
<div class="tutor-learning-area-qna" x-data="tutorQnA()">
7777
<div class="tutor-discussion-search tutor-p-6 tutor-border-b">
7878
<?php
79-
SearchFilter::make()
80-
->form_id( 'tutor-qna-search-form' )
81-
->placeholder( 'Search questions, topics...' )
82-
->action( UrlHelper::current() )
83-
->hidden_inputs( array( 'subpage' => 'qna' ) )
84-
->size( 'large' )
85-
->render();
79+
SearchFilter::make()
80+
->form_id( 'tutor-qna-search-form' )
81+
->placeholder( 'Search questions, topics...' )
82+
->action( UrlHelper::current() )
83+
->hidden_inputs( array( 'subpage' => 'qna' ) )
84+
->size( Size::LARGE )
85+
->render();
8686
?>
8787
</div>
8888

templates/learning-area/subpages/qna/qna-form.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
* @since 4.0.0
1010
*/
1111

12+
defined( 'ABSPATH' ) || exit;
13+
1214
use Tutor\Components\Button;
15+
use Tutor\Components\Constants\InputType;
1316
use Tutor\Components\Constants\Size;
1417
use Tutor\Components\Constants\Variant;
1518
use Tutor\Components\InputField;
16-
use Tutor\Components\Constants\InputType;
17-
18-
defined( 'ABSPATH' ) || exit;
19+
use TUTOR\Icon;
1920

2021
$form_id = isset( $form_id ) ? $form_id : '';
2122
$label = isset( $label ) ? $label : '';
@@ -29,7 +30,7 @@
2930

3031
?>
3132

32-
<form
33+
<form
3334
class="<?php echo esc_attr( $form_class ); ?>"
3435
x-data="{ ...tutorForm({ id: '<?php echo esc_attr( $form_id ); ?>', mode: 'onSubmit', defaultValues: { answer: '<?php echo esc_js( $default_value ); ?>' } }), focused: false }"
3536
x-bind="getFormBindings()"
@@ -51,15 +52,15 @@ class="<?php echo esc_attr( $form_class ); ?>"
5152
$input->render();
5253
?>
5354

54-
<div
55-
class="tutor-flex tutor-items-center tutor-mt-5 tutor-justify-between tutor-sm-justify-end"
56-
x-cloak
55+
<div
56+
class="tutor-flex tutor-items-center tutor-mt-5 tutor-justify-between tutor-sm-justify-end"
57+
x-cloak
5758
:class="{ 'tutor-hidden': !focused }"
5859
>
5960
<div class="tutor-tiny tutor-text-subdued tutor-flex tutor-items-center tutor-gap-2 tutor-sm-hidden">
60-
<?php tutor_utils()->render_svg_icon( \TUTOR\Icon::COMMAND, 12, 12 ); ?>
61+
<?php tutor_utils()->render_svg_icon( Icon::COMMAND, 12, 12 ); ?>
6162
<?php esc_html_e( 'Cmd/Ctrl +', 'tutor' ); ?>
62-
<?php tutor_utils()->render_svg_icon( \TUTOR\Icon::ENTER, 12, 12 ); ?>
63+
<?php tutor_utils()->render_svg_icon( Icon::ENTER, 12, 12 ); ?>
6364
<?php esc_html_e( 'Enter to Save', 'tutor' ); ?>
6465
</div>
6566
<div class="tutor-flex tutor-items-center tutor-gap-2">
@@ -75,7 +76,6 @@ class="tutor-flex tutor-items-center tutor-mt-5 tutor-justify-between tutor-sm-j
7576

7677
Button::make()
7778
->label( $submit_label )
78-
->variant( Variant::PRIMARY )
7979
->size( Size::X_SMALL )
8080
->attr( 'type', 'submit' )
8181
->attr( ':disabled', $is_pending )

templates/learning-area/subpages/qna/qna-replies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</span>
4545
<span class="tutor-text-secondary">
4646
<?php
47-
// Translators: %s is the time of comment.
47+
// translators: %s is the time of comment.
4848
echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $reply->comment_date_gmt ) ) ) );
4949
?>
5050
</span>

templates/learning-area/subpages/qna/qna-single.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
return;
2929
}
3030

31-
$user_id = get_current_user_id();
32-
$is_user_asker = $user_id === (int) $question->user_id;
31+
$user_id = get_current_user_id();
32+
$is_user_asker = $user_id === (int) $question->user_id;
33+
$qna_delete_modal_id = 'tutor-qna-delete-modal';
3334

3435
$replies = tutor_utils()->get_qa_answer_by_question( $question_id, $replies_order, 'frontend' );
3536
?>
@@ -75,7 +76,7 @@ class="tutor-popover"
7576
</button>
7677
<button
7778
class="tutor-popover-menu-item tutor-gap-5"
78-
@click="TutorCore.modal.showModal('tutor-qna-delete-modal', { question_id: <?php echo esc_html( $question->comment_ID ); ?> }); hide();"
79+
@click="TutorCore.modal.showModal('<?php echo esc_js( $qna_delete_modal_id ); ?>', { question_id: <?php echo esc_html( $question->comment_ID ); ?> }); hide();"
7980
>
8081
<?php tutor_utils()->render_svg_icon( Icon::DELETE_2, 20, 20 ); ?> <?php esc_html_e( 'Delete', 'tutor' ); ?>
8182
</button>
@@ -139,7 +140,7 @@ class="tutor-popover-menu-item tutor-gap-5"
139140

140141
<?php
141142
ConfirmationModal::make()
142-
->id( 'tutor-qna-delete-modal' )
143+
->id( $qna_delete_modal_id )
143144
->title( __( 'Delete This Question?', 'tutor' ) )
144145
->message( __( 'Are you sure you want to delete this question permanently? Please confirm your choice.', 'tutor' ) )
145146
->confirm_text( __( 'Yes, Delete This', 'tutor' ) )

0 commit comments

Comments
 (0)