Problem
When the user to search a restaurant on Whitelabel in Delivery mode, the system gives a restaurant available for delivery.
But in case of this restaurant is closed, the system show error for restaurant is unavailable, the same message in case not have delivery in this address.
This cause problems for users, because show de wrong message, the correct message is the restaurant is closed at this moment but have a delivery in this address.
Proposal of Solution
Show a message informing the user that restaurant is closed, but open at X hours.
Currently, the system check if the restaurant is open, but this verification is bad, because only validate if it is open, case restaurant is open show information and set the restaurant to make orders, but in case of restaurant closed, so don’t send information for system and the show wrong message.
Technical Problem
intl-whitelabel-app
The front-end get this information in this file: src/components/address-modal/index.tsx
And user this function useEffect for get results of delivery:
The const deliveryRestaurantData
in line 529 have the data about the restaurant, and this information comes in a delivery query of GraphQl useDeliveryRestaurantLazyQuery
:
Use this query of GraphQl:
intl-whitelabel-graphql
On repository of intl-whitelabel-graphql has this query:
File: src/functions/graphql/resolvers/restaurant.ts
In this file, have this function deliveryRestaurant
We need to pass some information for work in studio apollo or postman, this is an example for use in this query, this example work in PLK ES DEV.
Response of success is a big data, for this response we need to call the query with result valid and between hours work valid:
But in case the restaurant is closed, the information is every null and the status is NO_DELIVERY, and this is WRONG, because the restaurant has closed and no unavailable, the status should be CLOSED:
In this function deliveryRestaurant
it checks if the feature flag is active, because we use different way.
The flag is enable-dropoff-only-quote-from-delivery-service
and use some information for active:
PLK ES DEV has this flag active, so use the first way:
It uses the function createQuoteWhitelabelDeliveryService
of delivery providers:
file: src/functions/graphql/providers/delivery.ts
And in this file use the service.retrieveFirstQuote
This service is from repository intl-delivery-service.
intl-delivery-service
In the file src/modules/quote/quote.service.ts. We have the retrieveFirstQuote function.
In this function the code have other called, the getWinningQuote:
And this Function call other function getQuotes, and this function return correct errors, inform that restaurant has errors, and the error is “The restaurant is closed”.
But after this the code ignore this error and give an error forced, in return in case errors in retrieveFirstQuote is:
Because these are the errors ever are same thing, not has a treatment for the other flows.
Technical Solution
intl-delivery-service
In the file src/modules/restaurant/restaurant.service.ts have a function called findEligible
and in these functions have another function deriveEligibility
and in this function return errors of restaurant and return the next time that the restaurant open again, but now don’t use this, so we need to add this information.
Before:
After:
Just add nextOpenDate
in lines 174 and 175.
And the returned this function need to change too, because need pass the parameter nextOpenDate
and adjusted of logic to return the data in case of eligible
equals the false, in this validation we can validate if not have none eligible, so we use ineligible.
Before:
After:
In the file src/modules/quote/quote.service.ts in retrieveFirstQuote
function, we can get these informations in the getEligibleDeliveryRestaurantData
function, because now return the errors and the nextOpenDate.
After this changes, we can validate if a restaurant has closed and create a new throw for closed restaurant QuoteRestaurantClosedError
with this we can to go for catch of retrieveFirstQuote
function.
Just an example to fire throw:
And in this catch we can get the error of restaurant closed and manipulate this error, and change for return the status correct and the nextOpenDate.
The return after this changes:
We made a POC for this in this link: https://github.com/rbilabs/intl-delivery-service/pull/470
intl-whitelabel-app
Now with back-end returning the status correct and the field nextEarliestOpen
we can to do correct logic in the front-end.
In the file src/components/address-modal/index.tsx int the handleQuoteResult
function we have a logic for check the status of delivery quotes, so we need improve this logic, we can add more details and validate the statusStore. Also we need add new dispach for delivery closed.
About the dispach, we have a logic for it, and conciste in get the status of quote and store, we need create a new for closed restaurant.
With this made we can use this in moment for call a delivery and show the error correct in case of closed restaurant
We need change or create a new component for show message about closed restaurant. In this POC I’m use the component src/components/modal-no-delivery-stores-open/no-stores-open-delivery-modal.tsx this component don’t is used currently in the app, so we can change some thing and use, this is a example of component:
In the file of this component we need to change some things for work, for example we need to tranform in a React component and pass the atribute for next open date.
0 Comments