import React, { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { Platform, SafeAreaView, ScrollView, Text, View } from 'react-native'; import { useSelector } from 'react-redux'; import { IconSearch } from '../../../base/icons'; import JitsiScreen from '../../../base/modal/components/JitsiScreen'; import { LoadingIndicator } from '../../../base/react'; import Button from '../../../base/ui/components/native/Button'; import Input from '../../../base/ui/components/native/Input'; import { BUTTON_TYPES } from '../../../base/ui/constants.native'; import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef'; import { screen } from '../../../mobile/navigation/routes'; import { CONTENT_HEIGHT_OFFSET, LIST_HEIGHT_OFFSET, NOTES_LINES, NOTES_MAX_LENGTH } from '../../constants'; import { useSalesforceLinkDialog } from '../../useSalesforceLinkDialog'; import { RecordItem } from './RecordItem'; import styles from './styles'; /** * Component that renders the Salesforce link dialog. * * @returns {React$Element} */ const SalesforceLinkDialog = () => { const { t } = useTranslation(); const { clientHeight } = useSelector(state => state['features/base/responsive-ui']); const { hasDetailsErrors, hasRecordsErrors, isLoading, linkMeeting, notes, records, searchTerm, selectedRecord, selectedRecordOwner, setNotes, setSearchTerm, setSelectedRecord, showNoResults, showSearchResults } = useSalesforceLinkDialog(); const handlePress = useCallback(() => { navigate(screen.conference.main); selectedRecord && linkMeeting(); }, [ navigate, linkMeeting ]); const renderSpinner = () => ( ); const renderDetailsErrors = () => ( {t('dialog.searchResultsDetailsError')} ); const renderSelection = () => ( { selectedRecordOwner && } { hasDetailsErrors && renderDetailsErrors() } {t('dialog.addOptionalNote')} setNotes(value) } placeholder = { t('dialog.addMeetingNote') } value = { notes } /> ); const renderRecordsSearch = () => ( setSearchTerm(value) } placeholder = { t('dialog.searchInSalesforce') } value = { searchTerm } /> {(!isLoading && !hasRecordsErrors) && ( {showSearchResults ? t('dialog.searchResults', { count: records.length }) : t('dialog.recentlyUsedObjects') } )} ); const renderNoRecords = () => showNoResults && ( {t('dialog.searchResultsNotFound')} {t('dialog.searchResultsTryAgain')} ); const renderRecordsError = () => ( {t('dialog.searchResultsError')} ); const renderContent = () => { if (isLoading) { return renderSpinner(); } if (hasRecordsErrors) { return renderRecordsError(); } if (showNoResults) { return renderNoRecords(); } if (selectedRecord) { return renderSelection(); } return ( {records.map(item => ( setSelectedRecord(item) } { ...item } /> ))} ); }; return ( {!selectedRecord && renderRecordsSearch()} {renderContent()} { selectedRecord &&