import React, { useEffect, useState } from 'react'; import { UsersIcon, UserCheckIcon } from "lucide-react"; import { apiConfig } from '@/config/api.config'; import { useCallApi } from '@/hooks'; const API_URL = apiConfig.api_dashboard; interface Props { startdate: string; enddate: string; } const polarToCartesian = (cx: number, cy: number, radius: number, angleInDegrees: number) => { const angleInRadians = (angleInDegrees * Math.PI) / 180.0; return { x: cx + radius * Math.cos(angleInRadians), y: cy + radius * Math.sin(angleInRadians), }; }; const describeArc = ( x: number, y: number, radius: number, startAngle: number, endAngle: number ) => { const start = polarToCartesian(x, y, radius, endAngle); const end = polarToCartesian(x, y, radius, startAngle); const largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1"; return [ "M", start.x, start.y, "A", radius, radius, 0, largeArcFlag, 0, end.x, end.y, ].join(" "); }; const MemberActivity = ({ startdate, enddate }: Props) => { const { GetData } = useCallApi(); const [responseTransactionValue, setResponseTransactionValue] = useState(null); useEffect(() => { const fetchData = async () => { try { const res = await GetData(`${API_URL}/active-user`, { date_from: startdate, date_to: enddate, }); setResponseTransactionValue(res); } catch (error) { console.error('Error fetching data:', error); } }; fetchData(); }, [startdate, enddate, GetData]); const percentage = parseFloat((responseTransactionValue?.data?.total_customer_active_percentage ?? 0).toFixed(2)); const totalCustomer = responseTransactionValue?.data?.total_customer ?? 0; const activeCustomer = responseTransactionValue?.data?.total_customer_active ?? 0; const reguler = responseTransactionValue?.data?.reguler ?? 0; const premium = responseTransactionValue?.data?.premium ?? 0; const agent = responseTransactionValue?.data?.agent ?? 0; // Calculate pointer angle const angle = (percentage / 100) * 180; const pointerX = 50 + 25 * Math.cos((angle - 180) * Math.PI / 180); const pointerY = 50 + 25 * Math.sin((angle - 180) * Math.PI / 180); return (

Member Activity

{/* Sidebar Info */}
  • Total Customer: {totalCustomer}
  • Active Customer: {activeCustomer}
  • Reguler: {reguler}
  • Premium: {premium}
  • Agent: {agent}
{/* Gauge Chart */}

Active User

{/* Background arc */} {/* Active arc */} {percentage > 0 && ( )} {/* Pointer */}
{percentage}% 100%
); }; export default MemberActivity;