Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POS Enhancements #2031

Merged
merged 7 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,12 @@
"views.Settings.POS.Categories": "Categories",
"views.Settings.POS.Category": "Product category",
"views.Settings.POS.Category.name": "Category",
"views.Settings.POS.Category.noCategoriesDefined": "No categories defined yet",
"views.Settings.POS.saveCategory": "Save category",
"views.Settings.POS.Products": "Products",
"views.Settings.POS.Product": "Product",
"views.Settings.POS.Product.name": "Product name",
"views.Settings.POS.Product.noProductsDefined": "No products defined yet",
"views.Settings.POS.Product.sku": "SKU",
"views.Settings.POS.Product.price": "Price",
"views.Settings.POS.Product.active": "Active",
Expand Down Expand Up @@ -937,7 +939,6 @@
"pos.views.Wallet.PosPane.noOrdersStandalone": "No orders open at the moment",
"pos.views.Wallet.PosPane.noOrdersPaid": "No orders have been paid yet",
"pos.views.Wallet.PosPane.fetchingRates": "Fetching exchange rates",
"pos.views.Wallet.PosPane.noProducts": "No products have been created yet",
"pos.views.Wallet.PosPane.uncategorized": "Uncategorized",
"pos.views.Order.tax": "Tax",
"pos.views.Order.subtotalBitcoin": "Subtotal (Bitcoin)",
Expand Down
2 changes: 1 addition & 1 deletion views/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class OrderView extends React.Component<OrderProps, OrderState> {
const fiat = settings.fiat;
const disableTips: boolean = settings?.pos?.disableTips || false;
const enablePrinter: boolean =
(settings?.pos?.enablePrinter && RNPrint) || false;
(settings?.pos?.enablePrinter && !!RNPrint) || false;
const merchantName = settings?.pos?.merchantName;
const taxPercentage = settings?.pos?.taxPercentage;

Expand Down
99 changes: 64 additions & 35 deletions views/POS/Categories.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import * as React from 'react';
import { FlatList, TouchableOpacity, View } from 'react-native';
import { FlatList, Text, TouchableOpacity, View } from 'react-native';
import { ListItem, SearchBar } from 'react-native-elements';
import AddIcon from '../../assets/images/SVG/Add.svg';
import { inject, observer } from 'mobx-react';

import Header from '../../components/Header';
import LoadingIndicator from '../../components/LoadingIndicator';
import Screen from '../../components/Screen';

import InventoryStore from '../../stores/InventoryStore';

import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';

import ProductCategory from '../../models/ProductCategory';

import AddIcon from '../../assets/images/SVG/Add.svg';

interface ProductCategoriesProps {
navigation: any;
InventoryStore: InventoryStore;
Expand Down Expand Up @@ -50,7 +53,8 @@ export default class ProductCategories extends React.Component<
this.setState({
categories: categories
? categories.sort((a, b) => a.name.localeCompare(b.name))
: []
: [],
loading: false
});

return categories;
Expand Down Expand Up @@ -78,7 +82,7 @@ export default class ProductCategories extends React.Component<

render() {
const { navigation } = this.props;
const { categories, search } = this.state;
const { categories, search, loading } = this.state;

const Add = ({ navigation }: { navigation: any }) => (
<TouchableOpacity
Expand Down Expand Up @@ -134,37 +138,62 @@ export default class ProductCategories extends React.Component<
backgroundColor: themeColor('secondary')
}}
/>
<FlatList
data={categories}
renderItem={({ item }: { item: ProductCategory }) => (
<ListItem
containerStyle={{
borderBottomWidth: 0,
backgroundColor: 'transparent'
}}
onPress={async () => {
navigation.navigate(
'ProductCategoryDetails',
{ categoryId: item.id }
);
}}
>
<ListItem.Content>
<ListItem.Title
style={{
color: themeColor('text')
}}
>
{item.name}
</ListItem.Title>
</ListItem.Content>
</ListItem>
)}
keyExtractor={(item: ProductCategory, index) =>
`${item.id}-${index}`
}
ItemSeparatorComponent={this.renderSeparator}
/>
{loading && (
<View style={{ margin: 20 }}>
<LoadingIndicator />
</View>
)}
{!loading && categories?.length > 0 && (
<FlatList
data={categories}
renderItem={({
item
}: {
item: ProductCategory;
}) => (
<ListItem
containerStyle={{
borderBottomWidth: 0,
backgroundColor: 'transparent'
}}
onPress={async () => {
navigation.navigate(
'ProductCategoryDetails',
{ categoryId: item.id }
);
}}
>
<ListItem.Content>
<ListItem.Title
style={{
color: themeColor('text')
}}
>
{item.name}
</ListItem.Title>
</ListItem.Content>
</ListItem>
)}
keyExtractor={(item: ProductCategory, index) =>
`${item.id}-${index}`
}
ItemSeparatorComponent={this.renderSeparator}
/>
)}
{!loading && categories.length === 0 && (
<Text
style={{
color: themeColor('secondaryText'),
fontFamily: 'PPNeueMontreal-Book',
alignSelf: 'center',
marginTop: 20
}}
>
{localeString(
'views.Settings.POS.Category.noCategoriesDefined'
)}
</Text>
)}
</View>
</Screen>
);
Expand Down
32 changes: 24 additions & 8 deletions views/POS/Products.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as React from 'react';
import { FlatList, TouchableOpacity, View } from 'react-native';
import { FlatList, Text, TouchableOpacity, View } from 'react-native';
import { ListItem, SearchBar } from 'react-native-elements';
import AddIcon from '../../assets/images/SVG/Add.svg';
import { inject, observer } from 'mobx-react';

import Header from '../../components/Header';
import LoadingIndicator from '../../components/LoadingIndicator';
import Screen from '../../components/Screen';

import InventoryStore from '../../stores/InventoryStore';

import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';
import Product from '../../models/Product';
import LoadingIndicator from '../../components/LoadingIndicator';

interface ProductsProps {
navigation: any;
Expand All @@ -22,6 +22,7 @@ interface ProductsProps {
interface ProductsState {
search: string;
products: Array<Product>;
loading: boolean;
}

@inject('InventoryStore')
Expand All @@ -32,7 +33,8 @@ export default class Products extends React.Component<
> {
state = {
search: '',
products: []
products: [],
loading: true
};

async componentDidMount() {
Expand All @@ -49,7 +51,8 @@ export default class Products extends React.Component<
this.setState({
products: products
? products.sort((a, b) => a.name.localeCompare(b.name))
: []
: [],
loading: false
});

return products;
Expand All @@ -76,9 +79,8 @@ export default class Products extends React.Component<
};

render() {
const { navigation, InventoryStore } = this.props;
const { products, search } = this.state;
const { loading } = InventoryStore;
const { navigation } = this.props;
const { products, search, loading } = this.state;

const Add = ({ navigation }: { navigation: any }) => (
<TouchableOpacity
Expand Down Expand Up @@ -139,7 +141,7 @@ export default class Products extends React.Component<
<LoadingIndicator />
</View>
)}
{!loading && (
{!loading && products?.length > 0 && (
<FlatList
data={products}
renderItem={({ item }: { item: Product }) => (
Expand Down Expand Up @@ -171,6 +173,20 @@ export default class Products extends React.Component<
ItemSeparatorComponent={this.renderSeparator}
/>
)}
{!loading && products.length === 0 && (
<Text
style={{
color: themeColor('secondaryText'),
fontFamily: 'PPNeueMontreal-Book',
alignSelf: 'center',
marginTop: 20
}}
>
{localeString(
'views.Settings.POS.Product.noProductsDefined'
)}
</Text>
)}
</View>
</Screen>
);
Expand Down
Loading
Loading