carSeries.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. renderItem={({ item }) => (
  111. <Pressable
  112. onPress={() => handleSelectSeries(item.name)}
  113. >
  114. <View style={styles.listContainer}>
  115. <View style={styles.logoContainer}>
  116. <Text
  117. style={{
  118. fontSize: 24,
  119. fontWeight: '200'
  120. }}
  121. >
  122. {'logo'}
  123. </Text>
  124. </View>
  125. <View style={styles.itemContainer}>
  126. <Text style={styles.item}>{item.name}</Text>
  127. </View>
  128. </View>
  129. </Pressable>
  130. )}
  131. />
  132. </View>
  133. </View>
  134. );
  135. };
  136. const styles = StyleSheet.create({
  137. mainContainer: {
  138. flex: 1,
  139. flexDirection: 'column',
  140. backgroundColor: '#FFFFFF'
  141. },
  142. titleContainer: {
  143. flex: 1,
  144. alignItems: 'center',
  145. justifyContent: 'center'
  146. },
  147. paginationContainer: {
  148. flex: 0.3,
  149. paddingLeft: '6%',
  150. paddingBottom: '5%'
  151. },
  152. bottomContainer: {
  153. flex: 7
  154. },
  155. listContainer: {
  156. flex: 0.5,
  157. flexDirection: 'row',
  158. alignItems: 'center',
  159. paddingVertical: 15
  160. },
  161. logoContainer: {
  162. flex: 2,
  163. alignItems: 'center'
  164. },
  165. itemContainer: {
  166. flex: 8
  167. },
  168. item: {
  169. paddingLeft: '6%',
  170. fontSize: 24,
  171. fontWeight: '200'
  172. }
  173. });
  174. export default ChooseCarSeries;