-
Notifications
You must be signed in to change notification settings - Fork 843
Forms: Add feedback notes support #46309
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Forms: add feedback comments | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,218 @@ | ||||||
| /** | ||||||
| * External dependencies | ||||||
| */ | ||||||
| import apiFetch from '@wordpress/api-fetch'; | ||||||
| import { Button, TextareaControl, DropdownMenu, Spinner } from '@wordpress/components'; | ||||||
| import { store as coreStore } from '@wordpress/core-data'; | ||||||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||||||
| import { dateI18n, getSettings as getDateSettings } from '@wordpress/date'; | ||||||
| import { useState, useEffect, useCallback } from '@wordpress/element'; | ||||||
| import { __, sprintf } from '@wordpress/i18n'; | ||||||
| import { moreVertical, trash } from '@wordpress/icons'; | ||||||
| import { store as noticesStore } from '@wordpress/notices'; | ||||||
| /** | ||||||
| * Internal dependencies | ||||||
| */ | ||||||
| import type { FeedbackComment } from '../../../types'; | ||||||
| import './style.scss'; | ||||||
|
|
||||||
| export type FeedbackCommentsProps = { | ||||||
| postId: number; | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
| * Component for displaying and adding comments to feedback posts. | ||||||
| * Uses WordPress core comments REST API (wp/v2/comments). | ||||||
| * | ||||||
| * @param {FeedbackCommentsProps} props - Component props | ||||||
| * @return {JSX.Element} The feedback comments component | ||||||
| */ | ||||||
| const FeedbackComments = ( { postId }: FeedbackCommentsProps ): JSX.Element => { | ||||||
| const [ comments, setComments ] = useState< FeedbackComment[] >( [] ); | ||||||
| const [ isLoadingComments, setIsLoadingComments ] = useState( true ); | ||||||
| const [ newComment, setNewComment ] = useState( '' ); | ||||||
| const [ isSubmitting, setIsSubmitting ] = useState( false ); | ||||||
| const [ isDeleting, setIsDeleting ] = useState( false ); | ||||||
| const [ error, setError ] = useState< string | null >( null ); | ||||||
| const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); | ||||||
|
|
||||||
| // Get current user data | ||||||
| const currentUser = useSelect( select => { | ||||||
| return select( coreStore ).getCurrentUser(); | ||||||
| }, [] ); | ||||||
|
|
||||||
| const loadComments = useCallback( async () => { | ||||||
| setIsLoadingComments( true ); | ||||||
| setError( null ); | ||||||
|
|
||||||
| try { | ||||||
| const fetchedComments = await apiFetch< FeedbackComment[] >( { | ||||||
| path: `/wp/v2/comments?post=${ postId }&per_page=100&order=asc`, | ||||||
| } ); | ||||||
| setComments( fetchedComments || [] ); | ||||||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||||||
| } catch ( err ) { | ||||||
| setError( __( 'Failed to load comments.', 'jetpack-forms' ) ); | ||||||
| createErrorNotice( __( 'Failed to load comments.', 'jetpack-forms' ) ); | ||||||
| } finally { | ||||||
| setIsLoadingComments( false ); | ||||||
| } | ||||||
| }, [ postId, createErrorNotice ] ); | ||||||
|
|
||||||
| // Load comments on mount and when postId changes | ||||||
| useEffect( () => { | ||||||
| loadComments(); | ||||||
| }, [ postId, createErrorNotice, loadComments, setIsLoadingComments, setError, setComments ] ); | ||||||
|
||||||
| }, [ postId, createErrorNotice, loadComments, setIsLoadingComments, setError, setComments ] ); | |
| }, [ postId, loadComments ] ); |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message 'Failed to save the note.' is misleading in the delete handler. Should be 'Failed to delete the note.' to accurately describe the delete operation.
| createErrorNotice( __( 'Failed to save the note.', 'jetpack-forms' ) ); | |
| createErrorNotice( __( 'Failed to delete the note.', 'jetpack-forms' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'commnet' to 'comment' in the filename 'add-feedback-commnet-support'.