/* eslint-disable prettier/prettier */ import moment from 'moment'; import React, { useEffect, useRef, useState } from 'react'; import { Image, SafeAreaView, TextInput, TouchableOpacity, View, } from 'react-native'; import SelectDropdown from 'react-native-select-dropdown'; import AppText from '../../../../components/AppText'; import ButtonComponent from '../../../../components/ButtonComponent'; import { IconTimeSheet, IMAGES } from '../../../../values/images'; import ConfirmedShiftDetailContainer from './ConfirmedShiftDetail/ConfirmedShiftDetailContainer'; import { mainStyle } from './style'; const statusDropdownData = [ 'Tất cả trạng thái', 'Chờ duyệt', 'Duyệt', 'Từ chối', 'Nháp', 'Chưa nhập Timesheet', ]; const ConfirmedShiftScreen = ({ numberWeekOfYear, myApprovalRequestList, managerDate, currentPage, totalPage, setSearchValue, prevWeek, nextWeek, onPageNext, onPagePrevious, }) => { const typingTimeoutRef = useRef(null); const [isDesOpen, setOpenDes] = useState(false); //Table list const [myApprovalRequestFinalList, setMyApprovalRequestFinalList] = useState( [], ); const [userId, setUserId] = useState(); const handleSearchDebounce = text => { const value = text; if (typingTimeoutRef.current) { clearTimeout(typingTimeoutRef.current); } typingTimeoutRef.current = setTimeout(() => { setSearchValue(value); }, 300); }; const handleList = () => { if (myApprovalRequestList.length > 0) { const clone = [...myApprovalRequestList]; for (let i = 0; i < clone.length; i++) { clone[i].isExpand = false; if (clone[i].week == null) { clone[i].user.extend_total_hour = 0; clone[i].user.status = 'Chưa nhập Timesheet'; clone[i].user.extend_status_color = null; } else { clone[i].user.extend_total_hour = myApprovalRequestList[i].week.extend_total_hour; clone[i].user.status = myApprovalRequestList[i].week.extend_status_name; clone[i].user.extend_status_color = myApprovalRequestList[i].week.extend_status_color; } } setMyApprovalRequestFinalList(clone); } }; const onExpandRow = id => { const clone = [...myApprovalRequestFinalList]; let index = clone.findIndex(el => el?.user?.id === id); let element = clone.find(el => el?.user?.id === id); clone.splice(index, 1, { ...element, isExpand: true, }); setMyApprovalRequestFinalList(clone); }; const onCloseExpandRow = id => { const clone = [...myApprovalRequestFinalList]; let index = clone.findIndex(el => el?.user?.id === id); let element = clone.find(el => el?.user?.id === id); clone.splice(index, 1, { ...element, isExpand: false, }); setMyApprovalRequestFinalList(clone); }; const onStatusChange = item => { if (item === 'Tất cả trạng thái') { handleList(); } else { const clone = [...myApprovalRequestList]; const newClone = clone.filter(el => el?.user.status === item); //console.log(newClone); setMyApprovalRequestFinalList(newClone); } }; useEffect(() => { handleList(); }, [myApprovalRequestList]); return ( {isDesOpen ? ( ) : ( {/* Search */} handleSearchDebounce(text)} /> {/* Week */} {`Tuần ${numberWeekOfYear} `}{' '} {`${moment(managerDate?.currentDate).format( 'DD/MM/YYYY', )} - ${moment(managerDate?.theWeekend).format( 'DD/MM/YYYY', )}`} {/* Table header */} Danh sách nhân viên onStatusChange(selectedItem)} /> # Nhân viên Trạng thái timesheet {/* Row */} {myApprovalRequestFinalList.length > 0 ? ( myApprovalRequestFinalList.map((el, index) => ( {index + 1} {el?.user?.extend_user_full_name || '--'} {el?.user?.status} {el?.isExpand ? ( onCloseExpandRow(el?.user?.id)}> ) : ( onExpandRow(el?.user?.id)}> )} {el?.isExpand && ( Mã nhân viên {el?.user?.employee_code || '--'} Phòng ban {el?.user?.department || '--'} Chức vụ {el?.user?.position || '--'} Số giờ {el?.user?.extend_total_hour} { setUserId(el?.user?.id); setOpenDes(true); } // RootNavigation.navigate( // APP_NAVIGATE_SCREEN.CONFIRM_SHIFT_DETAIL, // { // sheetId: el?.user?.id, // numberOfWeek: numberWeekOfYear, // year: moment(managerDate?.currentDate).year(), // }, // ) } text="Xem chi tiết" /> )} )) ) : ( Không có dữ liệu )} {myApprovalRequestFinalList.length > 0 && ( onPagePrevious()} disabled={currentPage === 1}> {`Trang ${currentPage}/${totalPage}`} onPageNext()} disabled={currentPage === totalPage}> )} )} ); }; export default ConfirmedShiftScreen;