Skip to content

Commit

Permalink
Merge pull request #1903 from coopcycle/print-multiple
Browse files Browse the repository at this point in the history
Try to fix multiple printer tickets
  • Loading branch information
Atala authored Oct 23, 2024
2 parents 4f8e6ed + 6084f68 commit 011ef73
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
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}>
{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,
};
}

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(
state => state.restaurant.printingOrderId,
(printingOrderId) => printingOrderId !== null
);

0 comments on commit 011ef73

Please sign in to comment.