infoForm.js 2.8 KB
Newer Older
YoonDongMin's avatar
DongM    
YoonDongMin committed
1
import React from 'react';
YoonDongMin's avatar
YdM    
YoonDongMin committed
2
import { StyleSheet, Button, TextInput, View, Text, TouchableWithoutFeedback, Keyboard } from 'react-native';
YoonDongMin's avatar
DongM    
YoonDongMin committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { globalStyles } from '../styles/global.js'
import { Formik } from 'formik';
import * as yup from 'yup';

const ReviewSchema = yup.object({
    date: yup.string() //string만 받는다
        .required()  //아무것도 입력안했하면 안받음
        .min(4),  //최소4글짜
    person: yup.string()
        .required()
        .min(2),
    money: yup.string()
        .required(),
    remained_money: yup.string()
        .required()
})




YoonDongMin's avatar
YdM    
YoonDongMin committed
23
function InfoForm({ addInfo }) {
YoonDongMin's avatar
DongM    
YoonDongMin committed
24
    return (
YoonDongMin's avatar
YdM    
YoonDongMin committed
25
26
27
28
29
30
31
32
        <TouchableWithoutFeedback onPress={() => {
            Keyboard.dismiss();
        }}>
            <View style={globalStyles.container} >
                <Formik
                    initialValues={{ date: '', person: '', money: '', remained_money: '' }}
                    validationSchema={ReviewSchema}
                    onSubmit={(values) => {//위의 4개의 val들을 전달
YoonDongMin's avatar
DongM    
YoonDongMin committed
33

YoonDongMin's avatar
YdM    
YoonDongMin committed
34
35
                        addInfo(values);
                    }}
YoonDongMin's avatar
DongM    
YoonDongMin committed
36

YoonDongMin's avatar
YdM    
YoonDongMin committed
37
                >
YoonDongMin's avatar
DongM    
YoonDongMin committed
38

YoonDongMin's avatar
YdM    
YoonDongMin committed
39
40
41
42
43
44
45
46
                    {({ handleChange, handleSubmit, values }) => (
                        <View>
                            <TextInput
                                style={globalStyles.input}
                                placeholder='날짜'
                                onChangeText={handleChange('date')} //우리가 바꾸려는 val
                                value={values.date}
                            />
YoonDongMin's avatar
DongM    
YoonDongMin committed
47

YoonDongMin's avatar
YdM    
YoonDongMin committed
48
49
50
51
52
53
                            <TextInput
                                style={globalStyles.input}
                                placeholder='누구에게'
                                onChangeText={handleChange('person')}
                                value={values.person}
                            />
YoonDongMin's avatar
DongM    
YoonDongMin committed
54

YoonDongMin's avatar
YdM    
YoonDongMin committed
55
56
57
58
59
60
61
                            <TextInput
                                style={globalStyles.input}
                                placeholder='금액'
                                onChangeText={handleChange('money')}
                                value={values.money}
                                keyboardType='numeric'
                            />
YoonDongMin's avatar
DongM    
YoonDongMin committed
62

YoonDongMin's avatar
YdM    
YoonDongMin committed
63
64
65
66
67
68
69
                            <TextInput
                                style={globalStyles.input}
                                placeholder='남은 금액'
                                onChangeText={handleChange('remained_money')}
                                value={values.remained_money}
                                keyboardType='numeric'
                            />
YoonDongMin's avatar
DongM    
YoonDongMin committed
70

YoonDongMin's avatar
YdM    
YoonDongMin committed
71
72
73
74
75
76
77
78
                            <Button title='입력' color='maroon' onPress={handleSubmit} />
                        </View>
                    )}

                </Formik>

            </View >
        </TouchableWithoutFeedback>
YoonDongMin's avatar
DongM    
YoonDongMin committed
79
80
81
    )
}

YoonDongMin's avatar
YdM    
YoonDongMin committed
82
export default InfoForm;