File size: 2,781 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { recordTracksEvent } from '@automattic/calypso-analytics';
import { GetSupport } from '@automattic/odie-client/src/components/message/get-support';
import { useCanConnectToZendeskMessaging } from '@automattic/zendesk-client';
import { useI18n } from '@wordpress/react-i18n';
import { useState } from 'react';
import { useChatStatus } from '../hooks';
import { ThumbsDownIcon, ThumbsUpIcon } from '../icons/thumbs';

import './help-center-feedback-form.scss';

const HelpCenterFeedbackForm = ( { postId }: { postId: number } ) => {
	const { __ } = useI18n();
	const [ startedFeedback, setStartedFeedback ] = useState< boolean | null >( null );
	const [ answerValue, setAnswerValue ] = useState< number | null >( null );

	const { isEligibleForChat, forceEmailSupport } = useChatStatus();
	const { data: canConnectToZendesk } = useCanConnectToZendeskMessaging();

	const handleFeedbackClick = ( value: number ) => {
		setStartedFeedback( true );
		setAnswerValue( value );

		recordTracksEvent( 'calypso_inlinehelp_article_feedback_click', {
			did_the_article_help: value === 1 ? 'yes' : 'no',
			post_id: postId,
		} );
	};

	const FeedbackButtons = () => {
		return (
			<>
				<p>{ __( 'Was this helpful?', __i18n_text_domain__ ) }</p>
				<div className="help-center-feedback-form__buttons">
					<button
						// 1 is used as `yes` in crowdsignal as well, do not change
						onClick={ () => handleFeedbackClick( 1 ) }
					>
						{ __( 'Yes' ) } <ThumbsUpIcon />
					</button>
					<button
						// 2 is used as `no` in crowdsignal as well, do not change
						onClick={ () => handleFeedbackClick( 2 ) }
					>
						{ __( 'No' ) } <ThumbsDownIcon />
					</button>
				</div>
			</>
		);
	};

	const handleContactSupportClick = async ( destination: string ) => {
		recordTracksEvent( 'calypso_odie_chat_get_support', {
			location: 'article-feedback',
			destination,
			is_user_eligible: isEligibleForChat,
		} );
	};

	return (
		<div className="help-center-feedback__form">
			{ startedFeedback === null && <FeedbackButtons /> }
			{ startedFeedback !== null && answerValue === 1 && (
				<p>{ __( 'Great! Thanks.', __i18n_text_domain__ ) }</p>
			) }
			{ startedFeedback !== null && answerValue === 2 && (
				<>
					<div className="odie-chatbox-dislike-feedback-message">
						<p>
							{ __(
								'Would you like to get support? Select an option below:',
								__i18n_text_domain__
							) }
						</p>
					</div>
					<GetSupport
						onClickAdditionalEvent={ handleContactSupportClick }
						isUserEligibleForPaidSupport={ isEligibleForChat }
						canConnectToZendesk={ canConnectToZendesk }
						forceEmailSupport={ forceEmailSupport }
						forceAIConversation
					/>
				</>
			) }
		</div>
	);
};

export default HelpCenterFeedbackForm;