diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/libraries/src/hooks/dss/useMDMS.js b/frontend/micro-ui/web/micro-ui-internals/packages/libraries/src/hooks/dss/useMDMS.js index 2b420c260..bb0e6e2ac 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/libraries/src/hooks/dss/useMDMS.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/libraries/src/hooks/dss/useMDMS.js @@ -5,6 +5,7 @@ const useDssMDMS = (tenantId, moduleCode, type, config) => { const useDssDashboard = () => { return useQuery("DSS_DASHBOARD", () => MdmsService.getDssDashboard(tenantId, moduleCode), config); }; + const _default = () => { return useQuery([tenantId, moduleCode, type], () => MdmsService.getMultipleTypes(tenantId, moduleCode, type), config); }; diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/SearchUserForm.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/SearchUserForm.js index 5fddd2542..2ac58f8a5 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/SearchUserForm.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/SearchUserForm.js @@ -2,7 +2,10 @@ import { Loader, Header, Dropdown, LabelFieldPair, CardLabel, LinkLabel, SubmitB import React, { useState, useMemo, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { Controller, useForm, useWatch } from "react-hook-form"; -import MultiSelectDropdown from "./MultiSelectDropdown"; +import MultiSelectDropdown from "../components/pageComponents/Multiselect"; + +const XLSX = require("xlsx"); + function filterKeys(data, keys) { return data.map((item) => { const filteredItem = {}; @@ -79,7 +82,7 @@ function buildTree(data, hierarchy) { return tree; } -const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles }) => { +const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles, employeeData }) => { const { t } = useTranslation(); const [showToast, setShowToast] = useState(null); const [hierarchy, setHierarchy] = useState([ @@ -92,7 +95,9 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles { level: "code", value: 7, optionsKey: "name", isMandatory: false }, ]); const [tree, setTree] = useState(null); - const [rolesOptions, setRolesOptions] = useState(null) + const [rolesOptions, setRolesOptions] = useState(null); + const [isShowAllClicked, setIsShowAllClicked] = useState(false); + // const [zones,setZones] = useState([]) // const [circles,setCircles] = useState([]) // const [divisions,setDivisions] = useState([]) @@ -123,7 +128,7 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles name: "WSServiceRoles", }, ], - } + }, ], }, }, @@ -150,11 +155,13 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles const filteredResult = filterKeys(result, requiredKeys); const resultInTree = buildTree(filteredResult, hierarchy); const excludeCodes = ["HRMS_ADMIN", "LOC_ADMIN", "MDMS_ADMIN", "EMPLOYEE", "SYSTEM"]; - setRolesOptions(data?.MdmsRes?.["ws-services-masters"]?.["WSServiceRoles"]?.filter(row => !excludeCodes.includes(row?.code) - && - (row?.name === "Secretary" || row?.name === "Sarpanch" || row?.name === "Revenue Collector" || row?.name === "DIVISION ADMIN") - )) - + setRolesOptions( + data?.MdmsRes?.["ws-services-masters"]?.["WSServiceRoles"]?.filter( + (row) => + !excludeCodes.includes(row?.code) && + (row?.name === "Secretary" || row?.name === "Sarpanch" || row?.name === "Revenue Collector" || row?.name === "DIVISION ADMIN") + ) + ); //updating to state roles as requested // setRolesOptions([ // // { @@ -208,13 +215,13 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles unregister, } = useForm({ defaultValues: { - "zoneCode": "", - "circleCode": "", - "divisionCode": "", - "subDivisionCode": "", - "sectionCode": "", - "code": "", - "roles": [] + zoneCode: "", + circleCode: "", + divisionCode: "", + subDivisionCode: "", + sectionCode: "", + code: "", + roles: [], }, }); @@ -222,13 +229,13 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles const clearSearch = () => { reset({ - "zoneCode": "", - "circleCode": "", - "divisionCode": "", - "subDivisionCode": "", - "sectionCode": "", - "code": "", - "roles": [] + zoneCode: "", + circleCode: "", + divisionCode: "", + subDivisionCode: "", + sectionCode: "", + code: "", + roles: [], }); setUniqueRoles(null); setUniqueTenants(null); @@ -246,6 +253,44 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles // }) }; + useEffect(() => { + if (isShowAllClicked && employeeData) { + jsonToExcel(employeeData, "employees.xlsx"); + setIsShowAllClicked(false); + } + }, [employeeData]); + + function jsonToExcel(employeeData, fileName) { + const employees = employeeData.map((employee) => ({ + "User Id": employee.code, + Name: employee.user.name, + "Type of User": employee?.assignments[0]?.department, + Designation: t(employee?.assignments[0]?.designation), + Username: employee?.user?.mobileNumber, + Status: employee?.isActive ? "Active" : "Inactive", + Tenant: t(employee?.tenantId), + })); + + try { + const wb = XLSX.utils.book_new(); + const ws = XLSX.utils.json_to_sheet(employees); + + XLSX.utils.book_append_sheet(wb, ws, "Employees"); + + XLSX.writeFile(wb, fileName); + } catch (error) { + console.log("Error occurred", error); + } + } + + const showAllData = () => { + clearSearch(); + setIsShowAllClicked(true); + const listOfUniqueTenants = getUniqueLeafCodes(tree); + + setUniqueTenants(() => listOfUniqueTenants); + setUniqueRoles(() => rolesOptions?.filter((row) => row.code)?.map((role) => role.code)); + }; const onSubmit = (data) => { //assuming atleast one hierarchy is entered @@ -302,7 +347,7 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles //this is the list of tenants under the current subtree const listOfUniqueTenants = getUniqueLeafCodes(currentLevel); setUniqueTenants(() => listOfUniqueTenants); - setUniqueRoles(() => data?.roles?.filter(row => row.code)?.map(role => role.code)); + setUniqueRoles(() => data?.roles?.filter((row) => row.code)?.map((role) => role.code)); }; const optionsForHierarchy = (level, value) => { @@ -330,8 +375,9 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles const renderHierarchyFields = useMemo(() => { return hierarchy.map(({ level, optionsKey, isMandatory, ...rest }, idx) => ( - {`${t(Digit.Utils.locale.getTransformedLocale(`HR_SU_${level}`))} ${isMandatory ? "*" : "" - }`} + {`${t(Digit.Utils.locale.getTransformedLocale(`HR_SU_${level}`))} ${ + isMandatory ? "*" : "" + }`} ( { + rolesOptions?.forEach((option) => { + option.i18text = "ACCESSCONTROL_ROLES_ROLES_" + option?.code; + }); + }, [rolesOptions]); + if (isLoading || !setTree) { return ; } @@ -384,7 +436,7 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles
{ @@ -394,19 +446,19 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles return row?.[1] ? row[1] : null; }) .filter((e) => e) - ) + ); }} selected={props?.value || []} defaultLabel={t("HR_SU_SELECT_ROLES")} defaultUnit={t("COMMON_ROLES_SELECTED")} showSelectAll={true} t={t} - // config={config} - // disable={false} - // optionsDisable={config?.optionsDisable} + // config={config} + // disable={false} + // optionsDisable={config?.optionsDisable} />
- ) + ); }} rules={{}} defaultValue={[]} @@ -424,6 +476,14 @@ const SearchUserForm = ({ uniqueTenants, setUniqueTenants, roles, setUniqueRoles {t("HR_SU_CLEAR_SEARCH")} + { + showAllData(); + }} + > + {t("HR_SHOW_ALL_DATA")} + diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/Multiselect.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/Multiselect.js index 752bec612..730bc5d05 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/Multiselect.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/Multiselect.js @@ -88,12 +88,10 @@ const MultiSelectDropdown = ({ }, [selected?.length]); function fnToSelectOptionThroughProvidedSelection(selected) { - return selected?.map((e) => ( - { - [optionsKey]: e?.i18text? e.i18text : `ACCESSCONTROL_ROLES_ROLES_${e.code}`, - propsData: [null, e] - } - )); + return selected?.map((e) => ({ + [optionsKey]: e?.i18text ? e.i18text : `ACCESSCONTROL_ROLES_ROLES_${e.code}`, + propsData: [null, e], + })); } const [alreadyQueuedSelectedState, dispatch] = useReducer(reducer, selected, fnToSelectOptionThroughProvidedSelection); @@ -107,16 +105,15 @@ const MultiSelectDropdown = ({ } }, [active]); - useEffect(()=>{ - if (alreadyQueuedSelectedState?.length === filteredOptions?.length){ - if(alreadyQueuedSelectedState?.length != 0 && filteredOptions?.length != 0){ - setIsSelected(true) - } - }else{ - setIsSelected(false) - + useEffect(() => { + if (alreadyQueuedSelectedState?.length === filteredOptions?.length) { + if (alreadyQueuedSelectedState?.length != 0 && filteredOptions?.length != 0) { + setIsSelected(true); + } + } else { + setIsSelected(false); } - },[alreadyQueuedSelectedState]) + }, [alreadyQueuedSelectedState]); function handleOutsideClickAndSubmitSimultaneously() { setActive(false); diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/jurisdiction.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/jurisdiction.js index 15ad7adbb..af19a5905 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/jurisdiction.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/components/pageComponents/jurisdiction.js @@ -39,17 +39,17 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { !isEdit && sessionFormData?.Jurisdictions?.length > 0 ? makeDefaultValues(sessionFormData) : formData?.Jurisdictions || [ - { - id: undefined, - key: 1, - hierarchy: null, - boundaryType: null, - boundary: null, - division: {}, - divisionBoundary: [], - roles: [], - }, - ] + { + id: undefined, + key: 1, + hierarchy: null, + boundaryType: null, + boundary: null, + division: {}, + divisionBoundary: [], + roles: [], + }, + ] ); const [jurisdictionsData, setJuristictionsData] = useState([]); let hierarchylist = []; @@ -86,7 +86,6 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { return unique; }, []); - const uniqueDivisions = divisions?.reduce((unique, obj) => { const isDuplicate = unique.some((item) => item.id === obj.id && item.name === obj.name); if (!isDuplicate) { @@ -107,7 +106,6 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { ); if (uniqueSubDivisionsItems != null) { selectSubDivisionList(uniqueSubDivisionsItems); - } // selectSectionListList }, [data, userData]); @@ -197,7 +195,6 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { config.key, [...jurisdictionData, ...inactiveJurisdictions].filter((value) => Object.keys(value).length !== 0) ); - }, [jurisdictions, data?.MdmsRes]); const reviseIndexKeys = () => { @@ -235,7 +232,6 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { ]); setJuristictionsData((prev) => prev.map((unit, index) => ({ ...unit, key: index }))); } - } else { setjurisdictions((prev) => [ ...prev, @@ -250,31 +246,22 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { }, ]); setjurisdictions((prev) => prev.map((unit, index) => ({ ...unit, key: index }))); - } - - - }; function filterJurisdictions(unit, jurisdictions) { - const divisionBoundaryCodes = new Set(unit.divisionBoundary.map(item => item.code)); - return jurisdictions.filter(jurisdiction => { + const divisionBoundaryCodes = new Set(unit.divisionBoundary.map((item) => item.code)); + return jurisdictions.filter((jurisdiction) => { return !divisionBoundaryCodes.has(jurisdiction.boundary.code); }); } const handleRemoveUnit = (unit) => { if (STATE_ADMIN) { if (!isEdit) { - setjurisdictions(jurisdictions.filter( - (element) => element.key !== unit.key - )); + setjurisdictions(jurisdictions.filter((element) => element.key !== unit.key)); setjurisdictions((prev) => prev.map((unit, index) => ({ ...unit, key: index }))); - } - else { - setJuristictionsData(jurisdictionsData.filter( - (element) => element.key !== unit.key - )); + } else { + setJuristictionsData(jurisdictionsData.filter((element) => element.key !== unit.key)); let filterJurisdictionsItems = filterJurisdictions(unit, jurisdictions); setjurisdictions(filterJurisdictionsItems); setjurisdictions((prev) => prev.map((unit, index) => ({ ...unit, key: index }))); @@ -283,10 +270,7 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { clearErrors("Jurisdictions"); } reviseIndexKeys(); - } - - - else { + } else { if (unit.id) { let res = { id: unit?.id, @@ -315,15 +299,11 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { } reviseIndexKeys(); - } - }; let boundaryTypeoption = []; const [focusIndex, setFocusIndex] = useState(-1); - - function getroledata() { if (STATE_ADMIN) { // Specify the role codes you want to filter @@ -341,8 +321,9 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { const roleCodesToFilter = ["HRMS_ADMIN", "DIV_ADMIN", "MDMS_ADMIN", "LOC_ADMIN", "SYSTEM"]; // Use the filter method to extract roles with the specified codes return data?.MdmsRes?.["ws-services-masters"].WSServiceRoles?.filter((role) => { - return !roleCodesToFilter.includes(role.code) && - (role?.name === "Secretary" || role?.name === "Sarpanch" || role?.name === "Revenue Collector"); + return ( + !roleCodesToFilter.includes(role.code) && (role?.name === "Secretary" || role?.name === "Sarpanch" || role?.name === "Revenue Collector") + ); })?.map((role) => { return { code: role.code, name: role?.name ? role?.name : " ", i18text: "ACCESSCONTROL_ROLES_ROLES_" + role.code }; }); @@ -407,7 +388,7 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { // SUBDIVISION & SECTION subDivisionList={subDivisionList} sectionList={sectionList} - // SUBDIVISION & SECTION + // SUBDIVISION & SECTION /> )) )} @@ -457,9 +438,9 @@ function Jurisdiction({ if (ele.code === currentTenant) { defaultjurisdiction = ele; } - }) + }); return defaultjurisdiction; - } + }; useEffect(() => { setDivision( @@ -488,7 +469,6 @@ function Jurisdiction({ setjurisdictions((pre) => pre.map((item) => (item.key === jurisdiction.key ? { ...item, boundary: value } : item))); }; - const selectSubDivisionList = (value) => { setjurisdictions((pre) => pre.map((item) => (item.key === jurisdiction.key ? { ...item, subDivision: value } : item))); @@ -498,7 +478,7 @@ function Jurisdiction({ return { code: division.sectionCode, name: division.sectionName, - i18text: Digit.Utils.locale.getCityLocale(division.sectionCode) + i18text: Digit.Utils.locale.getCityLocale(division.sectionCode), }; }); const uniqueSections = sections?.reduce((unique, obj) => { @@ -771,9 +751,7 @@ function Jurisdiction({
0 && "50px", overflowY: "scroll" }}> {jurisdiction?.roles.length > 0 && jurisdiction?.roles.map((value, index) => { - return ( - onRemove(index, value)} /> - ) + return onRemove(index, value)} />; })}
diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/pages/SearchUser.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/pages/SearchUser.js index 2d8d7c554..f61b924a6 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/pages/SearchUser.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/hrms/src/pages/SearchUser.js @@ -1,11 +1,11 @@ -import React, { useState, useEffect } from 'react' -import SearchUserForm from '../components/SearchUserForm' -import SearchUserResults from '../components/SearchUserResults'; -import { Header } from '@egovernments/digit-ui-react-components' +import React, { useState, useEffect } from "react"; +import SearchUserForm from "../components/SearchUserForm"; +import SearchUserResults from "../components/SearchUserResults"; +import { Header } from "@egovernments/digit-ui-react-components"; import { useTranslation } from "react-i18next"; - const SearchUser = () => { + const { t } = useTranslation() const [uniqueTenants, setUniqueTenants] = useState(null) const [roles, setUniqueRoles] = useState(null) @@ -18,34 +18,37 @@ const SearchUser = () => { criteria: { tenantIds: uniqueTenants, roles: roles, - type: "EMPLOYEE" - } + type: "EMPLOYEE", + }, }, config: { enabled: !!uniqueTenants && !!roles, select: (data) => { - return data?.Employees + return data?.Employees; }, - }, - changeQueryName: { uniqueTenants, roles } + changeQueryName: { uniqueTenants, roles }, }; const { isLoading, data, revalidate, isFetching, error } = Digit.Hooks.useCustomAPIHook(requestCriteriaForEmployeeSearch); - - return (
{STATE_ADMIN ? t("HR_SDU") :t("HR_SU")}
- +
- ) -} + ); +}; -export default SearchUser \ No newline at end of file +export default SearchUser; diff --git a/package.json b/package.json new file mode 100644 index 000000000..b2e4f32f8 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "xlsx": "^0.18.5" + } +}