Skip to content

Commit

Permalink
Merge pull request #1922 from coopcycle/delivery-price-error
Browse files Browse the repository at this point in the history
Add error message if price calculation fails
  • Loading branch information
vladimir-8 authored Dec 12, 2024
2 parents 6e78f30 + 295069b commit 6bdd829
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@
"RESTAURANT_MORE_INFOS": "More information",
"PRICE_EXCLUDING_TAX": "Price excluding tax",
"PRICE_TOTAL": "Total price",
"PRICE_CALCULATION_FAILED": "Price calculation failed",
"PRICE_CALCULATION_FAILED_DISCLAIMER": "The price could not be calculated; please contact us to resolve the issue.",
"HIDE_INCIDENTS_TASKS": "Hide incidents",
"CART_TIME_RANGE_CHANGED_MODAL_TITLE": "Selected time range is no longer available for today anymore",
"CART_TIME_RANGE_CHANGED_MODAL_MESSAGE": "The opening hours do not allow the order to be placed today",
Expand All @@ -551,5 +553,5 @@
"LOOPEAT_HAS_RETURNS": "This task has zero waste returns",
"EDENRED_ELIGIBLE_AMOUNT": "Ticket Restaurant® eligible amount",
"EDENRED_COMPLEMENT": "Complement"
}
}
}
2 changes: 2 additions & 0 deletions src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@
"RESTAURANT_MORE_INFOS": "En savoir plus",
"PRICE_EXCLUDING_TAX": "Prix hors taxes",
"PRICE_TOTAL": "Prix total",
"PRICE_CALCULATION_FAILED": "Impossible de calculer le prix",
"PRICE_CALCULATION_FAILED_DISCLAIMER": "Le prix n’a pas pu être calculé, veuillez nous contacter pour résoudre le problème.",
"HIDE_INCIDENTS_TASKS": "Cacher les incidents",
"CART_TIME_RANGE_CHANGED_MODAL_TITLE": "Le créneau horaire sélectionné nʼest plus disponible pour aujourdʼhui",
"CART_TIME_RANGE_CHANGED_MODAL_MESSAGE": "Les horaires dʼouverture ne permettent pas de commander pour aujourdʼhui",
Expand Down
15 changes: 13 additions & 2 deletions src/navigation/store/ModalFormWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ export default function ModalFormWrapper({
handleSubmit,
t,
isSubmit = false,
disabled = false,
disabledMessage,
}) {
const backgroundColor = useBackgroundContainerColor();

const buttonLabel = disabled
? disabledMessage
: isSubmit
? t('SUBMIT')
: t('NEXT');

return (
<SafeAreaView
style={{
Expand All @@ -32,8 +40,11 @@ export default function ModalFormWrapper({
</Box>
</ScrollView>
<Box p="5">
<Button onPress={handleSubmit}>
{isSubmit ? t('SUBMIT') : t('NEXT')}
<Button
onPress={handleSubmit}
disabled={disabled}
style={disabled ? { opacity: 0.5 } : {}}>
{buttonLabel}
</Button>
</Box>
</KeyboardAdjustView>
Expand Down
13 changes: 11 additions & 2 deletions src/navigation/store/NewDeliveryPrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useTranslation } from 'react-i18next';
import { StyleSheet } from 'react-native';
import { useDispatch, useSelector } from 'react-redux';
import { createDelivery, getPrice } from '../../redux/Store/actions';
import FormInput from './components/FormInput';
import ModalFormWrapper from './ModalFormWrapper';
import FormInput from './components/FormInput';

function NewDeliveryPrice({ route, navigation }) {
const dispatch = useDispatch();
Expand All @@ -20,6 +20,7 @@ function NewDeliveryPrice({ route, navigation }) {
dispatch(getPrice(delivery));

function submit(values) {
if (price === null || priceExcludingTax === null) return;
dispatch(
createDelivery(values, () => {
navigation.navigate('StoreHome');
Expand All @@ -34,7 +35,12 @@ function NewDeliveryPrice({ route, navigation }) {
validateOnBlur={false}
validateOnChange={false}>
{({ handleSubmit }) => (
<ModalFormWrapper handleSubmit={handleSubmit} t={t} isSubmit>
<ModalFormWrapper
handleSubmit={handleSubmit}
t={t}
isSubmit
disabled={price === null || priceExcludingTax === null}
disabledMessage={t('PRICE_CALCULATION_FAILED')}>
<View style={styles.formGroup}>
<Text style={styles.label}>{t('PRICE_EXCLUDING_TAX')}</Text>
<FormInput value={priceExcludingTax} editable={false} />
Expand All @@ -43,6 +49,9 @@ function NewDeliveryPrice({ route, navigation }) {
<Text style={styles.label}>{t('PRICE_TOTAL')}</Text>
<FormInput value={price} editable={false} />
</View>
{price === null || priceExcludingTax === null ? (
<Text>{t('PRICE_CALCULATION_FAILED_DISCLAIMER')}</Text>
) : null}
</ModalFormWrapper>
)}
</Formik>
Expand Down
3 changes: 3 additions & 0 deletions src/redux/Store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export const LOAD_TIME_SLOT_CHOICES_SUCCESS =
'@store/LOAD_TIME_SLOT_CHOICES_SUCCESS';
export const LOAD_PACKAGES_SUCCESS = '@store/LOAD_PACKAGES_SUCCESS';
export const GET_PRICE_SUCCESS = '@store/GET_PRICE_SUCCESS';
export const GET_PRICE_ERROR = '@store/GET_PRICE_ERROR';

export const getPriceSuccess = createAction(GET_PRICE_SUCCESS);
export const getPriceError = createAction(GET_PRICE_ERROR);
export function getPrice(delivery) {
return (dispatch, getState) => {
const { app } = getState();
Expand All @@ -34,6 +36,7 @@ export function getPrice(delivery) {
dispatch(setLoading(false));
})
.catch(e => {
dispatch(getPriceError(e));
dispatch(setLoading(false));
});
};
Expand Down
9 changes: 9 additions & 0 deletions src/redux/Store/reducers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ASSERT_DELIVERY_ERROR,
CREATE_DELIVERY_SUCCESS,
GET_PRICE_ERROR,
GET_PRICE_SUCCESS,
INIT_SUCCESS,
LOAD_ADDRESSES_SUCCESS,
Expand Down Expand Up @@ -84,6 +85,14 @@ export default (state = initialState, action = {}) => {
price: formatPrice(amount),
priceExcludingTax: formatPrice(amount - tax.amount),
};

case GET_PRICE_ERROR:
return {
...state,
price: null,
priceExcludingTax: null,
};

case LOAD_DELIVERIES_SUCCESS:
const { store, deliveries, pagination } = action.payload;

Expand Down

0 comments on commit 6bdd829

Please sign in to comment.