Skip to content

Commit

Permalink
fix: replace delete button by cancel button and refactor code (#397)
Browse files Browse the repository at this point in the history
* RM#75132
  • Loading branch information
gca-axelor authored Feb 9, 2024
1 parent 8660c68 commit 50895b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,42 @@ const TimesheetDetailsButtons = ({

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

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

const updateStatusAPI = useCallback(
(toStatus: string) => {
dispatch(
(updateTimesheetStatus as any)({
timesheetId: timesheet.id,
version: timesheet.version,
toStatus: toStatus,
user: user,
}),
);
},
[dispatch, timesheet, user],
);

if (statusSelect === Timesheet.statusSelect.Draft) {
return (
<View style={styles.container}>
<Button
title={I18n.t('Hr_Delete')}
onPress={deleteTimesheetAPI}
title={I18n.t(isEmpty ? 'Hr_Delete' : 'Base_Cancel')}
onPress={() => {
isEmpty ? deleteAPI() : updateStatusAPI('cancel');
}}
width="45%"
color={Colors.errorColor}
iconName="trash3-fill"
iconName={isEmpty ? 'trash3-fill' : 'x-lg'}
/>
<Button
title={I18n.t('Hr_Send')}
onPress={() =>
dispatch(
(updateTimesheetStatus as any)({
timesheetId: timesheet.id,
version: timesheet.version,
toStatus: 'confirm',
user: user,
}),
)
}
onPress={() => updateStatusAPI('confirm')}
width="45%"
iconName="send-fill"
disabled={isEmpty}
Expand Down Expand Up @@ -110,16 +117,7 @@ const TimesheetDetailsButtons = ({
/>
<Button
title={I18n.t('Hr_Validate')}
onPress={() =>
dispatch(
(updateTimesheetStatus as any)({
timesheetId: timesheet.id,
version: timesheet.version,
toStatus: 'validate',
user: user,
}),
)
}
onPress={() => updateStatusAPI('validate')}
width="45%"
iconName="check-lg"
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/hr/src/features/timesheetLineSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const updateTimesheetLine = createAsyncThunk(
);

export const deleteTimesheetLine = createAsyncThunk(
'timesheet/deleteTimesheet',
'timesheet/deleteTimesheetLine',
async function (data = {}, {getState, dispatch}) {
return handlerApiCall({
fetchFunction: _deleteTimesheetLine,
Expand Down

0 comments on commit 50895b5

Please sign in to comment.