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.
 
 

432 lines
12 KiB

  1. import React, { Component } from "react";
  2. import * as colors from "../assets/css/Colors";
  3. import {
  4. StyleSheet,
  5. Text,
  6. View,
  7. Image,
  8. FlatList,
  9. TouchableOpacity,
  10. Alert,
  11. } from "react-native";
  12. import Moment from "moment";
  13. import { CommonActions } from "@react-navigation/native";
  14. import FontAwesome from "react-native-vector-icons/FontAwesome";
  15. import {
  16. Container,
  17. Header,
  18. Content,
  19. Left,
  20. Body,
  21. Right,
  22. Title,
  23. Button,
  24. Icon,
  25. Row,
  26. Col,
  27. Card,
  28. CardItem,
  29. Thumbnail,
  30. Form,
  31. Textarea,
  32. Footer,
  33. } from "native-base";
  34. import {
  35. doctor_image,
  36. create_booking,
  37. api_url,
  38. font_title,
  39. font_description,
  40. check_available_timing,
  41. api_url1,
  42. } from "../config/Constants";
  43. import QB from "quickblox-react-native-sdk";
  44. import { Loader } from "../components/GeneralComponents";
  45. import DateTimePicker from "react-native-modal-datetime-picker";
  46. import axios from "axios";
  47. import { connect } from "react-redux";
  48. import RazorpayCheckout from "react-native-razorpay";
  49. import { Input } from "react-native-elements";
  50. import back from "../assets/icons/back1.png";
  51. import time from "../assets/icons/time.png";
  52. export default class CreateAppointment extends Component {
  53. constructor(props) {
  54. super(props);
  55. this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
  56. this.state = {
  57. description: "",
  58. title: "",
  59. deliveryDatePickerVisible: false,
  60. delivery_date: "",
  61. delivery_time: "",
  62. start_time: "",
  63. doctor_id: this.props.route.params.id,
  64. type: this.props.route.params.type,
  65. price_per_conversation: this.props.route.params.price_per_conversation,
  66. isLoding: false,
  67. };
  68. }
  69. handleBackButtonClick = () => {
  70. this.props.navigation.goBack(null);
  71. };
  72. create_booking = async () => {
  73. this.setState({ isLoding: true });
  74. await axios({
  75. method: "post",
  76. url: `${api_url1}/doctor_booking/`,
  77. data: {
  78. // patient_id: global.id,
  79. doctor_id: this.state.doctor_id,
  80. start_time: this.state.start_time,
  81. // payment_mode:2,
  82. title: this.state.title,
  83. description: this.state.description,
  84. // total_amount: this.state.price_per_conversation,
  85. // booking_type: this.state.type },
  86. appointmentMode: "online",
  87. },
  88. })
  89. .then(async (response) => {
  90. this.setState({ isLoding: false });
  91. if (response.data.status == 0) {
  92. alert(response.data.message);
  93. } else {
  94. this.setState({ title: "", description: "", start_time: "" });
  95. }
  96. if (response.data.status == 1) {
  97. await Alert.alert(
  98. "Success",
  99. "Your order has been successfully placed.",
  100. [{ text: "OK", onPress: () => this.my_orders() }],
  101. { cancelable: false }
  102. );
  103. }
  104. })
  105. .catch((error) => {
  106. alert("something went wrong");
  107. this.setState({ isLoding: false });
  108. });
  109. };
  110. check_timing = async () => {
  111. this.setState({ isLoding: true });
  112. await axios({
  113. method: "post",
  114. url: api_url + check_available_timing,
  115. data: {
  116. doctor_id: this.state.doctor_id,
  117. start_time: this.state.start_time,
  118. booking_type: this.state.type,
  119. },
  120. })
  121. .then(async (response) => {
  122. this.setState({ isLoding: false });
  123. if (response.data.status == 0) {
  124. alert(response.data.message);
  125. } else {
  126. this.make_payment();
  127. }
  128. })
  129. .catch((error) => {
  130. alert("something went wrong");
  131. this.setState({ isLoding: false });
  132. });
  133. };
  134. check_validation = async () => {
  135. // if(this.state.title == ""){
  136. // alert('Please write title');
  137. // }else if(this.state.description == ""){
  138. // alert('Please write description');
  139. // }else if(this.state.start_time == ""){
  140. // alert('Please choose booking time');
  141. // }else{
  142. // this.check_timing();
  143. // }
  144. await axios.post(
  145. `${api_url1}/doctor_booking/`,
  146. {
  147. doctor: this.state.doctor_id,
  148. // this.state.doctor_id,
  149. // doctor: this.state.phone_number,
  150. description: this.state.description,
  151. // this.state.description,
  152. title: this.state.title,
  153. // this.state.password,
  154. appointmentTime: this.state.start_time,
  155. appointmentMode: "online",
  156. //"2021-12-10T08:40:08.675+00:00",
  157. // this.state.start_time,
  158. // Authorization: `Bearer ${global.fcm_token}`,
  159. },
  160. { headers: { Authorization: `Bearer ${global.fcm_token}` } }
  161. );
  162. // .then((res) => console.log(res.data));
  163. alert("Appointment fixed");
  164. this.props.navigation.navigate("Home");
  165. };
  166. make_payment = () => {
  167. var options = {
  168. currency: global.currency_short_code,
  169. key: global.razorpay_key,
  170. amount: this.state.price_per_conversation * 100,
  171. name: global.application_name,
  172. prefill: {
  173. email: global.email,
  174. contact: global.phone_number,
  175. name: global.customer_name,
  176. },
  177. theme: { color: colors.theme_fg },
  178. };
  179. RazorpayCheckout.open(options)
  180. .then(() => {
  181. this.create_booking();
  182. })
  183. .catch((error) => {
  184. alert("Your transaction declined");
  185. });
  186. };
  187. my_orders = () => {
  188. this.props.navigation.navigate("MyOrders");
  189. };
  190. showDeliveryDatePicker = () => {
  191. this.setState({ deliveryDatePickerVisible: true });
  192. };
  193. hideDeliveryDatePicker = () => {
  194. this.setState({ deliveryDatePickerVisible: false });
  195. };
  196. handleDeliveryDatePicked = async (date) => {
  197. var d = new Date(date);
  198. let delivery_date =
  199. d.getFullYear() +
  200. "-" +
  201. ("0" + (d.getMonth() + 1)).slice(-2) +
  202. "-" +
  203. d.getDate();
  204. // 2021-12-10T08:40:08.675+00:00
  205. let hr = d.getHours();
  206. let min = d.getMinutes();
  207. if (min < 10) {
  208. min = "0" + min;
  209. }
  210. let ampm = "AM";
  211. if (hr > 12) {
  212. hr -= 12;
  213. ampm = "PM";
  214. }
  215. let delivery_time = hr + ":" + min + " " + ampm;
  216. let start_time = delivery_date + " " + delivery_time;
  217. this.setState({
  218. start_time: start_time,
  219. delivery_date: delivery_date,
  220. deliveryDatePickerVisible: false,
  221. delivery_time: delivery_time,
  222. });
  223. };
  224. AppointmentList = () => {
  225. this.props.navigation.navigate("AppointmentDetail");
  226. };
  227. render() {
  228. return (
  229. <Container>
  230. <View>
  231. <View style={styles.create_style1}>
  232. <TouchableOpacity
  233. style={styles.create_style2}
  234. onPress={this.handleBackButtonClick}
  235. activeOpacity={1}
  236. >
  237. <Image
  238. style={{
  239. width: 20,
  240. height: 20,
  241. backgroundColor: "white",
  242. marginVertical: 12,
  243. }}
  244. source={back}
  245. />
  246. {/* <Icon
  247. onPress={this.handleBackButtonClick}
  248. style={styles.create_style3}
  249. name="arrow-back"
  250. /> */}
  251. </TouchableOpacity>
  252. <View style={styles.create_style4} />
  253. <Text style={styles.create_style5}>New Appointment</Text>
  254. </View>
  255. </View>
  256. <Content padder>
  257. <View style={styles.create_style6} />
  258. {/* <Text>{console.log(this.state.doctor)}</Text> */}
  259. {/* <Text>dr id{this.state.doctor_id}</Text> */}
  260. <Input
  261. inputStyle={styles.create_style7}
  262. label="Title"
  263. labelStyle={styles.create_style8}
  264. placeholder="I have viral fever last two days..."
  265. onChangeText={(TextInputValue) =>
  266. this.setState({ title: TextInputValue })
  267. }
  268. />
  269. {/* <Text>{this.state.title}</Text> */}
  270. <View style={styles.create_style9} />
  271. <Input
  272. inputStyle={styles.create_style10}
  273. label="Description"
  274. labelStyle={styles.create_style11}
  275. placeholder="Write short description..."
  276. onChangeText={(TextInputValue) =>
  277. this.setState({ description: TextInputValue })
  278. }
  279. />
  280. {/* <Text>{this.state.description}</Text> */}
  281. <View style={styles.create_style12} />
  282. <Row>
  283. <Body>
  284. <Button
  285. onPress={this.showDeliveryDatePicker}
  286. style={{ width: 100 }}
  287. transparent
  288. >
  289. {/* <Icon style={styles.create_style13} name="time" /> */}
  290. <Image
  291. style={{
  292. width: 40,
  293. height: 40,
  294. backgroundColor: "white",
  295. marginVertical: 12,
  296. marginLeft:19
  297. }}
  298. source={time}
  299. />
  300. </Button>
  301. <Text style={styles.create_style14}>
  302. (Select your date & time)
  303. </Text>
  304. <View style={styles.create_style15} />
  305. <Text style={styles.create_style16}>{this.state.start_time}</Text>
  306. <DateTimePicker
  307. isVisible={this.state.deliveryDatePickerVisible}
  308. onConfirm={this.handleDeliveryDatePicked}
  309. onCancel={this.hideDeliveryDatePicker}
  310. minimumDate={new Date()}
  311. mode="datetime"
  312. />
  313. </Body>
  314. </Row>
  315. <Loader visible={this.state.isLoding} />
  316. </Content>
  317. <Footer style={styles.create_style17}>
  318. <TouchableOpacity
  319. activeOpacity={1}
  320. style={styles.create_style18}
  321. onPress={this.check_validation}
  322. >
  323. <Row>
  324. <Col style={styles.create_style19}>
  325. <Text style={styles.create_style20}>SUBMIT</Text>
  326. </Col>
  327. </Row>
  328. </TouchableOpacity>
  329. </Footer>
  330. </Container>
  331. );
  332. }
  333. }
  334. const styles = StyleSheet.create({
  335. create_style1: { alignItems: "flex-start", margin: 10 },
  336. create_style2: { width: 100, justifyContent: "center" },
  337. create_style3: { color: colors.theme_fg_two, fontSize: 30 },
  338. create_style4: { margin: 5 },
  339. create_style5: {
  340. fontSize: 25,
  341. color: colors.theme_fg_two,
  342. fontFamily: font_title,
  343. },
  344. create_style6: { margin: 10 },
  345. create_style7: { fontSize: 14 },
  346. create_style8: { fontFamily: font_title },
  347. create_style9: { margin: 10 },
  348. create_style10: { fontSize: 14, height: 80 },
  349. create_style11: { fontFamily: font_title },
  350. create_style12: { margin: 10 },
  351. create_style13: { fontSize: 50, color: colors.theme_fg },
  352. create_style14: {
  353. fontSize: 12,
  354. color: colors.grey,
  355. fontFamily: font_description,
  356. },
  357. create_style15: { margin: 10 },
  358. create_style16: { fontFamily: font_description },
  359. create_style17: { backgroundColor: "transparent" },
  360. create_style18: { width: "100%", backgroundColor: colors.theme_bg },
  361. create_style19: { alignItems: "center", justifyContent: "center" },
  362. create_style20: {
  363. color: colors.theme_fg_three,
  364. fontFamily: font_title,
  365. fontSize: 18,
  366. },
  367. header: {
  368. justifyContent: "flex-start",
  369. height: "10%",
  370. backgroundColor: colors.theme_bg,
  371. borderBottomLeftRadius: 45,
  372. borderBottomRightRadius: 45,
  373. shadowOffset: { width: 0, height: 15 },
  374. shadowColor: colors.theme_bg,
  375. shadowOpacity: 0.1,
  376. shadowRadius: 8,
  377. elevation: 10,
  378. },
  379. header_card: {
  380. alignItems: "center",
  381. borderRadius: 15,
  382. justifyContent: "center",
  383. },
  384. header_card_item: {
  385. borderTopLeftRadius: 15,
  386. borderTopRightRadius: 15,
  387. borderBottomLeftRadius: 15,
  388. borderBottomRightRadius: 15,
  389. shadowOffset: { width: 0, height: 15 },
  390. shadowColor: colors.theme_bg,
  391. shadowOpacity: 0.1,
  392. shadowRadius: 8,
  393. elevation: 10,
  394. },
  395. icon: {
  396. color: colors.theme_fg_two,
  397. },
  398. header_body: {
  399. flex: 3,
  400. justifyContent: "center",
  401. },
  402. title: {
  403. alignSelf: "center",
  404. color: colors.theme_fg_two,
  405. alignSelf: "center",
  406. fontSize: 16,
  407. fontFamily: font_title,
  408. },
  409. prescription_image: {
  410. width: 100,
  411. height: 70,
  412. alignSelf: "center",
  413. borderColor: colors.theme_bg_three,
  414. borderWidth: 1,
  415. },
  416. });