Skip to content

Commit 45caac3

Browse files
authored
Merge pull request #2089 from coopcycle/disable-product-alert
Ask if product should be re-enabled tomorrow
2 parents 27eb773 + e0b659e commit 45caac3

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

src/i18n/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,9 @@
643643
"INCIDENT": "Incident",
644644
"CHECKOUT_STOP": "Cancel checkout",
645645
"CHECKOUT_STOP_CONFIRM": "Do you want to interrupt the order? You can still complete it later",
646-
"CHECKOUT_CONTINUE": "Continue checkout"
646+
"CHECKOUT_CONTINUE": "Continue checkout",
647+
"RESTAURANT_PRODUCT_DISABLE_ENABLE_TOMORROW": "Do you want to re-enable automatically the product tomorrow?",
648+
"NO_THANKS": "No, thanks",
649+
"YES": "Yes"
647650
}
648651
}

src/navigation/restaurant/Products.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Switch } from '@/components/ui/switch';
33
import { Text } from '@/components/ui/text';
44
import { Button, ButtonText } from '@/components/ui/button';
55
import React, { Component } from 'react';
6-
import { FlatList } from 'react-native';
6+
import { Alert, FlatList } from 'react-native';
77
import { SafeAreaView } from 'react-native-safe-area-context';
88

99
import { withTranslation } from 'react-i18next';
@@ -14,6 +14,8 @@ import {
1414
changeProductEnabled,
1515
loadMoreProducts,
1616
loadProducts,
17+
changeProductEnabledRequest,
18+
disableProductUntilTomorrow,
1719
} from '../../redux/Restaurant/actions';
1820

1921
class ProductsScreen extends Component {
@@ -22,7 +24,34 @@ class ProductsScreen extends Component {
2224
}
2325

2426
_toggleProductEnabled(product, value) {
25-
this.props.changeProductEnabled(product, value);
27+
28+
if (value === false) {
29+
30+
this.props.changeProductEnabledRequest(product, value);
31+
32+
Alert.alert(
33+
this.props.t('RESTAURANT_PRODUCT_DISABLE_ENABLE_TOMORROW'),
34+
'',
35+
[
36+
{
37+
text: this.props.t('NO_THANKS'),
38+
onPress: () => {
39+
this.props.changeProductEnabled(product, value);
40+
},
41+
},
42+
{
43+
text: this.props.t('YES'),
44+
onPress: () => {
45+
this.props.disableProductUntilTomorrow(product);
46+
}
47+
},
48+
],
49+
);
50+
51+
} else {
52+
this.props.changeProductEnabled(product, value);
53+
}
54+
2655
}
2756

2857
renderItem(item) {
@@ -89,6 +118,8 @@ function mapDispatchToProps(dispatch) {
89118
loadProducts: (restaurant) => dispatch(loadProducts(restaurant)),
90119
loadMoreProducts: () => dispatch(loadMoreProducts()),
91120
changeProductEnabled: (product, enabled) => dispatch(changeProductEnabled(product, enabled)),
121+
changeProductEnabledRequest: (product, enabled) => dispatch(changeProductEnabledRequest(product, enabled)),
122+
disableProductUntilTomorrow: (product) => dispatch(disableProductUntilTomorrow(product)),
92123
};
93124
}
94125

src/redux/Restaurant/actions.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,3 +989,17 @@ export function updateLoopeatFormats(order, loopeatFormats, cb) {
989989
});
990990
};
991991
}
992+
993+
export function disableProductUntilTomorrow(product) {
994+
return function (dispatch, getState) {
995+
996+
const httpClient = selectHttpClient(getState());
997+
998+
dispatch(changeProductEnabledRequest(product, false));
999+
1000+
return httpClient
1001+
.put(product['@id'] + '/disable', { until: 'tomorrow 00:00' })
1002+
.then(res => dispatch(changeProductEnabledSuccess(res)))
1003+
.catch(e => dispatch(changeProductEnabledFailure(e, product, true)));
1004+
};
1005+
}

0 commit comments

Comments
 (0)