|
| 1 | +import React, {useCallback} from 'react'; |
| 2 | +import useOnyx from '@hooks/useOnyx'; |
| 3 | +import useProactiveAppReview from '@hooks/useProactiveAppReview'; |
| 4 | +import requestStoreReview from '@libs/actions/StoreReview'; |
| 5 | +import {respondToProactiveAppReview} from '@libs/actions/User'; |
| 6 | +import Navigation from '@libs/Navigation/Navigation'; |
| 7 | +import ONYXKEYS from '@src/ONYXKEYS'; |
| 8 | +import ROUTES from '@src/ROUTES'; |
| 9 | +import type {AppReviewResponse} from '@src/types/onyx/AppReview'; |
| 10 | +import ProactiveAppReviewModal from './ProactiveAppReviewModal'; |
| 11 | + |
| 12 | +const CONCIERGE_POSITIVE_MESSAGE = "Hi there! I'm glad to hear you're enjoying Expensify. What's your favorite thing about the app? Thanks!"; |
| 13 | +const CONCIERGE_NEGATIVE_MESSAGE = "Hi there! I'm sorry to hear you aren't fully satisfied with Expensify. What's your #1 frustration? Thanks!"; |
| 14 | + |
| 15 | +function ProactiveAppReviewModalManager() { |
| 16 | + const {shouldShowModal, proactiveAppReview} = useProactiveAppReview(); |
| 17 | + const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID, {canBeMissing: true}); |
| 18 | + |
| 19 | + const handleResponse = useCallback( |
| 20 | + (response: AppReviewResponse, message?: string) => { |
| 21 | + // Call the action which will create an optimistic comment (if the message is provided) and call the API |
| 22 | + respondToProactiveAppReview(response, proactiveAppReview, message, conciergeReportID); |
| 23 | + |
| 24 | + // Navigate to Concierge DM if we have a report ID and this wasn't a skip |
| 25 | + if (conciergeReportID && response !== 'skip') { |
| 26 | + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(conciergeReportID)); |
| 27 | + } |
| 28 | + }, |
| 29 | + [conciergeReportID, proactiveAppReview], |
| 30 | + ); |
| 31 | + |
| 32 | + const handlePositive = useCallback(() => { |
| 33 | + handleResponse('positive', CONCIERGE_POSITIVE_MESSAGE); |
| 34 | + |
| 35 | + // Trigger native app store review prompt |
| 36 | + requestStoreReview(); |
| 37 | + }, [handleResponse]); |
| 38 | + |
| 39 | + const handleNegative = useCallback(() => { |
| 40 | + handleResponse('negative', CONCIERGE_NEGATIVE_MESSAGE); |
| 41 | + }, [handleResponse]); |
| 42 | + |
| 43 | + const handleSkip = useCallback(() => { |
| 44 | + handleResponse('skip'); |
| 45 | + }, [handleResponse]); |
| 46 | + |
| 47 | + return ( |
| 48 | + <ProactiveAppReviewModal |
| 49 | + isVisible={shouldShowModal} |
| 50 | + onPositive={handlePositive} |
| 51 | + onNegative={handleNegative} |
| 52 | + onSkip={handleSkip} |
| 53 | + /> |
| 54 | + ); |
| 55 | +} |
| 56 | + |
| 57 | +ProactiveAppReviewModalManager.displayName = 'ProactiveAppReviewModalManager'; |
| 58 | + |
| 59 | +export default ProactiveAppReviewModalManager; |
0 commit comments