diff --git a/src/components/AutoLogoutProvider.js b/src/components/AutoLogoutProvider.js index 5eda87f..2dbdc25 100644 --- a/src/components/AutoLogoutProvider.js +++ b/src/components/AutoLogoutProvider.js @@ -26,27 +26,25 @@ const AutoLogoutProvider = ({ children }) => { const userData = getUserData(); const checked = localStorage.getItem("checkPasswordExpired"); if(userData !== null){ - if(!userData.lotusNotesUser){ - //system user - if(checked === "false"){ - axios.get(`${apiPath}${GET_USER_PASSWORD_DURATION}`,{ - params:{ - id: userData.id + //system user + if(checked === "false"){ + axios.get(`${apiPath}${GET_USER_PASSWORD_DURATION}`,{ + params:{ + id: userData.id + } + }) + .then((response) => { + if (response.status === 200) { + setForceChangePassword(response.data.expired); + if(!response.data.expired){ + localStorage.setItem("checkPasswordExpired",true); + } } }) - .then((response) => { - if (response.status === 200) { - setForceChangePassword(response.data.expired); - if(!response.data.expired){ - localStorage.setItem("checkPasswordExpired",true); - } - } - }) - .catch(error => { - console.log(error); - return false; - }); - } + .catch(error => { + console.log(error); + return false; + }); } } }, []); diff --git a/src/pages/lionerUserDetailPage/UserInformationCard.js b/src/pages/lionerUserDetailPage/UserInformationCard.js index 69cd904..19e6225 100644 --- a/src/pages/lionerUserDetailPage/UserInformationCard.js +++ b/src/pages/lionerUserDetailPage/UserInformationCard.js @@ -29,6 +29,7 @@ import {parseString} from "xml2js"; import {useParams} from "react-router-dom"; import {isObjEmpty} from "../../utils/Utils"; import {GENERAL_RED_COLOR} from "../../themes/colorConst"; +import {USER_GROUP_COMBO} from "../../utils/ComboConst"; // ==============================|| DASHBOARD - DEFAULT ||============================== // @@ -37,181 +38,78 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, requestError}) => { const params = useParams(); const [currentUserData, setCurrentUserData] = React.useState({}); - const [subDivision, setSubDivision] = useState(null); + const [userGroup, setUserGroup] = useState(null); const [locked, setLocked] = useState(false); - const [isLotusNoteUser, setIsLotusNoteUser] = useState(false); - const [lotusNoteUserList, setLotusNoteUserList] = useState([]) - const [selectedLotusUser, setSelectedLotusUser] = useState(null); - const [receiveReminder, setReceiveReminder] = useState(false); - const [subDivisionList, setSubDivisionList] = useState([]); + const [userGroupList, setUserGroupList] = useState([]); const [showPassword, setShowPassword] = React.useState(false); const [onReady, setOnReady] = useState(false); const {register, getValues, setValue} = useForm() const [errors, setErrors] = useState({}); - const [tempLotusDetail, setTempLotusDetail] = useState(null); const handleClickShowPassword = () => setShowPassword((show) => !show); const handleMouseDownPassword = () => setShowPassword(!showPassword); - const handleReceiveSwitchToggle = () => { - setReceiveReminder(!receiveReminder); - }; - const handleLockSwitchToggle = () => { setLocked(!locked); }; - const handleLocationCodeChange = (event, value) => { - if (value.length >2 && !value.includes("(")) { - fetchLotusUserList(value); - } else { - setLotusNoteUserList(lotusNoteUserList); - } - }; - // Function to fetch user name options based on locationCode - const fetchLotusUserListDetail = async (input) => { - try { - axios.get(`${apiPath}${GET_LDAP_USER_LIST}`,{ - params:{ - "EMSDlotus": input, - } - }) - .then((response) => { - if (response.status === 200) { - let xml = response.data; - parseString(xml, function (err, result) { - const tempRecordList = convertXmlToObject(result.RECORDS.RECORD); - const tempRecord = getObjectByValueName(tempRecordList,"EMSDlotus", input) - setTempLotusDetail(tempRecord); - }); - } - }) - .catch(error => { - console.log(error); - return false; - }); - } catch (error) { - console.error('Error fetching user name options:', error); - } - }; - - const fetchLotusUserList = async (input) => { - try { - axios.get(`${apiPath}${GET_LDAP_USER_COMBO}`,{ - params:{ - "username": input, - } - }) - .then((response) => { - if (response.status === 200) { - setLotusNoteUserList(response.data.records); - } - }) - .catch(error => { - console.log(error); - return false; - }); - } catch (error) { - console.error('Error fetching user name options:', error); - } - }; - - // const validateEmail = (email) => { - // // Regular expression for email validation - // const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - // return emailRegex.test(email); - // }; - useEffect(() => { - if(!isObjEmpty(selectedLotusUser)){ - //set basic info - if(isNewRecord){ - setValue('username', selectedLotusUser.label); - } - setValue('email', selectedLotusUser.mail); - fetchLotusUserListDetail(selectedLotusUser.label); - } - else{ - if(isNewRecord){ - setValue('username', null); - setValue('post', null); - setValue('fullname',null); - setValue('email', null); - setValue("phone1", null); - } - } - }, [selectedLotusUser]); - - useEffect(()=>{ - if(!isObjEmpty(tempLotusDetail)){ - setValue('post',tempLotusDetail.EMSDtitle); - setValue('fullname',tempLotusDetail.EMSDlastname + " " + tempLotusDetail.EMSDfirstname); - setValue("phone1", tempLotusDetail.EMSDofftel.substring(0,8)); - } - else if(isNewRecord){ - setValue('post',""); - setValue('fullname',""); - setValue("phone1",""); - } - },[tempLotusDetail]); - - useEffect(() => { - axios.get(`${apiPath}${GET_SUB_DIVISION_COMBO_LIST}`) - .then((response) => { - if (response.status === 200) { - setSubDivisionList(response.data.records); - } - }) - .catch(error => { - console.log(error); - return false; - }); + // axios.get(`${apiPath}${GET_USER_GROUP_COMBO_LIST}`) + // .then((response) => { + // if (response.status === 200) { + // setSubDivisionList(response.data.records); + // } + // }) + // .catch(error => { + // console.log(error); + // return false; + // }); }, []); useEffect(() => { setErrors(requestError); }, [requestError]); - useEffect(() => { - if(isNewRecord){ - setValue("password", null); - setValue("username", null); - } - }, [isLotusNoteUser]); - useEffect(() => { //if user data from parent are not null if (Object.keys(userData).length > 0 && userData !== undefined) { - setIsLotusNoteUser(userData.data.lotusNotesUser); setCurrentUserData(userData.data); } }, [userData]); useEffect(() => { //if state data are ready and assign to different field - if (Object.keys(currentUserData).length > 0 &¤tUserData !== undefined) { + if (Object.keys(currentUserData).length > 0 && currentUserData !== undefined) { setLocked(currentUserData.locked); - setReceiveReminder(currentUserData.reminderFlag); - setSubDivision(getObjectById(subDivisionList, currentUserData.subDivisionId)); + setUserGroup(USER_GROUP_COMBO.find(item => item.id == userData.groupId)); setOnReady(true); } else if(isNewRecord){ setLocked(false); setOnReady(true); } - }, [currentUserData,subDivisionList]); + }, [currentUserData]); useEffect(() => { //upload latest data to parent if(isCollectData){ - const values = getValues(); + let submitUserGroupId = userGroup?.key; + if (userGroup?.key == userData.groupId) { // User Group is not updated + submitUserGroupId = 0; + } + + const values = { + ...getValues(), + userGroupId:submitUserGroupId + }; + const formErrors = {}; if (isStringEmptyAfterTrim(values.username) ) { formErrors.username = 'User Name is required'; } - if (isStringEmptyAfterTrim(values.password) && !isLotusNoteUser && isNewRecord){ + if (isStringEmptyAfterTrim(values.password) && isNewRecord){ formErrors.password = "Password is required" } @@ -219,18 +117,17 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, formErrors.fullname = 'Full Name is required'; } - if(isStringEmptyAfterTrim(values.email)){ - formErrors.email = 'Email is required'; + if (userGroup == null) { + formErrors.userGroup = 'User Group is required'; } + + // if(isStringEmptyAfterTrim(values.email)){ + // formErrors.email = 'Email is required'; + // } // else if(!validateEmail(values.email)){ // formErrors.email = 'Invalid Email'; // } - - if(subDivision === null){ - formErrors.subDivision = 'Sub-Division is required'; - } - setErrors(formErrors); if (Object.keys(formErrors).length === 0) { @@ -253,11 +150,7 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, else if(!response.data.isTaken){ const objectData ={ ...values, - lotusNotesUser: isLotusNoteUser ? true : selectedLotusUser !== null, - selectedLotusUser: (isLotusNoteUser && selectedLotusUser !== null)? selectedLotusUser.account : null, - subDivisionId: subDivision !== null ? subDivision.id : null, locked: locked, - reminderFlag: receiveReminder, } updateUserObject(objectData); } @@ -282,63 +175,15 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, : Information
- - - - - Lotus Note User: - - - - - setIsLotusNoteUser(event.target.checked)} - name="isLotusNoteUser" - color="primary" - size="medium" - disabled={!isNewRecord} - /> - - - - { - if(lotusNoteUserList.length >0){ - if(newValue !== null){ - if(getComboValueByLabel(lotusNoteUserList, newValue.label) !== null){ - setSelectedLotusUser(newValue); - } - } - else{ - setSelectedLotusUser(null); - } - } - }} - isOptionEqualToValue={isOptionEqualToValue} - renderInput={(params) => } - /> - - - + {/* + */} @@ -362,9 +207,9 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, value: currentUserData.username, })} id='username' - InputProps={{ - readOnly: isLotusNoteUser, - }} + // InputProps={{ + // readOnly: {}, + // }} disabled={!isNewRecord} error={!!errors.username} helperText={errors.username} @@ -383,17 +228,11 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, - {isLotusNoteUser || !isNewRecord? - - Password: - - : - - Password: - * - - } + sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}> + + Password: + {isNewRecord && (*)} + @@ -405,7 +244,7 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, {...register("password")} id='password' type={showPassword ? 'text' : 'password'} - disabled={isLotusNoteUser} + // disabled={} error={!!errors.password} autoComplete="off" inputProps={{ @@ -480,30 +319,6 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, - - - - Post: - - - - - - - - - @@ -511,7 +326,7 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, - Sub-Division: + User Group: * @@ -519,19 +334,24 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, item.id = currentUserData.groupId), + // })} + id="userGroup" size="small" - value={subDivision === null ? null : subDivision} - options={subDivisionList} + value= {userGroup} + // value={userGroup ?? null} + options={USER_GROUP_COMBO}//{userGroupList} onChange={(event, newValue) => { - setSubDivision(newValue); + setUserGroup(newValue); }} renderInput={(params) => ( Email: - * + {/* * */} @@ -610,38 +430,25 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData, - - - - Receive Reminder: - * - - - - - - - - + {!isNewRecord && ( + + + + + Locked: + {/* * */} + + - - - - - Locked: - * - - + + + - - - - + )} diff --git a/src/pages/lionerUserDetailPage/index.js b/src/pages/lionerUserDetailPage/index.js index 5d02bce..ca9a5d5 100644 --- a/src/pages/lionerUserDetailPage/index.js +++ b/src/pages/lionerUserDetailPage/index.js @@ -37,7 +37,7 @@ const UserMaintainPage = () => { const [userData, setUserData] = React.useState({}); const [onReady, setOnReady] = useState(false); const [isCollectData, setIsCollectData] = useState(false); - const [editedCustomerData, setEditedCustomerData] = useState({}); + const [editedUserData, setEditedUserData] = useState({}); const [userGroupData,setUserGroupData] = useState([]); const [userAuthData,setUserAuthData] = useState([]); const [userConfirm, setUserConfirm] = useState(false); @@ -45,7 +45,7 @@ const UserMaintainPage = () => { const [requestError, setRequestError] = useState({}); function updateUserObject(userData) { - setEditedCustomerData(userData); + setEditedUserData(userData); } function updateUserGroupList(userGroupData){ @@ -96,7 +96,7 @@ const UserMaintainPage = () => { // ==============================|| DELETE WINDOW RELATED ||============================== // useEffect(() => { - if(params.id > 0 ){ + if(params.id > 0){ axios.get(`${apiPath}${GET_USER_PATH}/${params.id}`) .then((response) => { if (response.status === 200) { @@ -146,22 +146,18 @@ const UserMaintainPage = () => { axios.post(`${apiPath}${CREATE_USER_PATH}`, { "id": parseInt(params.id), - "fullname": editedCustomerData.fullname.trim(), - "name": editedCustomerData.username.trim(), - "locked": editedCustomerData.locked, - "lotusNotesUser": editedCustomerData.lotusNotesUser, - "selectedLotusUser": editedCustomerData.selectedLotusUser, - "username": editedCustomerData.username.trim(), - "password": editedCustomerData.lotusNotesUser? null : editedCustomerData.password, - "phone1": editedCustomerData.phone1 === null ? "" : editedCustomerData.phone1.trim(), - "post": editedCustomerData.post === null ? "" : editedCustomerData.post.trim(), - "email": editedCustomerData.email === null ? "": editedCustomerData.email.trim(), - "reminderFlag": editedCustomerData.reminderFlag, - "subDivisionId": editedCustomerData.subDivisionId, - "addGroupIds": userGroupData, - "removeGroupIds": deletedUserGroup, - "addAuthIds": userAuthData, - "removeAuthIds": deletedUserAuth, + "fullname": editedUserData.fullname.trim(), + "name": editedUserData.username.trim(), + "locked": editedUserData.locked, + "username": editedUserData.username.trim(), + "phone1": editedUserData.phone1 === null ? "" : editedUserData.phone1.trim(), + // "post": editedUserData.post === null ? "" : editedUserData.post.trim(), + "email": editedUserData.email === null ? "": editedUserData.email.trim(), + "userGroupId": editedUserData.userGroupId ?? null, + // "addGroupIds": userGroupData, + // "removeGroupIds": deletedUserGroup, + // "addAuthIds": userAuthData, + // "removeAuthIds": deletedUserAuth, }, ).then((response) => { if (response.status === 200) { @@ -190,7 +186,7 @@ const UserMaintainPage = () => { } setUserConfirm(false); setIsCollectData(false); - }, [editedCustomerData]); + }, [editedUserData]); return ( !onReady ? @@ -202,7 +198,7 @@ const UserMaintainPage = () => { {isNewRecord? "Create User" : "Maintain User"} {/*col 1*/} - + { /> {/*col 2*/} - + {/* { - + */} {/*bottom button*/} @@ -262,25 +258,25 @@ const UserMaintainPage = () => { Cancel - - - - - + {!isNewRecord && ( + + + + + )} diff --git a/src/pages/lionerUserSearchPage/UserSearchForm.js b/src/pages/lionerUserSearchPage/UserSearchForm.js index 592c927..80d881d 100644 --- a/src/pages/lionerUserSearchPage/UserSearchForm.js +++ b/src/pages/lionerUserSearchPage/UserSearchForm.js @@ -12,13 +12,12 @@ import {useEffect, useState} from "react"; import Autocomplete from '@mui/material/Autocomplete'; import Checkbox from "@mui/material/Checkbox"; import * as React from "react"; -import axios from "axios"; import {apiPath} from "../../auth/utils"; -import {GET_SUB_DIVISION_COMBO_LIST} from "../../utils/ApiPathConst"; +// import {GET_USER_GROUP_COMBO_LIST} from "../../utils/ApiPathConst"; import {useNavigate} from 'react-router-dom'; import {ThemeProvider} from "@emotion/react"; import {LIONER_BUTTON_THEME} from "../../themes/colorConst"; -import {USER_TYPE_COMBO} from "../../utils/ComboConst"; +import {USER_GROUP_COMBO} from "../../utils/ComboConst"; import {CARD_MAX_WIDTH} from "../../themes/themeConst"; // ==============================|| DASHBOARD - DEFAULT ||============================== // @@ -27,9 +26,9 @@ const UserSearchForm = ({applySearch}) => { const navigate = useNavigate() const [type, setType] = useState([]); - const [subDivision, setSubDivision] = useState(null); + const [userGroup, setUserGroup] = useState(null); const [selectedUserType, setSelectedUserType] = useState(null); - const [subDivisionList, setSubDivisionList] = useState([]); + const [userGroupList, setUserGroupList] = useState([]); const [locked, setLocked] = useState(false); @@ -46,31 +45,31 @@ const UserSearchForm = ({applySearch}) => { username: data.userName, fullname: data.fullName, post: data.post, - subDivisionId: subDivision !== null ? subDivision.id : null, + groupId: userGroup !== null ? userGroup.id : null, email: data.email, phone: data.phone, - isLotusNotesUser: selectedUserType === null ? null : selectedUserType.id === 1 ? null : selectedUserType.id === 2, locked: locked, }; applySearch(temp); }; useEffect(() => { - axios.get(`${apiPath}${GET_SUB_DIVISION_COMBO_LIST}`) - .then((response) => { - if (response.status === 200) { - setSubDivisionList(response.data.records); - } - }) - .catch(error => { - console.log(error); - return false; - }); + // axios.get(`${apiPath}${GET_USER_GROUP_COMBO_LIST}`) + // .then((response) => { + // if (response.status === 200) { + // setUserGroupList(response.data.records); + // } + // }) + // .catch(error => { + // console.log(error); + // return false; + // }); + }, []); function resetForm(){ setType([]); - setSubDivision(null); + setUserGroup(null); setSelectedUserType(null); setLocked(false); reset(); @@ -120,29 +119,16 @@ const UserSearchForm = ({applySearch}) => { - Post - - - - - - - Sub-Division + User Group { - setSubDivision(newValue); + setUserGroup(newValue); }} renderInput={(params) => } /> @@ -174,57 +160,18 @@ const UserSearchForm = ({applySearch}) => { /> - + {/* - User Type + Show Locked User Only - { - setSelectedUserType(newValue); - }} - renderInput={(params) => } + setLocked(event.target.checked)} + name="checked" + color="primary" + size="medium" /> - {/* setSelectedUserType(event.target.checked)}*/} - {/* name="checked"*/} - {/* color="primary"*/} - {/* size="medium"*/} - {/* />*/} - {/* }*/} - {/* label={Lotus Notes User}*/} - {/*/>*/} - - - - setLocked(event.target.checked)} - name="checked" - color="primary" - size="medium" - /> - } - label={Locked} - /> - - {/**/} - {/* */} - {/**/} + */} diff --git a/src/pages/lionerUserSearchPage/UserTable.js b/src/pages/lionerUserSearchPage/UserTable.js index 01a6c0d..4fc6af7 100644 --- a/src/pages/lionerUserSearchPage/UserTable.js +++ b/src/pages/lionerUserSearchPage/UserTable.js @@ -11,7 +11,9 @@ import { useTheme } from '@mui/material/styles'; import Checkbox from '@mui/material/Checkbox'; import {CustomNoRowsOverlay} from "../../utils/CommonFunction"; import {LIONER_BUTTON_THEME} from "../../themes/colorConst"; +import {USER_GROUP_COMBO} from "../../utils/ComboConst"; import {ThemeProvider} from "@emotion/react"; + // ==============================|| EVENT TABLE ||============================== // export default function UserTable({recordList}) { @@ -70,30 +72,23 @@ export default function UserTable({recordList}) { flex: 0.75, }, { - id: 'post', - field: 'post', - headerName: 'Post', + id: 'groupId', + field: 'groupId', + headerName: 'User Group', flex: 0.5, - }, - { - id: 'email', - field: 'email', - headerName: 'Email', - flex: 1.45, renderCell: (params) => { + const userGroup = USER_GROUP_COMBO.find(item => item.id === params.value)?? {label: "N/A"}; return (
- {params.value} + {userGroup.label}
); } }, { - id: 'subDivision', - field: 'subDivision', - //type: 'date', - //sortable: false, - headerName: 'Sub-Division', + id: 'email', + field: 'email', + headerName: 'Email', flex: 1.45, renderCell: (params) => { return ( @@ -103,25 +98,6 @@ export default function UserTable({recordList}) { ); } }, - { - id: 'lotusNotesUser', - field: 'lotusNotesUser', - type: 'bool', - headerName: 'Lotus Notes', - flex: 0.63, - renderCell: (params) => { - return ( - - ); - }, - }, { id: 'locked', field: 'locked', @@ -130,14 +106,20 @@ export default function UserTable({recordList}) { flex: 0.5, renderCell: (params) => { return ( - + // ); }, }, diff --git a/src/pages/lionerUserSearchPage/index.js b/src/pages/lionerUserSearchPage/index.js index 115d965..56a90ef 100644 --- a/src/pages/lionerUserSearchPage/index.js +++ b/src/pages/lionerUserSearchPage/index.js @@ -28,10 +28,6 @@ const UserSettingPage = () => { getUserList(); }, []); - useEffect(() => { - setOnReady(true); - }, [record]); - useEffect(() => { getUserList(); }, [searchCriteria]); @@ -42,7 +38,11 @@ const UserSettingPage = () => { ) .then((response) => { if (response.status === 200) { - setRecord(response.data); + const suId = response.data.find(item => item.groupId == 3)?.id; + const res = response.data.filter(item => item?.id !== suId); + + setRecord(res); + setOnReady(true); } }) .catch(error => { @@ -56,9 +56,6 @@ const UserSettingPage = () => { } return ( - !onReady ? - - : @@ -76,6 +73,9 @@ const UserSettingPage = () => { {/*row 2*/} + {!onReady ? + + : { recordList={record} /> - + }
diff --git a/src/utils/ComboConst.js b/src/utils/ComboConst.js index 055832f..0460950 100644 --- a/src/utils/ComboConst.js +++ b/src/utils/ComboConst.js @@ -50,10 +50,10 @@ export const MODULE_COMBO = [ {id:3, key: 3, label: 'Award'}, ]; -export const USER_TYPE_COMBO = [ - {id:1, key: 1, label: 'All Type'}, - {id:2, key: 2, label: 'Lotus Note User'}, - {id:3, key: 3, label: 'System User'}, +export const USER_GROUP_COMBO = [ + // {id:0, key: 0, label: 'System Admin'}, + {id:1, key: 1, label: 'Case Officer'}, + {id:2, key: 2, label: 'Administrator'}, ]; export const EVENT_REGION_COMBO = [