MemoForm.js 2.18 KB
Newer Older
YoonDongMin's avatar
YDm    
YoonDongMin committed
1
2
import React, { useState } from 'react';
import { StyleSheet, Button, View, Text, TouchableWithoutFeedback, Keyboard } from 'react-native';
YoonDongMin's avatar
YdM    
YoonDongMin committed
3
4
5
import { globalStyles } from '../styles/global.js'
import { Formik } from 'formik';
import * as yup from 'yup';
YoonDongMin's avatar
YDm    
YoonDongMin committed
6
7
import DatePicker from '../components/DatePicker.js';
import InputBox from '../components/InputBox.js';
YoonDongMin's avatar
YdM    
YoonDongMin committed
8
9

const ReviewSchema = yup.object({
YoonDongMin's avatar
YDm    
YoonDongMin committed
10
11
12
13
    // date: yup.string() //string만 받는다
    //     .required()  //아무것도 입력안했하면 안받음
    // ,  //최소4글짜
    message: yup.string()
YoonDongMin's avatar
YdM    
YoonDongMin committed
14
15
16
17
18
        .required()
        .min(2),

})

YoonDongMin's avatar
YDm    
YoonDongMin committed
19
20
21
22
const getDate = () => {
    var date = new Date();
    return (String(date.toJSON()).split(/T/)[0])
}
YoonDongMin's avatar
YdM    
YoonDongMin committed
23
24
25
26
27
28
29
30
31


function MemoForm({ addInfo }) {
    return (
        <TouchableWithoutFeedback onPress={() => {
            Keyboard.dismiss();
        }}>
            <View style={globalStyles.container} >
                <Formik
YoonDongMin's avatar
YDm    
YoonDongMin committed
32
                    initialValues={{ date: '', message: '' }}
YoonDongMin's avatar
YdM    
YoonDongMin committed
33
34
35
36
37
38
39
40
41
                    validationSchema={ReviewSchema}
                    onSubmit={(values) => {//위의 4개의 val들을 전달

                        addInfo(values);
                    }}

                >
                    {({ handleChange, handleSubmit, values }) => (
                        <View>
YoonDongMin's avatar
YDm    
YoonDongMin committed
42
43
44
45
                            <DatePicker
                                inputTitle='날짜'
                                date={values.date || getDate()}//오늘날짜 아니면 바뀐날짜
                                setDate={handleChange('date')}
YoonDongMin's avatar
YdM    
YoonDongMin committed
46
                            />
YoonDongMin's avatar
YDm    
YoonDongMin committed
47
48
49
50
                            <InputBox
                                inputTitle="내용"
                                onChangeText={handleChange('message')}
                                value={values.message}
YoonDongMin's avatar
YdM    
YoonDongMin committed
51
52
53

                            />

YoonDongMin's avatar
YDm    
YoonDongMin committed
54
55
56
                            <View style={{ marginVertical: '10%', marginHorizontal: 10 }}>
                                <Button title='입력' color='dodgerblue' onPress={handleSubmit} />
                            </View>
YoonDongMin's avatar
YdM    
YoonDongMin committed
57
58
59
60
61
62
63
64
65
66
67
                        </View>
                    )}

                </Formik>

            </View >
        </TouchableWithoutFeedback>
    )
}

export default MemoForm;