import React, { useState } from 'react' import { PromotionsController, useLanguage, useUtils } from 'ordering-components/native' import FastImage from 'react-native-fast-image' import { PromotionsContainer, SingleOfferContainer, OfferInformation, SearchBarContainer, SingleBusinessOffer, AvailableBusinesses, OfferData, Code, BusinessInfo, WrapperSingleOffer } from './styles' import { SearchBar } from '../SearchBar' import NavBar from '../NavBar' import { useTheme } from 'styled-components/native'; import { OButton, OIcon, OModal, OText } from '../shared' import { Placeholder, PlaceholderLine } from 'rn-placeholder' import { NotFoundSource } from '../NotFoundSource' import { View, StyleSheet, ScrollView, RefreshControl, Platform } from 'react-native' import { PromotionParams } from '../../types' import { Container } from '../../layouts/Container' const PromotionsUI = (props: PromotionParams) => { const { navigation, offersState, handleSearchValue, searchValue, loadOffers, offerSelected, setOfferSelected } = props const theme = useTheme(); const styles = StyleSheet.create({ productStyle: { width: 75, height: 75, borderRadius: 7.6 }, buttonStyle: { width: '100%', height: 35, paddingLeft: 0, paddingRight: 0, borderRadius: 8 }, offerTitle: { fontSize: 14 }, offerDescription: { color: '#909BA9', fontSize: 12 }, offerExtraInfo: { fontSize: 12 }, modalButtonStyle: { width: 100, height: 35, paddingLeft: 0, paddingRight: 0, borderRadius: 7.6 } }); const [, t] = useLanguage() const [{ parseDate, parsePrice, optimizeImage }] = useUtils() const [openModal, setOpenModal] = useState(false) const [refreshing] = useState(false); const handleClickOffer = (offer: any) => { setOpenModal(true) setOfferSelected(offer) } const handleBusinessClick = (store: any) => { setOpenModal(false) navigation.navigate('Business', { store: store.slug }) } const handleOnRefresh = () => { if (!offersState.loading) { loadOffers(); } } const filteredOffers = offersState?.offers?.filter((offer: any) => offer.name.toLowerCase().includes(searchValue.toLowerCase())) const targetString = offerSelected?.target === 1 ? t('SUBTOTAL', 'Subtotal') : offerSelected?.target === 2 ? t('DELIVERY_FEE', 'Delivery fee') : t('SERVICE_FEE', 'Service fee') return ( handleOnRefresh()} /> } > navigation.goBack()} showCall={false} paddingTop={Platform.OS === 'ios' ? 20 : 10} style={{ paddingVertical: 0 }} btnStyle={{ paddingLeft: 0 }} /> {offersState?.loading && ( <> {[...Array(5).keys()].map((key, i) => ( ))} )} {((!offersState?.loading && filteredOffers?.length === 0) || offersState?.error) && ( )} {!offersState?.loading && offersState.offers?.length > 0 && filteredOffers?.map((offer: any) => ( {offer?.name} {!!offer?.description && ( {offer?.description} )} {t('EXPIRES', 'Expires')} {parseDate(offer?.end, { outputFormat: 'MMM DD, YYYY' })} {t('APPLY_FOR', 'Apply for')}: {offer.businesses.map((business: any, i: number) => ( {' '}{business?.name}{i + 1 < offer.businesses?.length ? ',' : ''} ))} handleClickOffer(offer)} text={t('VIEW', 'View')} style={styles.buttonStyle} textStyle={{ fontSize: 14, flexWrap: 'nowrap' }} /> ))} setOpenModal(false)} > {offerSelected?.name} / {t('VALUE_OF_OFFER', 'Value of offer')}: {offerSelected?.rate_type === 1 ? `${offerSelected?.rate}%` : `${parsePrice(offerSelected?.rate)}`} {offerSelected?.type === 2 && ( {t('YOUR_CODE', 'Your code')} {offerSelected.coupon} )} {t('APPLIES_TO', 'Applies to')}: {targetString} {offerSelected?.auto && ( {t('OFFER_AUTOMATIC', 'This offer applies automatic')} )} {!!offerSelected?.minimum && ( {t('MINIMUM_PURCHASE_FOR_OFFER', 'Minimum purchase for use this offer')}: {parsePrice(offerSelected?.minimum)} )} {!!offerSelected?.max_discount && ( {t('MAX_DISCOUNT_ALLOWED', 'Max discount allowed')}: {parsePrice(offerSelected?.max_discount)} )} {!!offerSelected?.description && ( {offerSelected?.description} )} {t('AVAILABLE_BUSINESSES_FOR_OFFER', 'Available businesses for this offer')}: {offerSelected?.businesses?.map((business: any) => { return ( {business?.logo ? ( ) : ( )} {business.name} handleBusinessClick(business)} text={t('GO_TO_BUSINESSS', 'Go to business')} style={styles.modalButtonStyle} textStyle={{ fontSize: 10 }} /> ) })} ) } export const Promotions = (props: PromotionParams) => { const PromotionsProps = { ...props, UIComponent: PromotionsUI } return ( ) }