Skip to content

Commit

Permalink
fix: change periodTotal to converted period in TimesheetDetailCard an…
Browse files Browse the repository at this point in the history
…d TimesheetHeader
  • Loading branch information
vhu-axelor committed Feb 7, 2024
1 parent 6d0d62a commit 3e91b18
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/apps/hr/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export {
fetchTimerById as fetchTimerByIdApi,
} from './timer-api';
export {
convertPeriodTimesheet as convertPeriodTimesheetApi,
fetchDraftTimesheet as fetchDraftTimesheetApi,
fetchTimesheet as fetchTimesheetApi,
fetchTimesheetById as fetchTimesheetByIdApi,
Expand Down
7 changes: 7 additions & 0 deletions packages/apps/hr/src/api/timesheet-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import {
axiosApiProvider,
createStandardFetch,
createStandardSearch,
getSearchCriterias,
Expand Down Expand Up @@ -187,3 +188,9 @@ export async function fetchDraftTimesheet({
page: 0,
});
}

export async function convertPeriodTimesheet({timesheetId}) {
return axiosApiProvider.get({
url: `ws/aos/timesheet/convertPeriod/${timesheetId}`,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, {useMemo} from 'react';
import React, {useEffect, useMemo, useState} from 'react';
import {StyleSheet, View} from 'react-native';
import {useSelector} from '@axelor/aos-mobile-core';
import {CardIconButton, useThemeColor} from '@axelor/aos-mobile-ui';
import {TimesheetCard} from '../../atoms';
import {convertPeriodTimesheet} from '../../../api/timesheet-api';
import {Timesheet} from '../../../types';

interface TimesheetDetailCardProps {
Expand All @@ -40,6 +41,8 @@ const TimesheetDetailCard = ({
}: TimesheetDetailCardProps) => {
const Colors = useThemeColor();

const [convertedPeriod, setConvertedPeriod] = useState(0);

const {timesheet: timesheetConfig} = useSelector(
(state: any) => state.appConfig,
);
Expand Down Expand Up @@ -78,6 +81,12 @@ const TimesheetDetailCard = ({
return false;
}, [isActions, _statusSelect, userCanValidate]);

useEffect(() => {
convertPeriodTimesheet({timesheetId: item.id}).then(res =>
setConvertedPeriod(res.data.object.periodTotalConvert),
);
}, [item.id]);

const handleSend = () => {
console.log('handleSend');
};
Expand All @@ -93,7 +102,7 @@ const TimesheetDetailCard = ({
startDate={item.fromDate}
endDate={item.toDate}
company={item.company.name}
totalDuration={item.periodTotal}
totalDuration={convertedPeriod}
durationUnit={item.timeLoggingPreferenceSelect}
employeeName={isValidationMode ? item.employee?.name : null}
style={styles.cardContainer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, {useMemo} from 'react';
import React, {useEffect, useMemo, useState} from 'react';
import {StyleSheet, View} from 'react-native';
import {
useNavigation,
Expand All @@ -25,6 +25,7 @@ import {
} from '@axelor/aos-mobile-core';
import {Badge, CircleButton, Text, useThemeColor} from '@axelor/aos-mobile-ui';
import {DatesInterval} from '../../atoms';
import {convertPeriodTimesheet} from '../../../api/timesheet-api';
import {Timesheet} from '../../../types';
import {getDurationUnit} from '../../../utils';

Expand All @@ -38,6 +39,8 @@ const TimesheetHeader = ({timesheet, statusSelect}: TimesheetHeaderProps) => {
const I18n = useTranslator();
const navigation = useNavigation();

const [convertedPeriod, setConvertedPeriod] = useState(0);

const {mobileSettings} = useSelector((state: any) => state.appConfig);

const isAddButton = useMemo(
Expand All @@ -47,6 +50,12 @@ const TimesheetHeader = ({timesheet, statusSelect}: TimesheetHeaderProps) => {
[mobileSettings?.isLineCreationOfTimesheetDetailsAllowed, statusSelect],
);

useEffect(() => {
convertPeriodTimesheet({timesheetId: timesheet.id}).then(res =>
setConvertedPeriod(res.data.object.periodTotalConvert),
);
}, [timesheet.id]);

return (
<View style={styles.container}>
<View style={styles.rowContainer}>
Expand All @@ -66,7 +75,7 @@ const TimesheetHeader = ({timesheet, statusSelect}: TimesheetHeaderProps) => {
{I18n.t('User_Company')} : {timesheet.company.name}
</Text>
<Text>
{I18n.t('Hr_TotalDuration')} : {timesheet.periodTotal}
{I18n.t('Hr_TotalDuration')} : {convertedPeriod}
{getDurationUnit(timesheet.timeLoggingPreferenceSelect, I18n)}
</Text>
</View>
Expand Down

0 comments on commit 3e91b18

Please sign in to comment.