QnA Refactored and edit delete options added #2361
Open
sazedul-haque wants to merge 15 commits intorefactor-dashboard-commentsfrom
Open
QnA Refactored and edit delete options added #2361sazedul-haque wants to merge 15 commits intorefactor-dashboard-commentsfrom
sazedul-haque wants to merge 15 commits intorefactor-dashboard-commentsfrom
Conversation
Enable inline editing and updating of Q&A questions and replies and add AJAX-powered replies loading. Key changes: - Add new read.svg icon and register it in icons/types and Icon class. - Add endpoints: UPDATE_QNA and LOAD_QNA_REPLIES. - Frontend (assets/src/js/frontend/dashboard/pages/discussions.ts): add updateQnAMutation, loadQnAReplies mutation, support for reply deletion context, reloadReplies now loads QnA or comment replies based on tab, and setEditing supports 'qna' context; update DOM after successful update and reset reply forms. - Backend (classes/Q_And_A.php): include JsonResponse trait, register tutor_qna_update and tutor_qna_load_replies handlers, implement tutor_qna_update to update comment content and load_replies to return rendered replies HTML. - UI/templates: add qna-form.php and qna-replies.php templates; update qna-card.php and qna-single.php to show/hide edit forms, wire up edit/delete actions, and adjust icon sizing/spacing. - Misc: small icon/spinner sizing and class tweaks for consistent UI. These changes let users edit their Q&A posts inline, update content via AJAX, and load reply lists dynamically for a smoother dashboard experience.
Change SVG color in the button mixin from $tutor-icon-idle to $tutor-icon-secondary so button icons use the secondary icon token. This aligns icon styling with the updated design tokens while leaving hover/disabled behavior unchanged.
Update Q&A card buttons for solved and important actions: replace `tutor-btn-link` with `tutor-btn-ghost` for consistent styling, and tighten the `:disabled` binding so a button is only disabled when the mutation is pending for that specific action and question ID (prevents unrelated buttons from being disabled while an action is in progress). Changes applied in templates/dashboard/discussions/qna-card.php.
Introduce Alpine-based tooltips for the QnA action buttons (solved and important) by wrapping each button in tutorTooltip x-data, adding x-ref trigger/content, x-show/x-cloak transitions and localized x-text content. Adjust tooltip SCSS: reduce default max-width from 200px to 180px and set default text-align to center, while keeping large tooltips left-aligned. Replace direct current_user_id vs question->user_id checks with the $is_user_asker flag for clearer intent and reuse.
JS: Rename QnA mutations/handlers and add modal/URL param utilities (MODALS, URL_PARAMS). Introduce createQnAMutation/replyQnAMutation/deleteQnAMutation, handle form resets on success, add reloadReplies(order) to fetch and inject replies without full page reload, persist order in URL, add loadingReplies state and keyboard submit handler, and adjust delete flow to close modal and either reload replies or update URL. Templates: remove old flat qna-single.php and reorganize QnA templates under templates/learning-area/subpages/qna/: move qna-card.php, and add qna-form.php, qna-replies.php, qna-single.php. Update qna.php to load the new partials, use tutor_load_template for forms, update component name to "QnA", and wire ConfirmationModal to use deleteQnAMutation. Adjust popover/modal payload keys (question_id) and form IDs.
Use convertToErrorMessage for all mutation onError handlers to normalize toast error messages; import the util in the discussions page JS. Standardize modal payload keys to question_id (snake_case) and adjust hide/showModal ordering. Update Q&A form template: rename header, bump @SInCE, add configurable submit_label default and use it for the submit button, and clear default form_class. Update confirm handler in qna-list to pass payload to the mutation. Remove unused component imports in qna-replies and avoid rendering EmptyState in qna-single (redirect instead); replace direct user_id checks with is_user_asker. General cleanup and consistency fixes across discussion templates and frontend code.
Add an AJAX error handler in assets/src/js/v2/qna.js to parse server error payloads and display a tutor_toast on failures. Replace direct wp_send_json_error/wp_send_json_success calls in classes/Q_And_A.php with response_bad_request() and json_response(), and use tutor_utils()->error_message where appropriate to standardize API responses so the front-end can reliably handle and show error/success messages.
Stop constructing a new error object in the mutation catch block and assign the original thrown error (cast to TError) to the mutation state and callbacks. onError and onSettled now receive the original error instead of a pared-down object, preserving additional properties (e.g. stack or custom fields) for consumers. No behavior change otherwise; isError is still set and the error is rethrown.
Move the Q&A learning-area navigation item out of Template and into the Q_And_A class. Adds UrlHelper import, registers a filter (tutor_learning_area_sub_page_nav_item) and implements add_learning_area_menu() to inject the Q&A item conditionally (global setting, per-course enable flag, and user enrollment). Also unsets any existing 'qna' entry to avoid duplicates and removes the static qna entry from Template.php.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.