All files / src/components/partner AttendanceExportButton.tsx

11.11% Statements 1/9
0% Branches 0/4
0% Functions 0/2
11.11% Lines 1/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                            5x                                                    
/**
 * AttendanceExportButton
 * Story 8.1: AC4 — Export attendance table as XLSX.
 */
import React, { useState } from 'react';
import { Button, CircularProgress } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { exportAttendanceReport } from '@/services/api/partnerAnalyticsApi';
 
interface Props {
  companyName: string;
  fromYear?: number;
}
 
export const AttendanceExportButton: React.FC<Props> = ({ companyName, fromYear }) => {
  const { t } = useTranslation('partners');
  const [loading, setLoading] = useState(false);
 
  const handleExport = async () => {
    setLoading(true);
    try {
      await exportAttendanceReport(companyName, fromYear);
    } finally {
      setLoading(false);
    }
  };
 
  return (
    <Button
      variant="outlined"
      size="small"
      onClick={handleExport}
      disabled={loading}
      data-testid="export-button"
      startIcon={loading ? <CircularProgress size={16} /> : undefined}
    >
      {loading ? t('portal.analytics.export.loading') : t('portal.analytics.export.button')}
    </Button>
  );
};