ordering-ui-react-native 0.14.78 → 0.14.79

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.14.78",
3
+ "version": "0.14.79",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -7,7 +7,8 @@ import {
7
7
  ScrollView,
8
8
  Platform,
9
9
  TouchableOpacity,
10
- RefreshControl
10
+ RefreshControl,
11
+ AppState
11
12
  } from 'react-native';
12
13
  import {
13
14
  BusinessList as BusinessesListingController,
@@ -63,8 +64,9 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
63
64
 
64
65
  const theme = useTheme();
65
66
  const isFocused = useIsFocused();
67
+ const appState = useRef(AppState.currentState)
68
+ const [appStateVisible, setAppStateVisible] = useState(appState.current);
66
69
  const [refreshing] = useState(false);
67
-
68
70
  const styles = StyleSheet.create({
69
71
  container: {
70
72
  marginBottom: 0,
@@ -168,15 +170,13 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
168
170
  const resetInactivityTimeout = () => {
169
171
  clearTimeout(timerId.current)
170
172
  timerId.current = setInterval(() => {
171
- if (!businessesList.loading) {
172
- getBusinesses(true)
173
- }
173
+ getBusinesses(true)
174
174
  }, 300000)
175
175
  }
176
176
 
177
177
  useEffect(() => {
178
178
  resetInactivityTimeout()
179
- }, [])
179
+ }, [businessesList.loading])
180
180
 
181
181
  const handleOnRefresh = () => {
182
182
  if (!businessesList.loading) {
@@ -197,6 +197,26 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
197
197
  })
198
198
  }, [orderState?.options?.address?.location])
199
199
 
