ordering-ui-react-native 0.22.12 → 0.22.14

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.22.12",
3
+ "version": "0.22.14",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -137,7 +137,7 @@ export const OrderHeaderComponent = (props: OrderHeader) => {
137
137
  const deliveryDate = () => {
138
138
  const dateString = order?.delivery_datetime_utc ?? order?.delivery_datetime
139
139
  const currentDate = new Date();
140
- const receivedDate: any = new Date(dateString);
140
+ const receivedDate: any = new Date(order?.delivery_datetime);
141
141
 
142
142
  const formattedDate = receivedDate <= currentDate
143
143
  ? `${t('ASAP_ABBREVIATION', 'ASAP')}(${parseDate(dateString, { utc: !!order?.delivery_datetime_utc })})`
@@ -52,31 +52,32 @@ export const usePrinterCommands = () => {
52
52
  const customerName = (order: any) => `${order?.customer?.name ?? ''} ${order?.customer?.middle_name ?? ''} ${order?.customer?.lastname ?? ''} ${order?.customer?.second_lastname ?? ''}`?.replace(' ', ' ')?.trim() ?? ''
53
53
 
54
54
  const deliveryDate = (order: any) => {
55
- const dateString = order?.delivery_datetime_utc ? order?.delivery_datetime_utc : order?.delivery_datetime
55
+ const dateString = order?.delivery_datetime_utc ?? order?.delivery_datetime
56
56
  const currentDate = new Date();
57
- const receivedDate: any = new Date(dateString.replace(/-/g, '/'));
57
+ const receivedDate: any = new Date(dateString);
58
+
58
59
  const formattedDate = receivedDate <= currentDate
59
- ? `${t('ASAP_ABBREVIATION', 'ASAP')}(${parseDate(receivedDate.toLocaleString(), { utc: !!order?.delivery_datetime_utc })})`
60
- : parseDate(receivedDate.toLocaleString(), { utc: !!order?.delivery_datetime_utc })
60
+ ? `${t('ASAP_ABBREVIATION', 'ASAP')}(${parseDate(dateString, { utc: !!order?.delivery_datetime_utc })})`
61
+ : parseDate(dateString, { utc: !!order?.delivery_datetime_utc })
61
62
  return formattedDate
62
63
  }
63
64
 
64
- const generateProductsText = (order: any) => {
65
+ const generateProductsText = (order: any, { endLine }: any) => {
65
66
  const list: any = []
66
67
 
67
68
  if (order?.products.length) {
68
69
  order?.products.map((product: any) => {
69
- list.push(`${product?.quantity} ${product?.name} \t ${parsePrice(product.total ?? getProductPrice(product))}\n`)
70
+ list.push(`${product?.quantity} ${product?.name} \t ${parsePrice(product.total ?? getProductPrice(product))}${endLine}`)
70
71
 
71
72
  if (product?.ingredients?.length) {
72
- list.push({ text: `\t ${t('INGREDIENTS', 'Ingredients')}:\n`, props: { fontSize: 10 } })
73
+ list.push({ text: `\t ${t('INGREDIENTS', 'Ingredients')}:${endLine}`, props: { fontSize: 10 } })
73
74
  product?.ingredients?.map((ingredient: any) => {
74
- list.push({ text: `\t ${t('NO', 'No')} ${ingredient.name}\n` , fontSize: 10 })
75
+ list.push({ text: `\t ${t('NO', 'No')} ${ingredient.name}${endLine}` , fontSize: 10 })
75
76
  })
76
77
  }
77
78
 
78
79
  product.options?.map((option: any) => {
79
- list.push({ text: `\t ${option.name}\n`, props: { fontSize: 10 } })
80
+ list.push({ text: `\t ${option.name}${endLine}`, props: { fontSize: 10 } })
80
81
 
81
82
  option.suboptions?.map((suboption: any) => {
82
83
  const { quantity, name, position, price } = suboption
@@ -87,23 +88,23 @@ export const usePrinterCommands = () => {
87
88
  : `${quantity} x ${name} +${parsePrice(price)}`
88
89
  : 'No'
89
90
 
90
- list.push({ text: `\t\t ${string}\n`, props: { fontSize: 10 } })
91
+ list.push({ text: `\t\t ${string}${endLine}`, props: { fontSize: 10 } })
91
92
  })
92
93
  })
93
94
 
94
95
  if (product.comment) {
95
- list.push({ text: `\t ${t('COMMENT', 'Comment')}\n`, props: { fontSize: 10 } })
96
- list.push({ text: `\t\t ${product.comment}\n`, props: { fontSize: 10 } })
96
+ list.push({ text: `\t ${t('COMMENT', 'Comment')}${endLine}`, props: { fontSize: 10 } })
97
+ list.push({ text: `\t\t ${product.comment}${endLine}`, props: { fontSize: 10 } })
97
98
  }
98
99
 
99
- list.push('_separator_\n')
100
+ list.push('_separator_')
100
101
  })
101
102
  }
102
103
 
103
104
  return list
104
105
  }
105
106
 
106
- const paymethodsList = (order: any) => {
107
+ const paymethodsList = (order: any, { endLine }: any) => {
107
108
  const list: any = []
108
109
 
109
110
  if (order?.payment_events?.length > 0) {
@@ -116,7 +117,7 @@ export const usePrinterCommands = () => {
116
117
  ? parsePrice(order?.cash, { currency: order?.currency })
117
118
  : `-${parsePrice(event?.amount, { currency: order?.currency })}`
118
119
 
119
- list.push(`${payment} \t ${amount}\n`)
120
+ list.push(`${payment} \t ${amount}${endLine}`)
120
121
  })
121
122
  }
122
123
 
@@ -126,60 +127,61 @@ export const usePrinterCommands = () => {
126
127
  const generateCommands = (order: any, printMode: string = 'append') => {
127
128
  let commands: any = [];
128
129
 
130
+ const isAppendMode = printMode === 'append'
131
+ const jumpLine = isAppendMode ? '\n' : ' '
132
+ const endLine = isAppendMode ? '\n' : ''
133
+
129
134
  const textProps = { fontSize: 12 }
130
135
 
131
136
  const appends: any = [
132
- { text: `${t('ORDER_NO', 'Order No.')} ${order.id}\n`, props: { fontSize: 16 } },
133
- ' ',
134
- `${order.orderStatus}\n`,
135
- { text: `${t('ORDER_TYPE', 'Order Type')}: ${deliveryStatus[order?.delivery_type]}\n`, props: { fontSize: 14 } },
136
- { text: `${t(`PAYMENT_METHOD${paymethodsLength(order) > 1 ? 'S' : ''}`, `Payment method${paymethodsLength(order) > 1 ? 's' : ''}`)}: ${handlePaymethodsListString(order)}\n`, props: { fontSize: 14 } },
137
- `${!!order?.delivery_option ? `${t('DELIVERY_PREFERENCE', 'Delivery Preference')}: ${t(order?.delivery_option?.name?.toUpperCase()?.replace(/ /g, '_'), order?.delivery_option?.name)}\n` : '\n'}`,
138
- `${t('DELIVERY_DATE', 'Delivery Date')}: ${deliveryDate(order)}\n`,
139
- '_separator_\n',
140
- { text: `${t('CUSTOMER_DETAILS', 'Customer details')}\n`, props: { fontSize: 14 } },
141
- `${t('FULL_NAME', 'Full Name')}: ${customerName(order)}\n`,
142
- `${t('EMAIL', 'Email')}: ${order?.customer?.email}\n`,
143
- `${!!order?.customer?.cellphone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.cellphone}\n` : '\n'}`,
144
- `${!!order?.customer?.phone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.phone}\n` : '\n'}`,
145
- `${t('FULL_ADDRESS', 'Full Addres')}: ${order?.customer?.address}\n`,
146
- `${!!order?.customer?.internal_number ? `${t('INTERNAL_NUMBER', 'Internal Number')}: ${order?.customer?.internal_number}\n` : '\n'}`,
147
- `${!!order?.customer?.zipcode ? `${t('ZIPCODE', 'Zipcode')}: ${order?.customer?.zipcode}\n` : '\n'}`,
148
- '_separator_\n',
149
- { text: `${t('BUSINESS_DETAILS', 'Business details')}\n`, props: { fontSize: 14 } },
150
- `${order?.business?.name}\n`,
151
- `${order?.business?.email}\n`,
152
- `${!!order?.business?.cellphone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.cellphone}\n` : '\n'}`,
153
- `${!!order?.business?.phone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.phone}\n` : '\n'}`,
154
- `${t('ADDRESS', 'Address')}: ${order?.business?.address}\n`,
155
- `${!!order?.business?.address_notes ? `${t('SPECIAL_ADDRESS', 'Special Address')}: ${order?.business?.address_notes}\n` : '\n'}`,
156
- '_separator_\n',
157
- { text: `${t('ORDER_DETAILS', 'Order Details')}\n`, props: { fontSize: 14 } },
158
- `${!!order?.comment ? `${t('ORDER_COMMENT', 'Order Comment')}: ${order?.comment}\n` : '\n'}`,
159
- ...generateProductsText(order),
160
- ' ',
161
- `${t('SUBTOTAL', 'Subtotal')} \t\t ${parsePrice(order.tax_type === 1 ? (order?.summary?.subtotal + order?.summary?.tax) ?? 0 : order?.summary?.subtotal ?? 0)}\n`,
162
- `${order?.summary?.discount > 0 ? `${order?.offer_type === 1 ? `${t('DISCOUNT', 'Discount')} (${verifyDecimals(order?.offer_rate, parsePrice)}%)\n` : t('DISCOUNT', 'Discount')} \t\t ${parsePrice(order?.summary?.discount)}\n` : '\n'}`,
163
- `${order?.tax_type !== 1 ? `${t('TAX', 'Tax')} (${verifyDecimals(order?.summary?.tax_rate, parseNumber)}%) \t\t ${parsePrice(order?.summary?.tax ?? 0)}\n` : '\n'}`,
164
- `${order?.summary?.delivery_price > 0 && order.delivery_type !== 2 ? `${t('DELIVERY_FEE', 'Delivery Fee')} \t\t ${parsePrice(order?.summary?.delivery_price ?? 0)}\n` : '\n'}`,
165
- `${(order?.summary?.driver_tip > 0 || order?.driver_tip > 0) && order.delivery_type !== 2 ? `${t('DRIVER_TIP', 'Driver tip')} ${percentTip(order) ? `(${percentTip(order)}%)` : ''} \t\t ${parsePrice(order?.summary?.driver_tip ?? 0)}\n` : '\n'}`,
166
- `${order?.summary?.service_fee > 0 ? `${t('SERVICE_FEE', 'Service Fee')} (${verifyDecimals(order?.summary?.service_fee, parseNumber)}%) \t\t ${parsePrice(order?.summary?.service_fee ?? 0)}\n` : '\n'}`,
167
- '_separator_\n',
168
- `${t('TOTAL', 'Total')} \t\t ${parsePrice(order?.summary?.total ?? 0)}\n`,
169
- ' ',
170
- `${order?.payment_events?.length > 0 ? `${t('PAYMENTS', 'Payments')}\n` : '\n'}`,
171
- ...paymethodsList(order),
172
- ' ',
173
- '\n',
174
- ' ',
175
- '\n',
137
+ { text: `${t('ORDER_NO', 'Order No.')} ${order.id}${endLine}`, props: { fontSize: 16 } },
138
+ jumpLine,
139
+ `${order.orderStatus}${endLine}`,
140
+ { text: `${t('ORDER_TYPE', 'Order Type')}: ${deliveryStatus[order?.delivery_type]}${endLine}`, props: { fontSize: 14 } },
141
+ { text: `${t(`PAYMENT_METHOD${paymethodsLength(order) > 1 ? 'S' : ''}`, `Payment method${paymethodsLength(order) > 1 ? 's' : ''}`)}: ${handlePaymethodsListString(order)}${endLine}`, props: { fontSize: 14 } },
142
+ `${!!order?.delivery_option ? `${t('DELIVERY_PREFERENCE', 'Delivery Preference')}: ${t(order?.delivery_option?.name?.toUpperCase()?.replace(/ /g, '_'), order?.delivery_option?.name)}${endLine}` : ''}`,
143
+ `${t('DELIVERY_DATE', 'Delivery Date')}: ${deliveryDate(order)}${endLine}`,
144
+ '_separator_',
145
+ { text: `${t('CUSTOMER_DETAILS', 'Customer details')}${endLine}`, props: { fontSize: 14 } },
146
+ `${t('FULL_NAME', 'Full Name')}: ${customerName(order)}${endLine}`,
147
+ `${t('EMAIL', 'Email')}: ${order?.customer?.email}${endLine}`,
148
+ `${!!order?.customer?.cellphone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.cellphone}${endLine}` : ''}`,
149
+ `${!!order?.customer?.phone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.phone}${endLine}` : ''}`,
150
+ `${t('FULL_ADDRESS', 'Full Addres')}: ${order?.customer?.address}${endLine}`,
151
+ `${!!order?.customer?.internal_number ? `${t('INTERNAL_NUMBER', 'Internal Number')}: ${order?.customer?.internal_number}${endLine}` : ''}`,
152
+ `${!!order?.customer?.zipcode ? `${t('ZIPCODE', 'Zipcode')}: ${order?.customer?.zipcode}${endLine}` : ''}`,
153
+ '_separator_',
154
+ { text: `${t('BUSINESS_DETAILS', 'Business details')}${endLine}`, props: { fontSize: 14 } },
155
+ `${order?.business?.name}${endLine}`,
156
+ `${order?.business?.email}${endLine}`,
157
+ `${!!order?.business?.cellphone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.cellphone}${endLine}` : ''}`,
158
+ `${!!order?.business?.phone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.phone}${endLine}` : ''}`,
159
+ `${t('ADDRESS', 'Address')}: ${order?.business?.address}${endLine}`,
160
+ `${!!order?.business?.address_notes ? `${t('SPECIAL_ADDRESS', 'Special Address')}: ${order?.business?.address_notes}${endLine}` : ''}`,
161
+ '_separator_',
162
+ { text: `${t('ORDER_DETAILS', 'Order Details')}${endLine}`, props: { fontSize: 14 } },
163
+ `${!!order?.comment ? `${t('ORDER_COMMENT', 'Order Comment')}: ${order?.comment}${endLine}` : ''}`,
164
+ ...generateProductsText(order, { endLine }),
165
+ `${t('SUBTOTAL', 'Subtotal')} \t\t ${parsePrice(order.tax_type === 1 ? (order?.summary?.subtotal + order?.summary?.tax) ?? 0 : order?.summary?.subtotal ?? 0)}${endLine}`,
166
+ `${order?.summary?.discount > 0 ? `${order?.offer_type === 1 ? `${t('DISCOUNT', 'Discount')} (${verifyDecimals(order?.offer_rate, parsePrice)}%)${endLine}` : t('DISCOUNT', 'Discount')} \t\t ${parsePrice(order?.summary?.discount)}${endLine}` : ''}`,
167
+ `${order?.tax_type !== 1 ? `${t('TAX', 'Tax')} (${verifyDecimals(order?.summary?.tax_rate, parseNumber)}%) \t\t ${parsePrice(order?.summary?.tax ?? 0)}${endLine}` : ''}`,
168
+ `${order?.summary?.delivery_price > 0 && order.delivery_type !== 2 ? `${t('DELIVERY_FEE', 'Delivery Fee')} \t\t ${parsePrice(order?.summary?.delivery_price ?? 0)}${endLine}` : ''}`,
169
+ `${(order?.summary?.driver_tip > 0 || order?.driver_tip > 0) && order.delivery_type !== 2 ? `${t('DRIVER_TIP', 'Driver tip')} ${percentTip(order) ? `(${percentTip(order)}%)` : ''} \t\t ${parsePrice(order?.summary?.driver_tip ?? 0)}${endLine}` : ''}`,
170
+ `${order?.summary?.service_fee > 0 ? `${t('SERVICE_FEE', 'Service Fee')} (${verifyDecimals(order?.summary?.service_fee, parseNumber)}%) \t\t ${parsePrice(order?.summary?.service_fee ?? 0)}${endLine}` : ''}`,
171
+ '_separator_',
172
+ `${t('TOTAL', 'Total')} \t\t ${parsePrice(order?.summary?.total ?? 0)}${endLine}`,
173
+ jumpLine,
174
+ `${order?.payment_events?.length > 0 ? `${t('PAYMENTS', 'Payments')}${endLine}` : ''}`,
175
+ ...paymethodsList(order, { endLine }),
176
+ jumpLine,
177
+ jumpLine,
176
178
  ]
177
179
 
178
180
  commands = [
179
181
  ...commands,
180
182
  ...appends.map((append: any) => {
181
183
  return append === '_separator_'
182
- ? { [printMode]: '---------------------------------------' }
184
+ ? { [printMode]: `---------------------------------------${endLine}` }
183
185
  : {
184
186
  [printMode]: append?.text ?? append,
185
187
  ...textProps,
@@ -101,7 +101,7 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
101
101
  const deliveryDate = (order: any) => {
102
102
  const dateString = order?.delivery_datetime_utc ?? order?.delivery_datetime
103
103
  const currentDate = new Date();
104
- const receivedDate: any = new Date(dateString);
104
+ const receivedDate: any = new Date(order?.delivery_datetime);
105
105
 
106
106
  const formattedDate = receivedDate <= currentDate
107
107
  ? `${t('ASAP_ABBREVIATION', 'ASAP')}(${parseDate(dateString, { utc: !!order?.delivery_datetime_utc })})`