diff --git a/packages/commonwealth/client/scripts/views/components/Comments/CommentEditor/CommentEditor.tsx b/packages/commonwealth/client/scripts/views/components/Comments/CommentEditor/CommentEditor.tsx index f94bde9a9d3..755756881b1 100644 --- a/packages/commonwealth/client/scripts/views/components/Comments/CommentEditor/CommentEditor.tsx +++ b/packages/commonwealth/client/scripts/views/components/Comments/CommentEditor/CommentEditor.tsx @@ -10,7 +10,6 @@ import { useAiCompletion } from 'state/api/ai'; import { generateCommentPrompt } from 'state/api/ai/prompts'; import useGetCommunityByIdQuery from 'state/api/communities/getCommuityById'; import { useAIFeatureEnabled, useUserAiSettingsStore } from 'state/ui/user'; -import { useTurnstile } from 'views/components/useTurnstile'; import { User } from 'views/components/user/user'; import { jumpHighlightComment } from 'views/pages/discussions/CommentTree/helpers'; import { ImageActionModal } from '../../ImageActionModal/ImageActionModal'; @@ -53,6 +52,10 @@ export type CommentEditorProps = { webSearchEnabled?: boolean; setWebSearchEnabled?: (enabled: boolean) => void; communityId?: string; + isTurnstileEnabled?: boolean; + turnstileToken?: string | null; + resetTurnstile?: () => void; + TurnstileWidget?: React.FC; }; // eslint-disable-next-line react/display-name @@ -81,6 +84,10 @@ const CommentEditor = forwardRef( webSearchEnabled, setWebSearchEnabled, communityId, + isTurnstileEnabled = false, + turnstileToken, + resetTurnstile, + TurnstileWidget, }, _ref, ) => { @@ -102,15 +109,6 @@ const CommentEditor = forwardRef( const { generateCompletion } = useAiCompletion(); - const { - resetTurnstile, - turnstileToken, - isTurnstileEnabled, - TurnstileWidget, - } = useTurnstile({ - action: 'create-comment', - }); - // Fetch community details const { data: community } = useGetCommunityByIdQuery({ id: thread?.communityId || '', @@ -162,6 +160,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`; }); }; + const TurnstileWidgetComponent = TurnstileWidget ?? (() => <>); const handleEnhancedSubmit = async () => { // Immediately close the editor before any operations onCancel?.( @@ -182,7 +181,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`; } catch (error) { console.error('Failed to submit comment:', error); if (isTurnstileEnabled) { - resetTurnstile(); + resetTurnstile?.(); } return; } @@ -236,7 +235,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`; } catch (error) { console.error('Error during submission:', error); if (isTurnstileEnabled) { - resetTurnstile(); + resetTurnstile?.(); } } }; @@ -316,7 +315,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`; placeholder={placeholder} /> - {isTurnstileEnabled && } + {isTurnstileEnabled && }
diff --git a/packages/commonwealth/client/scripts/views/components/StickEditorContainer/StickyInput/StickyInput.tsx b/packages/commonwealth/client/scripts/views/components/StickEditorContainer/StickyInput/StickyInput.tsx index 3874c0a1d73..75acc3e0d97 100644 --- a/packages/commonwealth/client/scripts/views/components/StickEditorContainer/StickyInput/StickyInput.tsx +++ b/packages/commonwealth/client/scripts/views/components/StickEditorContainer/StickyInput/StickyInput.tsx @@ -575,6 +575,10 @@ const StickyInput = (props: StickyInputProps) => { webSearchEnabled={webSearchEnabled} setWebSearchEnabled={setWebSearchEnabled} communityId={props.communityId} + isTurnstileEnabled={isTurnstileEnabled} + turnstileToken={turnstileToken} + resetTurnstile={resetTurnstile} + TurnstileWidget={TurnstileWidget} /> )}