import {__} from '@wordpress/i18n'; import Chart from 'react-apexcharts'; import React from 'react'; import styles from './styles.module.scss'; import {amountFormatter, getCampaignOptionsWindowData} from '@givewp/campaigns/utils'; import type {Campaign} from '@givewp/campaigns/admin/components/types'; const {currency} = getCampaignOptionsWindowData(); const currencyFormatter = amountFormatter(currency); type GoalProgressChartProps = { value: number; goal: number; goalType: Partial['goalType']; }; const goalTypeLabels = { amount: __('Amount raised', 'give'), donations: __('Number of donations', 'give'), donors: __('Number of donors', 'give'), amountFromSubscriptions: __('Recurring amount raised', 'give'), subscriptions: __('Number of recurring donations', 'give'), donorsFromSubscriptions: __('Number of recurring donors', 'give'), }; const GoalProgressChart = ({value, goal, goalType}: GoalProgressChartProps) => { const progress = Math.ceil((value / goal) * 100); const percentage = Math.min(progress, 100); const isCurrencyGoal = ['amount', 'amountFromSubscriptions'].includes(goalType); const formattedValue = isCurrencyGoal ? currencyFormatter.format(value) : value.toString(); const formattedGoal = isCurrencyGoal ? currencyFormatter.format(goal) : goal.toString(); return (
{__('Goal', 'give')}
{formattedGoal}
{goalTypeLabels[goalType]}
); }; export default GoalProgressChart;