UNPKG

react-native-unit-components

Version:

Unit React Native components

38 lines (33 loc) 1.78 kB
import type { RequestRefreshEvent } from './../../messages/webMessages/unitMessages'; import type { WebView } from 'react-native-webview'; import { DISPATCH_REQUEST_REFRESH } from './../../scripts/html/bodyScript'; import type { UNActivityComponentProps } from './UNActivityComponent'; import { WebComponentType } from '../../types/internal/webComponent.types'; export const getActivityParams = (props: UNActivityComponentProps) => { const accountIdParam = props.accountId ? `account-id="${props.accountId}"` : ''; const queryFilterParam = props.queryFilter ? `query-filter="${props.queryFilter}"` : ''; const paginationTypeParam = props.paginationType ? `pagination-type="${props.paginationType}"` : ''; const transactionsPerPageParam = props.transactionsPerPage ? `transactions-per-page="${props.transactionsPerPage}"` : ''; return ` customer-token="${props.customerToken}" ${accountIdParam} hide-filter-button="${props.hideFilterButton || false}" hide-back-to-top="${props.hideBackToTop || false}" hide-title="${props.hideTitle || false}" ${queryFilterParam} ${paginationTypeParam} ${transactionsPerPageParam} style="height: 100%" `; }; export const getActivityScript = () => { return DISPATCH_REQUEST_REFRESH; }; export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null) => { if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.activity.valueOf())) { currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`); } }; export const injectFiltersChanged = (currentWeb: WebView | null, query: string) => { currentWeb?.injectJavaScript(`dispatchActivityFilterChangedEvent('${query}')`); };