-
Notifications
You must be signed in to change notification settings - Fork 82
✨ Student Review Component #2285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,047
−417
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
8851da4
feat: Make profile header sticky, standardize dashboard navigation pe…
b-l-i-n-d b758b4a
feat: Enhance the Button component with an icon-only option.
b-l-i-n-d 671ea8b
feat: Implement dynamic review card rendering with structured data, a…
b-l-i-n-d d69b3fd
Merge branch '4.0.0-dev' into v4-reviews
b-l-i-n-d 22d42b6
fix: Error and clear button not rendering properly
b-l-i-n-d 2d9e39e
feat: new Icons added
b-l-i-n-d 459ec91
feat: Interactive star rating component
b-l-i-n-d 75734cf
feat: allow users to manage their given reviews in the dashboard
b-l-i-n-d 25c62fa
feat: Add frontend dashboard page for managing user reviews with edit…
b-l-i-n-d 9be916f
Merge branch '4.0.0-dev' into v4-reviews
b-l-i-n-d 16e5668
feat: Add pagination and empty state to given reviews dashboard and s…
b-l-i-n-d baa61e4
chore: Update imports
b-l-i-n-d 04f2485
chore: Remove unused codes
b-l-i-n-d 77de185
refactor: Remove unused codes
b-l-i-n-d d44db6a
refactor: Remove unnecessary exports
b-l-i-n-d 945c6c4
Merge branch '4.0.0-dev' into v4-reviews
b-l-i-n-d 4be26a7
refactor: Use tutor-transition mixing
b-l-i-n-d 542256d
Merge branch '4.0.0-dev' into v4-reviews
b-l-i-n-d 7857a3d
refactor: reimplement review deletion modal using ConfirmationModal c…
b-l-i-n-d 6876633
feat: Add loading state to delete review button and reload page after…
b-l-i-n-d c0d18be
feat: swap confirm and cancel button styles and order in Confirmation…
b-l-i-n-d 3aec007
feat: introduce StarRating component and integrate it into the review…
b-l-i-n-d 64aaddc
refactor: rename `showAverage` and `iconSize` methods to `show_averag…
b-l-i-n-d 872369c
chore: remove reviews demo component and its associated template file.
b-l-i-n-d aac71d7
style: update star rating average and count text styling classes
b-l-i-n-d 78cc51f
refactor: replace `confirm_button` and `cancel_button` methods with `…
b-l-i-n-d e1a6c44
style: Update confirmation button class from primary to destructive.
b-l-i-n-d 82d07e3
refactor: Align review data structure with WordPress comment fields a…
b-l-i-n-d 095ae21
fix: Use `comment_ID` and `comment_content` for review data instead o…
b-l-i-n-d 5833abf
Merge branch '4.0.0-dev' into v4-reviews
b-l-i-n-d e8211e0
refactor: Refactor star rating components and reviews template
b-l-i-n-d f4d1dd4
refactor: Store rendered component string in property
b-l-i-n-d 43190b3
feat: Add error message support to InputField component
b-l-i-n-d 3ec9ce8
refactor: Refactor account header to use Button component
b-l-i-n-d 43f7bab
refactor: Refactor dashboard reviews to unify received and given views
b-l-i-n-d 7c6c90e
feat: Add editable state to review card actions and form
b-l-i-n-d 942584d
refactor: Refactor reviews pagination and is_editable logic
b-l-i-n-d 44a296e
feat: Improve initials generation in Avatar component
b-l-i-n-d e073f6d
feat: Display student info in review cards
b-l-i-n-d 21bdc16
chore: Updated comment for review card
b-l-i-n-d 5a14b1f
refactor: Add review card component and reviews page template
b-l-i-n-d b2726ac
chore: Add missing newlines at end of template files
b-l-i-n-d f723969
refactor: Simplify initials processing in Avatar component
b-l-i-n-d 43e69b3
refactor: Replace anchor tags with buttons in profile header
b-l-i-n-d 66e3e4c
chore: Add newline at end of profile header file
b-l-i-n-d 8158355
refactor: Sanitize output and update pagination in reviews
b-l-i-n-d 2fa7cd7
Merge '4.0.0-dev' into 'v4-reviews'
b-l-i-n-d fe830c4
Merge branch '4.0.0-dev' of https://github.com/themeum/tutor into v4-…
b-l-i-n-d b88b729
Merge branch '4.0.0-dev' into v4-reviews
b-l-i-n-d 52a6b02
chore: add comments explaining phpcs ignore for SVG icon echoes in St…
b-l-i-n-d 82250a1
Merge branch '4.0.0-dev' into v4-reviews
b-l-i-n-d 2419e3f
refactor: Remove PHP_INT_MAX
b-l-i-n-d b32a0b8
refactor: rename StarRating and StarRatingInput methods to snake_case…
b-l-i-n-d ae69d94
docs: Add `@since 4.0.0` tags to properties and methods in StarRating…
b-l-i-n-d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| interface StarRatingConfig { | ||
| initialRating?: number; | ||
| fieldName: string; | ||
| } | ||
|
|
||
| const starRatingInput = (config: StarRatingConfig) => ({ | ||
| rating: config.initialRating || 1, | ||
| hoverRating: 0, | ||
| fieldName: config.fieldName, | ||
|
|
||
| get effectiveRating() { | ||
| return this.hoverRating > 0 ? this.hoverRating : this.rating; | ||
| }, | ||
|
|
||
| get feedback(): string { | ||
| const rating = this.effectiveRating; | ||
| if (rating === 0) { | ||
| return ''; | ||
| } | ||
|
|
||
| const labels: Record<number, string> = { | ||
| 1: __('Poor', 'tutor'), | ||
| 2: __('Fair', 'tutor'), | ||
| 3: __('Average', 'tutor'), | ||
| 4: __('Good', 'tutor'), | ||
| 5: __('Amazing', 'tutor'), | ||
| }; | ||
|
|
||
| if (Number.isInteger(rating)) { | ||
| return labels[rating] || ''; | ||
| } | ||
|
|
||
| // Handle fractional ratings (e.g., 4.5 -> "Good / Amazing") | ||
| const lower = Math.floor(rating); | ||
| const upper = Math.ceil(rating); | ||
|
|
||
| const lowerLabel = labels[lower]; | ||
| const upperLabel = labels[upper]; | ||
|
|
||
| if (lowerLabel && upperLabel) { | ||
| return `${lowerLabel} / ${upperLabel}`; | ||
| } | ||
|
|
||
| return lowerLabel || upperLabel || ''; | ||
| }, | ||
|
|
||
| setRating(val: number, onSet: (rating: number) => void) { | ||
| this.rating = val; | ||
| onSet(this.rating); | ||
| }, | ||
| }); | ||
|
|
||
| export const starRatingMeta = { | ||
| name: 'starRatingInput', | ||
| component: starRatingInput, | ||
| }; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| import { type MutationState } from '@Core/ts/services/Query'; | ||
|
|
||
| import { wpAjaxInstance } from '@TutorShared/utils/api'; | ||
| import endpoints from '@TutorShared/utils/endpoints'; | ||
| import { type TutorMutationResponse } from '@TutorShared/utils/types'; | ||
| import { convertToErrorMessage } from '@TutorShared/utils/util'; | ||
|
|
||
| interface ReviewFormProps { | ||
| comment_ID?: string; | ||
| comment_post_ID: string; | ||
| rating: string; | ||
| comment_content: string; | ||
| } | ||
|
|
||
| interface ReviewPayload { | ||
| course_id: string; | ||
| review_id?: string; | ||
| tutor_rating_gen_input: string; | ||
| review: string; | ||
| } | ||
|
|
||
| const reviewDeleteModal = () => { | ||
| const query = window.TutorCore.query; | ||
|
|
||
| return { | ||
| query, | ||
| $el: null as HTMLElement | null, | ||
| deleteReviewMutation: null as MutationState<unknown> | null, | ||
|
|
||
| init() { | ||
| if (!this.$el) { | ||
| return; | ||
| } | ||
|
|
||
| this.deleteReviewMutation = this.query.useMutation(this.deleteReview, { | ||
| onSuccess: (data: TutorMutationResponse<string>) => { | ||
| window.location.reload(); | ||
| window.TutorCore.toast.success(data?.message ?? __('Review deleted successfully', 'tutor')); | ||
| }, | ||
| onError: (error: Error) => { | ||
| window.TutorCore.toast.error(error.message || __('Failed to delete review', 'tutor')); | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| async handleDeleteReview(reviewId: string) { | ||
| await this.deleteReviewMutation?.mutate(reviewId); | ||
| }, | ||
|
|
||
| async deleteReview(reviewId: string) { | ||
| return wpAjaxInstance | ||
| .post(endpoints.DELETE_REVIEW, { | ||
| review_id: reviewId, | ||
| }) | ||
| .then((res) => res.data); | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| const reviewCard = (id: string) => { | ||
| const query = window.TutorCore.query; | ||
|
|
||
| return { | ||
| query, | ||
| id, | ||
| isEditMode: false, | ||
| $el: null as HTMLElement | null, | ||
| $refs: {} as { | ||
| edit: HTMLButtonElement; | ||
| delete: HTMLButtonElement; | ||
| cancel: HTMLButtonElement; | ||
| }, | ||
| saveRatingMutation: null as MutationState<TutorMutationResponse<string>> | null, | ||
|
|
||
| handlers: {} as { [key: string]: EventListener }, | ||
|
|
||
| init() { | ||
| if (!this.$el) { | ||
| return; | ||
| } | ||
|
|
||
| // Bind handlers once to maintain stable references for cleanup | ||
| this.handlers.toggleEditMode = () => this.toggleEditMode(); | ||
|
|
||
| this.$refs.edit?.addEventListener('click', this.handlers.toggleEditMode); | ||
| this.$refs.cancel?.addEventListener('click', this.handlers.toggleEditMode); | ||
| this.$refs.delete?.addEventListener('click', this.handlers.onDeleteButtonClick); | ||
|
|
||
| this.saveRatingMutation = this.query.useMutation(this.saveRating, { | ||
| onSuccess: (data: TutorMutationResponse<string>) => { | ||
| this.isEditMode = false; | ||
| window.TutorCore.toast.success(data.message); | ||
| window.location.reload(); | ||
| }, | ||
| onError: (error: Error) => { | ||
| window.TutorCore.toast.error(convertToErrorMessage(error)); | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| destroy() { | ||
| this.$refs.edit?.removeEventListener('click', this.handlers.toggleEditMode); | ||
| this.$refs.cancel?.removeEventListener('click', this.handlers.toggleEditMode); | ||
| this.$refs.delete?.removeEventListener('click', this.handlers.onDeleteButtonClick); | ||
| }, | ||
|
|
||
| async handleReviewSubmit(data: ReviewFormProps) { | ||
| const payload = this.convertFormDataToPayload(data); | ||
| await this.saveRatingMutation?.mutate(payload); | ||
| }, | ||
|
|
||
| async saveRating(payload: ReviewPayload) { | ||
| return wpAjaxInstance.post(endpoints.PLACE_RATING, payload).then((res) => res.data); | ||
| }, | ||
|
|
||
| convertFormDataToPayload(data: ReviewFormProps): ReviewPayload { | ||
| return { | ||
| ...(data.comment_ID && { comment_id: data.comment_ID }), | ||
| course_id: data.comment_post_ID, | ||
| tutor_rating_gen_input: data.rating, | ||
| review: data.comment_content, | ||
| }; | ||
| }, | ||
|
|
||
| toggleEditMode() { | ||
| this.isEditMode = !this.isEditMode; | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| const reviewServicesMeta = { | ||
| name: 'reviewDeleteModal', | ||
| component: reviewDeleteModal, | ||
| }; | ||
|
|
||
| const reviewCardMeta = { | ||
| name: 'reviewCard', | ||
| component: reviewCard, | ||
| }; | ||
|
|
||
| export const initializeReviews = () => { | ||
| window.TutorComponentRegistry.registerAll({ | ||
| components: [reviewCardMeta, reviewServicesMeta], | ||
b-l-i-n-d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| window.TutorComponentRegistry.initWithAlpine(window.Alpine); | ||
| }; | ||
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
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
9 changes: 9 additions & 0 deletions
9
assets/src/scss/frontend/dashboard/layout/_profile-pages.scss
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.