ordering-ui-react-native 0.23.48 → 0.23.49

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.23.48",
3
+ "version": "0.23.49",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,12 +1,13 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
2
  import PhoneInput from "react-native-phone-number-input";
3
- import { StyleSheet, View } from 'react-native';
3
+ import { Pressable, StyleSheet, View } from 'react-native';
4
4
  import { useLanguage, useConfig } from 'ordering-components/native';
5
5
  import { useTheme } from 'styled-components/native';
6
6
  import { Wrapper } from './styles'
7
7
 
8
8
  import { PhoneInputParams } from '../../types';
9
9
  import { OIcon, OText } from '../shared';
10
+ import { OModal } from '../../../../../src/components/shared'
10
11
  import { findExitingCode, transformCountryCode } from '../../utils'
11
12
 
12
13
  export const PhoneInputNumber = (props: PhoneInputParams) => {
@@ -25,7 +26,8 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
25
26
  isDisabled,
26
27
  isStartValidation,
27
28
  changeCountry,
28
- updateStateWithSubmit
29
+ updateStateWithSubmit,
30
+ defaultCodeFallback
29
31
  } = props
30
32
 
31
33
  const theme = useTheme();
@@ -34,7 +36,11 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
34
36
  const [{ configs }] = useConfig()
35
37
  const phoneInput = useRef<PhoneInput>(null);
36
38
  const [userphoneNumber, setUserphoneNumber] = useState('');
37
-
39
+ const [countryPhoneSuboptions, setCountryPhoneSuboptions] = useState({
40
+ open: false,
41
+ options: []
42
+ })
43
+ const countriesWithSubOptions = ['PR']
38
44
  const style = StyleSheet.create({
39
45
  input: {
40
46
  backgroundColor: theme.colors.white,
@@ -109,6 +115,37 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
109
115
  }
110
116
  }, [defaultValue])
111
117
 
118
+ useEffect(() => {
119
+ if (defaultCodeFallback && countriesWithSubOptions.includes(defaultCode) && phoneInput.current) {
120
+ phoneInput.current?.setState({
121
+ ...phoneInput.current.state,
122
+ code: `${defaultCodeFallback}`
123
+ })
124
+ }
125
+ }, [phoneInput.current])
126
+
127
+ const _changeCountry = (c) => {
128
+ changeCountry?.(c)
129
+ if (c.callingCode?.length > 1) {
130
+ setCountryPhoneSuboptions({
131
+ open: true,
132
+ options: c.callingCode
133
+ })
134
+ }
135
+ }
136
+
137
+ const handleSelectCallingCode = (option : any) => {
138
+ setCountryPhoneSuboptions({
139
+ open: false,
140
+ options: []
141
+ })
142
+ handleChangeNumber(`+${option}`)
143
+ phoneInput.current?.setState({
144
+ ...phoneInput.current.state,
145
+ code: `${option}`
146
+ })
147
+ }
148
+
112
149
  return (
113
150
  <Wrapper onPress={() => forwardRef?.current?.focus?.()}>
114
151
  {(isStartValidation && userphoneNumber === '') && (
@@ -130,7 +167,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
130
167
  : findExitingCode(configs?.default_country_code?.value?.toUpperCase())}
131
168
  onChangeFormattedText={(text: string) => handleChangeNumber(text)}
132
169
  withDarkTheme
133
- onChangeCountry={(country) => changeCountry?.(country)}
170
+ onChangeCountry={(country : any) => _changeCountry?.(country)}
134
171
  countryPickerProps={{ withAlphaFilter: true }}
135
172
  textContainerStyle={{ ...style.input, ...inputStyle ? inputStyle : {} }}
136
173
  textInputStyle={textStyle}
@@ -151,6 +188,39 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
151
188
  {data.error}
152
189
  </OText>
153
190
  )}
191
+ <OModal
192
+ open={countryPhoneSuboptions.open}
193
+ onClose={() => setCountryPhoneSuboptions({
194
+ open: false,
195
+ options: []
196
+ })}
197
+ title={t('SELECT_THE_PHONE_CODE', 'Select the phone code')}
198
+ entireModal
199
+ >
200
+ <View
201
+ style={{
202
+ alignItems: 'center'
203
+ }}
204
+ >
205
+ {countryPhoneSuboptions.options.map((option : any) => (
206
+ <Pressable
207
+ style={{
208
+ margin: 10,
209
+ padding: 10,
210
+ borderBottomColor: '#ccc',
211
+ borderBottomWidth: 1,
212
+ width: '100%'
213
+ }}
214
+ key={option}
215
+ onPress={() => handleSelectCallingCode(option)}
216
+ >
217
+ <OText>
218
+ {`+${option}`}
219
+ </OText>
220
+ </Pressable>
221
+ ))}
222
+ </View>
223
+ </OModal>
154
224
  </Wrapper>
155
225
  )
156
226
  }
@@ -432,6 +432,7 @@ export const UserFormDetailsUI = (props: any) => {
432
432
  changeCountry={(val: any) => changeCountry(val)}
433
433
  defaultValue={phoneUpdate ? '' : cellphoneValue()}
434
434
  defaultCode={user?.country_code ?? user?.country_phone_code ?? null}
435
+ defaultCodeFallback={user?.country_phone_code}
435
436
  boxStyle={styles.phoneSelect}
436
437
  inputStyle={styles.phoneInputStyle}
437
438
  textStyle={{ color: theme.colors.textNormal, fontSize: 12, padding: 0 }}
@@ -409,6 +409,7 @@ const UserVerificationUI = (props: any) => {
409
409
  defaultCode={phoneState?.country_phone_code.replace('+', '')}
410
410
  boxStyle={style.phoneSelect}
411
411
  inputStyle={style.phoneInputStyle}
412
+ defaultCodeFallback={phoneState?.country_phone_code.replace('+', '')}
412
413
  textStyle={{ color: theme.colors.textNormal, fontSize: 12, padding: 0 }}
413
414
  noDropIcon
414
415
  isDisabled
@@ -148,7 +148,8 @@ export interface PhoneInputParams {
148
148
  isDisabled?: any;
149
149
  isStartValidation?: any;
150
150
  changeCountry?: any;
151
- updateStateWithSubmit?: boolean
151
+ updateStateWithSubmit?: boolean,
152
+ defaultCodeFallback?: number
152
153
  }
153
154
 
154
155
  export interface LanguageSelectorParams {