import React from "react"; import { View, Text, Pressable, TextInput, KeyboardAvoidingView, ActivityIndicator, } from "react-native"; import { connect } from "react-redux"; import { userFactor } from "../../../redux/actions"; import onInput from "../../../utils/onInput"; //style import fontSize from "../../../constants/fontSize"; import Colors from "../../../constants/Colors"; import tw from "tailwind-rn"; function Code({ codeId, setCodeId, theme, loading }) { const [value, setValue] = React.useState(codeId || ""); const [requestFlag, setRequestFlag] = React.useState(false); const setOff = React.useCallback(() => { setRequestFlag(true); setCodeId({ offCodeValue: value }); }, [requestFlag, value]); React.useEffect(() => { if (!loading) { setRequestFlag(false); } }, [loading]); return ( setValue((text = onInput.englishAndNumberWithoutSpace(text))) } style={[ tw("border-0 flex-1 text-right pr-3"), { fontSize: fontSize.tiny, fontFamily: "regular", color: theme === "light" ? Colors.theme1.gray20 : Colors.theme1.white, }, ]} placeholder={"کد تخفیف دارید ؟"} placeholderTextColor={theme === 'light' ? Colors.theme1.gray20 + "aa" : Colors.theme1.white + 'aa'} value={value} /> setOff()} style={[ tw("py-3 px-5"), { backgroundColor: Colors.theme1.greenCF, borderTopLeftRadius: 1, borderBottomLeftRadius: 1, }, ]} > {loading && requestFlag ? ( ) : ( ثبت کد )} ); } const mapStateToProps = (state) => ({ codeId: state.userFactor.info?.codeId, loading: state.userFactor.loading, theme: state.publicApi.theme, }); const mapDispatchToProps = { setCodeId: userFactor.update, }; export default connect(mapStateToProps, mapDispatchToProps)(Code);