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 { Card } from '@/components/ui/Card';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
|
import { API_BASE_URL } from '@/utils/constants';
|
||||||
import {
|
import {
|
||||||
Mail,
|
Mail,
|
||||||
Download,
|
Download,
|
||||||
|
|
@ -66,11 +67,11 @@ export default function MarketingPage() {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
|
|
||||||
console.log('Loading marketing stats...');
|
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);
|
console.log('Token present:', !!token);
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/admin/marketing/stats`,
|
`${API_BASE_URL}/admin/marketing/stats`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
@ -124,7 +125,7 @@ export default function MarketingPage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/admin/marketing/export`,
|
`${API_BASE_URL}/admin/marketing/export`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
||||||
import { Card } from '@/components/ui/Card';
|
import { Card } from '@/components/ui/Card';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
|
import { API_BASE_URL } from '@/utils/constants';
|
||||||
import {
|
import {
|
||||||
Trophy,
|
Trophy,
|
||||||
Users,
|
Users,
|
||||||
|
|
@ -87,7 +88,7 @@ export default function TiragesPage() {
|
||||||
const checkExistingDraw = async () => {
|
const checkExistingDraw = async () => {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
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: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
|
|
@ -108,7 +109,7 @@ export default function TiragesPage() {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
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: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
@ -144,7 +145,7 @@ export default function TiragesPage() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
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',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
@ -184,7 +185,7 @@ export default function TiragesPage() {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}/report`,
|
`${API_BASE_URL}/draw/${existingDraw.id}/report`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
@ -267,7 +268,7 @@ ${report.draw.notifiedAt ? `📧 Gagnant notifié le: ${new Date(report.draw.not
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}/notify`,
|
`${API_BASE_URL}/draw/${existingDraw.id}/notify`,
|
||||||
{
|
{
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -293,7 +294,7 @@ ${report.draw.notifiedAt ? `📧 Gagnant notifié le: ${new Date(report.draw.not
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}/claim`,
|
`${API_BASE_URL}/draw/${existingDraw.id}/claim`,
|
||||||
{
|
{
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -326,7 +327,7 @@ ${report.draw.notifiedAt ? `📧 Gagnant notifié le: ${new Date(report.draw.not
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/draw/${existingDraw.id}`,
|
`${API_BASE_URL}/draw/${existingDraw.id}`,
|
||||||
{
|
{
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation';
|
||||||
import { useAuth } from '@/hooks';
|
import { useAuth } from '@/hooks';
|
||||||
import { Card } from '@/components/ui';
|
import { Card } from '@/components/ui';
|
||||||
import { Loading } from '@/components/ui/Loading';
|
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 toast from 'react-hot-toast';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ export default function EmployeDashboardPage() {
|
||||||
setLoadingTickets(true);
|
setLoadingTickets(true);
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/pending-tickets?limit=10`,
|
`${API_BASE_URL}/employee/pending-tickets?limit=10`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
@ -83,7 +83,7 @@ export default function EmployeDashboardPage() {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/stats`,
|
`${API_BASE_URL}/employee/stats`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Card } from '@/components/ui/Card';
|
import { Card } from '@/components/ui/Card';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
|
import { API_BASE_URL } from '@/utils/constants';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import {
|
import {
|
||||||
Search,
|
Search,
|
||||||
|
|
@ -66,7 +67,7 @@ export default function GainsClientPage() {
|
||||||
const queryParam = searchType === 'email' ? `email=${encodeURIComponent(searchValue)}` : `phone=${encodeURIComponent(searchValue)}`;
|
const queryParam = searchType === 'email' ? `email=${encodeURIComponent(searchValue)}` : `phone=${encodeURIComponent(searchValue)}`;
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/client-prizes?${queryParam}`,
|
`${API_BASE_URL}/employee/client-prizes?${queryParam}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
@ -100,7 +101,7 @@ export default function GainsClientPage() {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
const token = localStorage.getItem('auth_token') || localStorage.getItem('token');
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/validate-ticket`,
|
`${API_BASE_URL}/employee/validate-ticket`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
||||||
import { useAuth } from '@/hooks';
|
import { useAuth } from '@/hooks';
|
||||||
import { Card } from '@/components/ui';
|
import { Card } from '@/components/ui';
|
||||||
import { Loading } from '@/components/ui/Loading';
|
import { Loading } from '@/components/ui/Loading';
|
||||||
|
import { API_BASE_URL } from '@/utils/constants';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import {
|
import {
|
||||||
CheckCircle,
|
CheckCircle,
|
||||||
|
|
@ -48,7 +49,7 @@ export default function EmployeeHistoryPage() {
|
||||||
|
|
||||||
// Charger tous les tickets validés par cet employé
|
// Charger tous les tickets validés par cet employé
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/employee/history`,
|
`${API_BASE_URL}/employee/history`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { adminService } from '@/services/admin.service';
|
import { adminService } from '@/services/admin.service';
|
||||||
import { Ticket, PaginatedResponse } from '@/types';
|
import { Ticket, PaginatedResponse } from '@/types';
|
||||||
|
import { API_BASE_URL } from '@/utils/constants';
|
||||||
|
|
||||||
export default function TicketManagement() {
|
export default function TicketManagement() {
|
||||||
const [tickets, setTickets] = useState<Ticket[]>([]);
|
const [tickets, setTickets] = useState<Ticket[]>([]);
|
||||||
|
|
@ -402,7 +403,7 @@ export default function TicketManagement() {
|
||||||
<strong>Filtre statut:</strong> {filterStatus || 'Aucun'}
|
<strong>Filtre statut:</strong> {filterStatus || 'Aucun'}
|
||||||
</div>
|
</div>
|
||||||
<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>
|
||||||
<div className="pt-2">
|
<div className="pt-2">
|
||||||
<strong>Tickets reçus:</strong>
|
<strong>Tickets reçus:</strong>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user