import {
View,
Text,
Pressable,
TouchableOpacity,
ActivityIndicator,
Platform,
} from "react-native";
import React from "react";
import { connect } from "react-redux";
import {asyncAwesomeAlert} from "../../../utils/AsyncWrappers";
import { Ionicons, Entypo } from "@expo/vector-icons";
import { useNavigation } from "@react-navigation/native";
import { userFactor, userAddress } from "../../../redux/actions";
//style
import tw from "tailwind-rn";
import Colors from "../../../constants/Colors";
import fontSize from "../../../constants/fontSize";
const ios = Platform.OS === "ios";
const Address = ({
addresses,
update,
userId,
userAddressId,
loading,
mobile,
deleteItem,
theme,
}) => {
const navigation = useNavigation();
const [selectedItem, setSelectedItem] = React.useState(null);
const light = React.useMemo(() => {
return theme === "light";
}, [theme]);
React.useEffect(() => {
if (!loading) {
setSelectedItem(null);
}
}, [loading]);
const Location = ({ address, active }) => {
return (
{
setSelectedItem(address?.id);
active ? {} : update({ userAddressId: address?.id, userId });
}}
>
{selectedItem === address?.id && loading ? (
) : active ? (
) : (
)}
{address?.address}
navigation.navigate("CreateAddress", {
type: "editAddress",
form: address,
})
}
>
asyncAwesomeAlert("", "آدرس مورد نظر حذف شود؟", {
showCancelButton: true,
confirmText: "بله",
cancelText: "لغو",
onConfirm: () => deleteItem({ id: address?.id }),
})
}
style={tw('h-full')}
>
);
};
return (
{addresses?.length ? (
لطفا آدرس مورد نظر را انتخاب کنید.
) : null}
{addresses?.map((address, index) => (
))}
navigation.push("CreateAddress")}
>
یک آدرس جدید اضافه کنید
+
);
};
const mapStateToProps = (state) => ({
userId: state.user.status?.id,
userAddressId: state.userFactor.info?.userAddressId,
loading: state.userFactor.loading,
mobile: state.publicApi.mobile,
theme: state.publicApi.theme,
});
const mapDispatchToProps = {
update: userFactor.update,
deleteItem: userAddress.update
};
export default connect(mapStateToProps, mapDispatchToProps)(Address);