|
|
@@ -1,13 +1,12 @@
|
|
|
-import { View, Text, StyleSheet } from 'react-native';
|
|
|
+import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
|
|
import NormalInput from '../../../global/normal_input';
|
|
|
import NormalButton from '../../../global/normal_button';
|
|
|
import { useState } from 'react';
|
|
|
import SingleSelectButtonGroup from '../../../global/select_button';
|
|
|
import useSignUpStore from '../../../../providers/signup_form_store';
|
|
|
import PhoneInput from '../../../global/phone_input';
|
|
|
-import { SignUp, authenticationService } from '../../../../service/authService';
|
|
|
-import { CustomerData } from '../../../../types/signUpFormData';
|
|
|
-
|
|
|
+import { authenticationService } from '../../../../service/authService';
|
|
|
+import { Alert } from 'react-native';
|
|
|
type CreateWalletProps = {
|
|
|
goToNextPage: () => void;
|
|
|
};
|
|
|
@@ -16,6 +15,8 @@ const weChatAliPay = '微信支付/支付寶';
|
|
|
|
|
|
const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage }) => {
|
|
|
const options = [{ label: creditCard }, { label: weChatAliPay }];
|
|
|
+ const [isLoading, setIsLoading] = useState(false);
|
|
|
+ const [isLoading2, setIsLoading2] = useState(false);
|
|
|
const { signUpFormData, setSignUpFormData } = useSignUpStore();
|
|
|
|
|
|
const handleSelectedChange = (selectedLabel: string) => {
|
|
|
@@ -23,12 +24,24 @@ const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage }) => {
|
|
|
setError('');
|
|
|
};
|
|
|
|
|
|
- const handleNextWithSkip = () => {
|
|
|
- authenticationService.signUp(customerData);
|
|
|
- goToNextPage();
|
|
|
+ const handleNextWithSkip = async () => {
|
|
|
+ setIsLoading2(true);
|
|
|
+ try {
|
|
|
+ const result = await authenticationService.signUp(customerData);
|
|
|
+ if (result === true) {
|
|
|
+ goToNextPage();
|
|
|
+ } else {
|
|
|
+ Alert.alert('註冊錯誤', '註冊過程中出現錯誤,請稍後再試');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Sign up error:', error);
|
|
|
+ setError('註冊過程中出現錯誤,請稍後再試。');
|
|
|
+ } finally {
|
|
|
+ setIsLoading2(false);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
- const handleNext = () => {
|
|
|
+ const handleNext = async () => {
|
|
|
if (
|
|
|
signUpFormData.paymentMethod === '' ||
|
|
|
signUpFormData.phone === '' ||
|
|
|
@@ -37,9 +50,21 @@ const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage }) => {
|
|
|
setError('請確保所有資料都已填寫。');
|
|
|
} else {
|
|
|
setError('');
|
|
|
- authenticationService.signUp(customerData);
|
|
|
- // SignUp(customerData);
|
|
|
- goToNextPage();
|
|
|
+
|
|
|
+ setIsLoading(true);
|
|
|
+ try {
|
|
|
+ const result = await authenticationService.signUp(customerData);
|
|
|
+ if (result === true) {
|
|
|
+ goToNextPage();
|
|
|
+ } else {
|
|
|
+ Alert.alert('註冊錯誤', '註冊過程中出現錯誤,請稍後再試');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ setError('註冊過程中出現錯誤,請稍後再試。');
|
|
|
+ console.error('Sign up error:', error);
|
|
|
+ } finally {
|
|
|
+ setIsLoading(false);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -59,40 +84,23 @@ const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage }) => {
|
|
|
|
|
|
const [error, setError] = useState('');
|
|
|
|
|
|
- let customerData: CustomerData;
|
|
|
- if (signUpFormData.selectedCarModel === '') {
|
|
|
- // Empty SelectedCarModel means user has clicked "略過"
|
|
|
- customerData = {
|
|
|
- customerBaseInfo: {
|
|
|
- name: signUpFormData.nickName.trim(),
|
|
|
- email: signUpFormData.email,
|
|
|
- password: signUpFormData.password,
|
|
|
- gender: signUpFormData.gender,
|
|
|
- birthday: signUpFormData.birthDate,
|
|
|
- address: signUpFormData.address,
|
|
|
- phone: signUpFormData.phone,
|
|
|
- isUberDriver: signUpFormData.isUberDriver
|
|
|
- }
|
|
|
- };
|
|
|
- } else {
|
|
|
- customerData = {
|
|
|
- customerBaseInfo: {
|
|
|
- name: signUpFormData.nickName.trim(),
|
|
|
- email: signUpFormData.email,
|
|
|
- password: signUpFormData.password,
|
|
|
- gender: signUpFormData.gender,
|
|
|
- birthday: signUpFormData.birthDate,
|
|
|
- address: signUpFormData.address,
|
|
|
- phone: signUpFormData.phone,
|
|
|
- isUberDriver: signUpFormData.isUberDriver
|
|
|
- },
|
|
|
- customerCarInfo: {
|
|
|
- type_id: signUpFormData.selectedCarModel,
|
|
|
- brand_id: signUpFormData.selectedCarBrand,
|
|
|
- licensePlate: 'placeholder'
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
+ let customerData = {
|
|
|
+ customerBaseInfo: {
|
|
|
+ name: signUpFormData.nickName.trim(),
|
|
|
+ email: signUpFormData.email,
|
|
|
+ password: signUpFormData.password,
|
|
|
+ gender: signUpFormData.gender,
|
|
|
+ birthday: signUpFormData.birthDate,
|
|
|
+ address: signUpFormData.address,
|
|
|
+ phone: signUpFormData.phone,
|
|
|
+ isUberDriver: signUpFormData.isUberDriver
|
|
|
+ },
|
|
|
+ customerCarInfo: {
|
|
|
+ type_id: signUpFormData.selectedCarModel,
|
|
|
+ brand_id: signUpFormData.selectedCarBrand,
|
|
|
+ licensePlate: signUpFormData.licensePlate
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
@@ -115,7 +123,6 @@ const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage }) => {
|
|
|
}}
|
|
|
placeholder={phoneFieldPlaceholder}
|
|
|
/>
|
|
|
-
|
|
|
<NormalInput
|
|
|
placeholder="地址"
|
|
|
onChangeText={(address) => {
|
|
|
@@ -125,25 +132,38 @@ const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage }) => {
|
|
|
});
|
|
|
}}
|
|
|
/>
|
|
|
-
|
|
|
<SingleSelectButtonGroup
|
|
|
options={options}
|
|
|
onSelectionChange={handleSelectedChange}
|
|
|
- shouldShowRedOutline={error ? true : false}
|
|
|
selectedOption={selectLabelShown()}
|
|
|
/>
|
|
|
+ </View>
|
|
|
+ {error && <Text style={styles.errorMessage}>{error}</Text>}
|
|
|
+ <View>
|
|
|
<NormalButton
|
|
|
- title={<Text style={{ color: '#fff' }}>完成</Text>}
|
|
|
+ title={
|
|
|
+ isLoading ? (
|
|
|
+ <ActivityIndicator />
|
|
|
+ ) : (
|
|
|
+ <Text style={{ color: '#fff' }}>完成</Text>
|
|
|
+ )
|
|
|
+ }
|
|
|
onPress={handleNext}
|
|
|
extendedStyle={{}}
|
|
|
/>
|
|
|
<NormalButton
|
|
|
- title={<Text style={{ color: '#888888' }}>略過</Text>}
|
|
|
+ title={
|
|
|
+ isLoading2 ? (
|
|
|
+ <ActivityIndicator />
|
|
|
+ ) : (
|
|
|
+ <Text style={{ color: '#888888' }}>略過</Text>
|
|
|
+ )
|
|
|
+ }
|
|
|
onPress={handleNextWithSkip}
|
|
|
extendedStyle={{ backgroundColor: 'transparent' }}
|
|
|
+ buttonPressedStyle={{ backgroundColor: 'transparent' }}
|
|
|
/>
|
|
|
</View>
|
|
|
- {error && <Text style={styles.errorMessage}>{error}</Text>}
|
|
|
</View>
|
|
|
</>
|
|
|
);
|
|
|
@@ -163,7 +183,7 @@ const styles = StyleSheet.create({
|
|
|
color: '#ff0033',
|
|
|
fontWeight: '400',
|
|
|
marginLeft: 10,
|
|
|
- marginTop: 10
|
|
|
+ marginBottom: 10
|
|
|
}
|
|
|
});
|
|
|
export default CreateWallet;
|