DeptForm.js 2.63 KB
Newer Older
1
2
import React from 'react';
import { Button, View, TouchableWithoutFeedback, Keyboard } from 'react-native';
YoonDongMin's avatar
YDm    
YoonDongMin committed
3
4
5
6
7
import { globalStyles } from '../styles/global.js'
import { Formik } from 'formik';
import * as yup from 'yup';
import DatePicker from '../components/DatePicker.js';
import InputBox from '../components/InputBox';
8
import { getDateStr } from '../utils/dateFunction';
YoonDongMin's avatar
YDm    
YoonDongMin committed
9
10

const ReviewSchema = yup.object({
11
12
    date: yup.string()
        .required(),
YoonDongMin's avatar
YDm    
YoonDongMin committed
13
14
15
16
17
    message: yup.string()
        .required()
        .min(2),
    money: yup.number()
        .required(),
Choi Ga Young's avatar
Choi Ga Young committed
18
    repayment: yup.number()
YoonDongMin's avatar
YDm    
YoonDongMin committed
19
20
21
22
23
24
25
26
27
28
        .required()
})

function DeptForm({ addInfo }) {
    return (
        <TouchableWithoutFeedback onPress={() => {
            Keyboard.dismiss();
        }}>
            <View style={globalStyles.container} >
                <Formik
Choi Ga Young's avatar
Choi Ga Young committed
29
                    initialValues={{ date: getDateStr(), message: '', money: '', repayment: '' }}
YoonDongMin's avatar
YDm    
YoonDongMin committed
30
                    validationSchema={ReviewSchema}
31
                    onSubmit={(values) => {
YoonDongMin's avatar
YDm    
YoonDongMin committed
32
33
34
35
36
37
38
                        addInfo(values);
                    }}
                >
                    {({ handleChange, handleSubmit, values }) => (
                        <View>
                            <DatePicker
                                inputTitle='날짜'
Choi Ga Young's avatar
Choi Ga Young committed
39
                                date={values.date}
YoonDongMin's avatar
YDm    
YoonDongMin committed
40
41
42
43
44
45
46
47
                                setDate={handleChange('date')}
                            />
                            <InputBox
                                inputTitle="내용"
                                onChangeText={handleChange('message')}
                                value={values.message}
                            />
                            <InputBox
Choi Ga Young's avatar
Choi Ga Young committed
48
                                inputTitle="원금"
YoonDongMin's avatar
YDm    
YoonDongMin committed
49
50
51
52
53
                                onChangeText={handleChange('money')}
                                value={values.money}
                                keyboardType="numeric"
                            />
                            <InputBox
Choi Ga Young's avatar
Choi Ga Young committed
54
55
56
                                inputTitle="갚은 금액"
                                onChangeText={handleChange('repayment')}
                                value={values.repayment}
YoonDongMin's avatar
YDm    
YoonDongMin committed
57
58
59
60
                                keyboardType="numeric"
                            />

                            <View style={{ marginVertical: '10%', marginHorizontal: 10 }}>
61
                                <Button title='입력' color='dodgerblue' onPress={handleSubmit} />
YoonDongMin's avatar
YDm    
YoonDongMin committed
62
63
64
65
66
67
68
69
70
71
72
                            </View>

                        </View>
                    )}
                </Formik>
            </View >
        </TouchableWithoutFeedback>
    )
}

export default DeptForm;