UNPKG

react-native-booking-btaskee

Version:

A single / multiple, categorizable, customizable, localizable and searchable item booking component for react native which supports both Android & iOS.

209 lines (195 loc) 7.2 kB
import React, { useCallback, useState, useRef, useEffect, useMemo, memo, Fragment, } from 'react'; import moment from 'moment'; import _ from 'lodash'; import { location } from '../assets/images/index'; import { Spacing, Text, Image, Input, TouchableOpacity } from '@momo-platform/component-kits'; import { View, SafeAreaView, FlatList, TextInput, Dimensions, ScrollView, Modal, ActivityIndicator, BackHandler, Platform, StyleSheet, } from 'react-native'; import { formatPrice } from '../helper/index'; import { Duration, KeyboardAware, PickerTime, PickerDate } from '../components'; import { COLOR } from '../constants/index'; const { height: WINDOW_HEIGHT } = Dimensions.get('window'); import styles from './styles'; // hours, minutes default const HOURS_INDEX = 14; const MINUTES_INDEX = 30; function Booking({ containerProps = {}, containerAddress = {}, addressStyle = {}, textAddress = null, contentAddress = {}, imageAddressStyle = {}, locationImageProps = null, goChooseAddress = () => { }, changeAddress = {}, textChangeAddress = null, durationStyle = {}, textDuration = null, valueDurationProps = null, changeDuration = (duration) => { }, timeStyle = {}, textTime = null, dateProps = null, changeDateTime = (date) => { }, navigatorProps = null, noteStyle = {}, textNote = null, handleChangeTaskNote = (note) => { }, handleSaveTaskNote = () => { }, noteProps = null, placeholder = '', inputNoteStyle = {}, keyboardProps = {}, textProps = {}, viewContainerProps = {}, viewContentProps = {}, imageProps = {}, touchableStyle = {}, touchableProps = {}, textTouchProps = {}, durationProps = {}, dateTimeProps = {}, inputProps = {}, footerStyleProps = {}, goConfirm = () => { }, priceButtonStyleProps = {}, textPriceStyleProps = {}, textPricePromotionStyleProps = {}, textVND = '', textContinue = '', viewRenderAddressStyleProps = {}, textRenderAddressStyleProps = {}, viewAddressStyleProps = {}, textAddressStyleProps = {}, textAddressOption = '', props = {}, }) { let dateDefault = moment(moment().add(1, 'day').toDate()) .hour(HOURS_INDEX) .minute(MINUTES_INDEX) .second(0) .millisecond(0) .toDate(); const shouldRenderAddress = useMemo(() => { if (!_.isEmpty(props?.address)) { return <View style={{ marginLeft: Spacing.S }}> <Text style={{ fontWeight: 'bold', marginBottom: Spacing.S }}>{props?.address?.shortAddress}</Text> <Text>{props?.address?.address}</Text> </View> } return <View style={{ marginLeft: Spacing.S, alignSelf: 'center' }}> <Text style={styles.bold}>{'Chọn địa chỉ'}</Text> </View> }, [props.address]) const shouldRenderFooter = useMemo(() => { if (!_.isEmpty(props?.price) && props?.address) { return ( <View style={styles.footer}> <TouchableOpacity onPress={goConfirm} style={styles.priceButton} > <View> { (props?.promotion && props?.price?.finalCost !== props?.price?.cost) ? <Text.H4 style={[styles.price, styles.pricePromotion]}>{formatPrice(props?.price?.cost)} {textVND || 'VND'}</Text.H4> : null } <Text.H4 style={styles.price}>{formatPrice(props?.price?.finalCost)} {textVND || 'VND'}/{props?.duration}{'h'}</Text.H4> </View> <Text.H4 style={styles.price}>{textContinue || 'Tiếp theo'}</Text.H4> </TouchableOpacity> </View> ) }; return null; }, [props.price, props.date, props.duration, props.address, props.promotion]); return ( <> <KeyboardAware style={styles.container} showsVerticalScrollIndicator={false} {...keyboardProps} > {/* Address */} <Text style={styles.title} {...textProps}>{textAddress || 'Địa chỉ'}</Text> <View style={styles.contentAddress} {...viewContainerProps}> <View style={{ flexDirection: 'row', flex: 10 }} {...viewContentProps}> <Image cached style={styles.icon} source={location ? location : ''} {...imageProps} /> { shouldRenderAddress } </View> <TouchableOpacity onPress={goChooseAddress} style={touchableStyle} {...touchableProps} > <Text style={styles.changeAddress} {...textTouchProps}>{textChangeAddress || 'Thay đổi'}</Text> </TouchableOpacity> </View> {/* Duration */} <Text style={styles.title} {...textProps}>{textDuration || 'Thời lượng'}</Text> <Duration duration={props?.duration ? props?.duration : 3} changeDuration={(value) => props?.changeDuration(value)} {...durationProps} /> {/* Time */} <Text style={styles.title} {...textProps}>{textTime || 'Chọn thời gian làm việc'}</Text> <PickerDate date={props?.date ? props?.date : dateDefault} onChange={(date) => props?.changeDateTime(date)} {...dateTimeProps} /> <PickerTime date={props?.date ? props?.date : dateDefault} onChange={(date) => props?.changeDateTime(date)} navigator={props?.navigator ? props?.navigator : ''} {...dateTimeProps} /> {/* Note */} <Text style={styles.title} {...textProps}>{textNote || 'Ghi chú cho người làm'}</Text> <Input onChangeText={(text) => handleChangeTaskNote(text)} onBlur={handleSaveTaskNote} defaultValue={props.note ? props.note : ''} multiline={true} numberOfLines={12} placeholder={placeholder || 'Bạn có yêu cầu gì thêm, hãy nhập ở đây nhé!'} style={styles.inputNote} {...inputProps} /> </KeyboardAware> {/* footer */} { shouldRenderFooter } </> ); } export default memo(Booking);