import { useForm } from "@tanstack/react-form" import { Button, Card, CardHeader, CardBody, BaseControl, TextareaControl, Spinner } from "@wordpress/components" import { __ } from "@wordpress/i18n" import { useMutation, useQuery } from "@tanstack/react-query" import usePluginSelectedStore from "@/stores/pluginSelectedStore" import { getCommentsQueryOptions } from "@/shared/plugin-comments/query-options" import { addCommentMutationOptions } from "@/shared/plugin-comments/mutation-options" import NoteItem from "../NoteItem" const Notes = () => { const { plugin } = usePluginSelectedStore() const { mutate: addComment, isPending: isAddingComment } = useMutation(addCommentMutationOptions()) const form = useForm({ defaultValues: { comment_content: '', }, onSubmit: (values) => { addComment({ plugin_slug: plugin?.slug ?? '', comment_content: values.value.comment_content, }) form.reset() }, }) const { data: comments, isPending } = useQuery(getCommentsQueryOptions(plugin?.slug ?? '')) if (isPending) { return (
) } return ( {__('Notes', 'ploogins-ai-assistant')}
{ isAddingComment && (
) } {comments?.map((comment) => ( ))}
{ (comments && comments?.length > 0) &&
} ( field.handleChange(value as string)} placeholder={__('Add your notes here...', 'ploogins-ai-assistant')} rows={1} /> {field.state.meta.errors.length > 0 && ( {field.state.meta.errors.join(',')} )} )} />
) } export default Notes;