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.
This commit is contained in:
@@ -65,4 +65,10 @@ export const holidayApiService = {
|
||||
const response = await apiClient.get<IServerResponse<IHolidayCalendarEvent[]>>(`${rootUrl}/calendar?year=${year}&month=${month}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Populate holidays
|
||||
populateCountryHolidays: async (): Promise<IServerResponse<any>> => {
|
||||
const response = await apiClient.post<IServerResponse<any>>(`${rootUrl}/populate`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EditOutlined, MailOutlined, PhoneOutlined } from '@ant-design/icons';
|
||||
import { EditOutlined, MailOutlined, PhoneOutlined, DatabaseOutlined } from '@ant-design/icons';
|
||||
import { PageHeader } from '@ant-design/pro-components';
|
||||
import { Button, Card, Input, Space, Tooltip, Typography } from 'antd';
|
||||
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';
|
||||
@@ -10,6 +10,7 @@ import OrganizationName from '@/components/admin-center/overview/organization-na
|
||||
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';
|
||||
|
||||
@@ -19,6 +20,7 @@ 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');
|
||||
@@ -48,6 +50,21 @@ const Overview: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
@@ -55,7 +72,20 @@ const Overview: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div style={{ width: '100%' }}>
|
||||
<PageHeader title={<span>{t('overview')}</span>} style={{ padding: '16px 0' }} />
|
||||
<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
|
||||
|
||||
Reference in New Issue
Block a user