Skip to content

Commit 4cd7167

Browse files
committed
Fix: correct selection of customer after refresh or login
1 parent aa082f6 commit 4cd7167

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

pos/src/store/pos-store.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getMenuCourses } from '../lib/menu-course-api';
77
import { getCustomerGroups, getCustomerTerritories, getCustomerById } from '../lib/customer-api';
88
import { DEFAULT_ORDER_TYPE, OrderType } from '../data/order-types';
99
import { getTableOrder, TableOrder } from '../lib/order-api';
10-
10+
import { getPaymentModes } from '../lib/payment-api';
1111
// Constants
1212
const MAX_QUANTITY = 99;
1313
const MIN_QUANTITY = 0;
@@ -269,10 +269,17 @@ export const usePOSStore = create<POSStore>((set, get) => ({
269269

270270
// Set default customer if none selected
271271
if (!get().selectedCustomer && mappings.length > 0) {
272-
const firstMapping = mappings[0];
273-
const defaultCustomer = customerMap[firstMapping.order_type];
274-
if (defaultCustomer) {
275-
set({ selectedCustomer: defaultCustomer });
272+
const currentOrderType = get().selectedOrderType;
273+
const mappedCustomer = customerMap[currentOrderType];
274+
275+
if (mappedCustomer) {
276+
set({ selectedCustomer: mappedCustomer });
277+
} else {
278+
const firstMapping = mappings[0];
279+
const defaultCustomer = customerMap[firstMapping.order_type];
280+
if (defaultCustomer) {
281+
set({ selectedCustomer: defaultCustomer });
282+
}
276283
}
277284
}
278285
} catch (err) {
@@ -321,10 +328,17 @@ export const usePOSStore = create<POSStore>((set, get) => ({
321328

322329
// Set default customer if none selected
323330
if (!get().selectedCustomer && mappings.length > 0) {
324-
const firstMapping = mappings[0];
325-
const defaultCustomer = customerMap[firstMapping.order_type];
326-
if (defaultCustomer) {
327-
set({ selectedCustomer: defaultCustomer });
331+
const currentOrderType = get().selectedOrderType;
332+
const mappedCustomer = customerMap[currentOrderType];
333+
334+
if (mappedCustomer) {
335+
set({ selectedCustomer: mappedCustomer });
336+
} else {
337+
const firstMapping = mappings[0];
338+
const defaultCustomer = customerMap[firstMapping.order_type];
339+
if (defaultCustomer) {
340+
set({ selectedCustomer: defaultCustomer });
341+
}
328342
}
329343
}
330344
} catch (err) {

0 commit comments

Comments
 (0)