carSeries.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { useEffect, useState } from 'react';
  2. import React from 'react';
  3. import { View, Text, StyleSheet, Pressable, FlatList } from 'react-native';
  4. import { FlashList } from '@shopify/flash-list';
  5. import useSignUpStore from '../../../../../providers/signup_form_store';
  6. import { ICarSeries } from '../../../../../types/car';
  7. type CarBrandSeriesMap = {
  8. [brand: string]: ICarSeries[];
  9. };
  10. //hard-coded mock data
  11. const vehicles: CarBrandSeriesMap = {
  12. 'Brand A': [
  13. {
  14. imgUrl: 'logo1',
  15. name: 'Brand A - Series 1',
  16. id: 'Brand A - Series 1'
  17. },
  18. {
  19. imgUrl: 'logo2',
  20. name: 'Brand A - Series 2',
  21. id: 'Brand A - Series 2'
  22. },
  23. {
  24. imgUrl: 'logo3',
  25. name: 'Brand A - Series 3',
  26. id: 'Brand A - Series 3'
  27. },
  28. {
  29. imgUrl: 'logo4',
  30. name: 'Brand A - Series 4',
  31. id: 'Brand A - Series 4'
  32. }
  33. ],
  34. 'Brand B': [
  35. {
  36. imgUrl: 'logo1',
  37. name: 'Brand B - Series 1',
  38. id: 'Brand B - Series 1'
  39. },
  40. {
  41. imgUrl: 'logo2',
  42. name: 'Brand B - Series 2',
  43. id: 'Brand B - Series 2'
  44. },
  45. {
  46. imgUrl: 'logo3',
  47. name: 'Brand B - Series 3',
  48. id: 'Brand B - Series 3'
  49. },
  50. {
  51. imgUrl: 'logo4',
  52. name: 'Brand B - Series 4',
  53. id: 'Brand B - Series 4'
  54. }
  55. ],
  56. 'Brand C': [
  57. {
  58. imgUrl: 'logo1',
  59. name: 'Brand C - Series 1',
  60. id: 'Brand C - Series 1'
  61. },
  62. {
  63. imgUrl: 'logo2',
  64. name: 'Brand C - Series 2',
  65. id: 'Brand C - Series 2'
  66. },
  67. {
  68. imgUrl: 'logo3',
  69. name: 'Brand C - Series 3',
  70. id: 'Brand C - Series 3'
  71. },
  72. {
  73. imgUrl: 'logo4',
  74. name: 'Brand C - Series 4',
  75. id: 'Brand C - Series 4'
  76. }
  77. ]
  78. };
  79. type ChooseCarSeriesProps = {
  80. goToChooseCarBrandPage: () => void;
  81. goToChooseCarModelPage: () => void;
  82. };
  83. const ChooseCarSeries: React.FC<ChooseCarSeriesProps> = ({
  84. goToChooseCarBrandPage,
  85. goToChooseCarModelPage
  86. }) => {
  87. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  88. const handleSelectSeries = (brand: string) => {
  89. setSignUpFormData({
  90. ...signUpFormData,
  91. selectedCarSeries: brand
  92. });
  93. goToChooseCarModelPage();
  94. };
  95. return (
  96. <View style={styles.mainContainer}>
  97. <View style={styles.titleContainer}>
  98. <Text style={{ fontSize: 24, fontWeight: '300' }}>
  99. 選擇車系
  100. </Text>
  101. </View>
  102. <View style={styles.paginationContainer}>
  103. <Pressable onPress={goToChooseCarBrandPage}>
  104. <Text style={{ color: '#888888' }}>{`< 上一步`}</Text>
  105. </Pressable>
  106. </View>
  107. <View style={styles.bottomContainer}>
  108. <FlashList
  109. data={vehicles[signUpFormData.selectedCarBrand]}
  110. estimatedItemSize={20}
  111. renderItem={({ item }) => (
  112. <Pressable
  113. onPress={() => handleSelectSeries(item.name)}
  114. >
  115. <View style={styles.listContainer}>
  116. <View style={styles.logoContainer}>
  117. <Text
  118. style={{
  119. fontSize: 24,
  120. fontWeight: '200'
  121. }}
  122. >
  123. {'logo'}
  124. </Text>
  125. </View>
  126. <View style={styles.itemContainer}>
  127. <Text style={styles.item}>{item.name}</Text>
  128. </View>
  129. </View>
  130. </Pressable>
  131. )}
  132. />
  133. </View>
  134. </View>
  135. );
  136. };
  137. const styles = StyleSheet.create({
  138. mainContainer: {
  139. flex: 1,
  140. flexDirection: 'column',
  141. backgroundColor: '#FFFFFF'
  142. },
  143. titleContainer: {
  144. flex: 1,
  145. alignItems: 'center',
  146. justifyContent: 'center'
  147. },
  148. paginationContainer: {
  149. flex: 0.3,
  150. paddingLeft: '6%',
  151. paddingBottom: '5%'
  152. },
  153. bottomContainer: {
  154. flex: 7
  155. },
  156. listContainer: {
  157. flex: 0.5,
  158. flexDirection: 'row',
  159. alignItems: 'center',
  160. paddingVertical: 15
  161. },
  162. logoContainer: {
  163. flex: 2,
  164. alignItems: 'center'
  165. },
  166. itemContainer: {
  167. flex: 8
  168. },
  169. item: {
  170. paddingLeft: '6%',
  171. fontSize: 24,
  172. fontWeight: '200'
  173. }
  174. });
  175. export default ChooseCarSeries;