Modal1Component.js 5.73 KB
import React, {useState} from "react";
import {View, Text, Alert} from "react-native";
import {CheckBox} from "native-base";
import SquareButtonComponent from "../Base/SquareButtonComponent";
import {BUTTON_COLOR} from "../../constant";
import {resetLaneReducer} from "../../reducers/location";
import {useDispatch} from "react-redux";

const Modal1Component = (props) => {
    // 데이터
    const {setModalNumber, setShowButtons, setModalVisible, serviceStates, setServiceStates, selectKickServices} = props;
    const [showDetail, setShowDetail] = useState(true);

    // 함수
    const dispatch = useDispatch();
    const onPressCheckBox = (indexOfService) => {

        if (indexOfService === 1) {
            setServiceStates([...serviceStates.slice(0, indexOfService), !serviceStates[indexOfService], ...serviceStates.slice(indexOfService + 1)]);
        } else {
            setServiceStates([...serviceStates.slice(0, indexOfService), serviceStates[indexOfService], ...serviceStates.slice(indexOfService + 1)]);
        }
    };
    const onShowDetail = () => {
        setShowDetail(!showDetail);
    };
    const onDecideServices = () => {
        if (serviceStates.findIndex(v => v) === -1) {
            return Alert.alert('최소 하나 이상의 서비스를 선택하세요');
        }
        selectKickServices(serviceStates);
        setModalNumber(0);
        setShowButtons(true);
        setModalVisible(false);
        dispatch({type: resetLaneReducer});
    };

    // 렌더링
    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': 3, 'flexDirection': 'column'}}>
                <View style={{'flex': 1, 'flexDirection': 'row'}}>
                    <Text style={{fontSize: 16, fontWeight: 'bold', color: '#373737'}}>지쿠터(현재 미지원)</Text>
                    <CheckBox checked={serviceStates[0]} color="#4844ff"
                              onPress={() => onPressCheckBox(0)}/>
                </View>
                <View style={{'flex': 3, 'flexDirection': 'row'}}>
                    {!showDetail
                        ? <Text style={{fontSize: 16, color: '#373737'}}>#저렴한 가격 #최다 보유</Text>
                        : <Text style={{
                            fontSize: 15, color: '#373737'
                        }}>{`기본 1분 300 / 1분당 150\n최대 20km/h\n00-05시 새벽 할증 요금제`}</Text>}
                </View>
            </View>
            <View style={{'flex': 3, 'flexDirection': 'column'}}>
                <View style={{'flex': 1, 'flexDirection': 'row'}}>
                    <Text style={{fontSize: 16, fontWeight: 'bold', color: '#373737'}}>플라워 로드</Text>
                    <CheckBox checked={serviceStates[1]} color="#4844ff"
                              onPress={() => onPressCheckBox(1)}/>
                </View>
                <View style={{'flex': 3, 'flexDirection': 'row'}}>
                    {!showDetail
                        ? <Text style={{fontSize: 16, color: '#373737'}}>#빠른 속도</Text>
                        : <Text style={{
                            fontSize: 15, color: '#373737'
                        }}>{`기본 5분 1000/1분당 100\n최대 25km/h\n21시 이후 최대속도 18km 제한`}</Text>}
                </View>
            </View>
            <View style={{'flex': 3, 'flexDirection': 'column'}}>
                <View style={{'flex': 1, 'flexDirection': 'row'}}>
                    <Text style={{fontSize: 16, fontWeight: 'bold', color: '#373737'}}>씽씽(현재 미지원)</Text>
                    <CheckBox checked={serviceStates[2]} color="#4844ff"
                              onPress={() => onPressCheckBox(2)}/>
                </View>
                <View style={{'flex': 3, 'flexDirection': 'row'}}>
                    {!showDetail
                        ? <Text style={{fontSize: 16, color: '#373737'}}>#최신 기기</Text>
                        : <Text style={{
                            fontSize: 15, color: '#373737'
                        }}>{`평일/심야/주말 요금 상이\n최대 25km/h\n9월 말까지 50% 할인 행사중`}</Text>}
                </View>
            </View>
            <SquareButtonComponent
                onPress={onShowDetail}
                text={!showDetail ? '상세 정보 보기' : '간단 정보 보기'}
                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={onDecideServices}
                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>
    );
};

export default Modal1Component;