DeptDetails.js 3.08 KB
Newer Older
YoonDongMin's avatar
YdM    
YoonDongMin committed
1
import React, { useEffect, useState } from 'react';
2
import { StyleSheet, View, TouchableWithoutFeedback, Keyboard } from 'react-native';
YoonDongMin's avatar
YdM    
YoonDongMin committed
3
4
import InputBox from '../components/InputBox';
import StyledButton from '../components/StyledButton';
YoonDongMin's avatar
YDm    
YoonDongMin committed
5
6
import DatePicker from '../components/DatePicker.js';
import deptApi from '../db/deptPage.api';
7
import { getDateStr } from '../utils/dateFunction';
YoonDongMin's avatar
DongM    
YoonDongMin committed
8

YoonDongMin's avatar
YDm    
YoonDongMin committed
9
10
function DeptDetails({ route, navigation }) {
    const { item, loadLoan } = route.params
11
12
13
    const getDates = () => {
        const date = new Date();
        return (getDateStr(date))
YoonDongMin's avatar
YDm    
YoonDongMin committed
14
    }
15
    const [date, setDate] = useState(getDates())
YoonDongMin's avatar
YDm    
YoonDongMin committed
16
    const [message, setMessage] = useState('')
YoonDongMin's avatar
YdM    
YoonDongMin committed
17
18
    const [money, setMoney] = useState('')
    const [remained_money, setRemained_money] = useState('')
YoonDongMin's avatar
YDm    
YoonDongMin committed
19

YoonDongMin's avatar
YdM    
YoonDongMin committed
20
    useEffect(() => {
YoonDongMin's avatar
YDm    
YoonDongMin committed
21
22
23
24
        setDate(String(item.date))
        setMessage(item.message)
        setMoney(String(item.money))
        setRemained_money(String(item.remained_money))
YoonDongMin's avatar
YdM    
YoonDongMin committed
25
    }, [])
YoonDongMin's avatar
DongM    
YoonDongMin committed
26

YoonDongMin's avatar
YDm    
YoonDongMin committed
27
28
29
30
31
    const onUpdateHandle = async () => {
        await deptApi.updateDept({ date, message, money, remained_money }, item.id)
        loadLoan()
        navigation.navigate('DeptPage')
    }
YoonDongMin's avatar
DongM    
YoonDongMin committed
32
    return (
YoonDongMin's avatar
YdM    
YoonDongMin committed
33
34
35
36
        <TouchableWithoutFeedback onPress={() => {
            Keyboard.dismiss();
        }}>
            <View style={{ flex: 1 }}>
YoonDongMin's avatar
YDm    
YoonDongMin committed
37
38
                <View style={style.Font}>
                    <DatePicker
YoonDongMin's avatar
YdM    
YoonDongMin committed
39
                        inputTitle="날짜"
YoonDongMin's avatar
YDm    
YoonDongMin committed
40
41
                        date={date}
                        setDate={setDate}
YoonDongMin's avatar
YdM    
YoonDongMin committed
42
43
                    />
                    <InputBox
YoonDongMin's avatar
YDm    
YoonDongMin committed
44
45
                        inputTitle="내용"
                        value={message}
YoonDongMin's avatar
YdM    
YoonDongMin committed
46
                        onChangeText={
YoonDongMin's avatar
YDm    
YoonDongMin committed
47
                            (message) => setMessage(message)
YoonDongMin's avatar
YdM    
YoonDongMin committed
48
49
50
51
52
53
54
55
56
57
58
59
60
                        }
                    />
                    <InputBox
                        inputTitle="금액"
                        value={money}
                        onChangeText={
                            (money) => setMoney(money)
                        }
                    />
                    <InputBox
                        inputTitle="남은 금액"
                        value={remained_money}
                        onChangeText={
YoonDongMin's avatar
YDm    
YoonDongMin committed
61
                            (remained_money) => setRemained_money(remained_money)
YoonDongMin's avatar
YdM    
YoonDongMin committed
62
63
64
65
66
67
                        }
                    />
                </View>
                <View style={style.buttonRow}>
                    <StyledButton
                        name="수정"
YoonDongMin's avatar
YDm    
YoonDongMin committed
68
                        onPress={() => { onUpdateHandle() }}
YoonDongMin's avatar
YdM    
YoonDongMin committed
69
70
71
72
73
                        style={style.submitButton}
                    />
                </View>
            </View>
        </TouchableWithoutFeedback>
YoonDongMin's avatar
DongM    
YoonDongMin committed
74
75
76
    )
}

YoonDongMin's avatar
YdM    
YoonDongMin committed
77
78
const style = StyleSheet.create({

YoonDongMin's avatar
YDm    
YoonDongMin committed
79
80
81
82
    Font: {
        fontFamily: 'GowunDodum-Regular'
    },

YoonDongMin's avatar
YdM    
YoonDongMin committed
83
    buttonRow: {
YoonDongMin's avatar
YDm    
YoonDongMin committed
84
        fontFamily: 'GowunDodum-Regular',
YoonDongMin's avatar
YdM    
YoonDongMin committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
        flexDirection: 'row',
        alignItems: "center",
        marginHorizontal: 10,
        marginVertical: 3,
    },
    submitButton: {
        flex: 1,
        height: 50,
    },
    cancelButton: {
        flex: 1,
        height: 50,
    }
});

YoonDongMin's avatar
YDm    
YoonDongMin committed
100
export default DeptDetails;