Skip to content

Commit

Permalink
POS: update fetching and filtering of orders
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Jan 15, 2023
1 parent 9a3c2fa commit 4f56ef8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
17 changes: 14 additions & 3 deletions stores/PosStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const genIdemptotencyKey = () =>
`${genHex(8)}-${genHex(4)}-${genHex(4)}-${genHex(4)}-${genHex(12)}}`;

export default class PosStore {
@observable public orders: any = {};
@observable public orders: Array<Order> = [];
@observable public filteredOrders: Array<Order> = [];
@observable public loading = false;
@observable public error = false;

Expand All @@ -28,6 +29,15 @@ export default class PosStore {
this.settingsStore = settingsStore;
}

@action
public updateSearch = (value: string) => {
this.filteredOrders = this.orders.filter(
(item: any) =>
item.getItemsList.includes(value) ||
item.getItemsList.toLowerCase().includes(value)
);
};

@action
public makePayment = ({
orderId,
Expand All @@ -42,7 +52,7 @@ export default class PosStore {
ReactNativeBlobUtil.fetch(
'POST',
// DEV -> 'https://connect.squareupsandbox.com/v2/payments',
'https://connect.squareup.com/v2/payments',
'https://connect.squareupsandbox.com/v2/payments',
{
Authorization: `Bearer ${squareAccessToken}`,
'Content-Type': 'application/json'
Expand Down Expand Up @@ -91,7 +101,7 @@ export default class PosStore {
ReactNativeBlobUtil.fetch(
'POST',
// DEV -> 'https://connect.squareupsandbox.com/v2/orders/search'
'https://connect.squareup.com/v2/orders/search',
'https://connect.squareupsandbox.com/v2/orders/search',
{
Authorization: `Bearer ${squareAccessToken}`,
'Content-Type': 'application/json'
Expand All @@ -115,6 +125,7 @@ export default class PosStore {
.json()
.orders.map((order: any) => new Order(order));
this.orders = orders;
this.filteredOrders = orders;
} else {
this.orders = [];
this.loading = false;
Expand Down
5 changes: 4 additions & 1 deletion views/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ export default class OrderView extends React.Component<OrderProps, OrderState> {
).toFixed(2);
} else if (customType === 'amount') {
totalAmount = !isNaN(Number(customAmount))
? order.getTotalMoney + Number(customAmount)
? `${
Number(Number(order.getTotalMoney) +
Number(customAmount)).toFixed(2)
}`
: order.getTotalMoney;
tipAmount = !isNaN(Number(customAmount))
? Number(customAmount).toFixed(2)
Expand Down
29 changes: 10 additions & 19 deletions views/Wallet/PosPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ export default class PosPane extends React.PureComponent<
).start();
}

updateSearch = (value: string) => {
const { orders } = this.props.PosStore;
const result = orders.filter(
(item: any) =>
item.getItemsList.includes(value) ||
item.getItemsList.toLowerCase().includes(value)
);
this.setState({
search: value,
filteredOrders: result
});
};

renderItem = (order) => {
const { navigation, FiatStore } = this.props;
const { getRate } = FiatStore;
Expand All @@ -111,11 +98,10 @@ export default class PosPane extends React.PureComponent<

render() {
const { SettingsStore, PosStore, FiatStore, navigation } = this.props;
const { search, filteredOrders } = this.state;
const { loading, getOrders } = PosStore;
const orders = filteredOrders;
const { search } = this.state;
const { loading, getOrders, filteredOrders, updateSearch } = PosStore;
const { getRate, getFiatRates } = FiatStore;
const fiatLoading = FiatStore.loading;
const orders = filteredOrders;

const headerString = `${localeString('general.orders')} (${
orders.length || 0
Expand All @@ -129,7 +115,7 @@ export default class PosPane extends React.PureComponent<
SettingsStore={SettingsStore}
/>

{fiatLoading ? (
{getRate() === '$N/A' ? (
<Animated.View
style={{
alignSelf: 'center',
Expand Down Expand Up @@ -171,7 +157,12 @@ export default class PosPane extends React.PureComponent<
{!loading && (
<SearchBar
placeholder={localeString('general.search')}
onChangeText={this.updateSearch}
onChangeText={(value: string) => {
updateSearch(value);
this.setState({
search: value
});
}}
value={search}
inputStyle={{
color: themeColor('text')
Expand Down

0 comments on commit 4f56ef8

Please sign in to comment.