feat(admin-center): implement organization calculation method settings

- Added functionality to update the organization's calculation method (hourly or man-days) in the Admin Center.
- Created a new component for managing the calculation method, including UI elements for selection and saving changes.
- Updated API service to handle the new endpoint for updating the calculation method.
- Enhanced localization files to support new keys related to the calculation method settings.
- Introduced a settings page to manage organization working days and hours alongside the calculation method.
This commit is contained in:
chamikaJ
2025-07-24 12:53:46 +05:30
parent 67a75685a9
commit 4b54f2cc17
28 changed files with 1033 additions and 142 deletions

View File

@@ -280,4 +280,16 @@ export const adminCenterApiService = {
);
return response.data;
},
async updateOrganizationCalculationMethod(
calculationMethod: 'hourly' | 'man_days'
): Promise<IServerResponse<any>> {
const response = await apiClient.put<IServerResponse<any>>(
`${rootUrl}/organization/calculation-method`,
{
calculation_method: calculationMethod,
}
);
return response.data;
},
};

View File

@@ -0,0 +1,120 @@
import React, { useState, useEffect } from 'react';
import { Card, Select, Space, Typography, Tooltip, message, Button } from '@/shared/antd-imports';
import { useTranslation } from 'react-i18next';
import { InfoCircleOutlined, CalculatorOutlined, SaveOutlined } from '@ant-design/icons';
import { adminCenterApiService } from '@/api/admin-center/admin-center.api.service';
import { IOrganization } from '@/types/admin-center/admin-center.types';
const { Option } = Select;
const { Text, Title } = Typography;
interface OrganizationCalculationMethodProps {
organization: IOrganization | null;
refetch: () => void;
}
const OrganizationCalculationMethod: React.FC<OrganizationCalculationMethodProps> = ({
organization,
refetch
}) => {
const { t } = useTranslation('admin-center/overview');
const [updating, setUpdating] = useState(false);
const [currentMethod, setCurrentMethod] = useState<'hourly' | 'man_days'>(
organization?.calculation_method || 'hourly'
);
const [hasChanges, setHasChanges] = useState(false);
useEffect(() => {
if (organization) {
setCurrentMethod(organization.calculation_method || 'hourly');
setHasChanges(false);
}
}, [organization]);
const handleMethodChange = (newMethod: 'hourly' | 'man_days') => {
setCurrentMethod(newMethod);
setHasChanges(newMethod !== organization?.calculation_method);
};
const handleSave = async () => {
setUpdating(true);
try {
await adminCenterApiService.updateOrganizationCalculationMethod(currentMethod);
message.success(t('calculationMethodUpdated'));
setHasChanges(false);
refetch();
} catch (error) {
console.error('Failed to update organization calculation method:', error);
message.error(t('calculationMethodUpdateError'));
} finally {
setUpdating(false);
}
};
return (
<Card>
<Space direction="vertical" size="large" style={{ width: '100%' }}>
<Space align="center">
<CalculatorOutlined />
<Title level={5} style={{ margin: 0 }}>
{t('organizationCalculationMethod')}
</Title>
<Tooltip title={t('calculationMethodTooltip')}>
<InfoCircleOutlined style={{ color: '#666' }} />
</Tooltip>
</Space>
<Space direction="vertical" size="small" style={{ width: '100%' }}>
<Space align="center" wrap>
<Text strong>{t('calculationMethod')}:</Text>
<Select
value={currentMethod}
onChange={handleMethodChange}
disabled={updating}
style={{ width: 150 }}
>
<Option value="hourly">
<Space>
<span>{t('hourlyRates')}</span>
</Space>
</Option>
<Option value="man_days">
<Space>
<span>{t('manDays')}</span>
</Space>
</Option>
</Select>
{hasChanges && (
<Button
type="primary"
icon={<SaveOutlined />}
onClick={handleSave}
loading={updating}
size="small"
>
{t('saveChanges')}
</Button>
)}
</Space>
{currentMethod === 'hourly' && (
<Text type="secondary" style={{ fontSize: '12px' }}>
{t('hourlyCalculationDescription')}
</Text>
)}
{currentMethod === 'man_days' && (
<Text type="secondary" style={{ fontSize: '12px' }}>
{t('manDaysCalculationDescription')} ({organization?.hours_per_day}h/day)
</Text>
)}
</Space>
</Space>
</Card>
);
};
export default OrganizationCalculationMethod;

