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

Try to fix multiple printer tickets #1903

Merged
merged 3 commits into from
Oct 23, 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: 3 additions & 0 deletions src/navigation/restaurant/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { isMultiVendor } from '../../utils/order';
import {
selectIsPrinterConnected,
selectPrinter,
selectIsPrinting,
} from '../../redux/Restaurant/selectors';
import { DatadogLogger } from '../../Datadog';

Expand Down Expand Up @@ -66,6 +67,7 @@ class OrderScreen extends Component {
});
this.props.printOrder(order);
}}
disablePrintButton={ this.props.isPrinting }
/>
<OrderNotes order={order} />
<OrderItems order={order} />
Expand Down Expand Up @@ -124,6 +126,7 @@ function mapStateToProps(state, ownProps) {
order: ownProps.route.params?.order,
isPrinterConnected: selectIsPrinterConnected(state),
printer: selectPrinter(state),
isPrinting: selectIsPrinting(state),
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/navigation/restaurant/components/OrderButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import FontAwesome from 'react-native-vector-icons/FontAwesome';

const phoneNumberUtil = PhoneNumberUtil.getInstance();

const Comp = ({ order, isPrinterConnected, onPrinterClick, printOrder }) => {
const Comp = ({ order, isPrinterConnected, onPrinterClick, printOrder, disablePrintButton }) => {
const { t } = useTranslation();

let phoneNumber;
Expand All @@ -25,7 +25,8 @@ const Comp = ({ order, isPrinterConnected, onPrinterClick, printOrder }) => {
{isPrinterConnected && (
<Button
endIcon={<Icon as={FontAwesome} name="print" size="sm" />}
onPress={printOrder}>
onPress={printOrder}
isDisabled={disablePrintButton}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't see much value in passing these props through three components (Order.js > OrderHeading.js > OrderButtons.js). I would put them in OrderButtons directly

{t('RESTAURANT_ORDER_PRINT')}
</Button>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/navigation/restaurant/components/OrderHeading.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const OrderHeading = ({
isPrinterConnected,
onPrinterClick,
printOrder,
disablePrintButton,
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -89,6 +90,7 @@ const OrderHeading = ({
isPrinterConnected={isPrinterConnected}
onPrinterClick={onPrinterClick}
printOrder={printOrder}
disablePrintButton={disablePrintButton}
/>
</View>
</View>
Expand Down
10 changes: 8 additions & 2 deletions src/redux/Restaurant/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,10 @@ export default (state = initialState, action = {}) => {
const printTask = state.ordersToPrint[orderId];

if (!printTask) {
return state;
return {
...state,
printingOrderId: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was that only printFulfilled/printRejected actions with the same order ID as in printPending should reset the state (assuming that printing is sequential)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see a situation when it was not working?

};
}

if (printTask.copiesToPrint > 1) {
Expand Down Expand Up @@ -603,7 +606,10 @@ export default (state = initialState, action = {}) => {
const printTask = state.ordersToPrint[orderId];

if (!printTask) {
return state;
return {
...state,
printingOrderId: null,
};
}

return {
Expand Down
5 changes: 5 additions & 0 deletions src/redux/Restaurant/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,8 @@ export const selectIsActionable = createSelector(
);
},
);

export const selectIsPrinting = createSelector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a selector called selectPrintingOrderId. It can be used either here or directly from a React component

state => state.restaurant.printingOrderId,
(printingOrderId) => printingOrderId !== null
);
Loading