| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- import React, { useState } from 'react';
- import { StyleSheet, Text, TextInput, View } from 'react-native';
- import Button from '../../components/Button';
- import TextView from '../../components/TextView';
- import Modal from "react-native-modal";
- import { ModalProps } from "../../components/BottomModal";
- import Dialog from '../../components/Dialog';
- import apiVoucher from '../../api/apiVoucher';
- import { PageList } from '../Router';
- export default ViewRedeem = ({
- userInfo={},
- onChange
- }) => {
- const [visible, showDialog] = useState(false);
- const [promoCode, setPromoCode] = useState("");
- const redeemVoucher = () => {
- showDialog(false);
- if (promoCode) {
- setTimeout(() => {
- Dialog.showProgressDialog();
- apiVoucher.redeemVoucher({
- redemptionCode: promoCode
- }).then(res => {
- Dialog.dismissLoading();
- if (onChange) {
- onChange();
- }
- if (res.msg) {
- setTimeout(() => {
- Dialog.showDialog({
- title: $t("voucher.vouchers"),
- message: res.msg,
- showCancel: false
- })
- }, 500);
- }
- }).catch(err => {
- Dialog.dismissLoading();
- if (err.err) {
- setTimeout(() => {
- Dialog.showDialog({
- title: $t("common.error"),
- message: err.err,
- showCancel: false
- })
- }, 500);
- }
- })
- }, 300);
- } else {
- toastLong($t("voucher.plsInputPromoCode"))
- }
- }
- return (
- <View>
- <View style={styles.redeemLayout}>
- <Button
- style={styles.buttonLeft}
- viewStyle={styles.buttonView}
- onClick={() => showDialog(true)}>
- <MaterialCommunityIcons
- name="ticket-percent-outline"
- size={24}
- color={textPrimary}/>
- <TextView
- style={styles.buttonText}
- numberOfLines={1}>
- {$t("voucher.inputPromoCode")}
- </TextView>
- </Button>
- <Text style={styles.btnDivide}></Text>
- <Button
- style={styles.buttonRight}
- viewStyle={styles.buttonView}
- onClick={() => startPage(PageList.pointsHistory)}>
- <TextView
- style={styles.buttonText}
- numberOfLines={1}>
- {$t("voucher.availablePoints")}
- </TextView>
- <TextView
- style={styles.valueText}
- numberOfLines={1}>
- {userInfo?.points || '0'}
- </TextView>
- </Button>
- </View>
- <Modal
- isVisible={visible}
- onBackButtonPress={() => showDialog(false)}
- onBackdropPress={() => showDialog(false)}
- {...ModalProps}>
- <View style={Dialog.styles.modalDialog}>
- <TextView style={Dialog.styles.title}>{$t('voucher.inputPromoCode')}</TextView>
- <View style={Dialog.styles.message}>
- <TextInput
- style={styles.inputView}
- allowFontScaling={false}
- maxLength={6}
- placeholderTextColor={textPlacehoder}
- onChangeText={text => setPromoCode(text)}
- onSubmitEditing={() => redeemVoucher()}
- />
- </View>
- { isIOS
- ? <View style={Dialog.styles.modalFooter}>
- <Button
- style={Dialog.styles.btnGroup}
- viewStyle={Dialog.styles.btnView}
- textStyle={Dialog.styles.btnConfirm}
- text={$t('nav.confirm')}
- onClick={() => redeemVoucher()}/>
- <Button
- style={[Dialog.styles.btnGroup, Dialog.styles.btnRight]}
- viewStyle={Dialog.styles.btnView}
- textStyle={Dialog.styles.btnConfirm}
- text={$t('nav.cancel')}
- onClick={() => showDialog(false)}/>
- </View>
- : <View style={Dialog.styles.modalFooter}>
- <Dialog.AndroidButton
- title={$t('nav.cancel')}
- onPress={() => showDialog(false)}/>
- <Dialog.AndroidButton
- title={$t('nav.confirm')}
- onPress={() => redeemVoucher()}/>
- </View>
- }
- </View>
- </Modal>
- </View>
- );
- }
- const styles = StyleSheet.create({
- redeemLayout: {
- borderWidth: 1,
- borderColor: '#DADADA',
- borderRadius: 4,
- alignItems: 'center',
- flexDirection: 'row'
- },
- btnDivide: {
- width: 1,
- height: 26,
- backgroundColor: '#DADADA'
- },
- buttonLeft: {
- flex: 1,
- borderTopLeftRadius: 3,
- borderTopRightRadius: 0,
- borderBottomLeftRadius: 3,
- borderBottomRightRadius: 0,
- backgroundColor: 'transparent'
- },
- buttonRight: {
- flex: 1,
- borderTopLeftRadius: 0,
- borderTopRightRadius: 3,
- borderBottomLeftRadius: 0,
- borderBottomRightRadius: 3,
- backgroundColor: 'transparent'
- },
- buttonView: {
- flex: 1,
- height: 42,
- alignItems: 'center',
- flexDirection: 'row',
- justifyContent: 'center'
- },
- buttonText: {
- color: textPrimary,
- fontSize: 13,
- paddingLeft: 8,
- paddingRight: 8
- },
- valueText: {
- color: colorAccent,
- fontSize: 14
- },
- inputView: {
- color: textPrimary,
- fontSize: 14,
- height: 42,
- marginTop: 8,
- textAlign: 'center',
- paddingLeft: 12,
- paddingRight: 12,
- borderWidth: 1,
- borderColor: '#DADADA',
- borderRadius: 4,
- alignItems: 'center',
- flexDirection: 'row',
- textTransform: 'uppercase',
- backgroundColor: colorLight
- }
- })
|