Skip to content

Commit

Permalink
improved refactoring statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
duplixx committed Nov 1, 2024
1 parent bfcf39b commit 63faea3
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"@types/react": "^18.3.3",
"@types/react-beautiful-dnd": "^13.1.8",
"@types/react-bootstrap": "^0.32.32",
"@types/react-chartjs-2": "^2.5.7",
"@types/react-datepicker": "^7.0.0",
"@types/react-dom": "^18.3.0",
"@types/react-google-recaptcha": "^2.1.9",
Expand Down
11 changes: 11 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,17 @@
"attendance": "Attendance",
"to": "TO"
},
"eventAttendance": {
"historical_statistics": "Historical Statistics",
"Search member": "Search member",
"Member Name": "Member Name",
"Status": "Status",
"Events Attended": "Events Attended",
"Task Assigned": "Task Assigned",
"Member": "Member",
"Admin": "Admin",
"loading": "Loading..."
},
"forgotPassword": {
"title": "Talawa Forgot Password",
"registeredEmail": "Registered Email",
Expand Down
11 changes: 11 additions & 0 deletions public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,17 @@
"article": "Article",
"postNowVisibleInFeed": "Le post est maintenant visible dans le fil d'actualité"
},
"eventAttendance": {
"historical_statistics": "Statistiques historiques",
"Search member": "Rechercher un membre",
"Member Name": "Nom du membre",
"Status": "Statut",
"Events Attended": "Événements assistés",
"Task Assigned": "Tâche assignée",
"Member": "Membre",
"Admin": "Administrateur",
"loading": "Chargement..."
},
"settings": {
"eventAttended": "Événements Assistés",
"noeventsAttended": "Aucun événement assisté",
Expand Down
12 changes: 11 additions & 1 deletion public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,17 @@
"article": "लेख",
"postNowVisibleInFeed": "पोस्ट अब फीड में दिखाई दे रहा है"
},
"settings": {
"eventAttendance": {
"historical_statistics": "ऐतिहासिक आंकड़े",
"Search member": "सदस्य खोजें",
"Member Name": "सदस्य का नाम",
"Status": "स्थिति",
"Events Attended": "भाग लिए गए कार्यक्रम",
"Task Assigned": "सौंपा गया कार्य",
"Member": "सदस्य",
"Admin": "व्यवस्थापक",
"loading": "लोड हो रहा है"
}, "settings": {
"noeventsAttended": "कोई कार्यक्रम में उपस्थित नहीं",
"eventAttended": "भाग लिए गए कार्यक्रम",
"profileSettings": "पार्श्वचित्र समायोजन",
Expand Down
12 changes: 12 additions & 0 deletions public/locales/sp/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,18 @@
"article": "Artículo",
"postNowVisibleInFeed": "Publicar ahora visible en el feed"
},

"eventAttendance": {
"historical_statistics": "Estadísticas históricas",
"Search member": "Buscar miembro",
"Member Name": "Nombre del miembro",
"Status": "Estado",
"Events Attended": "Eventos asistidos",
"Task Assigned": "Tarea asignada",
"Member": "Miembro",
"Admin": "Administrador",
"loading": "Cargando..."
},
"settings": {
"settings": "Ajustes",
"eventAttended": "Événements Assistés",
Expand Down
11 changes: 11 additions & 0 deletions public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,17 @@
"article": "文章",
"postNowVisibleInFeed": "帖子现在在动态中可见"
},
"eventAttendance": {
"historical_statistics": "历史统计",
"Search member": "搜索成员",
"Member Name": "成员姓名",
"Status": "状态",
"Events Attended": "参加的活动",
"Task Assigned": "分配的任务",
"Member": "成员",
"Admin": "管理员",
"loading": "加载中..."
},
"settings": {
"noeventsAttended": "未参加任何活动",
"eventAttended": "参加的活动",
Expand Down
17 changes: 13 additions & 4 deletions src/components/EventManagement/EventAttendance/EventAttendance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ enum FilterPeriod {
}

function EventAttendance(): JSX.Element {
const { t } = useTranslation();
const { t } = useTranslation('translation', {
keyPrefix: 'eventAttendance',
});
const { eventId } = useParams<{ eventId: string }>();
const { orgId: currentUrl } = useParams();
const [filteredAttendees, setFilteredAttendees] = useState<InterfaceMember[]>(
Expand Down Expand Up @@ -114,6 +116,10 @@ function EventAttendance(): JSX.Element {
variables: {
id: eventId,
},
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first',
errorPolicy: 'all',
notifyOnNetworkStatusChange: true,
});

useEffect(() => {
Expand All @@ -139,6 +145,7 @@ function EventAttendance(): JSX.Element {
statistics={statistics}
handleClose={handleClose}
memberData={filteredAttendees}
t={t}
/>
<div className="d-flex justify-content-between">
<div className="d-flex w-100">
Expand All @@ -147,7 +154,7 @@ function EventAttendance(): JSX.Element {
onClick={showModal}
data-testid="stats-modal"
>
Historical Statistics
{t('historical_statistics')}
</Button>
</div>
<div className="d-flex justify-content-between align-items-end w-100 ">
Expand Down Expand Up @@ -217,12 +224,14 @@ function EventAttendance(): JSX.Element {
</div>
{/* <h3>{totalMembers}</h3> */}
<TableContainer component={Paper} className="mt-3">
<Table aria-label="customized table">
<Table aria-label={t('event_attendance_table')} role="grid">
<TableHead>
<TableRow className="" data-testid="table-header-row">
<TableRow className="" data-testid="table-header-row" role="row">
<TableCell
className={styles.customcell}
data-testid="header-index"
role="columnheader"
aria-sort="none"
>
#
</TableCell>
Expand Down
34 changes: 25 additions & 9 deletions src/components/EventManagement/EventAttendance/EventStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ import { useParams } from 'react-router-dom';
import { EVENT_DETAILS, RECURRING_EVENTS } from 'GraphQl/Queries/Queries';
import { useLazyQuery } from '@apollo/client';
import { exportToCSV } from 'utils/chartToPdf';
import type { TooltipItem } from 'chart.js';
import type { ChartOptions, TooltipItem } from 'chart.js';
import type {
InterfaceAttendanceStatisticsModalProps,
InterfaceEvent,
InterfaceRecurringEvent,
} from './InterfaceEvents';
import { toast } from 'react-toastify';

const CHART_COLORS = {
primary: '#1f77b4', // Color-blind friendly blue
secondary: '#ff7f0e', // Color-blind friendly orange
tertiary: '#2ca02c', // Color-blind friendly green
};
export const AttendanceStatisticsModal: React.FC<
InterfaceAttendanceStatisticsModalProps
> = ({ show, handleClose, statistics, memberData }): JSX.Element => {
> = ({ show, handleClose, statistics, memberData, t }): JSX.Element => {
const [selectedCategory, setSelectedCategory] = useState('Gender');
const { orgId, eventId } = useParams();
const [currentPage, setCurrentPage] = useState(0);
Expand Down Expand Up @@ -64,9 +70,10 @@ export const AttendanceStatisticsModal: React.FC<
),
[paginatedRecurringEvents],
);
const chartOptions = {
const chartOptions: ChartOptions<'line'> = {
responsive: true,
maintainAspectRatio: false,
animation: false,
scales: { y: { beginAtZero: true } },
plugins: {
tooltip: {
Expand Down Expand Up @@ -257,19 +264,28 @@ export const AttendanceStatisticsModal: React.FC<
exportToCSV(data, `${selectedCategory.toLowerCase()}_demographics.csv`);
}, [selectedCategory, categoryLabels, categoryData]);

const handleExport = (eventKey: string | null): number | void => {
const handleExport = (eventKey: string | null): void => {
switch (eventKey) {
case 'trends':
exportTrendsToCSV();
try {
exportTrendsToCSV();
} catch (error) {
console.error('Failed to export trends:', error);
toast.error('Failed to export trends');
}
break;
case 'demographics':
exportDemographicsToCSV();
try {
exportDemographicsToCSV();
} catch (error) {
console.error('Failed to export demographics:', error);
toast.error('Failed to export demographics');
}
break;
default:
return 0;
return;
}
};

useEffect(() => {
if (eventId) {
loadEventDetails({ variables: { id: eventId } });
Expand All @@ -295,7 +311,7 @@ export const AttendanceStatisticsModal: React.FC<
>
<Modal.Header closeButton className="bg-success">
<Modal.Title className="text-white" data-testid="modal-title">
Attendance Statistics
{t('historical_statistics')}
</Modal.Title>
</Modal.Header>
<Modal.Body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface InterfaceAttendanceStatisticsModalProps {
attendanceRate: number;
};
memberData: InterfaceMember[];
t: (key: string) => string;
}

export interface InterfaceMember {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import { EventsAttendedByUser } from './EventsAttendedByUser';

const mockT = (key: string): string => key;
const mockT = (key: string, params?: Record<string, string>): string => {
if (params) {
return Object.entries(params).reduce(
(acc, [key, value]) => acc.replace(`{{${key}}}`, value),
key,
);
}
return key;
};

describe('EventsAttendedByUser Component', () => {
const mockUserWithEvents = {
Expand Down
19 changes: 11 additions & 8 deletions src/components/UserPortal/UserProfile/UserAddressFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ export const UserAddressFields: React.FC<InterfaceUserAddressFieldsProps> = ({
<option value="" disabled>
{t('selectCountry')}
</option>
{countryOptions.map((country) => (
<option
key={country.value.toUpperCase()}
value={country.value.toUpperCase()}
>
{country.label}
</option>
))}
{[...countryOptions]
.sort((a, b) => a.label.localeCompare(b.label))
.map((country) => (
<option
key={country.value.toUpperCase()}
value={country.value.toUpperCase()}
aria-label={`Select ${country.label} as your country`}
>
{country.label}
</option>
))}
</Form.Control>
</Col>
</Row>
Expand Down
6 changes: 3 additions & 3 deletions src/screens/MemberDetail/MemberDetail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,9 @@ describe('MemberDetail', () => {
</BrowserRouter>
</MockedProvider>,
);
await wait(1000);
// Check if the card title is rendered
expect(screen.getByText('Events Attended')).toBeInTheDocument();
await waitFor(() => {
expect(screen.getByText('Events Attended')).toBeInTheDocument();
});
// Check for empty state immediately
expect(screen.getByText('No Events Attended')).toBeInTheDocument();
});
Expand Down
3 changes: 1 addition & 2 deletions src/screens/UserPortal/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ export default function settings(): JSX.Element {
async (
e: React.ChangeEvent<HTMLInputElement>,
): Promise<void> => {
const target = e.target as HTMLInputElement;
const file = target.files && target.files[0];
const file = e.target?.files?.[0];
if (file) {
const image = await convertToBase64(file);
setUserDetails({ ...userDetails, image });
Expand Down

0 comments on commit 63faea3

Please sign in to comment.