Modal2Component.js 4.93 KB
import React from 'react';
import {View, Text} from 'react-native';
import {useDispatch} from "react-redux";
import {setStartLocationSaga, setEndLocationSaga} from "../../reducers/location";
import TextInputComponent from "../Base/TextInputComponent";
import SquareButtonComponent from "../Base/SquareButtonComponent";
import {BUTTON_COLOR} from "../../constant";

const Modal2Component = (props) => {
    // 데이터
    const {closeModal, setShowButtons, setModalVisible, serviceStates, setModalNumber, startTextLocation, endTextLocation, setStartTextLocation, setEndTextLocation} = props;

    // 함수
    const dispatch = useDispatch();
    const onChangeStartLocation = (text) => {
        setStartTextLocation(text);
    };
    const onChangeFinishLocation = (text) => {
        setEndTextLocation(text);
    };
    const setLocation = async () => {
        try {
            if (startTextLocation && endTextLocation) {
                await dispatch({
                    type: setStartLocationSaga,
                    data: {
                        startTextLocation,
                    }
                });
                await dispatch({
                    type: setEndLocationSaga,
                    data: {
                        endTextLocation
                    }
                });
                if (serviceStates.findIndex(serviceState => serviceState) === -1) {
                    setModalNumber(2);
                    setShowButtons(false);
                    setModalVisible(true);
                } else {
                    setModalNumber(0);
                    setShowButtons(true);
                    setModalVisible(false);
                }
            }
        } catch (e) {
            console.error(e);
        }
    };
    const close = () => {
        closeModal();
    };

    // 렌더링
    return (
        <View style={{'flex': 1, width: 270}}>
            <View style={{'flex': 1, 'flexDirection': 'column', marginBottom: 15}}>
                <Text style={{fontSize: 24, fontWeight: 'bold', textAlign: 'center', color: '#373737'}}>
                    출발  도착 설정
                </Text>
            </View>
            <View style={{'flex': 9, 'flexDirection': 'column'}}>
                <TextInputComponent
                    onChangeText={onChangeStartLocation}
                    value={startTextLocation}
                    secureTextEntry={false}
                    placeholder={'출발 장소를 입력하세요'}
                    style1={{
                        marginLeft: 0,
                        marginRight: 0,
                        marginTop: 0,
                        marginBottom: 0,
                        padding: 15,
                    }}
                    style2={{
                        marginLeft: 15,
                        marginRight: 15,
                    }}
                />
                <TextInputComponent
                    onChangeText={onChangeFinishLocation}
                    value={endTextLocation}
                    secureTextEntry={false}
                    placeholder={'도착 장소를 입력하세요'}
                    style1={{
                        marginLeft: 0,
                        marginRight: 0,
                        marginTop: 0,
                        marginBottom: 0,
                        padding: 15,
                    }}
                    style2={{
                        marginLeft: 15,
                        marginRight: 15,
                    }}
                />
                <SquareButtonComponent
                    onPress={setLocation}
                    text={'출발지와 도착지 결정'}
                    style1={{
                        marginLeft: 0,
                        marginRight: 0,
                        marginTop: 10,
                        marginBottom: 0,
                        padding: 10,
                        borderRadius: 3,
                        backgroundColor: BUTTON_COLOR
                    }}
                    style2={{
                        fontSize: 16,
                        fontWeight: 'bold',
                        textAlign: 'center',
                        color: '#ffffff'
                    }}
                />
                <SquareButtonComponent
                    onPress={close}
                    text={'닫기'}
                    style1={{
                        marginLeft: 0,
                        marginRight: 0,
                        marginTop: 10,
                        marginBottom: 0,
                        padding: 10,
                        borderRadius: 3,
                        backgroundColor: BUTTON_COLOR
                    }}
                    style2={{
                        fontSize: 16,
                        fontWeight: 'bold',
                        textAlign: 'center',
                        color: '#ffffff'
                    }}
                />
            </View>
        </View>
    )
};

export default Modal2Component;