Unrated orders error fixed
This commit is contained in:
@@ -16,6 +16,7 @@ import { useCart } from '../contexts/CartContext';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { useFood } from '../contexts/FoodContext';
|
||||
import { payAndVerify, authHeaders } from '../utils/razorpay';
|
||||
import { getApiBaseUrl } from '../utils/api';
|
||||
import './CheckoutScreen.css';
|
||||
|
||||
type PaymentMethod = 'RITZ_TOKEN' | 'RAZORPAY';
|
||||
@@ -50,7 +51,7 @@ const CheckoutScreen: React.FC = () => {
|
||||
const fetchBalance = async () => {
|
||||
if (!user) return;
|
||||
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()
|
||||
});
|
||||
const data = await response.json();
|
||||
@@ -101,7 +102,7 @@ const CheckoutScreen: React.FC = () => {
|
||||
user: { id: user.id }
|
||||
};
|
||||
|
||||
const response = await fetch(`http://${window.location.hostname}:8080/api/orders`, {
|
||||
const response = await fetch(`${getApiBaseUrl()}/api/orders`, {
|
||||
method: 'POST',
|
||||
headers: authHeaders(),
|
||||
body: JSON.stringify(orderData),
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useFood } from '../contexts/FoodContext';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import walletIcon from '../assets/front.webp';
|
||||
import { getApiBaseUrl } from '../utils/api';
|
||||
import './HomeScreen.css';
|
||||
|
||||
const HomeScreen: React.FC = () => {
|
||||
@@ -36,7 +37,7 @@ const HomeScreen: React.FC = () => {
|
||||
|
||||
try {
|
||||
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: {
|
||||
...(token ? { 'Authorization': `Bearer ${token}` } : {})
|
||||
}
|
||||
@@ -59,7 +60,7 @@ const HomeScreen: React.FC = () => {
|
||||
|
||||
try {
|
||||
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',
|
||||
headers: {
|
||||
...(token ? { 'Authorization': `Bearer ${token}` } : {})
|
||||
@@ -80,7 +81,7 @@ const HomeScreen: React.FC = () => {
|
||||
const handleFeedbackSubmit = async (feedbackData: any) => {
|
||||
try {
|
||||
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',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -146,7 +147,7 @@ const HomeScreen: React.FC = () => {
|
||||
const fetchSearchResults = async () => {
|
||||
setIsSearching(true);
|
||||
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) {
|
||||
const data = await response.json();
|
||||
const products = data.content || data || [];
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useFood } from '../contexts/FoodContext';
|
||||
import CartTab from '../components/CartTab';
|
||||
import { VegNonVegIcon } from '../components/ItemCard';
|
||||
import './ItemDetailScreen.css';
|
||||
import { getApiBaseUrl } from '../utils/api';
|
||||
|
||||
const ItemDetailScreen: React.FC = () => {
|
||||
const { itemId } = useParams<{ itemId: string }>();
|
||||
@@ -32,7 +33,7 @@ const ItemDetailScreen: React.FC = () => {
|
||||
const fetchItem = async () => {
|
||||
setIsFetching(true);
|
||||
try {
|
||||
const response = await fetch(`http://${window.location.hostname}:8080/api/products/${itemId}`);
|
||||
const response = await fetch(`${getApiBaseUrl()}/api/products/${itemId}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
|
||||
@@ -47,7 +48,7 @@ const ItemDetailScreen: React.FC = () => {
|
||||
let finalRatingCount = 0;
|
||||
try {
|
||||
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}` } : {}
|
||||
});
|
||||
if (statsRes.ok) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useFood } from '../contexts/FoodContext';
|
||||
import { useCart } from '../contexts/CartContext';
|
||||
import type { FoodItem } from '../types';
|
||||
import './MyOrdersScreen.css';
|
||||
import { getApiBaseUrl } from '../utils/api';
|
||||
|
||||
interface Order {
|
||||
id: number;
|
||||
@@ -82,7 +83,7 @@ const MyOrdersScreen: React.FC = () => {
|
||||
const fetchOrders = async () => {
|
||||
try {
|
||||
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: {
|
||||
...(token ? { 'Authorization': `Bearer ${token}` } : {})
|
||||
}
|
||||
@@ -143,7 +144,7 @@ const MyOrdersScreen: React.FC = () => {
|
||||
setIsCancelling(true);
|
||||
try {
|
||||
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',
|
||||
headers: {
|
||||
...(token ? { 'Authorization': `Bearer ${token}` } : {})
|
||||
|
||||
@@ -6,6 +6,7 @@ import CartTab from '../components/CartTab';
|
||||
import BottomNav from '../components/BottomNav';
|
||||
import type { Stall } from '../types';
|
||||
import './StallDetailScreen.css';
|
||||
import { getApiBaseUrl } from '../utils/api';
|
||||
|
||||
const StallDetailScreen: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
@@ -18,7 +19,7 @@ const StallDetailScreen: React.FC = () => {
|
||||
const fetchStallDetails = async () => {
|
||||
setLoading(true);
|
||||
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');
|
||||
const data = await response.json();
|
||||
|
||||
@@ -61,8 +62,7 @@ const StallDetailScreen: React.FC = () => {
|
||||
fetchStallDetails();
|
||||
|
||||
// SSE Real-time stock updates
|
||||
const host = window.location.hostname;
|
||||
const eventSource = new EventSource(`http://${host}:8080/api/stock/stream`);
|
||||
const eventSource = new EventSource(`${getApiBaseUrl()}/api/stock/stream`);
|
||||
|
||||
eventSource.addEventListener('stockUpdate', (event: any) => {
|
||||
try {
|
||||
|
||||
@@ -7,6 +7,7 @@ import Header from '../components/Header';
|
||||
import BottomNav from '../components/BottomNav';
|
||||
import tokenImage from '../assets/display_ritz.webp';
|
||||
import './WalletScreen.css';
|
||||
import { getApiBaseUrl } from '../utils/api';
|
||||
|
||||
interface Transaction {
|
||||
id: number;
|
||||
@@ -40,7 +41,7 @@ const WalletScreen: React.FC = () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
// 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()
|
||||
});
|
||||
if (balanceRes.ok) {
|
||||
@@ -49,7 +50,7 @@ const WalletScreen: React.FC = () => {
|
||||
}
|
||||
|
||||
// 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()
|
||||
});
|
||||
if (txRes.ok) {
|
||||
@@ -71,7 +72,7 @@ const WalletScreen: React.FC = () => {
|
||||
setIsRedeeming(true);
|
||||
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',
|
||||
headers: authHeaders(),
|
||||
body: JSON.stringify({
|
||||
|
||||
6
ordering_site/src/utils/api.ts
Normal file
6
ordering_site/src/utils/api.ts
Normal 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`;
|
||||
};
|
||||
@@ -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 {
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
Reference in New Issue
Block a user