From d2b62302b5d7c9c0c582090e5eba6ee49b10def0 Mon Sep 17 00:00:00 2001 From: Vladimir <70273239+vladimir-8@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:38:35 -0800 Subject: [PATCH 1/2] change: display the next shipping time range instead of the opening hours --- src/components/RestaurantCard.js | 4 +- src/i18n/locales/en.json | 1 + src/navigation/checkout/Restaurant.js | 2 +- .../checkout/components/CartFooterButton.js | 4 +- .../checkout/components/RestaurantBadges.js | 6 +- .../checkout/components/RestaurantProfile.js | 69 ++++++++++--------- src/utils/checkout.js | 61 ++++++++-------- 7 files changed, 77 insertions(+), 70 deletions(-) diff --git a/src/components/RestaurantCard.js b/src/components/RestaurantCard.js index 24156af11..da3555823 100644 --- a/src/components/RestaurantCard.js +++ b/src/components/RestaurantCard.js @@ -3,7 +3,7 @@ import { Text } from 'native-base'; import { Image, StyleSheet, View } from 'react-native'; import { TimingBadge } from '../navigation/checkout/components/RestaurantBadges'; import { useBackgroundContainerColor } from '../styles/theme'; -import { isRestaurantAvailable } from '../utils/checkout'; +import { isRestaurantOrderingAvailable } from '../utils/checkout'; import { RestaurantBadge } from './RestaurantBadge'; import { RestaurantTag } from './RestaurantTag'; import { RestaurantBanner } from './RestaurantBanner'; @@ -92,7 +92,7 @@ const styles = StyleSheet.create({ export const RestaurantCard = ({ restaurant }) => { const backgroundColor = useBackgroundContainerColor(); - const isAvailable = isRestaurantAvailable(restaurant); + const isAvailable = isRestaurantOrderingAvailable(restaurant); return ( diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 1358bf509..0bb862a20 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -425,6 +425,7 @@ "RESTAURANT_PRODUCT_OPTIONS": "Product options", "RESTAURANT_PRE_ORDER": "Pre-order", "RESTAURANT_CLOSED_BUT_OPENS": "This restaurant is closed now but opens {{ datetime }}. You can still order for later on though!", + "RESTAURANT_CLOSED_PRE_ORDER": "This restaurant is closed now. You can still order for {{ datetime }} though!", "RESTAURANT_CLOSED_AND_NOT_AVAILABLE": "This restaurant is closed and not available until {{ datetime }}.", "CHECKOUT_AS_GUEST": "Checkout as guest", "GUEST_CHECKOUT_ORDER_EMAIL_HELP": "To send you updates about your order", diff --git a/src/navigation/checkout/Restaurant.js b/src/navigation/checkout/Restaurant.js index 584e81cb1..061f1f02f 100644 --- a/src/navigation/checkout/Restaurant.js +++ b/src/navigation/checkout/Restaurant.js @@ -221,7 +221,7 @@ function Restaurant(props) { {i18n.t('RESTAURANT_OPENING_HOURS')} { export const TimingBadge = ({ restaurant }) => { const color = useBaseTextColor(); - const isAvailable = isRestaurantAvailable(restaurant); - const shippingTime = getNextShippingTimeAsText(restaurant); + const isAvailable = isRestaurantOrderingAvailable(restaurant); const showPreOrder = shouldShowPreOrder(restaurant); + const shippingTime = getNextShippingTimeAsText(restaurant); return ( diff --git a/src/navigation/checkout/components/RestaurantProfile.js b/src/navigation/checkout/components/RestaurantProfile.js index 63fccc1c2..c8b1e6c16 100644 --- a/src/navigation/checkout/components/RestaurantProfile.js +++ b/src/navigation/checkout/components/RestaurantProfile.js @@ -15,8 +15,8 @@ import DangerAlert from '../../../components/DangerAlert'; import i18n from '../../../i18n'; import moment from 'moment/moment'; import { - isRestaurantAvailable, - isRestaurantOpeningSoon, + getNextShippingTime, + isRestaurantOrderingAvailable, shouldShowPreOrder, } from '../../../utils/checkout'; import { RestaurantBanner } from '../../../components/RestaurantBanner'; @@ -96,17 +96,26 @@ const styles = StyleSheet.create({ }); function OpeningHoursWarning({ - currentTimeSlot, - isAvailable, - isOpeningSoon, + openingHoursSpecification, + isOrderingAvailable, showPreOrder, + nextShippingTime, }) { - if (showPreOrder) { + if (!isOrderingAvailable) { + //FIXME: this is based on the regular opening hours + // and does not take closing rules ("Holidays") into account + const nextOpeningHours = openingHoursSpecification.currentTimeSlot.timeSlot; + + if (!nextOpeningHours) { + // when restaurant is disabled it will be shown on the banner + // and in the 'timing' section + return null; + } + return ( ; } @@ -152,28 +161,26 @@ function RestaurantProfile({ restaurant, openingHoursSpecification, onInfo }) { const stroke = useBaseTextColor(); const textSecondary = useSecondaryTextColor(); - const currentTimeSlot = useMemo( - () => openingHoursSpecification.currentTimeSlot, - [openingHoursSpecification], - ); - - const isAvailable = useMemo( - () => isRestaurantAvailable(restaurant), - [restaurant], - ); - const isOpeningSoon = useMemo( - () => isRestaurantOpeningSoon(restaurant), + const isOrderingAvailable = useMemo( + () => isRestaurantOrderingAvailable(restaurant), [restaurant], ); const showPreOrder = useMemo( () => shouldShowPreOrder(restaurant), [restaurant], ); + const nextShippingTime = useMemo( + () => getNextShippingTime(restaurant), + [restaurant], + ); return ( - + @@ -200,10 +207,10 @@ function RestaurantProfile({ restaurant, openingHoursSpecification, onInfo }) { diff --git a/src/utils/checkout.js b/src/utils/checkout.js index 3e80f8772..bfd650a93 100644 --- a/src/utils/checkout.js +++ b/src/utils/checkout.js @@ -11,13 +11,6 @@ function round5(x) { } function timingAsText(timing, now) { - // FIXME - // This hotfixes a bug on the API - // https://github.com/coopcycle/coopcycle-web/issues/2213 - if (timing.range[0] === timing.range[1]) { - return i18n.t('NOT_AVAILABLE_ATM'); - } - const lower = moment.parseZone(timing.range[0]); if (timing.fast) { @@ -43,18 +36,38 @@ function timingAsText(timing, now) { return lower.calendar(now); } +export function getNextShippingTime(restaurant) { + + const timing = restaurant.timing.delivery || restaurant.timing.collection; + + if (!timing) { + return null; + } + + // FIXME + // This hotfixes a bug on the API + // https://github.com/coopcycle/coopcycle-web/issues/2213 + if (!Array.isArray(timing.range)) { + return null; + } + if (timing.range[0] === timing.range[1]) { + return null; + } + + return timing; +} + + export function getNextShippingTimeAsText(restaurant, now) { now = now || moment(); - if (restaurant.timing.delivery) { - return timingAsText(restaurant.timing.delivery, now); - } + const timing = getNextShippingTime(restaurant); - if (restaurant.timing.collection) { - return timingAsText(restaurant.timing.collection, now); + if (!timing) { + return i18n.t('NOT_AVAILABLE_ATM'); } - return i18n.t('NOT_AVAILABLE_ATM'); + return timingAsText(timing, now); } export function getRestaurantCaption(restaurant) { @@ -65,23 +78,9 @@ export function getRestaurantCaption(restaurant) { * While the restaurant might be available (for ordering) * it might be either opened or closed at the moment */ -export function isRestaurantAvailable(restaurant) { - if (!restaurant.timing.delivery && !restaurant.timing.collection) { - return false; - } - - // FIXME - // This hotfixes a bug on the API - // https://github.com/coopcycle/coopcycle-web/issues/2213 - if ( - restaurant.timing.delivery && - Array.isArray(restaurant.timing.delivery.range) && - restaurant.timing.delivery.range[0] === restaurant.timing.delivery.range[1] - ) { - return false; - } - - return true; +export function isRestaurantOrderingAvailable(restaurant) { + const timing = getNextShippingTime(restaurant); + return Boolean(timing); } /** @@ -105,7 +104,7 @@ export function isRestaurantOpeningSoon(restaurant) { * If the pre-order is soon, we show a regular order button */ export function shouldShowPreOrder(restaurant) { - if (!isRestaurantAvailable(restaurant)) { + if (!isRestaurantOrderingAvailable(restaurant)) { return false; } From 35303c6bb18484cb5ee313f7b79805ba10712f7b Mon Sep 17 00:00:00 2001 From: Vladimir <70273239+vladimir-8@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:29:15 -0800 Subject: [PATCH 2/2] add: translations --- src/i18n/locales/es.json | 1 + src/i18n/locales/fr.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index d60259d02..f85f51093 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -405,6 +405,7 @@ "PRIVACY": "Privacidad", "RESTAURANT_PRE_ORDER": "Reservar", "RESTAURANT_CLOSED_BUT_OPENS": "Este comercio se encuentra cerrado pero vuelve a abrir {{ datetime }}. Puedes programar tu pedido!", + "RESTAURANT_CLOSED_PRE_ORDER": "Este restaurante está cerrado ahora. ¡Aún puedes pedir para {{ datetime }}!", "RESTAURANT_CLOSED_AND_NOT_AVAILABLE": "Este comercio se encuentra cerrado y no disponible hasta el {{ datetime }}.", "MY_ORDER": "Mi pedido", "CHECKOUT_AS_GUEST": "Comprar como inivitado", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 8844303a4..294ea7399 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -401,6 +401,7 @@ "CONNECT_WITH_FACEBOOK": "Se connecter avec Facebook", "RESTAURANT_PRE_ORDER": "Pré-commander", "RESTAURANT_CLOSED_BUT_OPENS": "Ce restaurant est fermé maintenant mais ouvre {{ datetime }}. Vous pouvez quand même commander pour plus tard !", + "RESTAURANT_CLOSED_PRE_ORDER": "Ce restaurant est fermé actuellement, vous pouvez tout même commander pour une livraison à {{ datetime }} !", "RESTAURANT_CLOSED_AND_NOT_AVAILABLE": "Ce restaurant est fermé et non disponible jusqu'à {{ datetime }}.", "CHECKOUT_AS_GUEST": "Commander en tant qu'invité", "GUEST_CHECKOUT_ORDER_EMAIL_HELP": "Pour vous envoyer des mises à jour à propos de votre commande",