From 28cae30fd93b7da4c6a6483c7a852be9e9e4cbbb Mon Sep 17 00:00:00 2001 From: mithunhegde-egov <152362871+mithunhegde-egov@users.noreply.github.com> Date: Thu, 5 Sep 2024 23:22:54 +0530 Subject: [PATCH] Tenant update (#1340) * update component added * update component added * tenant update component * update tenant search update * revert index.html --------- Co-authored-by: nabeelmd-eGov --- .../sandbox/src/configs/tenantSearchConfig.js | 1 - .../sandbox/src/configs/tenantUpdateConfig.js | 60 ++++++++++++ .../sandbox/src/pages/employee/index.js | 2 + .../pages/employee/tenantMgmt/TenantUpdate.js | 97 +++++++++++++++++++ .../pages/employee/tenantMgmt/TenantView.js | 5 +- .../sandbox/src/utils/TenantUpdateUtil.js | 14 +++ 6 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantUpdateConfig.js create mode 100644 micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantUpdate.js create mode 100644 micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/utils/TenantUpdateUtil.js diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantSearchConfig.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantSearchConfig.js index 488aa785150..81bb521fef6 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantSearchConfig.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantSearchConfig.js @@ -18,7 +18,6 @@ export const tenantSearchConfig = () => tableFormJsonPath: "requestBody.inbox", filterFormJsonPath: "requestBody.tenant", searchFormJsonPath: "requestBody.tenant", - }, sections: { search: { diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantUpdateConfig.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantUpdateConfig.js new file mode 100644 index 00000000000..2838103587a --- /dev/null +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/tenantUpdateConfig.js @@ -0,0 +1,60 @@ +export const tenantUpdateConfig = [ + { + head: null, + body: [ + { + inline: true, + label: "SANDBOX_CREATE_TENANT_NAME_LABEL", + isMandatory: true, + key: "tenantName", + type: "text", + disable: true, + populators: { name: "tenantName", error: "Required", validation: { pattern: /^[A-Za-z0-9]+$/i } }, + }, + { + inline: true, + label: "SANDBOX_CREATE_TENANT_EMAIL_LABEL", + isMandatory: true, + key: "emailId", + type: "text", + disable: true, + populators: { name: "emailId", error: "Required", validation: { pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i } }, + }, + { + inline: true, + label: "SANDBOX_CREATE_TENANT_CODE_LABEL", + isMandatory: true, + key: "tenantCode", + type: "text", + disable: true, + populators: { name: "tenantCode", error: "Required", validation: { pattern: /^[A-Za-z0-9.]+$/i } }, + }, + { + isMandatory: false, + key: "isActive", + type: "dropdown", + label: "SANDBOX_CREATE_TENANT_ACTIVE_LABEL", + disable: false, + populators: { + name: "isActive", + optionsKey: "name", + error: " Required", + required: true, + options: [ + { + code: "true", + name: "TRUE", + active: true, + }, + { + code: "false", + name: "FALSE", + active: true, + }, + ], + }, + }, + ], + }, + ]; + \ No newline at end of file diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/index.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/index.js index 09e5377e712..f9daf343859 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/index.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/index.js @@ -9,6 +9,7 @@ import TenantView from "./tenantMgmt/TenantView"; import TenantCreate from "./tenantMgmt/TenantCreate"; import ApplicationHome from "./applicationMgmt/ApplicationHome"; import ModuleMasterTable from "./applicationMgmt/ModuleMasterTable"; +import TenantUpdate from "./tenantMgmt/TenantUpdate"; import SetupMaster from "./applicationMgmt/SetupMaster"; const bredCrumbStyle = { maxWidth: "min-content" }; @@ -56,6 +57,7 @@ const App = ({ path, stateCode, userType, tenants }) => { } /> } /> } /> + } /> } /> } /> } /> diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantUpdate.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantUpdate.js new file mode 100644 index 00000000000..30703accc14 --- /dev/null +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantUpdate.js @@ -0,0 +1,97 @@ +import React, { useState, useEffect } from "react"; +import { useTranslation } from "react-i18next"; +import { useHistory ,useLocation} from "react-router-dom"; +import { FormComposerV2, Header, Toast } from "@egovernments/digit-ui-react-components"; +import { transformCreateData } from "../../../utils/TenantUpdateUtil"; +import { tenantUpdateConfig } from "../../../configs/tenantUpdateConfig"; + +const fieldStyle = { marginRight: 0 }; + +const TenantUpdate = () => { + const location = useLocation(); + const { name,code,email} = location.state || {}; + const defaultValue = { + tenantName:name, + tenantCode:code, + emailId:email, + isActive:"" + }; + const tenantId = Digit.ULBService.getCurrentTenantId(); + const { t } = useTranslation(); + const history = useHistory(); + const [showToast, setShowToast] = useState(false); + + const closeToast = () => { + setTimeout(() => { + setShowToast(false); + }, 5000); + }; + const reqCreate = { + url: `/tenant-management/subTenant/_update`, + params: {}, + body: {}, + config: { + enable: false, + }, + }; + const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCreate); + const onSubmit = async (data) => { + if(tenantId==code){ + setShowToast({ + label: t("SANDBOX_TENANT_CANNOT_UPDATE_TOAST"), + isError: true, + }); + } + else{ + await mutation.mutate( + { + url: `/tenant-management/subTenant/_update`, + body: transformCreateData(data), + config: { + enable: true, + }, + }, + { + onError: (error, variables) => { + setShowToast({ + label: error.toString(), + isError: true, + }); + setTimeout(() => { + setShowToast(false); + }, 5000); + }, + onSuccess: async (data) => { + setShowToast({ key: "success", label: t("SANDBOX_TENANT_UPDATE_SUCCESS_TOAST") }); + setTimeout(() => { + closeToast(); + history.push(`/${window?.contextPath}/employee/sandbox/tenant-management/search`); + }, 3000); + }, + } + ); + } + }; + return ( +
+
{t("SANDBOX_UPDATE_TENANT_HEADER")}
+ { + return { + ...config, + }; + })} + defaultValues={defaultValue} + onFormValueChange={(setValue, formData, formState, reset, setError, clearErrors, trigger, getValues) => {}} + onSubmit={(data) => onSubmit(data)} + fieldStyle={fieldStyle} + noBreakLine={true} + /> + + {showToast && setShowToast(false)} />} +
+ ); +}; + +export default TenantUpdate; diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantView.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantView.js index ae0d4c3aed2..c33639bb885 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantView.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantView.js @@ -32,7 +32,10 @@ const TenantView = () => { }, []); const onClickRow = ({ original: row }) => { - const value = row?.code; + const code = row?.code; + const name= row?.name; + const email=row?.email; + history.push(`/${window?.contextPath}/employee/sandbox/tenant-management/update`, {name,code,email}); }; return ( diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/utils/TenantUpdateUtil.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/utils/TenantUpdateUtil.js new file mode 100644 index 00000000000..fdee7c17a72 --- /dev/null +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/utils/TenantUpdateUtil.js @@ -0,0 +1,14 @@ +export const transformCreateData = (data) => { + const tenantId = Digit.ULBService.getCurrentTenantId(); + + return { + tenant: { + name: data.tenantName, + email: data.emailId, + code: data.tenantCode, + isActive:data.isActive.code, + parentId: tenantId, + }, + }; + }; + \ No newline at end of file