Skip to content

Commit d2b6230

Browse files
committed
change: display the next shipping time range instead of the opening hours
1 parent 8be1090 commit d2b6230

File tree

7 files changed

+77
-70
lines changed

7 files changed

+77
-70
lines changed

src/components/RestaurantCard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Text } from 'native-base';
33
import { Image, StyleSheet, View } from 'react-native';
44
import { TimingBadge } from '../navigation/checkout/components/RestaurantBadges';
55
import { useBackgroundContainerColor } from '../styles/theme';
6-
import { isRestaurantAvailable } from '../utils/checkout';
6+
import { isRestaurantOrderingAvailable } from '../utils/checkout';
77
import { RestaurantBadge } from './RestaurantBadge';
88
import { RestaurantTag } from './RestaurantTag';
99
import { RestaurantBanner } from './RestaurantBanner';
@@ -92,7 +92,7 @@ const styles = StyleSheet.create({
9292

9393
export const RestaurantCard = ({ restaurant }) => {
9494
const backgroundColor = useBackgroundContainerColor();
95-
const isAvailable = isRestaurantAvailable(restaurant);
95+
const isAvailable = isRestaurantOrderingAvailable(restaurant);
9696

9797
return (
9898
<View style={[styles.item, { backgroundColor }]}>

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
"RESTAURANT_PRODUCT_OPTIONS": "Product options",
426426
"RESTAURANT_PRE_ORDER": "Pre-order",
427427
"RESTAURANT_CLOSED_BUT_OPENS": "This restaurant is closed now but opens {{ datetime }}. You can still order for later on though!",
428+
"RESTAURANT_CLOSED_PRE_ORDER": "This restaurant is closed now. You can still order for {{ datetime }} though!",
428429
"RESTAURANT_CLOSED_AND_NOT_AVAILABLE": "This restaurant is closed and not available until {{ datetime }}.",
429430
"CHECKOUT_AS_GUEST": "Checkout as guest",
430431
"GUEST_CHECKOUT_ORDER_EMAIL_HELP": "To send you updates about your order",

src/navigation/checkout/Restaurant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function Restaurant(props) {
221221
{i18n.t('RESTAURANT_OPENING_HOURS')}
222222
</Text>
223223
<OpeningHours
224-
openingHoursSpecification={props.openingHoursSpecification}
224+
openingHoursSpecification={openingHoursSpecification}
225225
/>
226226
</Box>
227227
<Pressable

src/navigation/checkout/components/CartFooterButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Animated, View } from 'react-native';
77
import { formatPrice } from '../../../utils/formatting';
88
import FontAwesome from 'react-native-vector-icons/FontAwesome';
99
import {
10-
isRestaurantAvailable,
10+
isRestaurantOrderingAvailable,
1111
shouldShowPreOrder,
1212
} from '../../../utils/checkout';
1313
import { useSolidButtonTextColor } from '../../../styles/theme';
@@ -65,7 +65,7 @@ class CartFooterButton extends Component {
6565
render() {
6666
const { cart, restaurant } = this.props;
6767

68-
const isAvailable = isRestaurantAvailable(restaurant);
68+
const isAvailable = isRestaurantOrderingAvailable(restaurant);
6969
const showPreOrder = shouldShowPreOrder(restaurant);
7070

7171
if (!cart || cart.items.length === 0 || !isAvailable) {

src/navigation/checkout/components/RestaurantBadges.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Svg, { Path } from 'react-native-svg';
66
import { useBaseTextColor } from '../../../styles/theme';
77
import {
88
getNextShippingTimeAsText,
9-
isRestaurantAvailable,
9+
isRestaurantOrderingAvailable,
1010
shouldShowPreOrder,
1111
} from '../../../utils/checkout';
1212

@@ -49,9 +49,9 @@ export const CategoryBadge = ({ label }) => {
4949
export const TimingBadge = ({ restaurant }) => {
5050
const color = useBaseTextColor();
5151

52-
const isAvailable = isRestaurantAvailable(restaurant);
53-
const shippingTime = getNextShippingTimeAsText(restaurant);
52+
const isAvailable = isRestaurantOrderingAvailable(restaurant);
5453
const showPreOrder = shouldShowPreOrder(restaurant);
54+
const shippingTime = getNextShippingTimeAsText(restaurant);
5555

5656
return (
5757
<HStack style={[styles.badge]}>

src/navigation/checkout/components/RestaurantProfile.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import DangerAlert from '../../../components/DangerAlert';
1515
import i18n from '../../../i18n';
1616
import moment from 'moment/moment';
1717
import {
18-
isRestaurantAvailable,
19-
isRestaurantOpeningSoon,
18+
getNextShippingTime,
19+
isRestaurantOrderingAvailable,
2020
shouldShowPreOrder,
2121
} from '../../../utils/checkout';
2222
import { RestaurantBanner } from '../../../components/RestaurantBanner';
@@ -96,17 +96,26 @@ const styles = StyleSheet.create({
9696
});
9797

9898
function OpeningHoursWarning({
99-
currentTimeSlot,
100-
isAvailable,
101-
isOpeningSoon,
99+
openingHoursSpecification,
100+
isOrderingAvailable,
102101
showPreOrder,
102+
nextShippingTime,
103103
}) {
104-
if (showPreOrder) {
104+
if (!isOrderingAvailable) {
105+
//FIXME: this is based on the regular opening hours
106+
// and does not take closing rules ("Holidays") into account
107+
const nextOpeningHours = openingHoursSpecification.currentTimeSlot.timeSlot;
108+
109+
if (!nextOpeningHours) {
110+
// when restaurant is disabled it will be shown on the banner
111+
// and in the 'timing' section
112+
return null;
113+
}
114+
105115
return (
106116
<DangerAlert
107-
adjustsFontSizeToFit={true}
108-
text={`${i18n.t('RESTAURANT_CLOSED_BUT_OPENS', {
109-
datetime: moment(currentTimeSlot.timeSlot[0])
117+
text={`${i18n.t('RESTAURANT_CLOSED_AND_NOT_AVAILABLE', {
118+
datetime: moment(nextOpeningHours[0])
110119
.calendar(moment(), {
111120
sameElse: 'llll',
112121
})
@@ -116,11 +125,12 @@ function OpeningHoursWarning({
116125
);
117126
}
118127

119-
if (!isAvailable && isOpeningSoon) {
128+
if (showPreOrder) {
120129
return (
121130
<DangerAlert
122-
text={`${i18n.t('RESTAURANT_CLOSED_AND_NOT_AVAILABLE', {
123-
datetime: moment(currentTimeSlot.timeSlot[0])
131+
adjustsFontSizeToFit={true}
132+
text={`${i18n.t('RESTAURANT_CLOSED_PRE_ORDER', {
133+
datetime: moment(nextShippingTime.range[0])
124134
.calendar(moment(), {
125135
sameElse: 'llll',
126136
})
@@ -130,13 +140,12 @@ function OpeningHoursWarning({
130140
);
131141
}
132142

133-
// when restaurant is not available
134-
// it will be shown on the banner and in the 'timing' section
143+
// no warnings
135144
return null;
136145
}
137146

138-
function BannerOverlay({ isAvailable, showPreOrder }) {
139-
if (!isAvailable) {
147+
function BannerOverlay({ isOrderingAvailable, showPreOrder }) {
148+
if (!isOrderingAvailable) {
140149
return <RestaurantNotAvailableBannerOverlay />;
141150
}
142151

@@ -152,28 +161,26 @@ function RestaurantProfile({ restaurant, openingHoursSpecification, onInfo }) {
152161
const stroke = useBaseTextColor();
153162
const textSecondary = useSecondaryTextColor();
154163

155-
const currentTimeSlot = useMemo(
156-
() => openingHoursSpecification.currentTimeSlot,
157-
[openingHoursSpecification],
158-
);
159-
160-
const isAvailable = useMemo(
161-
() => isRestaurantAvailable(restaurant),
162-
[restaurant],
163-
);
164-
const isOpeningSoon = useMemo(
165-
() => isRestaurantOpeningSoon(restaurant),
164+
const isOrderingAvailable = useMemo(
165+
() => isRestaurantOrderingAvailable(restaurant),
166166
[restaurant],
167167
);
168168
const showPreOrder = useMemo(
169169
() => shouldShowPreOrder(restaurant),
170170
[restaurant],
171171
);
172+
const nextShippingTime = useMemo(
173+
() => getNextShippingTime(restaurant),
174+
[restaurant],
175+
);
172176

173177
return (
174178
<View style={([styles.profile], { backgroundColor })}>
175179
<RestaurantBanner src={restaurant.bannerImage ?? restaurant.image} />
176-
<BannerOverlay isAvailable={isAvailable} showPreOrder={showPreOrder} />
180+
<BannerOverlay
181+
isOrderingAvailable={isOrderingAvailable}
182+
showPreOrder={showPreOrder}
183+
/>
177184
<View style={styles.detailsWrapper}>
178185
<View style={[styles.logoWrapper, { backgroundColor }]}>
179186
<View style={styles.logoWrapperShadow}>
@@ -200,10 +207,10 @@ function RestaurantProfile({ restaurant, openingHoursSpecification, onInfo }) {
200207
</View>
201208
<View style={styles.content}>
202209
<OpeningHoursWarning
203-
currentTimeSlot={currentTimeSlot}
204-
isAvailable={isAvailable}
205-
isOpeningSoon={isOpeningSoon}
210+
openingHoursSpecification={openingHoursSpecification}
211+
isOrderingAvailable={isOrderingAvailable}
206212
showPreOrder={showPreOrder}
213+
nextShippingTime={nextShippingTime}
207214
/>
208215
<View style={{ display: 'flex', flexDirection: 'row', gap: 4 }}>
209216
<TimingBadge restaurant={restaurant} />

src/utils/checkout.js

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ function round5(x) {
1111
}
1212

1313
function timingAsText(timing, now) {
14-
// FIXME
15-
// This hotfixes a bug on the API
16-
// https://github.com/coopcycle/coopcycle-web/issues/2213
17-
if (timing.range[0] === timing.range[1]) {
18-
return i18n.t('NOT_AVAILABLE_ATM');
19-
}
20-
2114
const lower = moment.parseZone(timing.range[0]);
2215

2316
if (timing.fast) {
@@ -43,18 +36,38 @@ function timingAsText(timing, now) {
4336
return lower.calendar(now);
4437
}
4538

39+
export function getNextShippingTime(restaurant) {
40+
41+
const timing = restaurant.timing.delivery || restaurant.timing.collection;
42+
43+
if (!timing) {
44+
return null;
45+
}
46+
47+
// FIXME
48+
// This hotfixes a bug on the API
49+
// https://github.com/coopcycle/coopcycle-web/issues/2213
50+
if (!Array.isArray(timing.range)) {
51+
return null;
52+
}
53+
if (timing.range[0] === timing.range[1]) {
54+
return null;
55+
}
56+
57+
return timing;
58+
}
59+
60+
4661
export function getNextShippingTimeAsText(restaurant, now) {
4762
now = now || moment();
4863

49-
if (restaurant.timing.delivery) {
50-
return timingAsText(restaurant.timing.delivery, now);
51-
}
64+
const timing = getNextShippingTime(restaurant);
5265

53-
if (restaurant.timing.collection) {
54-
return timingAsText(restaurant.timing.collection, now);
66+
if (!timing) {
67+
return i18n.t('NOT_AVAILABLE_ATM');
5568
}
5669

57-
return i18n.t('NOT_AVAILABLE_ATM');
70+
return timingAsText(timing, now);
5871
}
5972

6073
export function getRestaurantCaption(restaurant) {
@@ -65,23 +78,9 @@ export function getRestaurantCaption(restaurant) {
6578
* While the restaurant might be available (for ordering)
6679
* it might be either opened or closed at the moment
6780
*/
68-
export function isRestaurantAvailable(restaurant) {
69-
if (!restaurant.timing.delivery && !restaurant.timing.collection) {
70-
return false;
71-
}
72-
73-
// FIXME
74-
// This hotfixes a bug on the API
75-
// https://github.com/coopcycle/coopcycle-web/issues/2213
76-
if (
77-
restaurant.timing.delivery &&
78-
Array.isArray(restaurant.timing.delivery.range) &&
79-
restaurant.timing.delivery.range[0] === restaurant.timing.delivery.range[1]
80-
) {
81-
return false;
82-
}
83-
84-
return true;
81+
export function isRestaurantOrderingAvailable(restaurant) {
82+
const timing = getNextShippingTime(restaurant);
83+
return Boolean(timing);
8584
}
8685

8786
/**
@@ -105,7 +104,7 @@ export function isRestaurantOpeningSoon(restaurant) {
105104
* If the pre-order is soon, we show a regular order button
106105
*/
107106
export function shouldShowPreOrder(restaurant) {
108-
if (!isRestaurantAvailable(restaurant)) {
107+
if (!isRestaurantOrderingAvailable(restaurant)) {
109108
return false;
110109
}
111110

0 commit comments

Comments
 (0)