fix: use API_BASE_URL constant instead of direct env access
Replace all instances of process.env.NEXT_PUBLIC_API_URL with API_BASE_URL constant for consistency and to ensure the API URL is properly defined at runtime. Files updated: - app/admin/marketing-data/page.tsx - app/admin/tirages/page.tsx - app/employe/dashboard/page.tsx - app/employe/gains-client/page.tsx - app/employe/historique/page.tsx - components/admin/TicketManagement.tsx This fixes the "undefined" API URL issue that was preventing API calls from working correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6a772eead6
commit
34474cc275
|
|
@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
|||
import { Card } from '@/components/ui/Card';
|
||||
import Button from '@/components/Button';
|
||||
import toast from 'react-hot-toast';
|
||||
import { API_BASE_URL } from '@/utils/constants';
|
||||
import {
|
||||
Mail,
|
||||
Download,
|
||||
|
|
@ -66,11 +67,11 @@ export default function MarketingPage() {
|
|||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
|
||||
console.log('Loading marketing stats...');
|
||||
console.log('API URL:', process.env.NEXT_PUBLIC_API_URL);
|
||||
console.log('API URL:', API_BASE_URL);
|
||||
console.log('Token present:', !!token);
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/admin/marketing/stats`,
|
||||
`${API_BASE_URL}/admin/marketing/stats`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -124,7 +125,7 @@ export default function MarketingPage() {
|
|||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/admin/marketing/export`,
|
||||
`${API_BASE_URL}/admin/marketing/export`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
|||
import { Card } from '@/components/ui/Card';
|
||||
import Button from '@/components/Button';
|
||||
import toast from 'react-hot-toast';
|
||||
import { API_BASE_URL } from '@/utils/constants';
|
||||
import {
|
||||
Trophy,
|
||||
Users,
|
||||
|
|
@ -87,7 +88,7 @@ export default function TiragesPage() {
|
|||
const checkExistingDraw = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/draw/check-existing`, {
|
||||
const response = await fetch(`${API_BASE_URL}/draw/check-existing`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
|
|
@ -108,7 +109,7 @@ export default function TiragesPage() {
|
|||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/eligible-participants?minTickets=${minTickets}&verified=${verifiedOnly}`,
|
||||
`${API_BASE_URL}/draw/eligible-participants?minTickets=${minTickets}&verified=${verifiedOnly}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -144,7 +145,7 @@ export default function TiragesPage() {
|
|||
setLoading(true);
|
||||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/draw/conduct`, {
|
||||
const response = await fetch(`${API_BASE_URL}/draw/conduct`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -184,7 +185,7 @@ export default function TiragesPage() {
|
|||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}/report`,
|
||||
`${API_BASE_URL}/draw/${existingDraw.id}/report`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -267,7 +268,7 @@ ${report.draw.notifiedAt ? `📧 Gagnant notifié le: ${new Date(report.draw.not
|
|||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}/notify`,
|
||||
`${API_BASE_URL}/draw/${existingDraw.id}/notify`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
|
|
@ -293,7 +294,7 @@ ${report.draw.notifiedAt ? `📧 Gagnant notifié le: ${new Date(report.draw.not
|
|||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}/claim`,
|
||||
`${API_BASE_URL}/draw/${existingDraw.id}/claim`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
|
|
@ -326,7 +327,7 @@ ${report.draw.notifiedAt ? `📧 Gagnant notifié le: ${new Date(report.draw.not
|
|||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}`,
|
||||
`${API_BASE_URL}/draw/${existingDraw.id}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation';
|
|||
import { useAuth } from '@/hooks';
|
||||
import { Card } from '@/components/ui';
|
||||
import { Loading } from '@/components/ui/Loading';
|
||||
import { ROUTES } from '@/utils/constants';
|
||||
import { ROUTES, API_BASE_URL } from '@/utils/constants';
|
||||
import toast from 'react-hot-toast';
|
||||
import Link from 'next/link';
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ export default function EmployeDashboardPage() {
|
|||
setLoadingTickets(true);
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/pending-tickets?limit=10`,
|
||||
`${API_BASE_URL}/employee/pending-tickets?limit=10`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -83,7 +83,7 @@ export default function EmployeDashboardPage() {
|
|||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/stats`,
|
||||
`${API_BASE_URL}/employee/stats`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import { useState } from 'react';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import Button from '@/components/Button';
|
||||
import { API_BASE_URL } from '@/utils/constants';
|
||||
import toast from 'react-hot-toast';
|
||||
import {
|
||||
Search,
|
||||
|
|
@ -66,7 +67,7 @@ export default function GainsClientPage() {
|
|||
const queryParam = searchType === 'email' ? `email=${encodeURIComponent(searchValue)}` : `phone=${encodeURIComponent(searchValue)}`;
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/client-prizes?${queryParam}`,
|
||||
`${API_BASE_URL}/employee/client-prizes?${queryParam}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -100,7 +101,7 @@ export default function GainsClientPage() {
|
|||
try {
|
||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/validate-ticket`,
|
||||
`${API_BASE_URL}/employee/validate-ticket`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
|||
import { useAuth } from '@/hooks';
|
||||
import { Card } from '@/components/ui';
|
||||
import { Loading } from '@/components/ui/Loading';
|
||||
import { API_BASE_URL } from '@/utils/constants';
|
||||
import toast from 'react-hot-toast';
|
||||
import {
|
||||
CheckCircle,
|
||||
|
|
@ -48,7 +49,7 @@ export default function EmployeeHistoryPage() {
|
|||
|
||||
// Charger tous les tickets validés par cet employé
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/history`,
|
||||
`${API_BASE_URL}/employee/history`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { adminService } from '@/services/admin.service';
|
||||
import { Ticket, PaginatedResponse } from '@/types';
|
||||
import { API_BASE_URL } from '@/utils/constants';
|
||||
|
||||
export default function TicketManagement() {
|
||||
const [tickets, setTickets] = useState<Ticket[]>([]);
|
||||
|
|
@ -402,7 +403,7 @@ export default function TicketManagement() {
|
|||
<strong>Filtre statut:</strong> {filterStatus || 'Aucun'}
|
||||
</div>
|
||||
<div>
|
||||
<strong>URL API:</strong> {process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000/api'}
|
||||
<strong>URL API:</strong> {API_BASE_URL}
|
||||
</div>
|
||||
<div className="pt-2">
|
||||
<strong>Tickets reçus:</strong>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user