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.

616 lines
17 KiB

  1. import Geolocation from "@react-native-community/geolocation";
  2. import React, { Component } from "react";
  3. import {
  4. View,
  5. StyleSheet,
  6. Text,
  7. TextInput,
  8. ScrollView,
  9. Image,
  10. BackHandler,
  11. Keyboard,
  12. TouchableOpacity,
  13. Picker,
  14. } from "react-native";
  15. import { CommonActions } from "@react-navigation/native";
  16. import {
  17. Icon,
  18. Card,
  19. CardItem,
  20. Left,
  21. Body,
  22. Right,
  23. Col,
  24. Row,
  25. Thumbnail,
  26. Button,
  27. } from "native-base";
  28. import Snackbar from "react-native-snackbar";
  29. import {
  30. api_url,
  31. register,
  32. height_20,
  33. logo_with_name,
  34. app_name,
  35. register_image,
  36. font_title,
  37. font_description,
  38. get_blood_list,
  39. api_url1,
  40. } from "../config/Constants";
  41. import { StatusBar, Loader } from "../components/GeneralComponents";
  42. import * as colors from "../assets/css/Colors";
  43. import axios from "axios";
  44. import { connect } from "react-redux";
  45. import {
  46. serviceActionPending,
  47. serviceActionError,
  48. serviceActionSuccess,
  49. } from "../actions/RegisterActions";
  50. import AsyncStorage from "@react-native-community/async-storage";
  51. import { Input } from "react-native-elements";
  52. import call from "../assets/icons/call.png";
  53. import person from "../assets/icons/person.png";
  54. import pass from "../assets/icons/pass.png";
  55. import email from "../assets/icons/email.png";
  56. import back from "../assets/icons/back1.png";
  57. class AddressEnter extends Component<Props> {
  58. constructor(props) {
  59. super(props);
  60. this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
  61. this.state = {
  62. address: "",
  63. validation: true,
  64. blood_group_list: [],
  65. fcm_token: global.fcm_token,
  66. country: "",
  67. // region: "",
  68. latitude: "",
  69. longitude: "",
  70. coords: "",
  71. pincode:'',
  72. city:'',
  73. State:''
  74. };
  75. // this.get_blood_list();
  76. this.handleUserNavigation();
  77. }
  78. componentWillMount() {
  79. BackHandler.addEventListener(
  80. "hardwareBackPress",
  81. this.handleBackButtonClick
  82. );
  83. }
  84. componentWillUnmount() {
  85. BackHandler.removeEventListener(
  86. "hardwareBackPress",
  87. this.handleBackButtonClick
  88. );
  89. }
  90. handleBackButtonClick() {
  91. this.props.navigation.navigate("AddressList");
  92. return true;
  93. }
  94. // selectCountry(val) {
  95. // this.setState({ country: val });
  96. // }
  97. // selectRegion(val) {
  98. // this.setState({ region: val });
  99. // }
  100. login = () => {
  101. this.props.navigation.navigate("Login");
  102. };
  103. home = () => {
  104. this.props.navigation.dispatch(
  105. CommonActions.reset({
  106. index: 0,
  107. routes: [{ name: "Home" }],
  108. })
  109. );
  110. };
  111. handleUserNavigation = async () => {
  112. try{
  113. await Geolocation.getCurrentPosition((info) => {
  114. this.setState({
  115. latitude: info.coords.latitude,
  116. longitude: info.coords.longitude,
  117. coords: info.coords,
  118. });
  119. console.log(info);
  120. })}
  121. catch(error){alert(error)}
  122. }
  123. register = async () => {
  124. this.handleUserNavigation();
  125. Keyboard.dismiss();
  126. // await this.checkValidate();
  127. // if (this.state.validation)
  128. // this.props.serviceActionPending();
  129. // let countries = Country.getAllCountries();
  130. // console.log(countries[0].name);
  131. await axios
  132. .post(
  133. `${api_url1}/clients/address/add`,
  134. {
  135. addressLine1: this.state.address,
  136. pincode: this.state.pincode,
  137. city: this.state.city,
  138. state: this.state.State,
  139. country: this.state.country,
  140. latitude:this.state.latitude,
  141. longitude: this.state.longitude,
  142. },
  143. { headers: { Authorization: `Bearer ${global.fcm_token}` } }
  144. )
  145. .then(async (response) => {
  146. console.log(response);
  147. // await this.props.serviceActionSuccess(response.data);
  148. // await this.saveData();
  149. // login()
  150. // console.log(response);
  151. alert("Address Added");
  152. this.props.navigation.navigate("AddressList");
  153. })
  154. .catch((error) => {
  155. console.log(error);
  156. });
  157. };
  158. get_blood_list = async () => {
  159. await axios({
  160. method: "get",
  161. url: api_url + get_blood_list,
  162. })
  163. .then(async (response) => {
  164. this.setState({ blood_group_list: response.data.result });
  165. })
  166. .catch((error) => {
  167. alert("Sorry, something went wrong!");
  168. });
  169. };
  170. saveData = async () => {
  171. if (this.props.status == 1) {
  172. try {
  173. await AsyncStorage.setItem("user_id", this.props.data.id.toString());
  174. await AsyncStorage.setItem(
  175. "username",
  176. this.props.data.customer_name.toString()
  177. );
  178. await AsyncStorage.setItem(
  179. "number",
  180. this.props.data.phone_number.toString()
  181. );
  182. await AsyncStorage.setItem("email", this.props.data.email.toString());
  183. global.id = await this.props.data.id;
  184. global.username = await this.props.data.customer_name;
  185. global.number = await this.props.data.phone_number;
  186. global.email = await this.props.data.email;
  187. await this.home();
  188. } catch (e) {}
  189. } else {
  190. alert(this.props.message);
  191. }
  192. };
  193. checkValidate=()=> {
  194. if(
  195. this.state.address == "" ||
  196. this.state.pincode == "" ||
  197. this.state.city == "" ||
  198. this.state.country == "" ||
  199. this.state.State == "" ||
  200. this.state.latitude == "" ||
  201. this.state.longitude==""
  202. ) {
  203. // this.state.validation = false;
  204. alert("Please fill all the fields.");
  205. // return true;
  206. } else {
  207. // this.state.validation = true;
  208. // return true;
  209. this.register(); }
  210. }
  211. select_blood_group = (value) => {
  212. this.setState({ blood_group: value });
  213. };
  214. showSnackbar(msg) {
  215. Snackbar.show({
  216. title: msg,
  217. duration: Snackbar.LENGTH_SHORT,
  218. });
  219. }
  220. render() {
  221. const { isLoding, error, data, message, status } = this.props;
  222. let bl_list = this.state.blood_group_list.map((s, i) => {
  223. return (
  224. <Picker.Item key={i} value={s.blood_group} label={s.blood_group} />
  225. );
  226. });
  227. return (
  228. <View style={styles.container}>
  229. <View>
  230. <StatusBar />
  231. </View>
  232. <Loader visible={isLoding} />
  233. <View>
  234. <View>
  235. </View>
  236. <View style={styles.reg_style1}>
  237. <TouchableOpacity
  238. style={styles.reg_style2}
  239. onPress={this.handleBackButtonClick}
  240. activeOpacity={1}
  241. >
  242. {/* <Icon
  243. onPress={this.handleBackButtonClick}
  244. style={styles.reg_style3}
  245. name="arrow-back"
  246. /> */}
  247. <Image
  248. style={{
  249. width: 20,
  250. height: 20,
  251. backgroundColor: "white",
  252. marginVertical: 6,
  253. marginLeft: 2,
  254. }}
  255. source={back}
  256. />
  257. </TouchableOpacity>
  258. <View style={styles.reg_style4} />
  259. <Text style={styles.reg_style5}>Enter Your location</Text>
  260. </View>
  261. </View>
  262. <ScrollView keyboardShouldPersistTaps="always">
  263. <View style={styles.reg_style6}>
  264. {/* <View style={styles.reg_style8}>
  265. {/* <Image style={styles.reg_style9} source={logo_with_name} /> */}
  266. {/* </View> */}
  267. <View style={styles.reg_style10} />
  268. <View style={styles.reg_style11}>
  269. <Input
  270. inputStyle={styles.reg_style12}
  271. label="Address line 1"
  272. labelStyle={styles.reg_style13}
  273. placeholder="Your home Address"
  274. leftIcon={
  275. // <Icon
  276. // name="person"
  277. // size={20}
  278. // color="black"
  279. // style={styles.reg_style14}
  280. // />
  281. <Image style={{ width: 22, height: 22 }} source={person} />
  282. }
  283. onChangeText={(TextInputValue) =>
  284. this.setState({ address: TextInputValue })
  285. }
  286. />
  287. </View>
  288. <View style={styles.reg_style15}>
  289. <Input
  290. inputStyle={styles.reg_style16}
  291. label="Pincode"
  292. labelStyle={styles.reg_style17}
  293. placeholder="+"
  294. // leftIcon={
  295. // // <Icon
  296. // // name="call"
  297. // // size={20}
  298. // // color="black"
  299. // // style={styles.reg_style18}
  300. // // />
  301. // <Image
  302. // style={{ width: 22,
  303. // height: 22,}}
  304. // source={call}
  305. // />
  306. // }
  307. keyboardType="phone-pad"
  308. onChangeText={(TextInputValue) =>
  309. this.setState({ pincode: TextInputValue })
  310. }
  311. />
  312. </View>
  313. <View style={styles.reg_style19}>
  314. <Input
  315. inputStyle={styles.reg_style20}
  316. label="City"
  317. labelStyle={styles.reg_style21}
  318. placeholder="eg:Delhi"
  319. // leftIcon={
  320. // // <Icon
  321. // // name="mail"
  322. // // size={20}
  323. // // color="black"
  324. // // style={styles.reg_style22}
  325. // // />
  326. // <Image
  327. // style={{ width: 22,
  328. // height: 22,}}
  329. // source={email}
  330. // />
  331. // }
  332. keyboardType="email-address"
  333. onChangeText={(TextInputValue) =>
  334. this.setState({ city: TextInputValue })
  335. }
  336. />
  337. </View>
  338. <Text>
  339. {/* wdhu {this.state.latitude} */}
  340. </Text>
  341. <View style={styles.reg_style23}>
  342. <Input
  343. inputStyle={styles.reg_style24}
  344. placeholder="eg. Mahahrashtra"
  345. label="State"
  346. labelStyle={styles.reg_style25}
  347. // leftIcon={
  348. // // <Icon
  349. // // name="key"
  350. // // size={20}
  351. // // color="black"
  352. // // style={styles.reg_style26}
  353. // // />
  354. // <Image
  355. // style={{ width: 22,
  356. // height: 22,}}
  357. // source={pass}
  358. // />
  359. // }
  360. // secureTextEntry={true}
  361. onChangeText={(TextInputValue) =>
  362. this.setState({ State: TextInputValue })
  363. }
  364. />
  365. </View>
  366. <View style={styles.reg_style11}>
  367. <Input
  368. inputStyle={styles.reg_style12}
  369. label="Country"
  370. labelStyle={styles.reg_style13}
  371. placeholder="Your home Address"
  372. // leftIcon={
  373. // // <Icon
  374. // // name="person"
  375. // // size={20}
  376. // // color="black"
  377. // // style={styles.reg_style14}
  378. // // />
  379. // <Image style={{ width: 22, height: 22 }} source={person} />
  380. // }
  381. onChangeText={(TextInputValue) =>
  382. this.setState({ country: TextInputValue })
  383. }
  384. />
  385. </View>
  386. <Text>
  387. {/* {this.state.country} */}
  388. </Text>
  389. <Text
  390. style={styles.reg_style13}
  391. >
  392. Your location : {this.state.latitude} , {this.state.longitude}
  393. </Text>
  394. <Text
  395. style={styles.reg_style13}
  396. >
  397. Accuracy:({this.state.coords.accuracy})
  398. </Text>
  399. {/* <View style={styles.reg_style27}> */}
  400. {/* <Text style={styles.reg_style28}>Blood Group</Text>
  401. <Picker
  402. selectedValue={this.state.blood_group}
  403. style={styles.reg_style29}
  404. onValueChange={(itemValue, itemIndex) =>
  405. this.select_blood_group(itemValue)
  406. }
  407. >
  408. {bl_list}
  409. </Picker>
  410. </View> */}
  411. <View style={styles.reg_style30} />
  412. <View style={styles.reg_style31}>
  413. <Button block style={styles.reg_style32} onPress={this.checkValidate}>
  414. <Text style={styles.reg_style33}>SUBMIT</Text>
  415. </Button>
  416. </View>
  417. <View
  418. style={{height:34}}
  419. />
  420. {/* <View style={styles.reg_style34}>
  421. <Text style={styles.reg_style35} onPress={this.login}>
  422. Already have an account?{" "}
  423. <Text style={styles.reg_style36}>LOGIN HERE</Text>
  424. </Text>
  425. </View> */}
  426. </View>
  427. </ScrollView>
  428. </View>
  429. );
  430. }
  431. }
  432. function mapStateToProps(state) {
  433. return {
  434. isLoding: state.register.isLoding,
  435. error: state.register.error,
  436. data: state.register.data,
  437. message: state.register.message,
  438. status: state.register.status,
  439. };
  440. }
  441. const mapDispatchToProps = (dispatch) => ({
  442. serviceActionPending: () => dispatch(serviceActionPending()),
  443. serviceActionError: (error) => dispatch(serviceActionError(error)),
  444. serviceActionSuccess: (data) => dispatch(serviceActionSuccess(data)),
  445. });
  446. export default connect(
  447. mapStateToProps,
  448. mapDispatchToProps
  449. )(AddressEnter);
  450. const styles = StyleSheet.create({
  451. reg_style1: { alignItems: "flex-start", margin: 10 },
  452. reg_style2: { width: 100, justifyContent: "center" },
  453. reg_style3: { color: colors.theme_fg_two, fontSize: 30 },
  454. reg_style4: { margin: 5 },
  455. reg_style5: {
  456. fontSize: 25,
  457. color: colors.theme_fg_two,
  458. fontFamily: font_title,
  459. },
  460. reg_style6: { justifyContent: "center", alignItems: "center" },
  461. reg_style7: { marginTop: "10%" },
  462. reg_style8: { height: 120, width: 120 },
  463. reg_style9: { flex: 1, width: undefined, height: undefined },
  464. reg_style10: { marginTop: "10%" },
  465. reg_style11: { width: "80%", alignSelf: "center" },
  466. reg_style12: { fontSize: 14, fontFamily: font_description },
  467. reg_style13: { fontFamily: font_title },
  468. reg_style14: { color: colors.theme_bg },
  469. reg_style15: { width: "80%", alignSelf: "center" },
  470. reg_style16: { fontSize: 14, fontFamily: font_description },
  471. reg_style17: { fontFamily: font_title },
  472. reg_style18: { color: colors.theme_bg },
  473. reg_style19: { width: "80%", alignSelf: "center" },
  474. reg_style20: { fontSize: 14, fontFamily: font_description },
  475. reg_style21: { fontFamily: font_title },
  476. reg_style22: { color: colors.theme_bg },
  477. reg_style23: { width: "80%", alignSelf: "center" },
  478. reg_style24: { fontSize: 14, fontFamily: font_description },
  479. reg_style25: { fontFamily: font_title },
  480. reg_style26: { color: colors.theme_bg },
  481. reg_style27: { width: "80%", alignSelf: "center" },
  482. reg_style28: {
  483. color: "grey",
  484. fontWeight: "bold",
  485. fontSize: 15,
  486. marginLeft: "3%",
  487. fontFamily: font_description,
  488. },
  489. reg_style29: { height: 50, width: "100%" },
  490. reg_style30: { marginTop: "5%" },
  491. reg_style31: { width: "80%", alignSelf: "center" },
  492. reg_style32: {
  493. backgroundColor: colors.theme_bg,
  494. borderRadius: 5,
  495. height: 40,
  496. },
  497. reg_style33: {
  498. color: colors.theme_fg_three,
  499. fontFamily: font_title,
  500. letterSpacing: 0.5,
  501. },
  502. reg_style34: {
  503. marginTop: "5%",
  504. justifyContent: "flex-end",
  505. alignItems: "center",
  506. position: "relative",
  507. bottom: 0,
  508. },
  509. reg_style35: {
  510. fontSize: 15,
  511. color: colors.theme_bg_two,
  512. marginTop: "8%",
  513. fontFamily: font_description,
  514. marginBottom: 20,
  515. },
  516. reg_style36: { color: colors.theme_fg },
  517. container: { flex: 1, flexDirection: "column" },
  518. header: {
  519. justifyContent: "flex-start",
  520. height: "10%",
  521. backgroundColor: colors.theme_bg,
  522. borderBottomLeftRadius: 45,
  523. borderBottomRightRadius: 45,
  524. shadowOffset: { width: 0, height: 15 },
  525. shadowColor: colors.theme_bg,
  526. shadowOpacity: 0.1,
  527. shadowRadius: 8,
  528. elevation: 10,
  529. },
  530. header_card: {
  531. alignItems: "center",
  532. borderRadius: 15,
  533. justifyContent: "center",
  534. },
  535. header_card_item: {
  536. borderTopLeftRadius: 15,
  537. borderTopRightRadius: 15,
  538. borderBottomLeftRadius: 15,
  539. borderBottomRightRadius: 15,
  540. shadowOffset: { width: 0, height: 15 },
  541. shadowColor: colors.theme_bg,
  542. shadowOpacity: 0.1,
  543. shadowRadius: 8,
  544. elevation: 10,
  545. },
  546. text_field: {
  547. height: 40,
  548. borderBottomColor: colors.theme_bg,
  549. borderBottomWidth: 1.5,
  550. padding: 5,
  551. },
  552. forgot_password_container: {
  553. width: "95%",
  554. alignItems: "flex-end",
  555. },
  556. forgot_text: {
  557. fontSize: 15,
  558. color: colors.theme_fg_four,
  559. },
  560. forgot_password_container: {
  561. width: "80%",
  562. alignItems: "flex-end",
  563. },
  564. forgot_text: {
  565. fontSize: 15,
  566. color: colors.theme_fg_four,
  567. },
  568. back_icon: {
  569. color: colors.theme_bg_three,
  570. marginLeft: 15,
  571. },
  572. });