選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AddressList.js 13 KiB

3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
3年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. import React, { Component } from "react";
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. ScrollView,
  7. Image,
  8. TouchableOpacity,
  9. } from "react-native";
  10. import { Container, Left, Icon, Footer, Col, Right } from "native-base";
  11. import { Button } from "react-native-elements";
  12. import axios from "axios";
  13. import { connect } from "react-redux";
  14. import back from "../assets/icons/back1.png";
  15. import { Loader } from "../components/GeneralComponents";
  16. import {
  17. listServiceActionPending,
  18. listServiceActionError,
  19. listServiceActionSuccess,
  20. deleteServiceActionPending,
  21. deleteServiceActionError,
  22. deleteServiceActionSuccess,
  23. } from "../actions/AddressListActions";
  24. import { selectAddress } from "../actions/CartActions";
  25. import {
  26. api_url1,
  27. address_list,
  28. address_delete,
  29. img_url,
  30. last_active_address,
  31. font_title,
  32. font_description,
  33. no_address_lottie,
  34. } from "../config/Constants";
  35. import { ConfirmDialog } from "react-native-simple-dialogs";
  36. import * as colors from "../assets/css/Colors";
  37. import RNAndroidLocationEnabler from "react-native-android-location-enabler";
  38. import LottieView from "lottie-react-native";
  39. class AddressList extends Component<Props> {
  40. constructor(props) {
  41. super(props);
  42. this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
  43. this.state = {
  44. dialogVisible: false,
  45. deleting_address: 0,
  46. from: this.props.route.params.from,
  47. isLoding: false,
  48. api_status: 0,
  49. result: [],
  50. order2: [],
  51. };
  52. this.getProfile();
  53. }
  54. componentDidMount() {
  55. this.getProfile();
  56. // this._unsubscribe = this.props.navigation.addListener("focus", () => {
  57. // this.address_list();
  58. // });
  59. }
  60. componentWillUnmount() {
  61. // this._unsubscribe();
  62. }
  63. getProfile = async () => {
  64. await axios
  65. .get(`${api_url1}/clients/profile`, {
  66. headers: { Authorization: `Bearer ${global.fcm_token}` },
  67. })
  68. .then((res) => {
  69. this.setState({ order2: res.data.data.addressess });
  70. console.log(res.data.data.addressess);
  71. })
  72. .catch((res) => {
  73. console.log(res);
  74. });
  75. };
  76. // address_list = async () => {
  77. // this.setState({ isLoding: true });
  78. // this.setState({ dialogVisible: false });
  79. // this.props.deleteServiceActionPending();
  80. // await axios({
  81. // method: "post",
  82. // url: api_url + address_list,
  83. // data: { customer_id: global.id },
  84. // })
  85. // .then(async (response) => {
  86. // //alert(JSON.stringify(response));
  87. // this.setState({
  88. // isLoding: false,
  89. // result: response.data.result,
  90. // api_status: 1,
  91. // });
  92. // await this.props.deleteServiceActionSuccess(response.data);
  93. // })
  94. // .catch((error) => {
  95. // this.setState({ isLoding: false });
  96. // this.props.deleteServiceActionError(error);
  97. // });
  98. // };
  99. address_delete = async (id) => {
  100. //eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxZDhiOGU3MDA5MWUyMDAxNjEzYWVkOSIsImlhdCI6MTY0MTg3OTYwNSwiZXhwIjoxNjUwNTE5NjA1fQ.Dc4VQba1h21Xj-PFI7ln--n1o-l7ilQgv8GlkASziCM
  101. // await axios
  102. // .delete(
  103. // `${api_url1}/clients/address/`,
  104. // { _id: id },
  105. // { headers: { Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxZDhiOGU3MDA5MWUyMDAxNjEzYWVkOSIsImlhdCI6MTY0MTg3OTYwNSwiZXhwIjoxNjUwNTE5NjA1fQ.Dc4VQba1h21Xj-PFI7ln--n1o-l7ilQgv8GlkASziCM` } }
  106. // //{ headers: { Authorization: `Bearer ${global.fcm_token}` } }
  107. // )
  108. // .then((res) => {
  109. // alert(res);
  110. // });
  111. await axios
  112. .delete(
  113. `${api_url1}/clients/address`,
  114. { headers: { Authorization: `Bearer ${global.fcm_token}` } }
  115. , { _id: id }
  116. )
  117. .then(async (response) => {
  118. // console.log(response);
  119. alert('address deleted');
  120. this.getProfile();
  121. })
  122. // this.setState({ isLoding: true });
  123. // this.setState({ dialogVisible: false });
  124. // this.props.deleteServiceActionPending();
  125. // await axios.delete(),
  126. // url: api_url + address_delete,
  127. // data: {address_id: id },
  128. // })
  129. // .then(async (response) => {
  130. // // this.setState({ isLoding: false });
  131. // // await this.props.deleteServiceActionSuccess(response.data);
  132. // // await this.setState({ deleting_address: 0 });
  133. // })
  134. // .catch((error) => {
  135. // this.setState({ isLoding: false });
  136. // this.props.deleteServiceActionError(error);
  137. // });
  138. };
  139. // open_popup(id) {
  140. // this.setState({ dialogVisible: true, deleting_address: id });
  141. // }
  142. // close_popup() {
  143. // this.setState({ dialogVisible: false, deleting_address: 0 });
  144. // }
  145. handleBackButtonClick = () => {
  146. this.props.navigation.goBack(null);
  147. };
  148. add_address = () => {
  149. this.props.navigation.navigate("AddressMap");
  150. };
  151. edit_address = (id) => {
  152. RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({
  153. interval: 10000,
  154. fastInterval: 5000,
  155. })
  156. .then((data) => {
  157. this.props.navigation.navigate("Address", { id: id });
  158. })
  159. .catch((err) => {
  160. alert("Please enable your location");
  161. });
  162. };
  163. select_address = async (id) => {
  164. this.setState({ isLoding: true });
  165. await axios({
  166. method: "post",
  167. url: api_url + last_active_address,
  168. data: { customer_id: global.id, address_id: id },
  169. })
  170. .then(async (response) => {
  171. this.setState({ isLoding: false });
  172. if (response.data.status == 1) {
  173. this.handleBackButtonClick();
  174. } else {
  175. alert(response.data.message);
  176. }
  177. })
  178. .catch((error) => {
  179. this.setState({ isLoding: false });
  180. alert("Sorry something went wrong");
  181. });
  182. };
  183. render() {
  184. const { isLoding, data } = this.props;
  185. const address_list = this.state.order2.map((row, key) => {
  186. return (
  187. <View style={styles.add_list_style1}>
  188. <View style={styles.add_list_style2}>
  189. <Left>
  190. <Text style={styles.add_list_style3}>Address #{key + 1}</Text>
  191. </Left>
  192. </View>
  193. {/* <View style={styles.add_list_style4}>
  194. <Image
  195. style={styles.add_list_style5}
  196. source={{ uri: img_url + row.static_map }}
  197. />
  198. </View> */}
  199. <View style={styles.add_list_style6}>
  200. <Left>
  201. <Text style={styles.add_list_style7}>{row.addressLine1}</Text>
  202. <Text style={styles.add_list_style7}>
  203. {row.city},{row.state},{row.country}
  204. </Text>
  205. <Text style={styles.add_list_style7}>{row.pincode}</Text>
  206. </Left>
  207. </View>
  208. <View style={styles.add_list_style8}>
  209. <Col style={styles.add_list_style9}>
  210. <View
  211. style={{
  212. flexDirection: "row",
  213. justifyContent: "space-between",
  214. }}
  215. >
  216. {/* <Text
  217. // onPress={this.edit_address.bind(this, row.id)}
  218. style={styles.add_list_style10}
  219. >
  220. EDIT
  221. </Text> */}
  222. <TouchableOpacity
  223. onPress={() => {
  224. this.address_delete(row._id);
  225. }}
  226. >
  227. <Text style={styles.add_list_style10}>Delete</Text>
  228. </TouchableOpacity>
  229. </View>
  230. <Right />
  231. </Col>
  232. {/*<Col style={{ width:'25%' }}>
  233. <Text onPress={this.open_popup.bind(this,row.id)} style={styles.btn} >DELETE</Text>
  234. </Col>*/}
  235. {this.state.from == "home" && (
  236. <Col style={styles.add_list_style11}>
  237. <Text
  238. onPress={this.select_address.bind(this, row.id)}
  239. style={styles.add_list_style12}
  240. >
  241. SELECT
  242. </Text>
  243. </Col>
  244. )}
  245. </View>
  246. </View>
  247. );
  248. });
  249. return (
  250. <Container style={styles.add_list_style13}>
  251. <View>
  252. <View style={styles.add_list_style14}>
  253. <TouchableOpacity
  254. style={styles.add_list_style15}
  255. onPress={this.handleBackButtonClick}
  256. activeOpacity={1}
  257. >
  258. <Image
  259. style={{
  260. width: 20,
  261. height: 20,
  262. backgroundColor: "white",
  263. marginVertical: 12,
  264. }}
  265. source={back}
  266. />
  267. </TouchableOpacity>
  268. <View style={styles.add_list_style17} />
  269. <Text style={styles.add_list_style18}>Address List</Text>
  270. </View>
  271. </View>
  272. <ScrollView>
  273. <View style={styles.add_list_style19}>
  274. {address_list}
  275. {data.length == 0 && this.state.api_status == 1 && (
  276. <View>
  277. <View style={styles.add_list_style20}>
  278. <LottieView source={no_address_lottie} autoPlay loop />
  279. </View>
  280. <Text style={styles.add_list_style21}>
  281. How can we find you?
  282. </Text>
  283. </View>
  284. )}
  285. </View>
  286. </ScrollView>
  287. <Footer style={styles.add_list_style22}>
  288. <View style={styles.add_list_style23}>
  289. <Button
  290. title="ADD NEW ADDRESS"
  291. onPress={this.add_address}
  292. buttonStyle={styles.add_list_style24}
  293. titleStyle={styles.add_list_style25}
  294. />
  295. </View>
  296. </Footer>
  297. {/* <Loader visible={isLoding} />
  298. <Loader visible={this.state.isLoding} /> */}
  299. <ConfirmDialog
  300. title="Confirm Dialog"
  301. message="Are you sure about that?"
  302. animationType="fade"
  303. visible={this.state.dialogVisible}
  304. onTouchOutside={() => this.setState({ dialogVisible: false })}
  305. positiveButton={{
  306. title: "YES",
  307. onPress: this.address_delete,
  308. titleStyle: {
  309. color: colors.theme_fg,
  310. fontFamily: font_description,
  311. },
  312. }}
  313. negativeButton={{
  314. title: "NO",
  315. onPress: () => this.setState({ dialogVisible: false }),
  316. titleStyle: {
  317. color: colors.theme_fg,
  318. fontFamily: font_description,
  319. },
  320. }}
  321. />
  322. </Container>
  323. );
  324. }
  325. }
  326. function mapStateToProps(state) {
  327. return {
  328. isLoding: state.address_list.isLoding,
  329. message: state.address_list.isLoding,
  330. status: state.address_list.isLoding,
  331. data: state.address_list.data,
  332. address_count: state.address_list.address_count,
  333. };
  334. }
  335. const mapDispatchToProps = (dispatch) => ({
  336. listServiceActionPending: () => dispatch(listServiceActionPending()),
  337. listServiceActionError: (error) => dispatch(listServiceActionError(error)),
  338. listServiceActionSuccess: (data) => dispatch(listServiceActionSuccess(data)),
  339. deleteServiceActionPending: () => dispatch(deleteServiceActionPending()),
  340. deleteServiceActionError: (error) =>
  341. dispatch(deleteServiceActionError(error)),
  342. deleteServiceActionSuccess: (data) =>
  343. dispatch(deleteServiceActionSuccess(data)),
  344. selectAddress: (data) => dispatch(selectAddress(data)),
  345. });
  346. export default connect(
  347. mapStateToProps,
  348. mapDispatchToProps
  349. )(AddressList);
  350. const styles = StyleSheet.create({
  351. add_list_style1: {
  352. width: "100%",
  353. padding: 10,
  354. backgroundColor: colors.theme_bg_three,
  355. marginBottom: 10,
  356. },
  357. add_list_style2: { flexDirection: "row" },
  358. add_list_style3: {
  359. fontSize: 15,
  360. fontFamily: font_title,
  361. color: colors.theme_fg_two,
  362. },
  363. add_list_style4: {
  364. height: 20,
  365. width: "100%",
  366. marginTop: 10,
  367. },
  368. add_list_style5: { flex: 1, width: undefined, height: undefined },
  369. add_list_style6: { flexDirection: "row" },
  370. add_list_style7: {
  371. fontSize: 15,
  372. marginTop: 5,
  373. fontFamily: font_description,
  374. },
  375. add_list_style8: {
  376. flexDirection: "row",
  377. marginTop: 10,
  378. },
  379. add_list_style9: { width: "25%" },
  380. add_list_style10: {
  381. fontSize: 14,
  382. fontFamily: font_title,
  383. color: colors.theme_fg,
  384. fontFamily: font_title,
  385. },
  386. add_list_style11: { width: "25%" },
  387. add_list_style12: {
  388. fontSize: 14,
  389. fontFamily: font_title,
  390. color: colors.theme_fg,
  391. fontFamily: font_title,
  392. },
  393. add_list_style13: { backgroundColor: colors.theme_bg_two },
  394. add_list_style14: { alignItems: "flex-start", margin: 20 },
  395. add_list_style15: { width: 100, justifyContent: "center" },
  396. add_list_style16: { color: colors.theme_fg_two, fontSize: 30 },
  397. add_list_style17: { margin: 5 },
  398. add_list_style18: {
  399. fontSize: 25,
  400. color: colors.theme_fg_two,
  401. fontFamily: font_title,
  402. },
  403. add_list_style19: {
  404. alignItems: "center",
  405. },
  406. add_list_style20: { height: 250, marginTop: "30%" },
  407. add_list_style21: { alignSelf: "center", fontFamily: font_title },
  408. add_list_style22: {
  409. backgroundColor: colors.theme_bg_three,
  410. },
  411. add_list_style23: {
  412. width: "90%",
  413. justifyContent: "center",
  414. },
  415. add_list_style24: {
  416. backgroundColor: colors.theme_bg,
  417. fontFamily: font_title,
  418. },
  419. add_list_style25: {
  420. color: colors.theme_bg_three,
  421. fontFamily: font_description,
  422. },
  423. });