You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

100 lines
2.6 KiB

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 (
<KeyboardAvoidingView
enabled
style={tw("flex w-full items-end mt-5 overflow-hidden")}
>
<View
style={[
tw("flex w-full flex-row-reverse rounded-sm mt-3"),
{ borderWidth: 1.5, borderColor: Colors.theme1[theme].greenCF },
]}
>
<TextInput
onChangeText={(text) =>
setValue((text = onInput.englishAndNumberWithoutSpace(text)))
}
style={[
tw("border-0 flex-1 text-right pr-3"),
{ fontSize: fontSize.tiny, fontFamily: "regular" },
]}
placeholder={"کد تخفیف دارید ؟"}
placeholderTextColor={Colors.theme1[theme].gray20 + "aa"}
value={value}
/>
<Pressable
onPress={() => setOff()}
style={[
tw("py-3 px-5"),
{
backgroundColor: Colors.theme1[theme].greenCF,
borderTopLeftRadius: 1,
borderBottomLeftRadius: 1,
},
]}
>
{loading && requestFlag ? (
<ActivityIndicator
size={fontSize.tiny}
color={Colors.theme1[theme].white}
style={tw("px-2")}
/>
) : (
<Text
style={[
tw("text-white"),
{ fontSize: fontSize.tiny, fontFamily: "bold" },
]}
>
ثبت کد
</Text>
)}
</Pressable>
</View>
</KeyboardAvoidingView>
);
}
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);