fix confirm working day

parent 70c8ad5f
...@@ -8,6 +8,14 @@ const confirmDateAPI = { ...@@ -8,6 +8,14 @@ const confirmDateAPI = {
`myAbsentApprovalRequests?Filters=${filter}&Sorts=${sort}&Page=${page}&PageSize=${pageSize}`, `myAbsentApprovalRequests?Filters=${filter}&Sorts=${sort}&Page=${page}&PageSize=${pageSize}`,
), ),
requestGetAbsentChart: () => axiosClient.get('myAbsentRequests/statistic'), requestGetAbsentChart: () => axiosClient.get('myAbsentRequests/statistic'),
requestPostConfirmWorkingDay: payload =>
axiosClient.post('absentRequests', payload),
requestPostApproveConfirmWorkingDay: ({id}) =>
axiosClient.post(`absentRequests/${id}/approve?comment=&nextApproverId=`),
requestMyAbsentRequest: ({page, pageSize}) =>
axiosClient.get(
`myAbsentRequests?Filters=&Sorts=-start&Page=${page}&PageSize=${pageSize}`,
),
}; };
export default confirmDateAPI; export default confirmDateAPI;
...@@ -5,15 +5,7 @@ import colors from '../../values/colors'; ...@@ -5,15 +5,7 @@ import colors from '../../values/colors';
const FONT_FAMILY_BASE = fonts.beProLight; const FONT_FAMILY_BASE = fonts.beProLight;
const AppText = ({ const AppText = ({variant, children, style, onPress, color, isSubText}) => {
variant,
children,
style,
onPress,
color,
isSubText,
isBold,
}) => {
const defaultStyle = { const defaultStyle = {
fontFamily: FONT_FAMILY_BASE, fontFamily: FONT_FAMILY_BASE,
fontSize: isSubText ? 12 : 14, fontSize: isSubText ? 12 : 14,
......
...@@ -8,13 +8,27 @@ import ConfirmModalDetails from './confirm-modals/ConfirmModalDetails'; ...@@ -8,13 +8,27 @@ import ConfirmModalDetails from './confirm-modals/ConfirmModalDetails';
import { import {
getAbsentChart, getAbsentChart,
getConfirmApprovedDate, getConfirmApprovedDate,
getMyAbsentRequests,
getUserConfirmDay, getUserConfirmDay,
handleSelectManagersConfirmWorkingDayRequest,
postConfirmWorkingDay,
postSubmitApproveConfirmWorkingDayRequest,
} from './confirmDateSlice'; } from './confirmDateSlice';
import ConfirmDateMainView from './template/ConfirmMainView'; import ConfirmDateMainView from './template/ConfirmMainView';
import confirmDatePropsProvider from './confirmDatePropsProvider'; import confirmDatePropsProvider from './confirmDatePropsProvider';
import Utils from '../../utils'; import Utils from '../../utils';
import {launchImageLibrary} from 'react-native-image-picker';
import {handleSelectManagersLeaveRequest} from '../onleave/onLeaveSlice';
import {ToastMessage} from '../../utils/MessageUtil';
import moment from 'moment';
const ConfirmDateContainer = props => { const ConfirmDateContainer = props => {
const {confirmDateList, confirmApprovedDateList, userInfo} = props; const {
confirmDateList,
confirmApprovedDateList,
userInfo,
directManagersList,
myAbsentRequests,
} = props;
const dispatch = useDispatch(); const dispatch = useDispatch();
const [requestApproveArr, setRequestApproveArr] = useState([]); const [requestApproveArr, setRequestApproveArr] = useState([]);
...@@ -47,19 +61,59 @@ const ConfirmDateContainer = props => { ...@@ -47,19 +61,59 @@ const ConfirmDateContainer = props => {
const [modalRequestConfirmWorkingDays, setModalRequestConfirmWorkingDays] = const [modalRequestConfirmWorkingDays, setModalRequestConfirmWorkingDays] =
useState({ useState({
visible: false, visible: false,
userInfo: null,
isRequest: false,
}); });
const [dayPress, setDayPress] = useState(); const [dayPress, setDayPress] = useState();
// open the modal
const onOpenDetailModal = detailItem => {};
const onOpenModalRequestConfirmWorkingDays = () => { const [openTimePicker, setOpenTimePicker] = useState({
setModalRequestConfirmWorkingDays({userinfo: userInfo, visible: true}); startDate: false,
finishDate: false,
startTime: false,
finishTime: false,
});
const [confirmDateRequestImage, setConfirmDateRequestImage] = useState([]);
const [confirmDateRequestTicket, setConfirmDateRequestTicket] = useState({
startDate: new Date(),
finishDate: new Date(),
reason: '',
});
// open the modal
const onOpenModalRequestConfirmWorkingDays = userDetails => {
const user = {
id: userDetails?.staff_id,
avatar: userDetails?.extend_creator_avatar,
full_name: userDetails?.extend_creator_full_name,
employee_code: userDetails?.extend_creator_employee_code,
position: userDetails?.extend_creator_position,
isApprover: userDetails?.approver_id === userInfo?.id,
confirmStatus: userDetails?.extend_approved_status_name !== 'APPROVED',
confirm_working_id: userDetails?.id,
};
setModalRequestConfirmWorkingDays({
userInfo: userDetails ? user : userInfo,
visible: true,
isRequest: !userDetails ? true : false,
});
if (userDetails) {
setConfirmDateRequestTicket({
startDate: new Date(userDetails?.start),
finishDate: new Date(userDetails?.finish),
reason: userDetails?.reason,
});
}
}; };
const onCloseModalRequestConfirmWorkingDays = () => { const onCloseModalRequestConfirmWorkingDays = () => {
setModalRequestConfirmWorkingDays({userinfo: null, visible: false}); setModalRequestConfirmWorkingDays({
userInfo: null,
visible: false,
isRequest: false,
});
}; };
// main function // main function
const navigateToDayWage = () => { const navigateToDayWage = () => {
RootNavigation.navigate(APP_NAVIGATE_SCREEN.DAY_WAGE); RootNavigation.navigate(APP_NAVIGATE_SCREEN.DAY_WAGE);
...@@ -271,8 +325,126 @@ const ConfirmDateContainer = props => { ...@@ -271,8 +325,126 @@ const ConfirmDateContainer = props => {
} }
}); });
}, [dataChart.month, dispatch]); }, [dataChart.month, dispatch]);
const fetchMyAbsentRequests = () => {
dispatch(getMyAbsentRequests({page: 1, pageSize: 5}));
};
//============================= REQUEST CONFIRM WORKING DAYS =============================//
const openGallery = () => {
launchImageLibrary(
{
mediaType: 'photo',
includeBase64: true,
},
response => {
if (!response.didCancel) {
//console.log('AAA');
const {assets} = response;
setConfirmDateRequestImage(prev => [...prev, ...assets]);
//console.log(response.assets[0].uri)
}
},
);
};
const onDeleteConfirmDateRequestImage = index => {
const clone = [...confirmDateRequestImage];
clone.splice(index, 1);
setConfirmDateRequestImage([...clone]);
};
const onSelectManagerConfirmWorkingDayRequest = (index, value) => {
dispatch(handleSelectManagersLeaveRequest({index, value}));
};
const onSubmitConfirmWorkingDayRequest = () => {
if (handleSubmitConfirmWorkingDayRequest()) {
const approver = directManagersList.filter(item => item.isChecked);
const payload = {
start: confirmDateRequestTicket.startDate,
finish: confirmDateRequestTicket.finishDate,
approver_id: approver.length > 0 ? approver[0].id : null,
reason: confirmDateRequestTicket.reason,
timeStart: moment(confirmDateRequestTicket.startDate).format('HH:mm'),
timeFinish: moment(confirmDateRequestTicket.finishDate).format('HH:mm'),
};
dispatch(postConfirmWorkingDay(payload)).then(response => {
const {success} = Utils.getValues(response, 'payload', false);
success && fetchAbsentApprovalRequests();
ToastMessage({
title: 'Hệ thống',
message: `Đã gửi yêu cầu xác nhận ${
success ? 'thành công' : 'thất bại'
}`,
type: success ? 'success' : 'error',
});
onCloseModalRequestConfirmWorkingDays();
});
}
};
const handleSubmitConfirmWorkingDayRequest = () => {
if (directManagersList?.length === 0) {
return false;
}
const isSelectedManager = directManagersList.filter(item => item.isChecked);
if (confirmDateRequestTicket.reason.length === 0) {
ToastMessage({
title: 'Hệ thống',
message: 'Vui lòng nhập lý do',
type: 'error',
});
return false;
} else if (
moment(confirmDateRequestTicket.startDate) >
moment(confirmDateRequestTicket.finishDate)
) {
ToastMessage({
title: 'Hệ thống',
message: 'Vui lòng chọn ngày bắt đầu nhỏ hơn ngày kết thúc',
type: 'error',
timeVisible: 5000,
});
return false;
} else if (isSelectedManager.length === 0) {
ToastMessage({
title: 'Hệ thống',
message: 'Vui lòng chọn người duyệt!!!',
type: 'error',
timeVisible: 5000,
});
return false;
} else {
return true;
}
};
const onSubmitApproveConfirmWorkingDaysRequest = confirm_working_id => {
try {
dispatch(
postSubmitApproveConfirmWorkingDayRequest({id: confirm_working_id}),
).then(response => {
const {success} = Utils.getValues(response, 'payload', false);
if (success) {
fetchAbsentApprovalRequests();
onCloseModalRequestConfirmWorkingDays();
}
ToastMessage({
title: 'Hệ thống',
message: `Duyệt xác nhận ngày công ${
success ? 'thành công' : 'thất bại'
}`,
type: success ? 'success' : 'error',
});
});
} catch (err) {
ToastMessage({
title: 'Hệ thống',
message: 'Đã có lỗi xảy ra !!!',
type: 'error',
});
}
};
// useEffect // useEffect
useEffect(() => {
fetchMyAbsentRequests();
}, []);
useEffect(() => { useEffect(() => {
confirmDateList && formatDataConfirmListFromApi(); confirmDateList && formatDataConfirmListFromApi();
}, [confirmDateList]); }, [confirmDateList]);
...@@ -302,8 +474,15 @@ const ConfirmDateContainer = props => { ...@@ -302,8 +474,15 @@ const ConfirmDateContainer = props => {
approveReqPayload, approveReqPayload,
dayPress, dayPress,
modalRequestConfirmWorkingDays, modalRequestConfirmWorkingDays,
confirmDateRequestImage,
confirmDateRequestTicket,
openTimePicker,
directManagersList,
myAbsentRequests,
setOpenTimePicker,
setConfirmDateRequestTicket,
openGallery,
onChangeDayPressInChart, onChangeDayPressInChart,
onOpenDetailModal,
onLoadMoreConfirmList, onLoadMoreConfirmList,
navigateToDayWage, navigateToDayWage,
onLoadMoreRequestApprove, onLoadMoreRequestApprove,
...@@ -313,6 +492,10 @@ const ConfirmDateContainer = props => { ...@@ -313,6 +492,10 @@ const ConfirmDateContainer = props => {
onChangeMonthFilter, onChangeMonthFilter,
onCloseModalRequestConfirmWorkingDays, onCloseModalRequestConfirmWorkingDays,
onOpenModalRequestConfirmWorkingDays, onOpenModalRequestConfirmWorkingDays,
onDeleteConfirmDateRequestImage,
onSelectManagerConfirmWorkingDayRequest,
onSubmitConfirmWorkingDayRequest,
onSubmitApproveConfirmWorkingDaysRequest,
}; };
return <ConfirmDateMainView {...confirmDatePropsProvider(confirmProps)} />; return <ConfirmDateMainView {...confirmDatePropsProvider(confirmProps)} />;
}; };
......
...@@ -18,6 +18,18 @@ export default function confirmDatePropsProvider(props) { ...@@ -18,6 +18,18 @@ export default function confirmDatePropsProvider(props) {
onChangeMonthFilter, onChangeMonthFilter,
onCloseModalRequestConfirmWorkingDays, onCloseModalRequestConfirmWorkingDays,
onOpenModalRequestConfirmWorkingDays, onOpenModalRequestConfirmWorkingDays,
onDeleteConfirmDateRequestImage,
confirmDateRequestImage,
openGallery,
confirmDateRequestTicket,
setConfirmDateRequestTicket,
openTimePicker,
setOpenTimePicker,
directManagersList,
onSelectManagerConfirmWorkingDayRequest,
onSubmitConfirmWorkingDayRequest,
onSubmitApproveConfirmWorkingDaysRequest,
myAbsentRequests,
} = props; } = props;
return { return {
userInfo, userInfo,
...@@ -40,9 +52,26 @@ export default function confirmDatePropsProvider(props) { ...@@ -40,9 +52,26 @@ export default function confirmDatePropsProvider(props) {
approveReqPayload, approveReqPayload,
onChangeSelectFilter, onChangeSelectFilter,
requestApproveArr, requestApproveArr,
onOpenDetailModal, onOpenModalRequestConfirmWorkingDays,
},
modalRequestConfirmWorkingDaysProps: {
userInfo: modalRequestConfirmWorkingDays.userInfo,
onClose: onCloseModalRequestConfirmWorkingDays,
isRequest: modalRequestConfirmWorkingDays.isRequest,
confirmDateRequestImage,
onDeleteConfirmDateRequestImage,
openGallery,
setOpenTimePicker,
confirmDateRequestTicket,
openTimePicker,
directManagersList,
setConfirmDateRequestTicket,
onSelectManagerConfirmWorkingDayRequest,
onSubmitConfirmWorkingDayRequest,
onSubmitApproveConfirmWorkingDaysRequest,
}, },
onCloseModalRequestConfirmWorkingDays, onCloseModalRequestConfirmWorkingDays,
onOpenModalRequestConfirmWorkingDays, onOpenModalRequestConfirmWorkingDays,
myAbsentRequests,
}; };
} }
...@@ -2,10 +2,14 @@ import {createAsyncThunk, createSlice} from '@reduxjs/toolkit'; ...@@ -2,10 +2,14 @@ import {createAsyncThunk, createSlice} from '@reduxjs/toolkit';
import serviceRequest from '../../app/serviceRequest'; import serviceRequest from '../../app/serviceRequest';
import Utils from '../../utils';
import authAPI from '../../api/authAPI';
import confirmDateAPI from '../../api/confirmDateAPI'; import confirmDateAPI from '../../api/confirmDateAPI';
const initialState = {};
import Utils from '../../utils';
const initialState = {
confirmApprovedDateList: [],
myAbsentRequests: [],
};
export const getUserConfirmDay = createAsyncThunk( export const getUserConfirmDay = createAsyncThunk(
'confirmDate/getUserConfirmDay', 'confirmDate/getUserConfirmDay',
...@@ -33,6 +37,19 @@ export const getConfirmApprovedDate = createAsyncThunk( ...@@ -33,6 +37,19 @@ export const getConfirmApprovedDate = createAsyncThunk(
}); });
}, },
); );
export const getMyAbsentRequests = createAsyncThunk(
'confirmDate/getMyAbsentRequests',
async (data, thunkAPI) => {
return serviceRequest({
dispatch: thunkAPI.dispatch,
serviceMethod: confirmDateAPI.requestMyAbsentRequest,
payload: data,
options: {
skipLoader: false,
},
});
},
);
export const getAbsentChart = createAsyncThunk( export const getAbsentChart = createAsyncThunk(
'confirmDate/getAbsentChart', 'confirmDate/getAbsentChart',
async (data, thunkAPI) => { async (data, thunkAPI) => {
...@@ -46,7 +63,32 @@ export const getAbsentChart = createAsyncThunk( ...@@ -46,7 +63,32 @@ export const getAbsentChart = createAsyncThunk(
}); });
}, },
); );
export const postConfirmWorkingDay = createAsyncThunk(
'confirmDate/postConfirmWorkingDay',
async (data, thunkAPI) => {
return serviceRequest({
dispatch: thunkAPI.dispatch,
serviceMethod: confirmDateAPI.requestPostConfirmWorkingDay,
payload: data,
options: {
skipLoader: false,
},
});
},
);
export const postSubmitApproveConfirmWorkingDayRequest = createAsyncThunk(
'confirmDate/postSubmitApproveConfirmWorkingDayRequest',
async (data, thunkAPI) => {
return serviceRequest({
dispatch: thunkAPI.dispatch,
serviceMethod: confirmDateAPI.requestPostApproveConfirmWorkingDay,
payload: data,
options: {
skipLoader: false,
},
});
},
);
const authSlice = createSlice({ const authSlice = createSlice({
name: 'confirmDate', name: 'confirmDate',
initialState: initialState, initialState: initialState,
...@@ -54,7 +96,6 @@ const authSlice = createSlice({ ...@@ -54,7 +96,6 @@ const authSlice = createSlice({
extraReducers: builder => { extraReducers: builder => {
builder.addCase(getUserConfirmDay.fulfilled, (state, action) => { builder.addCase(getUserConfirmDay.fulfilled, (state, action) => {
const {success} = Utils.getValues(action, 'payload', false); const {success} = Utils.getValues(action, 'payload', false);
if (success) { if (success) {
state.confirmDateList = Utils.getValues( state.confirmDateList = Utils.getValues(
action, action,
...@@ -73,8 +114,19 @@ const authSlice = createSlice({ ...@@ -73,8 +114,19 @@ const authSlice = createSlice({
); );
} }
}); });
builder.addCase(getMyAbsentRequests.fulfilled, (state, action) => {
const {success} = Utils.getValues(action, 'payload', false);
if (success) {
state.myAbsentRequests = Utils.getValues(
action,
'payload.data.collection',
[],
);
}
});
}, },
}); });
const {reducer} = authSlice; const {reducer, actions} = authSlice;
export default reducer; export default reducer;
import React from 'react'; import React from 'react';
import {useSelector} from 'react-redux'; import {useSelector} from 'react-redux';
import {authSelector, confirmDateSelector} from '../../app/selectors'; import {
authSelector,
confirmDateSelector,
onLeaveSelector,
} from '../../app/selectors';
import ConfirmDateContainer from './ConfirmDateContainer'; import ConfirmDateContainer from './ConfirmDateContainer';
export default function ConfirmDateScreen() { export default function ConfirmDateScreen() {
const authSelect = useSelector(authSelector); const authSelect = useSelector(authSelector);
const confirmDateSelect = useSelector(confirmDateSelector); const confirmDateSelect = useSelector(confirmDateSelector);
const onLeaveSelect = useSelector(onLeaveSelector);
const {directManagersList = []} = onLeaveSelect;
const {userInfo} = authSelect; const {userInfo} = authSelect;
const {confirmDateList, confirmApprovedDateList} = confirmDateSelect; const {confirmDateList, confirmApprovedDateList, myAbsentRequests} =
confirmDateSelect;
const confirmScreenProps = { const confirmScreenProps = {
userInfo, userInfo,
confirmDateList, confirmDateList,
confirmApprovedDateList, confirmApprovedDateList,
directManagersList,
myAbsentRequests,
}; };
return <ConfirmDateContainer {...confirmScreenProps} />; return <ConfirmDateContainer {...confirmScreenProps} />;
} }
...@@ -120,10 +120,10 @@ const styles = StyleSheet.create({ ...@@ -120,10 +120,10 @@ const styles = StyleSheet.create({
marginTop: 22, marginTop: 22,
}, },
modalView: { modalView: {
backgroundColor: 'white', backgroundColor: colors.white,
borderRadius: 20, borderRadius: 20,
padding: 20, padding: 10,
shadowColor: '#000', shadowColor: colors.black1,
shadowOffset: { shadowOffset: {
width: 0, width: 0,
height: 2, height: 2,
...@@ -131,8 +131,9 @@ const styles = StyleSheet.create({ ...@@ -131,8 +131,9 @@ const styles = StyleSheet.create({
shadowOpacity: 0.25, shadowOpacity: 0.25,
shadowRadius: 4, shadowRadius: 4,
elevation: 5, elevation: 5,
marginTop: 20, marginTop: 80,
height: windowHeight, height: windowHeight,
width: '100%',
}, },
button: { button: {
borderRadius: 20, borderRadius: 20,
...@@ -151,7 +152,7 @@ const styles = StyleSheet.create({ ...@@ -151,7 +152,7 @@ const styles = StyleSheet.create({
textAlign: 'center', textAlign: 'center',
}, },
modalTitle: { modalTitle: {
fontWeight: '500', fontWeight: '800',
fontSize: 16, fontSize: 16,
}, },
dropdown1DropdownStyle: {backgroundColor: '#EFEFEF'}, dropdown1DropdownStyle: {backgroundColor: '#EFEFEF'},
...@@ -181,9 +182,8 @@ const styles = StyleSheet.create({ ...@@ -181,9 +182,8 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
}, },
inputText: { inputText: {
backgroundColor: '#FFF', backgroundColor: colors.white,
borderBottomWidth: 0.2, width: 200,
borderColor: '#444',
}, },
touchableOpacity: { touchableOpacity: {
borderColor: colors.primary_blue, borderColor: colors.primary_blue,
...@@ -201,7 +201,7 @@ const styles = StyleSheet.create({ ...@@ -201,7 +201,7 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
height: 40, height: 40,
borderRadius: 8, borderRadius: 8,
width: 100, paddingHorizontal: 10,
}, },
btnCancel: { btnCancel: {
backgroundColor: colors.white, backgroundColor: colors.white,
...@@ -411,4 +411,44 @@ export const statisticsConfirmWorkdaysStyles = StyleSheet.create({ ...@@ -411,4 +411,44 @@ export const statisticsConfirmWorkdaysStyles = StyleSheet.create({
borderRadius: 5, borderRadius: 5,
}, },
}); });
export const modalRequestConfirmWorkdaysStyles = StyleSheet.create({
avatarUser: {
width: 50,
height: 50,
borderRadius: 30,
},
btnCancel: {
backgroundColor: colors.white,
justifyContent: 'center',
alignItems: 'center',
height: 40,
borderRadius: 8,
width: 100,
},
rowView: {
flexDirection: 'row',
marginTop: 10,
justifyContent: 'space-between',
alignItems: 'center',
},
addConfirmDateRequestImageBtn: {
borderColor: colors.primary_blue,
borderStyle: 'dotted',
borderWidth: 2,
justifyContent: 'center',
alignItems: 'center',
height: 50,
padding: 10,
width: 50,
},
chooseTimeSection: {
alignItems: 'flex-end',
flexDirection: 'row',
justifyContent: 'space-between',
borderBottomWidth: 0.5,
height: 35,
width: 200,
borderColor: colors.grey444,
},
});
export default styles; export default styles;
This diff is collapsed.
...@@ -417,7 +417,7 @@ export const leavesModalStyles = StyleSheet.create({ ...@@ -417,7 +417,7 @@ export const leavesModalStyles = StyleSheet.create({
}, },
modalView: { modalView: {
backgroundColor: 'white', backgroundColor: colors.white,
borderRadius: 20, borderRadius: 20,
paddingHorizontal: 10, paddingHorizontal: 10,
shadowColor: colors.black1, shadowColor: colors.black1,
......
...@@ -24,5 +24,8 @@ const commonStyles = StyleSheet.create({ ...@@ -24,5 +24,8 @@ const commonStyles = StyleSheet.create({
marginVertical10: { marginVertical10: {
marginVertical: 10, marginVertical: 10,
}, },
marginVertical20: {
marginVertical: 20,
},
}); });
export default commonStyles; export default commonStyles;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment