205 lines
6.2 KiB
TypeScript
205 lines
6.2 KiB
TypeScript
import { View, ViewStyle } from "react-native";
|
|
import ComparisonWidget from "../../../components/widgets/ComparisonWidget";
|
|
import HeaderLottieAnimationWidget from "../../../components/widgets/HeaderLottieAnimationWidget";
|
|
import HeaderWithAssetsWidget from "../../../components/widgets/HeaderWithAssetsWidget";
|
|
import SliderWidget from "../../../components/widgets/SliderWidget";
|
|
import TitleWithAssetsWidget from "../../../components/widgets/TitleWithAssetsWidget";
|
|
import FAB from "../../../components/widgets/fab/FAB";
|
|
import FooterWithCardWidget from "../../../components/widgets/footer-with-card-widget/FooterWithCardWidget";
|
|
import GridWithCardWidget from "../../../components/widgets/grid-with-card-widget/GridWithCardWidget";
|
|
import SumInsuredWidget from "../../../components/widgets/sum-insured-carousel-widget/SumInsuredWidget";
|
|
import TitleSubtitleWithAssetWidget from "../../../components/widgets/title-subtitle-with-asset-widget/TitleSubtitleWithAssetWidget";
|
|
import TitleWidget from "../../../components/widgets/title-widget/TitleWidget";
|
|
import TitleWithListWidget from "../../../components/widgets/title-with-list-widget/TitleWithListWidget";
|
|
import { GenericActionPayload } from "../actions/GenericAction";
|
|
import {
|
|
COMPARISON_WIDGET,
|
|
FAB_REQUEST_TO_CALLBACK,
|
|
FOOTER_WITH_CARD_WIDGET,
|
|
GRID_WITH_CARD_WIDGET,
|
|
HEADER_LOTTIE_ANIMATION_WIDGET,
|
|
HEADER_WITH_ASSETS_WIDGET,
|
|
SLIDER_WIDGET,
|
|
SUM_INSURED_WIDGET,
|
|
TITLE_SUBTITLE_WITH_ASSET_WIDGET,
|
|
TITLE_WIDGET,
|
|
TITLE_WITH_ASSETS_WIDGET,
|
|
TITLE_WITH_LIST_WIDGET,
|
|
} from "../constants/WidgetNameConstants";
|
|
import { CtaData } from "../interface";
|
|
import { GenericWidgetData, Widget } from "../interface/widgets/Widget";
|
|
import { SumInsuredWidgetData } from "../interface/widgets/widgetData/SumInsuredWidgetData";
|
|
import { ScreenState } from "../screen/BaseScreen";
|
|
|
|
export const GetWidgetView = {
|
|
getWidget: (
|
|
widget: Widget,
|
|
handleActions: (
|
|
value?: any | undefined | null,
|
|
actionPayload?: GenericActionPayload
|
|
) => void,
|
|
widgetIndex: number,
|
|
handleClick?: (ctaData: CtaData) => void,
|
|
screenState?: ScreenState | null
|
|
): JSX.Element => {
|
|
const { widgetName, widgetData, widgetStyle } = widget;
|
|
return resolveWidgetView(
|
|
widgetName,
|
|
widgetData,
|
|
widgetStyle,
|
|
handleActions,
|
|
widgetIndex,
|
|
handleClick,
|
|
screenState
|
|
);
|
|
},
|
|
};
|
|
function resolveWidgetView(
|
|
widgetName: string,
|
|
widgetData: GenericWidgetData,
|
|
widgetStyle: ViewStyle,
|
|
handleActions: (
|
|
value?: any | undefined | null,
|
|
screenActionPayload?: GenericActionPayload
|
|
) => void,
|
|
widgetIndex: number,
|
|
handleClick?: (ctaData: CtaData) => void,
|
|
screenState?: ScreenState | null
|
|
) {
|
|
switch (widgetName) {
|
|
case SLIDER_WIDGET:
|
|
return (
|
|
<SliderWidget
|
|
widgetData={widgetData}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
/>
|
|
);
|
|
case TITLE_WIDGET:
|
|
return (
|
|
<TitleWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
handleClick={handleClick}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
/>
|
|
);
|
|
case SUM_INSURED_WIDGET:
|
|
return (
|
|
<SumInsuredWidget
|
|
widgetData={widgetData}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={
|
|
widgetIndex +
|
|
"_" +
|
|
(widgetData as SumInsuredWidgetData).carouselListData?.length!!
|
|
}
|
|
/>
|
|
);
|
|
case TITLE_WITH_LIST_WIDGET:
|
|
return (
|
|
<TitleWithListWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
handleClick={handleClick}
|
|
/>
|
|
);
|
|
case COMPARISON_WIDGET:
|
|
return (
|
|
<ComparisonWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
handleClick={handleClick}
|
|
/>
|
|
);
|
|
case TITLE_WITH_ASSETS_WIDGET:
|
|
return (
|
|
<TitleWithAssetsWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
handleClick={handleClick}
|
|
/>
|
|
);
|
|
case FOOTER_WITH_CARD_WIDGET:
|
|
return (
|
|
<FooterWithCardWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
handleClick={handleClick}
|
|
screenState={screenState}
|
|
/>
|
|
);
|
|
case HEADER_WITH_ASSETS_WIDGET:
|
|
return (
|
|
<HeaderWithAssetsWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
handleClick={handleClick}
|
|
/>
|
|
);
|
|
case HEADER_LOTTIE_ANIMATION_WIDGET:
|
|
return (
|
|
<HeaderLottieAnimationWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
handleClick={handleClick}
|
|
/>
|
|
);
|
|
case GRID_WITH_CARD_WIDGET:
|
|
return (
|
|
<GridWithCardWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
handleClick={handleClick}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
/>
|
|
);
|
|
case TITLE_SUBTITLE_WITH_ASSET_WIDGET:
|
|
return (
|
|
<TitleSubtitleWithAssetWidget
|
|
widgetData={widgetData}
|
|
widgetStyle={widgetStyle}
|
|
handleActions={handleActions}
|
|
handleClick={handleClick}
|
|
widgetIndex={widgetIndex}
|
|
key={widgetIndex}
|
|
/>
|
|
);
|
|
case FAB_REQUEST_TO_CALLBACK:
|
|
return (
|
|
<FAB
|
|
widgetData={widgetData}
|
|
handleActions={handleActions}
|
|
key={widgetIndex}
|
|
handleClick={handleClick}
|
|
/>
|
|
);
|
|
default:
|
|
return <View />;
|
|
}
|
|
}
|