View File

@@ -4,6 +4,7 @@ import {
ProfileOutlined,
TeamOutlined,
UserOutlined,
SettingOutlined,
} from '@/shared/antd-imports';
import React, { ReactNode, lazy } from 'react';
const Overview = lazy(() => import('./overview/overview'));
@@ -11,6 +12,7 @@ const Users = lazy(() => import('./users/users'));
const Teams = lazy(() => import('./teams/teams'));
const Billing = lazy(() => import('./billing/billing'));
const Projects = lazy(() => import('./projects/projects'));
const Settings = lazy(() => import('./settings/settings'));
// type of a menu item in admin center sidebar
type AdminCenterMenuItems = {
@@ -57,4 +59,11 @@ export const adminCenterItems: AdminCenterMenuItems[] = [
icon: React.createElement(CreditCardOutlined),
element: React.createElement(Billing),
},
{
key: 'settings',
name: 'settings',
endpoint: 'settings',
icon: React.createElement(SettingOutlined),
element: React.createElement(Settings),
},
];

View File

@@ -1,7 +1,10 @@
import { EditOutlined, MailOutlined, PhoneOutlined } from '@/shared/antd-imports';
import { PageHeader } from '@ant-design/pro-components';
import { Button, Card, Input, Space, Tooltip, Typography } from '@/shared/antd-imports';
import React, { useEffect, useState } from 'react';
import {
Card,
Space,
Typography,
} from '@/shared/antd-imports';
import { PageHeader } from '@ant-design/pro-components';
import OrganizationAdminsTable from '@/components/admin-center/overview/organization-admins-table/organization-admins-table';
import { useAppSelector } from '@/hooks/useAppSelector';
import { RootState } from '@/app/store';
@@ -11,9 +14,6 @@ import OrganizationOwner from '@/components/admin-center/overview/organization-o
import { adminCenterApiService } from '@/api/admin-center/admin-center.api.service';
import { IOrganization, IOrganizationAdmin } from '@/types/admin-center/admin-center.types';
import logger from '@/utils/errorLogger';
import { tr } from 'date-fns/locale';
const { Text } = Typography;
const Overview: React.FC = () => {
const [organization, setOrganization] = useState<IOrganization | null>(null);

View File

@@ -0,0 +1 @@
export { default } from './settings';

View File

@@ -0,0 +1,156 @@
import React, { useEffect, useState } from 'react';
import {
Button,
Card,
Input,
Space,
Typography,
Checkbox,
Col,
Form,
Row,
message,
} from '@/shared/antd-imports';
import { PageHeader } from '@ant-design/pro-components';
import { useTranslation } from 'react-i18next';
import { adminCenterApiService } from '@/api/admin-center/admin-center.api.service';
import { IOrganization } from '@/types/admin-center/admin-center.types';
import logger from '@/utils/errorLogger';
import { scheduleAPIService } from '@/api/schedule/schedule.api.service';
import { Settings } from '@/types/schedule/schedule-v2.types';
import OrganizationCalculationMethod from '@/components/admin-center/overview/organization-calculation-method/organization-calculation-method';
const SettingsPage: React.FC = () => {
const [organization, setOrganization] = useState<IOrganization | null>(null);
const [workingDays, setWorkingDays] = useState<Settings['workingDays']>([]);
const [workingHours, setWorkingHours] = useState<Settings['workingHours']>(8);
const [saving, setSaving] = useState(false);
const [form] = Form.useForm();
const { t } = useTranslation('admin-center/settings');
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 getOrgWorkingSettings = async () => {
try {
const res = await scheduleAPIService.fetchScheduleSettings();
if (res && res.done) {
setWorkingDays(
res.body.workingDays || ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
);
setWorkingHours(res.body.workingHours || 8);
form.setFieldsValue({
workingDays: res.body.workingDays || [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
],
workingHours: res.body.workingHours || 8,
});
}
} catch (error) {
logger.error('Error getting organization working settings', error);
}
};
const handleSave = async (values: any) => {
setSaving(true);
try {
const res = await scheduleAPIService.updateScheduleSettings({
workingDays: values.workingDays,
workingHours: values.workingHours,
});
if (res && res.done) {
message.success(t('saved'));
setWorkingDays(values.workingDays);
setWorkingHours(values.workingHours);
getOrgWorkingSettings();
}
} catch (error) {
logger.error('Error updating organization working days/hours', error);
message.error(t('errorSaving'));
} finally {
setSaving(false);
}
};
useEffect(() => {
getOrganizationDetails();
getOrgWorkingSettings();
}, []);
return (
<div style={{ width: '100%' }}>
<PageHeader title={<span>{t('settings')}</span>} style={{ padding: '16px 0' }} />
<Space direction="vertical" style={{ width: '100%' }} size={22}>
<Card>
<Typography.Title level={5} style={{ margin: 0 }}>
{t('organizationWorkingDaysAndHours') || 'Organization Working Days & Hours'}
</Typography.Title>
<Form
layout="vertical"
form={form}
initialValues={{ workingDays, workingHours }}
onFinish={handleSave}
style={{ marginTop: 16 }}
>
<Form.Item label={t('workingDays')} name="workingDays">
<Checkbox.Group>
<Row>
<Col span={8}>
<Checkbox value="Monday">{t('monday')}</Checkbox>
</Col>
<Col span={8}>
<Checkbox value="Tuesday">{t('tuesday')}</Checkbox>
</Col>
<Col span={8}>
<Checkbox value="Wednesday">{t('wednesday')}</Checkbox>
</Col>
<Col span={8}>
<Checkbox value="Thursday">{t('thursday')}</Checkbox>
</Col>
<Col span={8}>
<Checkbox value="Friday">{t('friday')}</Checkbox>
</Col>
<Col span={8}>
<Checkbox value="Saturday">{t('saturday')}</Checkbox>
</Col>
<Col span={8}>
<Checkbox value="Sunday">{t('sunday')}</Checkbox>
</Col>
</Row>
</Checkbox.Group>
</Form.Item>
<Form.Item label={t('workingHours')} name="workingHours">
<Input type="number" min={1} max={24} suffix={t('hours')} width={100} />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" loading={saving}>
{t('saveButton') || 'Save'}
</Button>
</Form.Item>
</Form>
</Card>
<OrganizationCalculationMethod
organization={organization}
refetch={getOrganizationDetails}
/>
</Space>
</div>
);
};
export default SettingsPage;

View File

@@ -1,4 +1,4 @@
import { ISUBSCRIPTION_TYPE } from '@/shared/constants';
import { ISUBSCRIPTION_TYPE } from "@/shared/constants";
export interface IOrganization {
name?: string;
@@ -6,6 +6,8 @@ export interface IOrganization {
email?: string;
contact_number?: string;
contact_number_secondary?: string;
calculation_method?: 'hourly' | 'man_days';
hours_per_day?: number;
}
export interface IOrganizationAdmin {
@@ -79,7 +81,6 @@ export interface IBillingAccountInfo {
unit_price?: number;
unit_price_per_month?: number;
usedPercentage?: number;
used_percent?: number;
usedStorage?: number;
is_custom?: boolean;
is_ltd_user?: boolean;
@@ -230,4 +231,4 @@ export interface IFreePlanSettings {
export interface IOrganizationProjectsGetResponse {
total?: number;
data?: IOrganizationProject[];
}
}