200
+ useEffect(() => {
201
+ const onFocusApp = (nextAppState : any) => {
202
+ if (
203
+ appState.current.match(/inactive|background/) &&
204
+ nextAppState === "active"
205
+ ) {
206
+ if (!businessesList.loading) {
207
+ getBusinesses(true);
208
+ }
209
+ }
210
+ appState.current = nextAppState;
211
+ setAppStateVisible(appState.current);
212
+ }
213
+
214
+ AppState.addEventListener("change", onFocusApp);
215
+ return () => {
216
+ AppState.removeEventListener('change', onFocusApp);
217
+ };
218
+ }, [])
219
+
200
220
  useFocusEffect(
201
221
  useCallback(() => {
202
222
  getBusinesses(true)
@@ -3,14 +3,17 @@ import { TouchableOpacity, View } from 'react-native';
3
3
  import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons';
4
4
 
5
5
  import { UDContainer, UDHeader, UDForm, UDInfo, EditBtn } from './styles';
6
-
7
6
  import {
8
7
  UserFormDetails as UserFormController,
9
8
  useLanguage,
10
9
  useSession,
10
+ ToastType,
11
+ useToast
11
12
  } from 'ordering-components/native';
12
13
  import { useTheme } from 'styled-components/native';
13
- import { OIcon, OText } from '../shared';
14
+ import { OIcon, OText, OModal } from '../shared';
15
+ import { VerifyPhone } from '../VerifyPhone';
16
+ import Spinner from 'react-native-loading-spinner-overlay';
14
17
 
15
18
  import { UserFormDetailsUI } from '../UserFormDetails';
16
19
  import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
@@ -26,15 +29,33 @@ const UserDetailsUI = (props: any) => {
26
29
  isUserDetailsEdit,
27
30
  phoneUpdate,
28
31
  togglePhoneUpdate,
29
- isCheckout
32
+ isCheckout,
33
+ checkPhoneCodeState,
34
+ handleSendVerifyCode,
35
+ handleCheckPhoneCode,
36
+ verifyPhoneState,
37
+ isVerifiedPhone,
38
+ setCheckPhoneCodeState
30
39
  } = props
31
40
 
32
41
  const theme = useTheme();
33
42
 
34
43
  const [, t] = useLanguage()
35
44
  const [{ user }] = useSession()
45
+ const [, { showToast }] = useToast();
46
+
36
47
  const userData = props.userData || (!formState.result.error && formState.result?.result) || user
37
48
 
49
+ const [isModalVisible, setIsModalVisible] = useState(false);
50
+ const [willVerifyOtpState, setWillVerifyOtpState] = useState(false);
51
+ const [phoneInputData, setPhoneInputData] = useState({
52
+ error: '',
53
+ phone: {
54
+ country_phone_code: null,
55
+ cellphone: null,
56
+ },
57
+ });
58
+
38
59
 
39
60
  useEffect(() => {
40
61
  if (isUserDetailsEdit) {
@@ -55,6 +76,54 @@ const UserDetailsUI = (props: any) => {
55
76
  }
56
77
  }, [user?.country_phone_code])
57
78
 
79
+ const handleVerifyCodeClick = () => {
80
+ if (formState?.changes?.cellphone && formState?.changes?.country_phone_code) {
81
+ const { cellphone, country_phone_code: countryPhoneCode } = formState?.changes
82
+
83
+ setPhoneInputData({
84
+ error: '',
85
+ phone: {
86
+ country_phone_code: countryPhoneCode,
87
+ cellphone: cellphone,
88
+ },
89
+ });
90
+ handleSendVerifyCode({
91
+ cellphone: cellphone,
92
+ country_phone_code: countryPhoneCode
93
+ })
94
+ }
95
+ }
96
+
97
+ useEffect(() => {
98
+ if (willVerifyOtpState) handleVerifyCodeClick()
99
+ }, [willVerifyOtpState])
100
+
101
+ useEffect(() => {
102
+ if (verifyPhoneState && !verifyPhoneState?.loading) {
103
+ if (verifyPhoneState.result?.error) {
104
+ const message = typeof verifyPhoneState?.result?.result === 'string'
105
+ ? verifyPhoneState?.result?.result
106
+ : verifyPhoneState?.result?.result[0]
107
+ verifyPhoneState.result?.result && showToast(
108
+ ToastType.Error,
109
+ message
110
+ )
111
+ setWillVerifyOtpState(false)
112
+ return
113
+ }
114
+
115
+ const okResult = verifyPhoneState.result?.result === 'OK'
116
+ if (okResult) {
117
+ !isModalVisible && setIsModalVisible(true)
118
+ setWillVerifyOtpState(false)
119
+ }
120
+ }
121
+ }, [verifyPhoneState])
122
+
123
+ useEffect(() => {
124
+ if (isVerifiedPhone) setIsModalVisible(false)
125
+ }, [isVerifiedPhone])
126
+
58
127
  return (
59
128
  <>
60
129
  {(validationFields.loading || formState.loading) && (
@@ -117,10 +186,32 @@ const UserDetailsUI = (props: any) => {
117
186
  )}
118
187
  </UDInfo>
119
188
  ) : (
120
- <UserFormDetailsUI {...props} phoneUpdate={phoneUpdate} togglePhoneUpdate={togglePhoneUpdate} isCheckout={isCheckout} />
189
+ <UserFormDetailsUI
190
+ {...props}
191
+ phoneUpdate={phoneUpdate}
192
+ togglePhoneUpdate={togglePhoneUpdate}
193
+ isCheckout={isCheckout}
194
+ setWillVerifyOtpState={setWillVerifyOtpState}
195
+ />
121
196
  )}
122
197
  </UDContainer>
123
198
  )}
199
+ <OModal
200
+ open={isModalVisible}
201
+ onClose={() => setIsModalVisible(false)}
202
+ entireModal
203
+ >
204
+ <VerifyPhone
205
+ phone={phoneInputData.phone}
206
+ verifyPhoneState={verifyPhoneState}
207
+ checkPhoneCodeState={checkPhoneCodeState}
208
+ handleCheckPhoneCode={handleCheckPhoneCode}
209
+ setCheckPhoneCodeState={setCheckPhoneCodeState}
210
+ handleVerifyCodeClick={handleVerifyCodeClick}
211
+ onClose={() => setIsModalVisible(false)}
212
+ />
213
+ </OModal>
214
+ <Spinner visible={verifyPhoneState?.loading} />
124
215
  </>
125
216
  )
126
217
  }
@@ -25,6 +25,8 @@ export const UserFormDetailsUI = (props: any) => {
25
25
  handleButtonUpdateClick,
26
26
  phoneUpdate,
27
27
  hideUpdateButton,
28
+ setWillVerifyOtpState,
29
+ isVerifiedPhone
28
30
  handleChangePromotions
29
31
  } = props;
30
32
 
