CalDetail.js 1.97 KB
Newer Older
1
import React, { useEffect, useState } from 'react';
2
import { SafeAreaView, View, Text, StyleSheet, FlatList } from 'react-native';
3
4
import calApi from './db/calendarInfo.api';
const DetailItem = ({ item }) => {
5

6
  return (
7
8
    <>
      <View style={{
9
10
11
        flexDirection: "row", padding: "5%", borderColor: '#d3d3d3', //light grey
        borderWidth: 1, borderTopWidth: 0,
      }}>
Choi Ga Young's avatar
Choi Ga Young committed
12
13
        <Text style={[style.itemText, item.type === 1 ? style.inputColor : style.outputColor]}>{item.category}</Text>
        <Text style={[style.itemTextNum, style.Font]}>{item.contents}</Text>
Choi Ga Young's avatar
Choi Ga Young committed
14
        <Text style={[style.itemTextNum, style.Font]}>{(item.price).toLocaleString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}</Text>
15
16
17
18
      </View>
    </>
  );
};
Choi Ga Young's avatar
Choi Ga Young committed
19

Choi Ga Young's avatar
Choi Ga Young committed
20
const DetailInfo = ({ route }) => {
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  const [resData, setResData] = useState([])
  const getDetailData = async () => {
    try {
      const resdata = await calApi.detailData({ findDate: route.params })
      setResData(resdata)
    } catch (error) {
      console.log('error in getDetailData', error)
    }
  }
  const renderDetail = ({ item }) => {
    return (
      <DetailItem item={item} />
    )
  }
  useEffect(() => {
    getDetailData()
  }, [])
Choi Ga Young's avatar
Choi Ga Young committed
38
39
  return (
    <>
40
      <SafeAreaView>
41
        {
Choi Ga Young's avatar
Choi Ga Young committed
42
          resData.length !== 0 ? <FlatList
43
44
45
            data={resData}
            renderItem={renderDetail}
            keyExtractor={item => item.id}
Choi Ga Young's avatar
Choi Ga Young committed
46
          /> : <View style={{ margin: "20%" }}> 
Choi Ga Young's avatar
Choi Ga Young committed
47
            <Text style={{ textAlign: "center", fontSize: 20, fontFamily: 'GowunDodum-Regular' }}>내역이 없습니다.</Text>
48
          </View>
Choi Ga Young's avatar
Choi Ga Young committed
49
        } 
50
      </SafeAreaView>
Choi Ga Young's avatar
Choi Ga Young committed
51
    </>
Choi Ga Young's avatar
Choi Ga Young committed
52
53
54
55
  )
}
const style = StyleSheet.create({
  Font: {
56
57
58
59
60
61
62
63
64
    fontSize: 20,
    color: '#424242'
  },
  inputColor: {
    color: '#1E90FF'
  },
  outputColor: {
    color: '#dc143c'
  },
Choi Ga Young's avatar
Choi Ga Young committed
65
66
  itemTextNum: {
    flex: 1,
Choi Ga Young's avatar
Choi Ga Young committed
67
68
    textAlign: "center",
    fontFamily: 'GowunDodum-Regular'
Choi Ga Young's avatar
Choi Ga Young committed
69
  },
70
  itemText: {
Choi Ga Young's avatar
Choi Ga Young committed
71
72
    flex: 1,
    fontFamily: 'GowunDodum-Regular'
Choi Ga Young's avatar
Choi Ga Young committed
73
74
75
76
  }
});

export default DetailInfo;