UNPKG

react-native-unit-components

Version:

Unit React Native components

55 lines 2.03 kB
import React, { useState } from 'react'; import { PageMessage } from '../../messages/webMessages/pageMessage'; import { UnitComponentsMessage } from '../../messages/webMessages/unitComponentsMessages'; import { WebComponent } from '../../webComponent/WebComponent'; import { getNextRepaymentParams } from './UNNextRepaymentComponent.utils'; import { RESPONSE_KEYS } from '../../messages/webMessages/onLoadMessage'; import { PresentationMode, WebComponentType } from '../../types/internal/webComponent.types'; import { withReduxStore } from '../../helpers/store/helpers'; import { UNBaseView } from '../../nativeComponents/UNBaseView'; const UNNextRepaymentComponent = props => { const [height, setHeight] = useState(0); const handleUnitOnLoad = response => { if (!props.onLoad) { return; } if (RESPONSE_KEYS.errors in response) { props.onLoad(response); return; } if (RESPONSE_KEYS.repayment in response) { props.onLoad(response[RESPONSE_KEYS.repayment]); return; } console.error('On Load Error: unexpected response type.'); return; }; const handleMessage = message => { switch (message.type) { case UnitComponentsMessage.UNIT_ON_LOAD: handleUnitOnLoad(message.details); break; case PageMessage.PAGE_HEIGHT: setHeight(message.details.height); break; } }; return /*#__PURE__*/React.createElement(UNBaseView, { style: { height, width: '100%' }, onLoadError: handleUnitOnLoad, fallback: /*#__PURE__*/React.createElement(React.Fragment, null) }, /*#__PURE__*/React.createElement(WebComponent, { type: WebComponentType.nextRepayment, presentationMode: PresentationMode.Default, params: getNextRepaymentParams(props), theme: props.theme, language: props.language, onMessage: message => handleMessage(message), isScrollable: false })); }; export default withReduxStore(UNNextRepaymentComponent); //# sourceMappingURL=UNNextRepaymentComponent.js.map