registerChooseVehiclesTwo.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. interface CarModel {
  2. name: string;
  3. year: number;
  4. id: string;
  5. }
  6. import React, { useEffect, useState } from 'react';
  7. import { View, Text, Image, Pressable, StyleSheet, ScrollView } from 'react-native';
  8. import { FlashList } from '@shopify/flash-list';
  9. import { router, useLocalSearchParams } from 'expo-router';
  10. import { SafeAreaView } from 'react-native-safe-area-context';
  11. import { useNavigation } from '@react-navigation/native';
  12. import { set } from 'date-fns';
  13. import useVehicleStore from '../../providers/vehicle_store';
  14. import { PreviousPageBlackSvg } from '../../component/global/SVG';
  15. interface CarType {
  16. id: number;
  17. name: string;
  18. }
  19. const RegisterChooseVehiclesTwo = () => {
  20. const { brandId, brandName, carTypes } = useLocalSearchParams<{
  21. brandId: string;
  22. brandName: string;
  23. carTypes: string;
  24. }>();
  25. const [parsedCarTypes, setParsedCarTypes] = useState<CarType[]>([]);
  26. useEffect(() => {
  27. if (carTypes) {
  28. const parsed = JSON.parse(carTypes);
  29. setParsedCarTypes(parsed);
  30. }
  31. }, [carTypes]);
  32. const {
  33. vehicleBrand,
  34. vehicleModel,
  35. BrandID,
  36. ModelID,
  37. licensePlate,
  38. setVehicleBrand,
  39. setVehicleModel,
  40. setBrandID,
  41. setModelID,
  42. setLicensePlate
  43. } = useVehicleStore();
  44. const logoPath = `../../../../../assets/${vehicleBrand.toLowerCase()}.png`;
  45. const [carModels, setCarModels] = useState<CarModel[]>([]);
  46. const navigation = useNavigation();
  47. const renderModelItem = ({ item: model }: { item: CarModel }) => (
  48. <>
  49. <Pressable
  50. className="flex-1 items-center justify-center py-6"
  51. onPress={() => {
  52. setVehicleModel(model.name);
  53. setModelID(model.id);
  54. navigation.pop(2);
  55. }}
  56. >
  57. <Text style={styles.modelYear} className="pb-1">
  58. {model.year}
  59. </Text>
  60. <Text style={styles.modelName}>{model.name}</Text>
  61. </Pressable>
  62. <View className="border-t mx-4 border-[#CCCCCC]" />
  63. </>
  64. );
  65. return (
  66. <SafeAreaView className="flex-1 bg-white" edges={['top', 'right', 'left']}>
  67. <ScrollView showsVerticalScrollIndicator={false} className="flex-1 mx-[5%]">
  68. <View style={{ marginTop: 25 }}>
  69. <Pressable
  70. className="self-start"
  71. onPress={() => {
  72. if (router.canGoBack()) {
  73. router.back();
  74. } else {
  75. router.replace('/accountMainPage');
  76. }
  77. }}
  78. >
  79. <PreviousPageBlackSvg />
  80. </Pressable>
  81. <Text
  82. style={{
  83. fontSize: 30,
  84. marginTop: 25,
  85. marginBottom: 10
  86. }}
  87. >
  88. 選擇車輛型號
  89. </Text>
  90. <View className="flex flex-row items-center space-x-8">
  91. {/* <Image source={getBrandLogo(vehicleBrand)} className="w-20 h-20 " resizeMode="contain" /> */}
  92. <Text className="text-4xl italic tracking-wider">{vehicleBrand}</Text>
  93. </View>
  94. </View>
  95. <View className="flex-1">
  96. <FlashList
  97. data={parsedCarTypes}
  98. renderItem={renderModelItem}
  99. keyExtractor={(item) => item.name}
  100. numColumns={1}
  101. />
  102. </View>
  103. </ScrollView>
  104. </SafeAreaView>
  105. );
  106. };
  107. const styles = StyleSheet.create({
  108. modelItem: {
  109. flex: 1,
  110. height: 100,
  111. justifyContent: 'center',
  112. alignItems: 'center',
  113. backgroundColor: '#F0F0F0',
  114. margin: 5,
  115. borderRadius: 10
  116. },
  117. modelName: {
  118. fontSize: 16,
  119. fontWeight: 'bold'
  120. },
  121. modelYear: {
  122. fontSize: 14,
  123. color: '#666'
  124. }
  125. });
  126. export default RegisterChooseVehiclesTwo;