Unrated orders error fixed

This commit is contained in:
Sidharth Prabhu
2026-08-04 14:21:14 +05:30
parent f898adff22
commit 5fa3a57e84
8 changed files with 30 additions and 17 deletions

View File

@@ -16,6 +16,7 @@ import { useCart } from '../contexts/CartContext';
import { useAuth } from '../contexts/AuthContext'; import { useAuth } from '../contexts/AuthContext';
import { useFood } from '../contexts/FoodContext'; import { useFood } from '../contexts/FoodContext';
import { payAndVerify, authHeaders } from '../utils/razorpay'; import { payAndVerify, authHeaders } from '../utils/razorpay';
import { getApiBaseUrl } from '../utils/api';
import './CheckoutScreen.css'; import './CheckoutScreen.css';
type PaymentMethod = 'RITZ_TOKEN' | 'RAZORPAY'; type PaymentMethod = 'RITZ_TOKEN' | 'RAZORPAY';
@@ -50,7 +51,7 @@ const CheckoutScreen: React.FC = () => {
const fetchBalance = async () => { const fetchBalance = async () => {
if (!user) return; if (!user) return;
try { try {
const response = await fetch(`http://${window.location.hostname}:8080/api/wallet/balance/${user.id}`, { const response = await fetch(`${getApiBaseUrl()}/api/wallet/balance/${user.id}`, {
headers: authHeaders() headers: authHeaders()
}); });
const data = await response.json(); const data = await response.json();
@@ -101,7 +102,7 @@ const CheckoutScreen: React.FC = () => {
user: { id: user.id } user: { id: user.id }
}; };
const response = await fetch(`http://${window.location.hostname}:8080/api/orders`, { const response = await fetch(`${getApiBaseUrl()}/api/orders`, {
method: 'POST', method: 'POST',
headers: authHeaders(), headers: authHeaders(),
body: JSON.stringify(orderData), body: JSON.stringify(orderData),

View File

@@ -10,6 +10,7 @@ import { useFood } from '../contexts/FoodContext';
import { useAuth } from '../contexts/AuthContext'; import { useAuth } from '../contexts/AuthContext';
import { motion, AnimatePresence } from 'framer-motion'; import { motion, AnimatePresence } from 'framer-motion';
import walletIcon from '../assets/front.webp'; import walletIcon from '../assets/front.webp';
import { getApiBaseUrl } from '../utils/api';
import './HomeScreen.css'; import './HomeScreen.css';
const HomeScreen: React.FC = () => { const HomeScreen: React.FC = () => {
@@ -36,7 +37,7 @@ const HomeScreen: React.FC = () => {
try { try {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
const response = await fetch(`http://${window.location.hostname}:8080/api/feedback/latest-unrated/${user?.id}`, { const response = await fetch(`${getApiBaseUrl()}/api/feedback/latest-unrated/${user?.id}`, {
headers: { headers: {
...(token ? { 'Authorization': `Bearer ${token}` } : {}) ...(token ? { 'Authorization': `Bearer ${token}` } : {})
} }
@@ -59,7 +60,7 @@ const HomeScreen: React.FC = () => {
try { try {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
await fetch(`http://${window.location.hostname}:8080/api/feedback/skip/${unratedOrder.id}`, { await fetch(`${getApiBaseUrl()}/api/feedback/skip/${unratedOrder.id}`, {
method: 'POST', method: 'POST',
headers: { headers: {
...(token ? { 'Authorization': `Bearer ${token}` } : {}) ...(token ? { 'Authorization': `Bearer ${token}` } : {})
@@ -80,7 +81,7 @@ const HomeScreen: React.FC = () => {
const handleFeedbackSubmit = async (feedbackData: any) => { const handleFeedbackSubmit = async (feedbackData: any) => {
try { try {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
const response = await fetch(`http://${window.location.hostname}:8080/api/feedback/submit`, { const response = await fetch(`${getApiBaseUrl()}/api/feedback/submit`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@@ -146,7 +147,7 @@ const HomeScreen: React.FC = () => {
const fetchSearchResults = async () => { const fetchSearchResults = async () => {
setIsSearching(true); setIsSearching(true);
try { try {
const response = await fetch(`http://${window.location.hostname}:8080/api/products?search=${encodeURIComponent(debouncedSearch)}&size=100`); const response = await fetch(`${getApiBaseUrl()}/api/products?search=${encodeURIComponent(debouncedSearch)}&size=100`);
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
const products = data.content || data || []; const products = data.content || data || [];

View File

@@ -8,6 +8,7 @@ import { useFood } from '../contexts/FoodContext';
import CartTab from '../components/CartTab'; import CartTab from '../components/CartTab';
import { VegNonVegIcon } from '../components/ItemCard'; import { VegNonVegIcon } from '../components/ItemCard';
import './ItemDetailScreen.css'; import './ItemDetailScreen.css';
import { getApiBaseUrl } from '../utils/api';
const ItemDetailScreen: React.FC = () => { const ItemDetailScreen: React.FC = () => {
const { itemId } = useParams<{ itemId: string }>(); const { itemId } = useParams<{ itemId: string }>();
@@ -32,7 +33,7 @@ const ItemDetailScreen: React.FC = () => {
const fetchItem = async () => { const fetchItem = async () => {
setIsFetching(true); setIsFetching(true);
try { try {
const response = await fetch(`http://${window.location.hostname}:8080/api/products/${itemId}`); const response = await fetch(`${getApiBaseUrl()}/api/products/${itemId}`);
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
@@ -47,7 +48,7 @@ const ItemDetailScreen: React.FC = () => {
let finalRatingCount = 0; let finalRatingCount = 0;
try { try {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
const statsRes = await fetch(`http://${window.location.hostname}:8080/api/feedback/item-stats?productName=${encodeURIComponent(data.name)}`, { const statsRes = await fetch(`${getApiBaseUrl()}/api/feedback/item-stats?productName=${encodeURIComponent(data.name)}`, {
headers: token ? { 'Authorization': `Bearer ${token}` } : {} headers: token ? { 'Authorization': `Bearer ${token}` } : {}
}); });
if (statsRes.ok) { if (statsRes.ok) {

View File

@@ -10,6 +10,7 @@ import { useFood } from '../contexts/FoodContext';
import { useCart } from '../contexts/CartContext'; import { useCart } from '../contexts/CartContext';
import type { FoodItem } from '../types'; import type { FoodItem } from '../types';
import './MyOrdersScreen.css'; import './MyOrdersScreen.css';
import { getApiBaseUrl } from '../utils/api';
interface Order { interface Order {
id: number; id: number;
@@ -82,7 +83,7 @@ const MyOrdersScreen: React.FC = () => {
const fetchOrders = async () => { const fetchOrders = async () => {
try { try {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
const response = await fetch(`http://${window.location.hostname}:8080/api/orders/user/${user?.id}`, { const response = await fetch(`${getApiBaseUrl()}/api/orders/user/${user?.id}`, {
headers: { headers: {
...(token ? { 'Authorization': `Bearer ${token}` } : {}) ...(token ? { 'Authorization': `Bearer ${token}` } : {})
} }
@@ -143,7 +144,7 @@ const MyOrdersScreen: React.FC = () => {
setIsCancelling(true); setIsCancelling(true);
try { try {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
const response = await fetch(`http://${window.location.hostname}:8080/api/orders/${orderId}/cancel`, { const response = await fetch(`${getApiBaseUrl()}/api/orders/${orderId}/cancel`, {
method: 'POST', method: 'POST',
headers: { headers: {
...(token ? { 'Authorization': `Bearer ${token}` } : {}) ...(token ? { 'Authorization': `Bearer ${token}` } : {})

View File

@@ -6,6 +6,7 @@ import CartTab from '../components/CartTab';
import BottomNav from '../components/BottomNav'; import BottomNav from '../components/BottomNav';
import type { Stall } from '../types'; import type { Stall } from '../types';
import './StallDetailScreen.css'; import './StallDetailScreen.css';
import { getApiBaseUrl } from '../utils/api';
const StallDetailScreen: React.FC = () => { const StallDetailScreen: React.FC = () => {
const { id } = useParams<{ id: string }>(); const { id } = useParams<{ id: string }>();
@@ -18,7 +19,7 @@ const StallDetailScreen: React.FC = () => {
const fetchStallDetails = async () => { const fetchStallDetails = async () => {
setLoading(true); setLoading(true);
try { try {
const response = await fetch(`http://${window.location.hostname}:8080/api/stalls/${id}`); const response = await fetch(`${getApiBaseUrl()}/api/stalls/${id}`);
if (!response.ok) throw new Error('Stall not found'); if (!response.ok) throw new Error('Stall not found');
const data = await response.json(); const data = await response.json();
@@ -61,8 +62,7 @@ const StallDetailScreen: React.FC = () => {
fetchStallDetails(); fetchStallDetails();
// SSE Real-time stock updates // SSE Real-time stock updates
const host = window.location.hostname; const eventSource = new EventSource(`${getApiBaseUrl()}/api/stock/stream`);
const eventSource = new EventSource(`http://${host}:8080/api/stock/stream`);
eventSource.addEventListener('stockUpdate', (event: any) => { eventSource.addEventListener('stockUpdate', (event: any) => {
try { try {

View File

@@ -7,6 +7,7 @@ import Header from '../components/Header';
import BottomNav from '../components/BottomNav'; import BottomNav from '../components/BottomNav';
import tokenImage from '../assets/display_ritz.webp'; import tokenImage from '../assets/display_ritz.webp';
import './WalletScreen.css'; import './WalletScreen.css';
import { getApiBaseUrl } from '../utils/api';
interface Transaction { interface Transaction {
id: number; id: number;
@@ -40,7 +41,7 @@ const WalletScreen: React.FC = () => {
try { try {
setIsLoading(true); setIsLoading(true);
// Fetch balance // Fetch balance
const balanceRes = await fetch(`http://${window.location.hostname}:8080/api/wallet/balance/${user.id}`, { const balanceRes = await fetch(`${getApiBaseUrl()}/api/wallet/balance/${user.id}`, {
headers: authHeaders() headers: authHeaders()
}); });
if (balanceRes.ok) { if (balanceRes.ok) {
@@ -49,7 +50,7 @@ const WalletScreen: React.FC = () => {
} }
// Fetch transactions // Fetch transactions
const txRes = await fetch(`http://${window.location.hostname}:8080/api/wallet/transactions/${user.id}`, { const txRes = await fetch(`${getApiBaseUrl()}/api/wallet/transactions/${user.id}`, {
headers: authHeaders() headers: authHeaders()
}); });
if (txRes.ok) { if (txRes.ok) {
@@ -71,7 +72,7 @@ const WalletScreen: React.FC = () => {
setIsRedeeming(true); setIsRedeeming(true);
setRedeemStatus({ type: null, message: '' }); setRedeemStatus({ type: null, message: '' });
const response = await fetch(`http://${window.location.hostname}:8080/api/coupons/redeem`, { const response = await fetch(`${getApiBaseUrl()}/api/coupons/redeem`, {
method: 'POST', method: 'POST',
headers: authHeaders(), headers: authHeaders(),
body: JSON.stringify({ body: JSON.stringify({

View File

@@ -0,0 +1,6 @@
export const getApiBaseUrl = (): string => {
if (window.location.protocol === 'https:') {
return 'https://cmsapi.rit-services.in';
}
return `http://${window.location.hostname}:8080`;
};

View File

@@ -55,7 +55,9 @@ declare global {
} }
} }
const API_HOST = () => `http://${window.location.hostname}:8080`; import { getApiBaseUrl } from './api';
const API_HOST = () => getApiBaseUrl();
export function authHeaders(): HeadersInit { export function authHeaders(): HeadersInit {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');