Skip to content

Commit

Permalink
Moved functions to helper
Browse files Browse the repository at this point in the history
  • Loading branch information
fahad-aot committed Dec 16, 2024
1 parent cfbc738 commit 6892ae6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
17 changes: 1 addition & 16 deletions forms-flow-web/src/components/Form/EditForm/FormSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {

import MultiSelectComponent from "../../CustomComponents/MultiSelect";
import { MULTITENANCY_ENABLED } from "../../../constants/constants";
import { addTenantkey } from "../../../helper/helper";
import { addTenantkey, addTenantkeyAsSuffix,removeTenantKeyFromPath } from "../../../helper/helper";
import { useDispatch, useSelector } from "react-redux";
import { getUserRoles } from "../../../apiManager/services/authorizationService";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -108,21 +108,6 @@ const FormSettings = forwardRef((props, ref) => {
}
},[MULTITENANCY_ENABLED]);

const addTenantkeyAsSuffix = (value, tenantkey) => {
if (value.toLowerCase().endsWith(`-${tenantkey}`)) {
return value.toLowerCase();
} else {
return `${value.toLowerCase()}${tenantkey}-`;
}
};

const removeTenantKeyFromPath = (value, tenantKey) => {
const tenantKeyCheck = value.match(`${tenantKey}-`)?.[0];
return tenantKeyCheck?.toLowerCase() === `${tenantKey.toLowerCase()}-`
? value.replace(`${tenantKey.toLowerCase()}-`, "")
: value;
};

/* ------------------------- validating form name and path ------------------------ */

const validateField = async (field, value) => {
Expand Down
18 changes: 17 additions & 1 deletion forms-flow-web/src/helper/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,21 @@ const isFormComponentsChanged = ({restoredFormData, restoredFormId, formData, fo
);
};

// Adding tenantKey as suffix
const addTenantkeyAsSuffix = (value, tenantkey) => {
if (value.toLowerCase().endsWith(`-${tenantkey}`)) {
return value.toLowerCase();
} else {
return `${value.toLowerCase()}${tenantkey}-`;
}
};
//removing Tenantkey from path if there is tenantkey ekse return the value
const removeTenantKeyFromPath = (value, tenantKey) => {
const tenantKeyCheck = value.match(`${tenantKey}-`)?.[0];
return tenantKeyCheck?.toLowerCase() === `${tenantKey.toLowerCase()}-`
? value.replace(`${tenantKey.toLowerCase()}-`, "")
: value;
};

export { generateUniqueId, replaceUrl, addTenantkey, removeTenantKey, textTruncate, renderPage,
filterSelectOptionByLabel, isFormComponentsChanged};
filterSelectOptionByLabel, isFormComponentsChanged, removeTenantKeyFromPath,addTenantkeyAsSuffix};

0 comments on commit 6892ae6

Please sign in to comment.