Files
worklenz/worklenz-frontend/src/pages/admin-center/overview/overview.tsx
chamikaJ f73c151da2 feat(holiday-system): add holiday population functionality and API integration
- Implemented a new API endpoint to populate country holidays in the database.
- Enhanced the HolidayController to handle holiday population logic for multiple countries.
- Updated the holiday API router to include the new populate endpoint.
- Added a service method in the frontend to trigger holiday population.
- Integrated a button in the admin center overview for easy access to populate holidays.
- Improved error handling and user feedback during the holiday population process.
2025-07-17 11:27:29 +05:30

123 lines
4.1 KiB
TypeScript

import { EditOutlined, MailOutlined, PhoneOutlined, DatabaseOutlined } from '@ant-design/icons';
import { PageHeader } from '@ant-design/pro-components';
import { Button, Card, Input, Space, Tooltip, Typography, message } from 'antd';
import React, { useEffect, useState } from 'react';
import OrganizationAdminsTable from '@/components/admin-center/overview/organization-admins-table/organization-admins-table';
import { useAppSelector } from '@/hooks/useAppSelector';
import { RootState } from '@/app/store';
import { useTranslation } from 'react-i18next';
import OrganizationName from '@/components/admin-center/overview/organization-name/organization-name';
import OrganizationOwner from '@/components/admin-center/overview/organization-owner/organization-owner';
import HolidayCalendar from '@/components/admin-center/overview/holiday-calendar/holiday-calendar';
import { adminCenterApiService } from '@/api/admin-center/admin-center.api.service';
import { holidayApiService } from '@/api/holiday/holiday.api.service';
import { IOrganization, IOrganizationAdmin } from '@/types/admin-center/admin-center.types';
import logger from '@/utils/errorLogger';
const { Text } = Typography;
const Overview: React.FC = () => {
const [organization, setOrganization] = useState<IOrganization | null>(null);
const [organizationAdmins, setOrganizationAdmins] = useState<IOrganizationAdmin[] | null>(null);
const [loadingAdmins, setLoadingAdmins] = useState(false);
const [populatingHolidays, setPopulatingHolidays] = useState(false);
const themeMode = useAppSelector((state: RootState) => state.themeReducer.mode);
const { t } = useTranslation('admin-center/overview');
const getOrganizationDetails = async () => {
try {
const res = await adminCenterApiService.getOrganizationDetails();
if (res.done) {
setOrganization(res.body);
}
} catch (error) {
logger.error('Error getting organization details', error);
}
};
const getOrganizationAdmins = async () => {
setLoadingAdmins(true);
try {
const res = await adminCenterApiService.getOrganizationAdmins();
if (res.done) {
setOrganizationAdmins(res.body);
}
} catch (error) {
logger.error('Error getting organization admins', error);
} finally {
setLoadingAdmins(false);
}
};
const handlePopulateHolidays = async () => {
setPopulatingHolidays(true);
try {
const res = await holidayApiService.populateCountryHolidays();
if (res.done) {
message.success(`Successfully populated ${res.body.total_populated} holidays`);
}
} catch (error) {
logger.error('Error populating holidays', error);
message.error('Failed to populate holidays');
} finally {
setPopulatingHolidays(false);
}
};
useEffect(() => {
getOrganizationDetails();
getOrganizationAdmins();
}, []);
return (
<div style={{ width: '100%' }}>
<PageHeader
title={<span>{t('overview')}</span>}
style={{ padding: '16px 0' }}
extra={[
<Button
key="populate-holidays"
icon={<DatabaseOutlined />}
onClick={handlePopulateHolidays}
loading={populatingHolidays}
>
Populate Holidays Database
</Button>
]}
/>
<Space direction="vertical" style={{ width: '100%' }} size={22}>
<OrganizationName
themeMode={themeMode}
name={organization?.name || ''}
t={t}
refetch={getOrganizationDetails}
/>
<OrganizationOwner
themeMode={themeMode}
organization={organization}
t={t}
refetch={getOrganizationDetails}
/>
<Card>
<Typography.Title level={5} style={{ margin: 0 }}>
{t('admins')}
</Typography.Title>
<OrganizationAdminsTable
organizationAdmins={organizationAdmins}
loading={loadingAdmins}
themeMode={themeMode}
/>
</Card>
<HolidayCalendar themeMode={themeMode} />
</Space>
</div>
);
};
export default Overview;