ordering-ui-react-native 0.16.45-release → 0.16.46-release

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.16.45-release",
3
+ "version": "0.16.46-release",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -91,6 +91,10 @@ export const OrderContentComponent = (props: OrderContent) => {
91
91
  return order?.taxes?.filter((tax: any) => tax?.type === 1)?.reduce((carry: number, tax: any) => carry + (tax?.summary?.tax_after_discount ?? tax?.summary?.tax), 0)
92
92
  }
93
93
 
94
+ const containsOnlyNumbers = (str: string) => {
95
+ return /^\d+$/.test(str);
96
+ }
97
+
94
98
  return (
95
99
  <OrderContent isOrderGroup={isOrderGroup} lastOrder={lastOrder}>
96
100
  {isOrderGroup && (
@@ -148,7 +152,7 @@ export const OrderContentComponent = (props: OrderContent) => {
148
152
  <View style={styles.linkWithIcons}>
149
153
  <OLink
150
154
  PressStyle={styles.linkWithIcons}
151
- url={`tel:${order?.business?.cellphone}`}
155
+ url={`tel:${containsOnlyNumbers(order?.business?.cellphone) ? order?.business?.cellphone : 'invalid'}`}
152
156
  shorcut={`${order?.business?.cellphone}`}
153
157
  TextStyle={styles.textLink}
154
158
  />
@@ -159,7 +163,7 @@ export const OrderContentComponent = (props: OrderContent) => {
159
163
  <View style={styles.linkWithIcons}>
160
164
  <OLink
161
165
  PressStyle={styles.linkWithIcons}
162
- url={`tel:${order?.business?.phone}`}
166
+ url={`tel:${containsOnlyNumbers(order?.business?.cellphone) ? order?.business?.phone : 'invalid'}`}
163
167
  shorcut={order?.business?.phone}
164
168
  TextStyle={styles.textLink}
165
169
  />
@@ -274,7 +278,7 @@ export const OrderContentComponent = (props: OrderContent) => {
274
278
  <View style={styles.linkWithIcons}>
275
279
  <OLink
276
280
  PressStyle={styles.linkWithIcons}
277
- url={`tel:${!!order?.customer?.country_phone_code ? '+' + order?.customer?.country_phone_code : ''} ${order?.customer?.cellphone}`}
281
+ url={`tel:${!!order?.customer?.country_phone_code ? '+' + order?.customer?.country_phone_code : ''} ${containsOnlyNumbers(order?.customer?.cellphone) ? order?.customer?.cellphone : 'invalid'}`}
278
282
  shorcut={`${!!order?.customer?.country_phone_code ? '+' + order?.customer?.country_phone_code : ''} ${order?.customer?.cellphone}`}
279
283
  TextStyle={styles.textLink}
280
284
  />
@@ -285,7 +289,7 @@ export const OrderContentComponent = (props: OrderContent) => {
285
289
  <View style={styles.linkWithIcons}>
286
290
  <OLink
287
291
  PressStyle={styles.linkWithIcons}
288
- url={`tel:${order?.customer?.phone}`}
292
+ url={`tel:${containsOnlyNumbers(order?.customer?.phone) ? order?.customer?.phone : 'invalid'}`}
289
293
  shorcut={order?.customer?.phone}
290
294
  TextStyle={styles.textLink}
291
295
  />
@@ -29,8 +29,19 @@ const OLink = (props: Props): React.ReactElement => {
29
29
  ],
30
30
  );
31
31
 
32
+ const handleInvalidNumberAlert = () =>
33
+ Alert.alert(
34
+ t('ERROR_OPENING_THE_LINK', 'Error opening the link'),
35
+ t('INVALID_NUMBER', 'Invalid number'),
36
+ [
37
+ {
38
+ text: t('OK', 'Ok'),
39
+ },
40
+ ],
41
+ );
42
+
32
43
  const handleOpenUrl = async (breakFunction = false) => {
33
- if(breakFunction) {
44
+ if (breakFunction) {
34
45
  return
35
46
  }
36
47
  if (!url) {
@@ -40,8 +51,9 @@ const OLink = (props: Props): React.ReactElement => {
40
51
 
41
52
  try {
42
53
  const supported = await Linking.canOpenURL(url);
43
-
44
- if (supported) {
54
+ if (url && url?.includes('tel:')) {
55
+ url?.includes('invalid') ? handleInvalidNumberAlert() : await Linking.openURL(url)
56
+ } else if (supported) {
45
57
  await Linking.openURL(url);
46
58
  } else {
47
59
  handleAlert();
@@ -57,17 +69,17 @@ const OLink = (props: Props): React.ReactElement => {
57
69
  <OButton
58
70
  onClick={() => handleOpenUrl()}
59
71
  text={shorcut} imgRightSrc=''
60
- textStyle={{color: 'white'}}
61
- style={{width: '100%', alignSelf: 'center', borderRadius: 10}}
72
+ textStyle={{ color: 'white' }}
73
+ style={{ width: '100%', alignSelf: 'center', borderRadius: 10 }}
62
74
  />
63
75
  ) : (
64
- <OText
65
- style={TextStyle}
66
- numberOfLines={1}
67
- ellipsizeMode="tail"
68
- color={color}>
69
- {shorcut}
70
- </OText>
76
+ <OText
77
+ style={TextStyle}
78
+ numberOfLines={1}
79
+ ellipsizeMode="tail"
80
+ color={color}>
81
+ {shorcut}
82
+ </OText>
71
83
  )}
72
84
  </Pressable>
73
85
  );
@@ -232,7 +232,7 @@ export const ProductItemAccordion = (props: ProductItemAccordionParams) => {
232
232
  <View style={{ display: 'flex', flexDirection: 'column', flex: 1, alignItems: 'flex-end', maxWidth: 100 }}>
233
233
  <View style={{ flexDirection: 'row' }}>
234
234
  <OText size={12} lineHeight={18} weight={'400'}>{parsePrice(product.total || product.price)}</OText>
235
- {(productInfo().ingredients.length > 0 || productInfo().options.length > 0 || product.comment) && (
235
+ {(productInfo().ingredients.length > 0 || productInfo().options.length > 0 || !!product.comment) && (
236
236
  <MaterialCommunityIcon name='chevron-down' size={18} />
237
237
  )}
238
238
  </View>
@@ -305,7 +305,7 @@ export const ProductItemAccordion = (props: ProductItemAccordionParams) => {
305
305
  ))}
306
306
  </ProductOptionsList>
307
307
  )}
308
- {product.comment && (
308
+ {!!product.comment && (
309
309
  <ProductComment>
310
310
  <OText size={10} color={theme.colors.textSecondary}>{t('SPECIAL_COMMENT', 'Special Comment')}</OText>
311
311
  <OText size={10} color={theme.colors.textThird}>{product.comment}</OText>