Skip to content

Commit

Permalink
refactor: restore possibility to delete timesheet when there is no line
Browse files Browse the repository at this point in the history
  • Loading branch information
vhu-axelor committed Feb 9, 2024
1 parent ba00ed7 commit bdcfe07
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 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 @@ -59,6 +59,7 @@ export {
export {
addTimerTimesheet as addTimerTimesheetApi,
createTimesheet as createTimesheetApi,
deleteTimesheet as deleteTimesheetApi,
fetchDraftTimesheet as fetchDraftTimesheetApi,
fetchTimesheet as fetchTimesheetApi,
fetchTimesheetById as fetchTimesheetByIdApi,
Expand Down
6 changes: 6 additions & 0 deletions packages/apps/hr/src/api/timesheet-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,9 @@ export async function updateTimesheetStatus({
},
});
}

export async function deleteTimesheet({timesheetId}) {
return axiosApiProvider.delete({
url: `ws/rest/com.axelor.apps.hr.db.Timesheet/${timesheetId}`,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
} from '@axelor/aos-mobile-core';
import {Button, useThemeColor} from '@axelor/aos-mobile-ui';
import {TimesheetRefusalPopup} from '../../templates';
import {updateTimesheetStatus} from '../../../features/timesheetSlice';
import {
deleteTimesheet,
updateTimesheetStatus,
} from '../../../features/timesheetSlice';
import {Timesheet} from '../../../types';

interface TimesheetDetailsButtonsProps {
Expand All @@ -49,13 +52,20 @@ const TimesheetDetailsButtons = ({

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

const deleteAPI = useCallback(() => {
dispatch(
(deleteTimesheet as any)({timesheetId: timesheet.id, userId: user.id}),
);
navigation.pop();
}, [dispatch, navigation, timesheet.id, user.id]);

const updateStatusAPI = useCallback(
(status: string) => {
(toStatus: string) => {
dispatch(
(updateTimesheetStatus as any)({
timesheetId: timesheet.id,
version: timesheet.version,
toStatus: status,
toStatus: toStatus,
user: user,
}),
);
Expand All @@ -67,14 +77,13 @@ const TimesheetDetailsButtons = ({
return (
<View style={styles.container}>
<Button
title={I18n.t('Base_Cancel')}
title={I18n.t(isEmpty ? 'Hr_Delete' : 'Base_Cancel')}
onPress={() => {
updateStatusAPI('cancel');
navigation.pop();
isEmpty ? deleteAPI() : updateStatusAPI('cancel');
}}
width="45%"
color={Colors.errorColor}
iconName="x-lg"
iconName={isEmpty ? 'trash3-fill' : 'x-lg'}
/>
<Button
title={I18n.t('Hr_Send')}
Expand Down
1 change: 1 addition & 0 deletions packages/apps/hr/src/features/asyncFunctions-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export {
export {
addTimerTimesheet,
createTimesheet,
deleteTimesheet,
fetchDraftTimesheet,
fetchTimesheet,
fetchTimesheetById,
Expand Down
16 changes: 16 additions & 0 deletions packages/apps/hr/src/features/timesheetSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import {
addTimerTimesheet as _addTimerTimesheet,
createTimesheet as _createTimesheet,
deleteTimesheet as _deleteTimesheet,
fetchDraftTimesheet as _fetchDraftTimesheet,
fetchTimesheet as _fetchTimesheet,
fetchTimesheetById as _fetchTimesheetById,
Expand Down Expand Up @@ -133,6 +134,21 @@ export const updateTimesheetStatus = createAsyncThunk(
},
);

export const deleteTimesheet = createAsyncThunk(
'timesheet/deleteTimesheet',
async function (data = {}, {getState, dispatch}) {
return handlerApiCall({
fetchFunction: _deleteTimesheet,
data,
action: 'Hr_SliceAction_DeleteTimesheet',
getState,
responseOptions: {isArrayResponse: false, showToast: true},
}).then(() => {
dispatch(fetchTimesheet({userId: data.userId}));
});
},
);

const initialState = {
loadingMyTimesheet: true,
moreLoadingMyTimesheet: false,
Expand Down

0 comments on commit bdcfe07

Please sign in to comment.