@@ -139,8 +141,8 @@ export const UserFormDetailsUI = (props: any) => {
139
141
  if (
140
142
  formState.changes?.cellphone === null &&
141
143
  ((validationFields?.fields?.checkout?.cellphone?.enabled &&
142
- validationFields?.fields?.checkout?.cellphone?.required) ||
143
- configs?.verification_phone_required?.value === '1')
144
+ validationFields?.fields?.checkout?.cellphone?.required) ||
145
+ configs?.verification_phone_required?.value === '1')
144
146
  ) {
145
147
  showToast(
146
148
  ToastType.Error,
@@ -151,6 +153,9 @@ export const UserFormDetailsUI = (props: any) => {
151
153
  );
152
154
  return;
153
155
  }
156
+ if (formState?.changes?.cellphone && !isVerifiedPhone) {
157
+ showToast(ToastType.Error, t('VERIFY_ERROR_PHONE_NUMBER', 'The Phone Number field is not verified'))
158
+ }
154
159
  let changes = null;
155
160
  if (user?.cellphone && !userPhoneNumber) {
156
161
  changes = {
@@ -211,6 +216,13 @@ export const UserFormDetailsUI = (props: any) => {
211
216
  }
212
217
  }
213
218
  }, [user, isEdit]);
219
+
220
+ useEffect(() => {
221
+ if (!phoneInputData.error && phoneInputData?.phone?.country_phone_code && phoneInputData?.phone?.cellphone) {
222
+ setWillVerifyOtpState(true)
223
+ }
224
+ }, [phoneInputData])
225
+
214
226
  return (
215
227
  <>
216
228
  <UDForm>
@@ -5,7 +5,7 @@ import {
5
5
  useLanguage,
6
6
  ToastType,
7
7
  useToast,
8
- useConfig
8
+ useConfig
9
9
  } from 'ordering-components/native';
10
10
  import { useTheme } from 'styled-components/native';
11
11
  import { useForm } from 'react-hook-form';
@@ -15,10 +15,11 @@ import { KeyboardAvoidingView, Platform, StyleSheet, View } from 'react-native';
15
15
  import { ProfileParams } from '../../types';
16
16
  import { UserFormDetailsUI } from '../UserFormDetails';
17
17
 
18
- import { OIcon, OIconButton } from '../shared';
18
+ import { OIcon, OIconButton, OModal } from '../shared';
19
19
  import { CenterView } from './styles';
20
20
  import NavBar from '../NavBar';
21
21
  import { Container } from '../../layouts/Container';
22
+ import { VerifyPhone } from '../VerifyPhone'
22
23
 
23
24
  const ProfileUI = (props: ProfileParams) => {
24
25
  const {
@@ -32,6 +33,12 @@ const ProfileUI = (props: ProfileParams) => {
32
33
  cleanFormState,
33
34
  handleChangeInput,
34
35
  handleButtonUpdateClick,
36
+ checkPhoneCodeState,
37
+ handleSendVerifyCode,
38
+ handleCheckPhoneCode,
39
+ verifyPhoneState,
40
+ isVerifiedPhone,
41
+ setCheckPhoneCodeState
35
42
  } = props;
36
43
 
37
44
  const theme = useTheme();
@@ -61,6 +68,8 @@ const ProfileUI = (props: ProfileParams) => {
61
68
  const [, t] = useLanguage();
62
69
  const [, { showToast }] = useToast();
63
70
  const { handleSubmit, errors, setValue, control } = useForm();
71
+ const [isModalVisible, setIsModalVisible] = useState(false);
72
+ const [willVerifyOtpState, setWillVerifyOtpState] = useState(false);
64
73
 
65
74
  const [phoneInputData, setPhoneInputData] = useState({
66
75
  error: '',
@@ -79,8 +88,8 @@ const ProfileUI = (props: ProfileParams) => {
79
88
  if (
80
89
  formState.changes.cellphone === '' &&
81
90
  ((validationFields?.fields?.checkout?.cellphone?.enabled &&
82
- validationFields?.fields?.checkout?.cellphone?.required) ||
83
- configs?.verification_phone_required?.value === '1')
91
+ validationFields?.fields?.checkout?.cellphone?.required) ||
92
+ configs?.verification_phone_required?.value === '1')
84
93
  ) {
85
94
  showToast(
86
95
  ToastType.Error,
@@ -182,6 +191,24 @@ const ProfileUI = (props: ProfileParams) => {
182
191
  return rules;
183
192
  };
184
193
 
194
+ const handleVerifyCodeClick = () => {
195
+ if (formState?.changes?.cellphone && formState?.changes?.country_phone_code) {
196
+ const { cellphone, country_phone_code: countryPhoneCode } = formState?.changes
197
+
198
+ setPhoneInputData({
199
+ error: '',
200
+ phone: {
201
+ country_phone_code: countryPhoneCode,
202
+ cellphone: cellphone,
203
+ },
204
+ });
205
+ handleSendVerifyCode({
206
+ cellphone: cellphone,
207
+ country_phone_code: countryPhoneCode
208
+ })
209
+ }
210
+ }
211
+
185
212
  useEffect(() => {
186
213
  if (formState.result.result && !formState.loading) {
187
214
  if (formState.result?.error) {
@@ -216,44 +243,95 @@ const ProfileUI = (props: ProfileParams) => {
216
243
  }
217
244
  }, [user?.country_phone_code]);
218
245
 
246
+ useEffect(() => {
247
+ if (willVerifyOtpState) handleVerifyCodeClick()
248
+ }, [willVerifyOtpState])
249
+
250
+ useEffect(() => {
251
+ if (verifyPhoneState && !verifyPhoneState?.loading) {
252
+ if (verifyPhoneState.result?.error) {
253
+ const message = typeof verifyPhoneState?.result?.result === 'string'
254
+ ? verifyPhoneState?.result?.result
255
+ : verifyPhoneState?.result?.result[0]
256
+ verifyPhoneState.result?.result && showToast(
257
+ ToastType.Error,
258
+ message
259
+ )
260
+ setWillVerifyOtpState(false)
261
+ return
262
+ }
263
+
264
+ const okResult = verifyPhoneState.result?.result === 'OK'
265
+ if (okResult) {
266
+ !isModalVisible && setIsModalVisible(true)
267
+ setWillVerifyOtpState(false)
268
+ }
269
+ }
270
+ }, [verifyPhoneState])
271
+
272
+ useEffect(() => {
273
+ if (isVerifiedPhone) setIsModalVisible(false)
274
+ }, [isVerifiedPhone])
275
+
219
276
  return (
220
- <KeyboardAvoidingView behavior={Platform.OS == 'ios' ? 'padding' : 'height'} enabled style={{ flex: 1, flexDirection: 'column',justifyContent: 'center'}}>
221
- <Container noPadding>
222
- <NavBar
223
- onActionLeft={() => navigation.goBack()}
224
- btnStyle={{ paddingStart: 0 }}
225
- title={t('ACCOUNT', 'Account')}
226
- isVertical
227
- style={styles.navBarStyle}
228
- />
229
- <CenterView style={styles.pagePadding}>
230
- <View style={styles.photo}>
231
- <OIcon
232
- url={user?.photo}
233
- src={!user?.photo && theme.images.general.user}
234
- width={79}
235
- height={79}
277
+ <>
278
+ <KeyboardAvoidingView behavior={Platform.OS == 'ios' ? 'padding' : 'height'} enabled style={{ flex: 1, flexDirection: 'column', justifyContent: 'center' }}>
279
+ <Container noPadding>
280
+ <NavBar
281
+ onActionLeft={() => navigation.goBack()}
282
+ btnStyle={{ paddingStart: 0 }}
283
+ title={t('ACCOUNT', 'Account')}
284
+ isVertical
285
+ style={styles.navBarStyle}
286
+ />
287
+ <CenterView style={styles.pagePadding}>
288
+ <View style={styles.photo}>
289
+ <OIcon
290
+ url={user?.photo}
291
+ src={!user?.photo && theme.images.general.user}
292
+ width={79}
293
+ height={79}
294
+ />
295
+ </View>
296
+ <OIconButton
297
+ icon={theme.images.general.camera}
298
+ borderColor={theme.colors.clear}
299
+ iconStyle={{ width: 16, height: 16 }}
300
+ style={{ maxWidth: 40, position: 'absolute', bottom: -2, alignSelf: 'center' }}
301
+ onClick={() => handleImagePicker()}
302
+ />
303
+ </CenterView>
304
+ <View style={{ height: 8, marginLeft: -40, marginRight: -40, backgroundColor: theme.colors.backgroundGray100, marginVertical: 32, zIndex: 10 }} />
305
+ <Spinner visible={formState?.loading || verifyPhoneState?.loading} />
306
+ <View style={styles.pagePadding}>
307
+ <UserFormDetailsUI
308
+ {...props}
309
+ isEdit
310
+ setWillVerifyOtpState={setWillVerifyOtpState}
236
311
  />
237
312
  </View>
238
- <OIconButton
239
- icon={theme.images.general.camera}
240
- borderColor={theme.colors.clear}
241
- iconStyle={{ width: 16, height: 16 }}
242
- style={{ maxWidth: 40, position: 'absolute', bottom: -2, alignSelf: 'center' }}
243
- onClick={() => handleImagePicker()}
244
- />
245
- </CenterView>
246
- <View style={{ height: 8, marginLeft: -40, marginRight: -40, backgroundColor: theme.colors.backgroundGray100, marginVertical: 32, zIndex: 10 }} />
247
- <Spinner visible={formState?.loading} />
248
- <View style={styles.pagePadding}>
249
- <UserFormDetailsUI {...props} isEdit />
250
- </View>
251
- </Container>
252
- </KeyboardAvoidingView>
313
+ </Container>
314
+ </KeyboardAvoidingView>
315
+ <OModal
316
+ open={isModalVisible}
317
+ onClose={() => setIsModalVisible(false)}
318
+ entireModal
319
+ >
320
+ <VerifyPhone
321
+ phone={phoneInputData.phone}
322
+ verifyPhoneState={verifyPhoneState}
323
+ checkPhoneCodeState={checkPhoneCodeState}
324
+ handleCheckPhoneCode={handleCheckPhoneCode}
325
+ setCheckPhoneCodeState={setCheckPhoneCodeState}
326
+ handleVerifyCodeClick={handleVerifyCodeClick}
327
+ onClose={() => setIsModalVisible(false)}
328
+ />
329
+ </OModal>
330
+ </>
331
+
253
332
  );
254
333
  };
255
334
 
256
-
257
335
  export const UserProfileForm = (props: any) => {
258
336
  const profileProps = {
259
337
  ...props,
@@ -37,8 +37,8 @@ export const VerifyPhone = (props: any) => {
37
37
  height: 75,
38
38
  marginBottom: 25,
39
39
  borderWidth: 1,
40
- borderColor: theme.colors.disabled,
41
- borderRadius: 20,
40
+ borderColor: theme.colors.inputBorderColor,
41
+ borderRadius: 8,
42
42
  textAlign: 'center',
43
43
  fontSize: 40
44
44
  }
@@ -131,11 +131,11 @@ export const VerifyPhone = (props: any) => {
131
131
 
132
132
  return (
133
133
  <Container>
134
- <OText size={30} style={{ textAlign: 'left' }}>
135
- {t('VERIFY_PHONE', 'Verify Phone')}
134
+ <OText size={26} style={{ textAlign: 'left', fontWeight: '600', marginTop: 10, marginBottom: 30 }}>
135
+ {t('ENTER_VERIFICATION_CODE', 'Enter verification code')}
136
136
  </OText>
137
137
  {lastNumbers && (
138
- <OText size={20} color={theme.colors.disabled}>
138
+ <OText size={16} color={theme.colors.disabled}>
139
139
  {`${t('MESSAGE_ENTER_VERIFY_CODE', 'Please, enter the verification code we sent to your mobile ending with')} **${lastNumbers}`}
140
140
  </OText>
141
141
  )}
@@ -174,7 +174,7 @@ export const VerifyPhone = (props: any) => {
174
174
  ).result?.result)?.map((e: any, i: number) => (
175
175
  <OText
176
176
  key={i}
177
- size={20}
177
+ size={16}
178
178
  color={theme.colors.error}
179
179
  >
180
180
  {`* ${t(getTraduction(e))}`}
@@ -183,12 +183,9 @@ export const VerifyPhone = (props: any) => {
183
183
  </ErrorSection>
184
184
  )}
185
185
  <ResendSection>
186
- <OText size={16} style={{ marginRight: 5 }}>
187
- {t('ARE_YOU_NOT_SEEING_THE_CODE', 'Are you not seeing the code?')}
188
- </OText>
189
186
  <Pressable onPress={() => handleSendCodeAgain()}>
190
187
  <OText size={16} color={theme.colors.primary}>
191
- {t('SEND_AGAIN', 'Send Again')}
188
+ {t('RESEND_CODE', 'Resend code')}
192
189
  </OText>
193
190
  </Pressable>
194
191
  </ResendSection>
@@ -19,13 +19,12 @@ export const CountDownContainer = styled.View`
19
19
  export const ResendSection = styled.View`
20
20
  display: flex;
21
21
  flex-direction: row;
22
- justify-content: center;
23
22
  margin-bottom: 30px;
24
23
  `
25
24
 
26
25
  export const WrappCountdown = styled.View`
27
26
  padding-top: 20px;
28
- padding-bottom: 20px;
27
+ padding-bottom: 50px;
29
28
  `
30
29
 
31
30
  export const InputsSection = styled.View`
@@ -31,6 +31,12 @@ export interface ProfileParams {
31
31
  validationFields?: any;
32
32
  showField?: any;
33
33
  isRequiredField?: any;
34
+ handleSendVerifyCode?: any;
35
+ handleCheckPhoneCode?: any;
36
+ checkPhoneCodeState?: any;
37
+ verifyPhoneState?: any;
38
+ setCheckPhoneCodeState?: any;
39
+ isVerifiedPhone?: any;
34
40
  }
35
41
 
36
42
  export interface AddressListParams {