| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- // import { View, Text, StyleSheet, Pressable, TextInput } from 'react-native';
- // import NormalInput from '../../../global/normal_input';
- // import NormalButton from '../../../global/normal_button';
- // import { useEffect, useState } from 'react';
- // import useSignUpStore from '../../../../providers/signup_form_store';
- // import DropdownSelect from '../../../global/dropdown_select';
- // import { chargeStationService } from '../../../../service/chargeStationService';
- // import Checkbox from 'expo-checkbox';
- // type CarInformationProps = {
- // goToNextPage: () => void;
- // goToChooseCarPage: () => void;
- // };
- // const CarInformation: React.FC<CarInformationProps> = ({
- // goToNextPage,
- // goToChooseCarPage
- // }) => {
- // const { signUpFormData, setSignUpFormData } = useSignUpStore();
- // const [error, setError] = useState('');
- // const [isChecked, setChecked] = useState(false);
- // const [brandNameDropdownOptions, setBrandNameDropdownOptions] = useState(
- // []
- // );
- // const [brandData, setBrandData] = useState([]);
- // const [brandTypeDropdownOptions, setBrandTypeDropdownOptions] = useState([
- // {
- // label: '車輛型號',
- // value: '車輛型號'
- // }
- // ]);
- // useEffect(() => {
- // const fetchData = async () => {
- // try {
- // const result = await chargeStationService.fetchCarBrand();
- // setBrandData(result.data);
- // const brandInfo = result.data.map((item) => ({
- // name: item.name,
- // id: item.id,
- // img_url: item.img_url
- // }));
- // // console.log(JSON.stringify(brandInfo, null, 2));
- // const brandName = brandInfo.map((item) => item.name);
- // console.log(brandName);
- // const brandNameDropdownOptions = brandInfo.map((item) => ({
- // label: item.name,
- // value: item.id
- // }));
- // setBrandNameDropdownOptions(brandNameDropdownOptions);
- // } catch (error) {
- // console.log(error);
- // }
- // };
- // fetchData();
- // }, []);
- // useEffect(() => {
- // if (signUpFormData.selectedCarBrand) {
- // const selectedBrand = brandData.find(
- // (brand) => brand.id === signUpFormData.selectedCarBrand
- // );
- // if (selectedBrand && selectedBrand.car_types) {
- // const typeOptions = selectedBrand.car_types.map((carType) => ({
- // label: carType.name,
- // value: carType.id
- // }));
- // setBrandTypeDropdownOptions(typeOptions);
- // } else {
- // setBrandTypeDropdownOptions([]);
- // }
- // } else {
- // setBrandTypeDropdownOptions([]);
- // }
- // }, [signUpFormData.selectedCarBrand, brandData]);
- // const handleNext = () => {
- // if (
- // signUpFormData.selectedCarBrand === '0000' ||
- // signUpFormData.selectedCarSeries === '0000' ||
- // signUpFormData.licensePlate === '0000'
- // ) {
- // setError('請確保所有資料都已填寫。');
- // } else {
- // setError('');
- // goToNextPage();
- // }
- // };
- // return (
- // <>
- // <View style={styles.container}>
- // <Text style={styles.text}>您的車輛</Text>
- // <View
- // style={{
- // display: 'flex',
- // flexDirection: 'column',
- // gap: 10
- // }}
- // >
- // <View
- // style={{
- // display: 'flex',
- // flexDirection: 'column',
- // gap: 10
- // }}
- // >
- // <DropdownSelect
- // dropdownOptions={brandNameDropdownOptions}
- // placeholder={'車輛品牌'}
- // onSelect={(ID) => {
- // setSignUpFormData({
- // selectedCarBrand: ID
- // });
- // console.log(ID);
- // }}
- // extendedStyle={{
- // borderWidth: 1,
- // padding: 20,
- // borderRadius: 12,
- // borderColor: '#bbbbbb'
- // }}
- // />
- // <DropdownSelect
- // dropdownOptions={brandTypeDropdownOptions}
- // placeholder={'車輛品牌'}
- // onSelect={(carTypeID) =>
- // setSignUpFormData({
- // selectedCarSeries: carTypeID
- // })
- // }
- // extendedStyle={{
- // borderWidth: 1,
- // padding: 20,
- // borderRadius: 12,
- // borderColor: '#bbbbbb'
- // }}
- // />
- // <TextInput
- // style={styles.fakeTextInput}
- // onChangeText={(text) => {
- // setSignUpFormData({
- // licensePlate: text
- // });
- // // console.log(licensePlate);
- // }}
- // // value={signUpFormData.licensePlate}
- // placeholder="車輛牌照號碼"
- // placeholderTextColor="#888"
- // />
- // </View>
- // {/* <View className="flex-row items-center">
- // <Text className="mt-4 mb-4 text-lg">
- // 設置為預設車輛
- // </Text>
- // <Checkbox
- // style={styles.checkbox}
- // value={isChecked}
- // onValueChange={setChecked}
- // color={isChecked ? '#025c72' : undefined}
- // />
- // </View> */}
- // {/* <Pressable
- // style={styles.button}
- // onPress={goToChooseCarPage}
- // >
- // <TextInput
- // style={styles.fakeTextInput}
- // placeholder="車輛品牌"
- // editable={false}
- // pointerEvents="none"
- // ></TextInput>
- // <TextInput
- // style={styles.fakeTextInput}
- // placeholder="車輛型號"
- // editable={false}
- // pointerEvents="none"
- // ></TextInput>
- // <TextInput
- // style={styles.fakeTextInput}
- // placeholder="車輛號碼"
- // editable={false}
- // pointerEvents="none"
- // ></TextInput>
- // </Pressable> */}
- // <NormalButton
- // title={<Text style={{ color: '#fff' }}>下一步</Text>}
- // onPress={handleNext}
- // extendedStyle={{}}
- // />
- // {error && <Text style={styles.errorMessage}>{error}</Text>}
- // <NormalButton
- // title={<Text style={{ color: '#888888' }}>略過</Text>}
- // onPress={goToNextPage}
- // extendedStyle={{ backgroundColor: 'transparent' }}
- // />
- // </View>
- // </View>
- // </>
- // );
- // };
- // const styles = StyleSheet.create({
- // container: {
- // flex: 1,
- // marginHorizontal: 20
- // },
- // button: { flex: 1, gap: 10, marginTop: 5 },
- // fakeTextInput: {
- // maxWidth: '100%',
- // fontSize: 16,
- // borderWidth: 1,
- // padding: 20,
- // borderRadius: 12,
- // borderColor: '#bbbbbb'
- // },
- // text: {
- // fontSize: 20,
- // paddingBottom: 10
- // },
- // errorMessage: {
- // fontSize: 14,
- // color: '#ff0033',
- // fontWeight: '400',
- // marginLeft: 10,
- // marginTop: 10
- // },
- // checkbox: {
- // margin: 8
- // }
- // });
- // export default CarInformation;
- import { View, Text, StyleSheet, Pressable, TextInput } from 'react-native';
- import NormalInput from '../../../global/normal_input';
- import NormalButton from '../../../global/normal_button';
- import { useEffect, useState } from 'react';
- import useSignUpStore from '../../../../providers/signup_form_store';
- import DropdownSelect from '../../../global/dropdown_select';
- import { chargeStationService } from '../../../../service/chargeStationService';
- import Checkbox from 'expo-checkbox';
- import { router } from 'expo-router';
- import useVehicleStore from '../../../../providers/vehicle_store';
- type CarInformationProps = {
- goToNextPage: () => void;
- goToChooseCarPage: () => void;
- };
- const CarInformation: React.FC<CarInformationProps> = ({ goToNextPage, goToChooseCarPage }) => {
- const { signUpFormData, setSignUpFormData } = useSignUpStore();
- const [error, setError] = useState('');
- const [isChecked, setChecked] = useState(false);
- const [brandNameDropdownOptions, setBrandNameDropdownOptions] = useState([]);
- const [brandData, setBrandData] = useState([]);
- const [brandTypeDropdownOptions, setBrandTypeDropdownOptions] = useState([
- {
- label: '車輛型號',
- value: '車輛型號'
- }
- ]);
- const {
- vehicleBrand,
- vehicleModel,
- BrandID,
- ModelID,
- licensePlate,
- setVehicleBrand,
- setVehicleModel,
- setBrandID,
- setModelID,
- setLicensePlate
- } = useVehicleStore();
- useEffect(() => {
- const fetchData = async () => {
- try {
- const result = await chargeStationService.fetchCarBrand();
- setBrandData(result.data);
- const brandInfo = result.data.map((item) => ({
- name: item.name,
- id: item.id,
- img_url: item.img_url
- }));
- // console.log(JSON.stringify(brandInfo, null, 2));
- const brandName = brandInfo.map((item) => item.name);
- console.log(brandName);
- const brandNameDropdownOptions = brandInfo.map((item) => ({
- label: item.name,
- value: item.id
- }));
- setBrandNameDropdownOptions(brandNameDropdownOptions);
- } catch (error) {
- console.log(error);
- }
- };
- fetchData();
- }, []);
- useEffect(() => {
- if (signUpFormData.selectedCarBrand) {
- const selectedBrand = brandData.find((brand) => brand.id === signUpFormData.selectedCarBrand);
- if (selectedBrand && selectedBrand.car_types) {
- const typeOptions = selectedBrand.car_types.map((carType) => ({
- label: carType.name,
- value: carType.id
- }));
- setBrandTypeDropdownOptions(typeOptions);
- } else {
- setBrandTypeDropdownOptions([]);
- }
- } else {
- setBrandTypeDropdownOptions([]);
- }
- }, [signUpFormData.selectedCarBrand, brandData]);
- //HERE I need to get car information, and the final create wallet i need to get car information
- const handleNext = () => {
- if (
- BrandID === '' ||
- ModelID === '' ||
- signUpFormData.licensePlate === '0000' ||
- signUpFormData.licensePlate === ''
- ) {
- setError('請確保所有資料都已填寫。');
- } else {
- setError('');
- goToNextPage();
- }
- };
- return (
- <>
- <View style={styles.container}>
- <Text style={styles.text}>您的車輛</Text>
- <View
- style={{
- display: 'flex',
- flexDirection: 'column',
- gap: 10
- }}
- >
- <View
- style={{
- display: 'flex',
- flexDirection: 'column',
- gap: 10
- }}
- >
- <Pressable
- style={styles.button}
- onPress={() => router.push('(public)/registerChooseVehiclesOne')}
- >
- <TextInput
- style={styles.fakeTextInput}
- placeholder={vehicleBrand ? vehicleBrand : '車輛品牌'}
- editable={false}
- pointerEvents="none"
- ></TextInput>
- <TextInput
- style={styles.fakeTextInput}
- placeholder={vehicleModel ? vehicleModel : '車輛型號'}
- editable={false}
- pointerEvents="none"
- ></TextInput>
- </Pressable>
- <TextInput
- style={styles.fakeTextInput}
- onChangeText={(text) => {
- setSignUpFormData({
- licensePlate: text.toUpperCase()
- });
- // console.log(licensePlate);
- }}
- // value={signUpFormData.licensePlate}
- placeholder="車輛牌照號碼"
- autoCapitalize="characters"
- placeholderTextColor="#888"
- />
- </View>
- <NormalButton
- title={<Text style={{ color: '#fff' }}>下一步</Text>}
- onPress={handleNext}
- extendedStyle={{}}
- />
- {error && <Text style={styles.errorMessage}>{error}</Text>}
- <NormalButton
- title={<Text style={{ color: '#888888' }}>略過</Text>}
- onPress={goToNextPage}
- extendedStyle={{ backgroundColor: 'transparent' }}
- />
- </View>
- </View>
- </>
- );
- };
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- marginHorizontal: 20
- },
- button: { flex: 1, gap: 10, marginTop: 5 },
- fakeTextInput: {
- maxWidth: '100%',
- fontSize: 16,
- borderWidth: 1,
- padding: 20,
- borderRadius: 12,
- borderColor: '#bbbbbb'
- },
- text: {
- fontSize: 20,
- paddingBottom: 10
- },
- errorMessage: {
- fontSize: 14,
- color: '#ff0033',
- fontWeight: '400',
- marginLeft: 10,
- marginTop: 10
- },
- checkbox: {
- margin: 8
- }
- });
- export default CarInformation;
|