export interface ReferrerIncomesStatistics { openlink: DateCount[]; registration:…
- User
export interface ReferrerIncomesStatistics { open_link: DateCount[]; registration: DateCount[]; order_pay: DateCount[]; subscription_pay: DateCount[]; }
export interface Referrer { user_id: number; user_name: string; user_email: string; key: string; status: “new” | “active” | “disabled”; } export const referrerIncomesStatistics = (token: string, from: string, to: string, user_id?: number|null): Promise<{data:ReferrerIncomesStatistics}|undefined> => { const userId = user_id ? &user_id=${user_id} : “”;
return apiClient( /referrer-incomes/statistics?date_from={from}&date_to={to}${userId}, “get”, token, ); };
const [referralList, setReferralList] = useState<Array | null>(null); const [referralId, setReferralId] = useState<Array>([3,6,1]); useEffect(() => { referrersList(bearer) .then(data => { if (!data) return; setReferralList(data.data); }); referrerIncomesStatistics(bearer, from, to, referralId) .then(data => { if (!data) return; setData(data.data); }); }, [referralId]); нужно сделать так, что если в referralId несколько символов, то делать на каждый id запрос? забивать данные внутри, а потом когда все запросы отправле сетать в data новый useState
react typescript. import {CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from “recharts”; И данные которые получаются в стейте data нужно отрисовать <LineChart data={data} margin={{ top: 0, right: 20, bottom: 10, left: 0 }}
- Assistant
You can achieve this by using
Promise.all()to make multiple requests for each referralId and then combine the results.- Create a new state for ReferrerIncomesStatistics
const [data, setData] = useState<ReferrerIncomesStatistics | null>(null);