Skip to content

Commit f542731

Browse files
authored
[PERTE-584] Don't allow store orders to set a manual price (#2075)
1 parent ef912bd commit f542731

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

src/navigation/delivery/NewDeliveryPrice.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function NewDeliveryPrice({ route }) {
2525
const priceExcludingTax = useSelector(selectPriceExcludingTax);
2626
const [isManualPriceEnabled, setIsManualPriceEnabled] = useState(false);
2727

28-
const { deliveryCallback } = useDeliveryCallback();
28+
const { deliveryCallback, allowManualPrice = false } = useDeliveryCallback();
2929

3030
useEffect(() => {
3131
dispatch(getPrice(delivery));
@@ -130,9 +130,11 @@ export default function NewDeliveryPrice({ route }) {
130130
)}
131131
</View>
132132
</>) : null}
133-
<Button onPress={onPressManualPriceToggle(setFieldValue)}>
134-
<ButtonText>{t('MANUAL_PRICE_TOGGLE_' + (isManualPriceEnabled ? 'OFF' : 'ON'))}</ButtonText>
135-
</Button>
133+
{allowManualPrice ? (
134+
<Button onPress={onPressManualPriceToggle(setFieldValue)}>
135+
<ButtonText>{t('MANUAL_PRICE_TOGGLE_' + (isManualPriceEnabled ? 'OFF' : 'ON'))}</ButtonText>
136+
</Button>
137+
) : null}
136138
</ModalFormWrapper>
137139
)}
138140
</Formik>

src/navigation/delivery/contexts/DeliveryCallbackContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { createContext, useContext } from 'react';
22

3-
const DeliveryCallbackContext = createContext();
3+
const DeliveryCallbackContext = createContext({});
44

5-
export const DeliveryCallbackProvider = ({ children, callback }) => (
5+
export const DeliveryCallbackProvider = ({ children, callback, options = {} }) => (
66
<DeliveryCallbackContext.Provider
77
value={{
88
deliveryCallback: callback,
9+
...options
910
}}>
1011
{children}
1112
</DeliveryCallbackContext.Provider>

src/navigation/navigators/DispatchNavigator.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,23 @@ export default function DispatchNavigator({ navigation }) {
194194
presentation: 'modal',
195195
});
196196

197-
const deliveryCallback = newDelivery => {
198-
navigation.navigate('DispatchAllTasks');
199-
dispatch(createDeliverySuccess(newDelivery));
200-
};
201-
202197
useEffect(() => {
203198
const clearSelectedTasksState = navigation.addListener('blur', () => {
204199
dispatch(clearSelectedTasks());
205200
});
206201
return clearSelectedTasksState;
207202
}, [navigation, dispatch]);
208203

204+
const deliveryCallback = newDelivery => {
205+
navigation.navigate('DispatchAllTasks');
206+
dispatch(createDeliverySuccess(newDelivery));
207+
};
208+
const deliveryCallbackOptions = {
209+
allowManualPrice: true,
210+
};
211+
209212
return (
210-
<DeliveryCallbackProvider callback={deliveryCallback}>
213+
<DeliveryCallbackProvider callback={deliveryCallback} options={deliveryCallbackOptions}>
211214
<TaskListsProvider defaultIsFromCourier={false}>
212215
<RootStack.Navigator screenOptions={screenOptions}>
213216
<RootStack.Screen

src/navigation/navigators/StoreNavigator.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ export default ({ navigation }) => {
8282
navigation.navigate('StoreHome');
8383
dispatch(createDeliverySuccess(newDelivery));
8484
};
85+
const deliveryCallbackOptions = {
86+
allowManualPrice: false,
87+
};
8588

8689
return (
87-
<DeliveryCallbackProvider callback={deliveryCallback}>
90+
<DeliveryCallbackProvider callback={deliveryCallback} options={deliveryCallbackOptions}>
8891
<RootStack.Navigator screenOptions={screenOptions}>
8992
<RootStack.Screen
9093
name="StoreHome"

0 commit comments

Comments
 (0)