mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-23 23:28:12 +02:00
feat: add CatalogueAdmin component to manage and monitor catalogue scraping operations.
This commit is contained in:
1 parent
09a647a437
commit
6ed923c1ee
1 file changed
+12
-3
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { Loader2, Play, Clock, CheckCircle2, XCircle, AlertCircle } from 'lucide-react';
|
import { Loader2, Play, Clock, CheckCircle2, XCircle, AlertCircle } from 'lucide-react';
|
||||||
|
import { useAuth } from '../../hooks/use-auth';
|
||||||
|
|
||||||
const API_BASE = '/api/catalogues/admin';
|
const API_BASE = '/api/catalogues/admin';
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ export default function CatalogueAdmin() {
|
|||||||
const [logs, setLogs] = useState([]);
|
const [logs, setLogs] = useState([]);
|
||||||
const [stats, setStats] = useState(null);
|
const [stats, setStats] = useState(null);
|
||||||
const [enseignes, setEnseignes] = useState([]);
|
const [enseignes, setEnseignes] = useState([]);
|
||||||
|
const { getAuthHeaders } = useAuth();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadEnseignes();
|
loadEnseignes();
|
||||||
@@ -29,7 +31,9 @@ export default function CatalogueAdmin() {
|
|||||||
|
|
||||||
const loadStats = async () => {
|
const loadStats = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE}/stats`);
|
const response = await axios.get(`${API_BASE}/stats`, {
|
||||||
|
headers: getAuthHeaders()
|
||||||
|
});
|
||||||
setStats(response.data);
|
setStats(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading stats:', error);
|
console.error('Error loading stats:', error);
|
||||||
@@ -39,7 +43,9 @@ export default function CatalogueAdmin() {
|
|||||||
const loadLogs = async () => {
|
const loadLogs = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE}/scraping/logs?limit=20`);
|
const response = await axios.get(`${API_BASE}/scraping/logs?limit=20`, {
|
||||||
|
headers: getAuthHeaders()
|
||||||
|
});
|
||||||
setLogs(response.data);
|
setLogs(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading logs:', error);
|
console.error('Error loading logs:', error);
|
||||||
@@ -53,7 +59,10 @@ export default function CatalogueAdmin() {
|
|||||||
setScraping(true);
|
setScraping(true);
|
||||||
try {
|
try {
|
||||||
const params = enseigneId ? { enseigne_id: enseigneId } : {};
|
const params = enseigneId ? { enseigne_id: enseigneId } : {};
|
||||||
const response = await axios.post(`${API_BASE}/scraping/trigger`, null, { params });
|
const response = await axios.post(`${API_BASE}/scraping/trigger`, null, {
|
||||||
|
params,
|
||||||
|
headers: getAuthHeaders()
|
||||||
|
});
|
||||||
|
|
||||||
toast.success(response.data.message);
|
toast.success(response.data.message);
|
||||||
toast.info(`${response.data.catalogues_nouveaux} nouveaux catalogues trouvés`);
|
toast.info(`${response.data.catalogues_nouveaux} nouveaux catalogues trouvés`);
|
||||||
|
|||||||
Reference in new issue
Block a user