Assignment: City/Product Sales Browser using React
Company Name:Cytel
Result - Selected for Next Round
Objective
Develop a simple React application that displays city and product sales information with routing and dynamic data fetching. The app should allow users to navigate between different pages, and it should track how many cities and products have been visited. The data should be refreshed upon user request.
Requirements
Application Overview:
- Display two counters at the top of the page:
- Cities Visited:0
- Products Visited:0
- Provide aRefreshbutton that resets the counters and reloads the data.
Home Page:
- URL: /
- Display two lists:
- List of city names fetched from the API.
- List of product names fetched from the API.
- Initialize theCities VisitedandProducts Visitedcounters to 0 when the app starts.
API Endpoints:
- To fetch all cities: https://assessments.reliscore.com/api/cities
- To fetch all products: https://assessments.reliscore.com/api/sales/products
City Details Page:
- URL: /api/sales/
/
- Clicking on a city name from the home page navigates to a city-specific page.
- Fetch and display a list of product names and the quantity sold in the selected city using the following endpoint: https://assessments.reliscore.com/api/sales/
/ (Replace
with the actual city name.)
- Increment theCities Visitedcounter by 1 whenever a city page is visited.
Product Details Page:
- URL: /sales/product/
/
- Clicking on a product name from any page navigates to a product-specific page.
- Fetch and display a list of all city names where the product has been sold and the amount sold in each city using the following endpoint: https://assessments.reliscore.com/api/sales/product/
/ (Replace
with the actual product name.)
- Increment theProducts Visitedcounter by 1 whenever a product page is visited.
Refresh Button:
- Clicking theRefreshbutton on any page should:
- Reload all data from the respective APIs.
- Reset theCities VisitedandProducts Visitedcounters to 0.
Single Page Application (SPA) with Routing:
- Implement the application as a single-page application (SPA) using React.
- Utilize routing to handle navigation between different pages (e.g., city details, product details) while ensuring that the browser’s back and forward buttons function correctly.
- Ensure that users can navigate directly to any page using the appropriate URL.
Evaluation Criteria:
- Appropriate use of reusable React components.
- Efficient use of React features such as hooks and state management.
- Proper implementation of routing to simulate different pages.
- Adherence to best practices in code structure and modularity.
Deliverables
- A fully functional React application meeting the requirements outlined above.
- The project should be structured, well-commented, and easy to navigate.
- Ensure that the application handles edge cases, such as missing data or incorrect URLs.
Notes
- Test your application thoroughly to ensure all features work as expected.
- Make sure the app is responsive and works well on different screen sizes.
API Responses Overview
Cities API Response:
- Endpoint: https://assessments.reliscore.com/api/cities
- Response Format:
{ "status": "success", "data": [ "Bombay", "Bangalore", "Pune", "Kolkata", "Chennai", "New Delhi" ] }
Copy after login
Description: This API returns a list of city names where sales data is available. The data array contains the names of these cities.
Sales Data for a Specific City:
- Endpoint: https://assessments.reliscore.com/api/sales/pune (Replace pune with any other city name as needed)
- Response Format:
{ "status": "success", "data": { "product1": 137, "product2": 23, "product3": 77 } }
Copy after login
Copy after login
Copy after login
Description: This API returns sales data for a specific city. The data object contains key-value pairs where the key is the product name and the value is the number of items sold in that city.
Products List API Response:
- Endpoint: https://assessments.reliscore.com/api/sales/products
- Response Format:
{ "status": "success", "data": { "product1": 137, "product2": 23, "product3": 77 } }
Copy after login
Copy after login
Copy after login
Description: This API returns a list of all products with their total sales figures. The data object contains key-value pairs where the key is the product name and the value is the total number of items sold across all cities.
Product Detail API Response:
- Endpoint: https://assessments.reliscore.com/api/sales/product/product1 (Replace product1 with any other product name as needed)
- Response Format:
{ "status": "success", "data": { "product1": 137, "product2": 23, "product3": 77 } }
Copy after login
Copy after login
Copy after login
Description: This API returns the sales data for a specific product across different cities. The data object contains key-value pairs where the key is the city name and the value is the number of items sold for that product in that city.
Note:
Please ensure that you fully understand the requirements before starting the implementation. There’s a minor issue with the API response for the product/
endpoint, but it can be worked around with the provided data. Adding the API responses for reference above.
You are encouraged to implement the solution and make any necessary modifications to the APIs as needed to meet the requirements. If you need more details or are interested in similar assignments, you can refer to my E-Commerce Project.
The above is the detailed content of React Coding Challenge -City/Product Sales Browser using React. For more information, please follow other related articles on the PHP Chinese website!