Добавлено использование токена авторизации из куки в компонентах: AgentsBarChart, AgentsTable, BillingMetricCards, BillingPieChart, BillingStatChart, MetricCards, PayoutsTransactionsTable, ReferralsTable, RevenueChart и SalesTable. Реализована проверка наличия токена перед выполнением запросов к API, добавлены соответствующие сообщения об ошибках при его отсутствии.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer } from "recharts";
|
||||
import styles from "../styles/billing.module.css";
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
"done": "#10B981",
|
||||
@@ -15,7 +16,17 @@ const STATUS_COLORS: Record<string, string> = {
|
||||
const BillingPieChart: React.FC = () => {
|
||||
const [data, setData] = useState<{ name: string; value: number; fill: string }[]>([]);
|
||||
useEffect(() => {
|
||||
fetch("/api/billing/chart/pie")
|
||||
const token = Cookies.get("access_token");
|
||||
if (!token) {
|
||||
console.warn("Токен авторизации не найден.");
|
||||
return;
|
||||
}
|
||||
|
||||
fetch("/api/billing/chart/pie", {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((apiData) => {
|
||||
const mapped = apiData.map((item: { status: string; count: number }) => ({
|
||||
|
||||
Reference in New Issue
Block a user