Skip to content

Commit

Permalink
Tenant update (#1340)
Browse files Browse the repository at this point in the history
* update component added

* update component added

* tenant update component

* update tenant search update

* revert index.html

---------

Co-authored-by: nabeelmd-eGov <[email protected]>
  • Loading branch information
mithunhegde-egov and nabeelmd-eGov committed Sep 5, 2024
1 parent 58ff2f5 commit 28cae30
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const tenantSearchConfig = () =>
tableFormJsonPath: "requestBody.inbox",
filterFormJsonPath: "requestBody.tenant",
searchFormJsonPath: "requestBody.tenant",

},
sections: {
search: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
},
],
},
},
],
},
];

Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down Expand Up @@ -56,6 +57,7 @@ const App = ({ path, stateCode, userType, tenants }) => {
<PrivateRoute path={`${path}/tenant-search`} component={() => <SandboxSearch />} />
<PrivateRoute path={`${path}/tenant-management/create`} component={() => <TenantCreate />} />
<PrivateRoute path={`${path}/tenant-management/search`} component={() => <TenantView />} />
<PrivateRoute path={`${path}/tenant-management/update`} component={() => <TenantUpdate />} />
<PrivateRoute path={`${path}/application-management/home`} component={() => <ApplicationHome />} />
<PrivateRoute path={`${path}/application-management/module-master`} component={() => <SandboxSearch />} />
<PrivateRoute path={`${path}/application-management/setup-master`} component={() => <SetupMaster />} />
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Header> {t("SANDBOX_UPDATE_TENANT_HEADER")}</Header>
<FormComposerV2
label={t("SANDBOX_UPDATE_TENANT_SUBMIT_BUTTON")}
config={tenantUpdateConfig.map((config) => {
return {
...config,
};
})}
defaultValues={defaultValue}
onFormValueChange={(setValue, formData, formState, reset, setError, clearErrors, trigger, getValues) => {}}
onSubmit={(data) => onSubmit(data)}
fieldStyle={fieldStyle}
noBreakLine={true}
/>

{showToast && <Toast error={showToast?.isError} label={showToast?.label} isDleteBtn={"true"} onClose={() => setShowToast(false)} />}
</div>
);
};

export default TenantUpdate;
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
},
};
};

0 comments on commit 28cae30

Please sign in to comment.