ordering-ui-react-native 0.23.53 → 0.23.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/themes/business/src/components/NewOrderNotification/index.tsx +2 -1
- package/themes/business/src/components/UserProfileForm/index.tsx +41 -7
- package/themes/business/src/components/UserProfileForm/styles.tsx +7 -0
- package/themes/business/src/hooks/useLocation.tsx +16 -12
- package/themes/business/src/types/index.tsx +3 -0
- package/themes/original/src/components/PhoneInputNumber/index.tsx +6 -5
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { View, StyleSheet, ScrollView, ActivityIndicator, Pressable } from 'react-native';
|
|
3
|
+
import { _retrieveStoreData, _clearStoreData } from '../../providers/StoreUtil';
|
|
3
4
|
import { useForm } from 'react-hook-form';
|
|
4
5
|
import { launchImageLibrary } from 'react-native-image-picker';
|
|
5
6
|
import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
UserData,
|
|
21
22
|
EditButton,
|
|
22
23
|
EnabledStatusDriver,
|
|
24
|
+
RemoveAccount
|
|
23
25
|
} from './styles';
|
|
24
26
|
import { LogoutButton } from '../LogoutButton';
|
|
25
27
|
import { LanguageSelector } from '../LanguageSelector';
|
|
@@ -36,6 +38,8 @@ import {
|
|
|
36
38
|
OInput,
|
|
37
39
|
OModal,
|
|
38
40
|
} from '../../components/shared';
|
|
41
|
+
import { OAlert } from '../../../../../src/components/shared'
|
|
42
|
+
|
|
39
43
|
import { sortInputFields, getTraduction } from '../../utils';
|
|
40
44
|
import { ProfileParams } from '../../types';
|
|
41
45
|
import { NotFoundSource } from '../NotFoundSource';
|
|
@@ -49,6 +53,7 @@ const ProfileUI = (props: ProfileParams) => {
|
|
|
49
53
|
toggleIsEdit,
|
|
50
54
|
cleanFormState,
|
|
51
55
|
handleToggleAvalaibleStatusDriver,
|
|
56
|
+
handleRemoveAccount,
|
|
52
57
|
isAlsea,
|
|
53
58
|
isShowDriverStatus,
|
|
54
59
|
navigation
|
|
@@ -62,6 +67,7 @@ const ProfileUI = (props: ProfileParams) => {
|
|
|
62
67
|
const [{ loading }, { loadOriginalValidationFields }] = useValidationFields()
|
|
63
68
|
const { errors } = useForm();
|
|
64
69
|
const theme = useTheme();
|
|
70
|
+
const [confirm, setConfirm] = useState<any>({ open: false, content: null, handleOnAccept: null, id: null, title: null })
|
|
65
71
|
|
|
66
72
|
const [phoneInputData, setPhoneInputData] = useState<any>({
|
|
67
73
|
error: '',
|
|
@@ -76,13 +82,7 @@ const ProfileUI = (props: ProfileParams) => {
|
|
|
76
82
|
const [phoneToShow, setPhoneToShow] = useState('');
|
|
77
83
|
const [openModal, setOpenModal] = useState(false)
|
|
78
84
|
const allowDriverUpdateData = user?.level !== 4 || configs?.allow_driver_update_data?.value === "1"
|
|
79
|
-
|
|
80
|
-
if (phoneInputData.phone.cellphone) {
|
|
81
|
-
const codeNumberPhone = phoneInputData.phone.country_phone_code
|
|
82
|
-
const numberPhone = phoneInputData.phone.cellphone
|
|
83
|
-
setPhoneToShow(`(${codeNumberPhone}) ${numberPhone}`);
|
|
84
|
-
}
|
|
85
|
-
}, [phoneInputData.phone.cellphone]);
|
|
85
|
+
const isAdmin = user?.level === 0
|
|
86
86
|
|
|
87
87
|
const setUserCellPhone = (isEdit = false) => {
|
|
88
88
|
if (userPhoneNumber && !userPhoneNumber.includes('null') && !isEdit) {
|
|
@@ -148,6 +148,28 @@ const ProfileUI = (props: ProfileParams) => {
|
|
|
148
148
|
});
|
|
149
149
|
};
|
|
150
150
|
|
|
151
|
+
const onRemoveAccount = async () => {
|
|
152
|
+
setConfirm({
|
|
153
|
+
open: true,
|
|
154
|
+
content: [t('QUESTION_REMOVE_ACCOUNT', 'Are you sure that you want to remove your account?')],
|
|
155
|
+
title: t('ACCOUNT_ALERT', 'Account alert'),
|
|
156
|
+
handleOnAccept: () => {
|
|
157
|
+
setConfirm({ ...confirm, open: false })
|
|
158
|
+
handleRemoveAccount && handleRemoveAccount(user?.id)
|
|
159
|
+
_clearStoreData({ excludedKeys: ['isTutorial', 'language'] });
|
|
160
|
+
props?.setRootState && props?.setRootState({ isAuth: false, token: null })
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (phoneInputData.phone.cellphone) {
|
|
167
|
+
const codeNumberPhone = phoneInputData.phone.country_phone_code
|
|
168
|
+
const numberPhone = phoneInputData.phone.cellphone
|
|
169
|
+
setPhoneToShow(`(${codeNumberPhone}) ${numberPhone}`);
|
|
170
|
+
}
|
|
171
|
+
}, [phoneInputData.phone.cellphone]);
|
|
172
|
+
|
|
151
173
|
useEffect(() => {
|
|
152
174
|
const isLoadingDriver = userState?.loadingDriver ?? true;
|
|
153
175
|
|
|
@@ -544,6 +566,10 @@ const ProfileUI = (props: ProfileParams) => {
|
|
|
544
566
|
|
|
545
567
|
<LogoutButton setRootState={props.setRootState} />
|
|
546
568
|
</Actions>
|
|
569
|
+
<RemoveAccount disabled={isAdmin} onPress={() => onRemoveAccount()} activeOpacity={0.7}>
|
|
570
|
+
<AntDesignIcon size={16} name='close' color={theme.colors.textNormal} style={{ marginEnd: 14 }} />
|
|
571
|
+
<OText size={14} lineHeight={24} weight={'400'} style={{ opacity: isAdmin ? 0.5 : 1 }} color={theme.colors.danger500}>{t('REMOVE_ACCOUNT', 'Remove account')}</OText>
|
|
572
|
+
</RemoveAccount>
|
|
547
573
|
<OModal
|
|
548
574
|
open={openModal}
|
|
549
575
|
onClose={() => setOpenModal(false)}
|
|
@@ -554,6 +580,14 @@ const ProfileUI = (props: ProfileParams) => {
|
|
|
554
580
|
<DriverSchedule schedule={user?.schedule} />
|
|
555
581
|
)}
|
|
556
582
|
</OModal>
|
|
583
|
+
<OAlert
|
|
584
|
+
open={confirm.open}
|
|
585
|
+
title={confirm.title}
|
|
586
|
+
content={confirm.content}
|
|
587
|
+
onAccept={confirm.handleOnAccept}
|
|
588
|
+
onCancel={() => setConfirm({ ...confirm, open: false, title: null })}
|
|
589
|
+
onClose={() => setConfirm({ ...confirm, open: false, title: null })}
|
|
590
|
+
/>
|
|
557
591
|
</ScrollView>
|
|
558
592
|
)}
|
|
559
593
|
</>
|
|
@@ -34,3 +34,10 @@ export const Actions = styled.View`
|
|
|
34
34
|
justify-content: space-between;
|
|
35
35
|
align-items: flex-start;
|
|
36
36
|
`;
|
|
37
|
+
|
|
38
|
+
export const RemoveAccount = styled.TouchableOpacity`
|
|
39
|
+
flex-direction: row;
|
|
40
|
+
justify-content: flex-start;
|
|
41
|
+
align-items: center;
|
|
42
|
+
margin-bottom: 24px;
|
|
43
|
+
`
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { useEffect, useState, useRef } from 'react';
|
|
2
2
|
import GeoLocation from 'react-native-geolocation-service';
|
|
3
3
|
import { Location } from '../types';
|
|
4
|
-
import {useApi, useSession, useLanguage} from 'ordering-components/native'
|
|
4
|
+
import { useApi, useSession, useLanguage } from 'ordering-components/native'
|
|
5
5
|
|
|
6
6
|
export const useLocation = () => {
|
|
7
|
-
const [,t] = useLanguage()
|
|
7
|
+
const [, t] = useLanguage()
|
|
8
8
|
const [ordering] = useApi()
|
|
9
|
-
const [{token, user}] = useSession()
|
|
9
|
+
const [{ token, user }] = useSession()
|
|
10
10
|
const [hasLocation, setHasLocation] = useState(false);
|
|
11
11
|
const [initialPosition, setInitialPosition] = useState<Location>({
|
|
12
12
|
longitude: 0,
|
|
13
13
|
latitude: 0,
|
|
14
14
|
speed: 0,
|
|
15
|
+
mocked: false
|
|
15
16
|
});
|
|
16
17
|
const [userLocation, setUserLocation] = useState<Location>({
|
|
17
18
|
longitude: 0,
|
|
18
19
|
latitude: 0,
|
|
19
20
|
speed: 0,
|
|
21
|
+
mocked: false
|
|
20
22
|
});
|
|
21
|
-
const [newLocation,setNewLocation] = useState<any>({ loading: false, error: null, newLocation: null })
|
|
23
|
+
const [newLocation, setNewLocation] = useState<any>({ loading: false, error: null, newLocation: null })
|
|
22
24
|
const [routeLines, setRoutesLines] = useState<Location[]>([]);
|
|
23
25
|
const isMounted = useRef(true);
|
|
24
26
|
|
|
@@ -37,7 +39,7 @@ export const useLocation = () => {
|
|
|
37
39
|
if (!isMounted.current) return;
|
|
38
40
|
setInitialPosition(location);
|
|
39
41
|
setUserLocation(location);
|
|
40
|
-
setRoutesLines(routes => [...routes, location]);
|
|
42
|
+
setRoutesLines((routes: any) => [...routes, location]);
|
|
41
43
|
setHasLocation(true);
|
|
42
44
|
})
|
|
43
45
|
.catch(err => console.log(err));
|
|
@@ -46,14 +48,15 @@ export const useLocation = () => {
|
|
|
46
48
|
const getCurrentLocation = (): Promise<Location> => {
|
|
47
49
|
return new Promise((resolve, reject) => {
|
|
48
50
|
GeoLocation.getCurrentPosition(
|
|
49
|
-
({ coords }) => {
|
|
51
|
+
({ coords, mocked }: any) => {
|
|
50
52
|
resolve({
|
|
51
53
|
latitude: typeof coords.latitude === 'number' && !Number.isNaN(coords.latitude) ? coords.latitude : 0,
|
|
52
54
|
longitude: typeof coords.longitude === 'number' && !Number.isNaN(coords.longitude) ? coords.longitude : 0,
|
|
53
55
|
speed: coords.speed,
|
|
56
|
+
mocked
|
|
54
57
|
});
|
|
55
58
|
},
|
|
56
|
-
err => reject({ err }),
|
|
59
|
+
(err: any) => reject({ err }),
|
|
57
60
|
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
|
|
58
61
|
);
|
|
59
62
|
});
|
|
@@ -61,18 +64,19 @@ export const useLocation = () => {
|
|
|
61
64
|
|
|
62
65
|
const followUserLocation = () => {
|
|
63
66
|
watchId.current = GeoLocation.watchPosition(
|
|
64
|
-
({ coords }) => {
|
|
67
|
+
({ coords, mocked }: any) => {
|
|
65
68
|
if (!isMounted.current) return;
|
|
66
69
|
if (typeof coords.latitude !== 'number' || typeof coords.longitude !== 'number') return
|
|
67
70
|
const location: Location = {
|
|
68
71
|
latitude: coords.latitude || 0,
|
|
69
72
|
longitude: coords.longitude || 0,
|
|
70
73
|
speed: coords.speed,
|
|
74
|
+
mocked
|
|
71
75
|
};
|
|
72
76
|
setUserLocation(location);
|
|
73
|
-
setRoutesLines(routes => [...routes, location]);
|
|
77
|
+
setRoutesLines((routes: any) => [...routes, location]);
|
|
74
78
|
},
|
|
75
|
-
err => console.log(err),
|
|
79
|
+
(err: any) => console.log(err),
|
|
76
80
|
{ enableHighAccuracy: true, distanceFilter: 3 },
|
|
77
81
|
);
|
|
78
82
|
};
|
|
@@ -83,14 +87,14 @@ export const useLocation = () => {
|
|
|
83
87
|
|
|
84
88
|
const updateDriverPosition = async (newLocation = {}) => {
|
|
85
89
|
try {
|
|
86
|
-
setNewLocation({...newLocation, loading: true})
|
|
90
|
+
setNewLocation({ ...newLocation, loading: true })
|
|
87
91
|
const { content: { error, result } } = await ordering.setAccessToken(token).users(user?.id).driverLocations().save(newLocation)
|
|
88
92
|
if (error) {
|
|
89
93
|
setNewLocation({ ...newLocation, loading: false, error: [result[0] || result || t('ERROR_UPDATING_POSITION', 'Error updating position')] })
|
|
90
94
|
} else {
|
|
91
95
|
setNewLocation({ ...newLocation, loading: false, newLocation: { ...newLocation, ...result } })
|
|
92
96
|
}
|
|
93
|
-
} catch (error
|
|
97
|
+
} catch (error: any) {
|
|
94
98
|
setNewLocation({ ...newLocation, loading: false, error: [error?.message || t('NETWORK_ERROR', 'Network Error')] })
|
|
95
99
|
}
|
|
96
100
|
}
|
|
@@ -43,6 +43,7 @@ export interface ProfileParams {
|
|
|
43
43
|
navigation?: any;
|
|
44
44
|
isEdit?: boolean;
|
|
45
45
|
formState?: any;
|
|
46
|
+
setRootState?: any;
|
|
46
47
|
userState?: any;
|
|
47
48
|
toggleIsEdit?: any;
|
|
48
49
|
cleanFormState?: any;
|
|
@@ -51,6 +52,7 @@ export interface ProfileParams {
|
|
|
51
52
|
handleChangeInput?: any;
|
|
52
53
|
handleButtonUpdateClick?: any;
|
|
53
54
|
handleToggleAvalaibleStatusDriver?: any;
|
|
55
|
+
handleRemoveAccount?: any;
|
|
54
56
|
onNavigationRedirect?: any;
|
|
55
57
|
handlechangeImage?: any;
|
|
56
58
|
validationFields?: any;
|
|
@@ -541,6 +543,7 @@ export interface Location {
|
|
|
541
543
|
latitude: number;
|
|
542
544
|
longitude: number;
|
|
543
545
|
speed: number;
|
|
546
|
+
mocked?: boolean;
|
|
544
547
|
}
|
|
545
548
|
|
|
546
549
|
export interface GoogleMapsParams {
|
|
@@ -40,6 +40,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
|
|
|
40
40
|
open: false,
|
|
41
41
|
options: []
|
|
42
42
|
})
|
|
43
|
+
const isDisableNumberValidation = parseInt(configs?.validation_phone_number_lib?.value ?? 1, 10)
|
|
43
44
|
const countriesWithSubOptions = ['PR']
|
|
44
45
|
const style = StyleSheet.create({
|
|
45
46
|
input: {
|
|
@@ -74,7 +75,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
|
|
|
74
75
|
const regex = /^[0-9]*$/
|
|
75
76
|
const cellphone = userphoneNumber.slice(0, 0) + userphoneNumber.slice(1, userphoneNumber.length)
|
|
76
77
|
const validNumber = regex.test(cellphone)
|
|
77
|
-
if ((!checkValid && formattedNumber?.number) || !validNumber) {
|
|
78
|
+
if (((!checkValid && formattedNumber?.number) || !validNumber) && !!isDisableNumberValidation) {
|
|
78
79
|
handleData && handleData({
|
|
79
80
|
...data,
|
|
80
81
|
error: t('INVALID_ERROR_PHONE_NUMBER', 'The Phone Number field is invalid')
|
|
@@ -86,7 +87,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
|
|
|
86
87
|
error: '',
|
|
87
88
|
phone: {
|
|
88
89
|
country_phone_code: callingCode,
|
|
89
|
-
cellphone: formattedNumber?.number
|
|
90
|
+
cellphone: !isDisableNumberValidation ? userphoneNumber : formattedNumber?.number
|
|
90
91
|
}
|
|
91
92
|
})
|
|
92
93
|
} else {
|
|
@@ -134,7 +135,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
const handleSelectCallingCode = (option
|
|
138
|
+
const handleSelectCallingCode = (option: any) => {
|
|
138
139
|
setCountryPhoneSuboptions({
|
|
139
140
|
open: false,
|
|
140
141
|
options: []
|
|
@@ -167,7 +168,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
|
|
|
167
168
|
: findExitingCode(configs?.default_country_code?.value?.toUpperCase())}
|
|
168
169
|
onChangeFormattedText={(text: string) => handleChangeNumber(text)}
|
|
169
170
|
withDarkTheme
|
|
170
|
-
onChangeCountry={(country
|
|
171
|
+
onChangeCountry={(country: any) => _changeCountry?.(country)}
|
|
171
172
|
countryPickerProps={{ withAlphaFilter: true }}
|
|
172
173
|
textContainerStyle={{ ...style.input, ...inputStyle ? inputStyle : {} }}
|
|
173
174
|
textInputStyle={textStyle}
|
|
@@ -202,7 +203,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
|
|
|
202
203
|
alignItems: 'center'
|
|
203
204
|
}}
|
|
204
205
|
>
|
|
205
|
-
{countryPhoneSuboptions.options.map((option
|
|
206
|
+
{countryPhoneSuboptions.options.map((option: any) => (
|
|
206
207
|
<Pressable
|
|
207
208
|
style={{
|
|
208
209
|
margin: 10,
|