Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.46 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { StatusBar, View, StyleSheet, Image, AsyncStorage, Alert, } from "react-native";
  3. import { Container, Header, Title, Content, CardItem, Button, Left, Right, Body, Icon, Text, Card, Item, Picker, Thumbnail } from 'native-base';
  4. import { Col, Row, Grid } from 'react-native-easy-grid';
  5. import { Dimensions } from "react-native";
  6. import Footernya from "../../components/Footer";
  7. import moment from 'moment';
  8. import timezone from 'moment-timezone';
  9. import Moment from 'react-moment';
  10. import GlobalConfig from "../../components/GlobalConfig";
  11. import 'moment/locale/id';
  12.  
  13. class Home extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. dataDasboard: [],
  18. AbsenMasuk: "00:00:00",
  19. AbsenKeluar: "00:00:00",
  20. DateRealtime: new Date()
  21. };
  22. this.baseState = this.state;
  23. }
  24.  
  25. static navigationOptions = {
  26. headerShown: false
  27. };
  28.  
  29. componentDidMount() {
  30. this.resetState();
  31. setInterval(() => {
  32. this.setState({
  33. DateRealtime: new Date()
  34. })
  35. }, 900);
  36.  
  37. this._onFocusListener = this.props.navigation.addListener(
  38. "didFocus",
  39. payload => {
  40. this.resetState();
  41. }
  42. )
  43. }
  44.  
  45. resetState = () => {
  46. this.setState(this.baseState);
  47. AsyncStorage.getItem("dataPegawai").then(rowPegawai => {
  48. this.setState({
  49. dataDasboard: JSON.parse(rowPegawai)
  50. });
  51. });
  52. AsyncStorage.getItem("AbsenMasuk").then(rowAbsenMasuk => {
  53. this.setState({
  54. AbsenMasuk: JSON.parse(rowAbsenMasuk),
  55. });
  56. });
  57. AsyncStorage.getItem("AbsenKeluar").then(rowAbsenKeluar => {
  58. this.setState({
  59. AbsenKeluar: JSON.parse(rowAbsenKeluar),
  60. });
  61. });
  62.  
  63. }
  64.  
  65. // resetState = () => {
  66. // this.setState(initialState);
  67. // }
  68.  
  69. render() {
  70. const uri = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSGcxfdWbW21mRzk98NIssKFX_ExVo2LGnV4MizqE8gIu60-w01&s";
  71. const dateToFormat = moment(this.state.DateRealtime).format("dddd, D MMMM YYYY");
  72. const timeToFormat = moment(this.state.DateRealtime).format("HH:mm:ss");
  73. const dateNow = moment(this.state.DateRealtime).format("MMMM YYYY");
  74.  
  75. const jamMasuk = moment(this.state.dataDasboard.jamKerjaMasuk, "HH:mm:ss").format("HH");
  76. const menitMasuk = moment(this.state.dataDasboard.jamKerjaMasuk, "HH:mm:ss").format("mm");
  77. const jamKeluar = moment(this.state.dataDasboard.jamKerjaPulang, "HH:mm:ss").format("HH");
  78. const menitKeluar = moment(this.state.dataDasboard.jamKerjaPulang, "HH:mm:ss").format("mm");
  79.  
  80. const jamMasukAbsen = moment(this.state.AbsenMasuk, "HH:mm:ss").format("HH");
  81. const menitMasukAbsen = moment(this.state.AbsenMasuk, "HH:mm:ss").format("mm");
  82. const jamKeluarAbsen = moment(this.state.AbsenKeluar, "HH:mm:ss").format("HH");
  83. const menitKeluarAbsen = moment(this.state.AbsenKeluar, "HH:mm:ss").format("mm");
  84.  
  85. return (
  86. <Container>
  87. <StatusBar backgroundColor="#3669CF" />
  88. <Content>
  89.  
  90. <View style={{ backgroundColor: '#3669CF' }}>
  91. {/* <Text style={{ color: "white", fontSize: 14, marginLeft: 10 }}>Senin, 25 Maret 2020</Text> */}
  92. {/* <Text style={{ color: "white", fontSize: 14, marginLeft: 10 }}>{this.state.curTime}</Text> */}
  93. <Grid style={{ marginLeft: 10, marginRight: 10 }}>
  94. <Col>
  95. {/* <Text style={{ color: "white", fontSize: 14 }}>
  96. {moment.locale('id').tz(new Date(), 'Asia/Jakarta').format("dddd, D MMMM YYYY")
  97. }
  98. </Text> */}
  99. <Text tz="Asia/Jakarta" locale="id" interval={1000} style={{ color: "white", fontSize: 14 }}>{dateToFormat}</Text>
  100.  
  101. </Col>
  102. <Col>
  103. <Text tz="Asia/Jakarta" locale="id" interval={1000} style={{ color: "white", fontSize: 14, textAlign: 'right' }}>
  104. {timeToFormat}
  105. </Text>
  106. </Col>
  107. </Grid>
  108. {/* <Text style={{ marginLeft: 10 }}>
  109. <Text style={{ color: "white", fontSize: 14 }}>
  110. {moment(new Date()).format("dddd, D MM YYYY")
  111. }
  112. </Text>
  113. <Text style={{ color: "white", fontSize: 14, textAlign: 'left' }}>
  114. {moment(new Date()).format("hh:mm:ss")
  115. }
  116. </Text>
  117. </Text> */}
  118. </View>
  119. <View style={gaya.profile}>
  120. <Thumbnail large source={{ uri: uri }} style={{ marginTop: 15 }} />
  121. <Text style={{ color: "white", fontSize: 20, fontWeight: 'bold' }}>{this.state.dataDasboard.NamaPegawai}</Text>
  122. <Text style={{ color: "white", fontSize: 14, marginBottom: 15 }}>{this.state.dataDasboard.NamaOPD}</Text>
  123. </View>
  124. <Card style={gaya.roundedAtasbawah}>
  125. <CardItem style={gaya.roundedAtasbawah} >
  126. <Grid>
  127. <Row>
  128. <Grid>
  129. <Row>
  130. <View style={{
  131. backgroundColor: "#E3E5E7", borderTopLeftRadius: 10,
  132. borderTopRightRadius: 10,
  133. borderBottomLeftRadius: 10,
  134. borderBottomRightRadius: 10,
  135. width: "100%", height: "100%",
  136. justifyContent: 'center',
  137. alignItems: 'center',
  138. }}>
  139. <Text>
  140. <Text style={{ fontSize: 15, color: "#5E646E" }}>Absensi Bulan </Text>
  141. <Text style={{ fontWeight: "bold", color: "#3472CD" }}>{dateNow}</Text>
  142. </Text>
  143. </View>
  144. </Row>
  145. <Row>
  146. <Col>
  147. <Card style={gaya.centerVH}>
  148. <CardItem header style={[gaya.hadirHead, gaya.centerVH]}>
  149. <Text style={{ color: "white" }}>Hadir</Text>
  150. </CardItem>
  151. <CardItem style={[gaya.hadirIsi, gaya.centerVH]}>
  152. <Text style={{ color: 'white', fontSize: 70 }}>{this.state.dataDasboard.hadir}</Text>
  153. </CardItem>
  154. </Card>
  155. </Col>
  156. <Col>
  157. <Card style={gaya.centerVH}>
  158. <CardItem header style={[gaya.tdkhadirHead, gaya.centerVH]}>
  159. <Text style={{ color: "white" }}>Tidak Hadir</Text>
  160. </CardItem>
  161. <CardItem style={[gaya.tdkhadirIsi, gaya.centerVH]}>
  162. <Text style={{ color: 'white', fontSize: 70 }}>{this.state.dataDasboard.tidak_hadir}</Text>
  163. </CardItem>
  164. </Card>
  165. </Col>
  166. </Row>
  167. </Grid>
  168. </Row>
  169. <Row>
  170. <Grid>
  171. <Col style={{ width: "55%", height: "100%" }}>
  172. <Grid>
  173. <Col style={{ width: "30%", height: "100%", justifyContent: 'center', alignItems: 'center' }}>
  174. <Image source={require('../../assets/img/jam.png')} style={{ width: 50, height: 50 }} />
  175. </Col>
  176. <Col style={{ width: "70%", height: "100%", justifyContent: 'center' }}>
  177. <Text>Jam Kerja</Text>
  178. <Text>
  179. <Text style={gaya.fontJam}>{jamMasuk}</Text>
  180. <Text>.{menitMasuk}</Text>
  181. <Text style={gaya.fontJam}> - </Text>
  182. <Text style={gaya.fontJam}>{jamKeluar}</Text>
  183. <Text>.{menitKeluar}</Text>
  184. </Text>
  185. </Col>
  186. </Grid>
  187. </Col>
  188. <Col style={{ width: "45%", height: "100%", justifyContent: 'center', alignItems: 'center', }}>
  189. <Button rounded success style={{ height: "30%", width: "100%", marginBottom: 10 }}>
  190. <Text>
  191. <Text style={gaya.fontJamPPtipis}>Datang: </Text>
  192. <Text style={gaya.fontJamPP}>{this.state.AbsenMasuk === null ? "--" : jamMasukAbsen}</Text>
  193. <Text style={gaya.fontJamPPtipis}>.{this.state.AbsenMasuk === null ? "--" : menitMasukAbsen}</Text>
  194. </Text>
  195. </Button>
  196. <Button rounded warning style={{ height: "30%", width: "100%" }}>
  197. <Text>
  198. <Text style={gaya.fontJamPPtipis}>Pulang: </Text>
  199. <Text style={gaya.fontJamPP}>{this.state.AbsenKeluar === null ? "--" : jamKeluarAbsen}</Text>
  200. <Text style={gaya.fontJamPPtipis}>.{this.state.AbsenKeluar === null ? "--" : menitKeluarAbsen}</Text>
  201. </Text>
  202. </Button>
  203. </Col>
  204. </Grid>
  205. </Row>
  206. </Grid>
  207. </CardItem>
  208. </Card>
  209.  
  210.  
  211. <View style={gaya.centerVH} >
  212. <Button danger rounded onPress={() => this.props.navigation.navigate("Absensi")} style={{ height: 70 }}>
  213. <Text>Lakukan Absensi Sekarang</Text>
  214. </Button>
  215. </View>
  216.  
  217. </Content >
  218. <Footernya />
  219. </Container >
  220. );
  221. }
  222. }
  223. const gaya = StyleSheet.create({
  224. profile: {
  225. justifyContent: 'center',
  226. alignItems: 'center',
  227. backgroundColor: '#3669CF',
  228. borderBottomLeftRadius: 50,
  229. borderBottomRightRadius: 50
  230. },
  231. roundedAtasbawah: {
  232. borderTopLeftRadius: 30,
  233. borderTopRightRadius: 30,
  234. borderBottomLeftRadius: 30,
  235. borderBottomRightRadius: 30
  236. },
  237. centerVH: {
  238. justifyContent: 'center',
  239. alignItems: 'center',
  240. },
  241. hadirHead: {
  242. backgroundColor: '#3669CF',
  243. height: 20,
  244. width: "100%"
  245. },
  246. hadirIsi: {
  247. backgroundColor: '#4586EC',
  248. width: "100%",
  249. },
  250. tdkhadirHead: {
  251. backgroundColor: '#C0392B',
  252. height: 20,
  253. width: "100%"
  254. },
  255. tdkhadirIsi: {
  256. backgroundColor: '#E74C3C',
  257. width: "100%",
  258. },
  259. fontJam: {
  260. fontSize: 20,
  261. fontWeight: "bold"
  262. },
  263. fontJamPP: {
  264. color: "white",
  265. fontSize: 20,
  266. fontWeight: "bold"
  267. },
  268. fontJamPPtipis: {
  269. color: "white"
  270. }
  271. });
  272. export default Home;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement