Skip to content

Commit

Permalink
Merge pull request #2436 from fahad-aot/bugfix/FWF-4022-tenantkey-edi…
Browse files Browse the repository at this point in the history
…table-in-pathbugfix/FWF-4022-tenantkey-editable-in-path

bugfix/fwf-4022:Fixed tenantkey prefix editable in path
  • Loading branch information
arun-s-aot authored Dec 16, 2024
2 parents dbfc70d + 6892ae6 commit 3ea8c26
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
7 changes: 5 additions & 2 deletions forms-flow-web/src/components/Form/EditForm/FormEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import NewVersionModal from "../../Modals/NewVersionModal";
import { currentFormReducer } from "../../../modules/formReducer.js";
import { toast } from "react-toastify";
import userRoles from "../../../constants/permissions.js";
import { generateUniqueId, isFormComponentsChanged } from "../../../helper/helper.js";
import { generateUniqueId, isFormComponentsChanged, addTenantkey } from "../../../helper/helper.js";
import { useMutation } from "react-query";
import NavigateBlocker from "../../CustomComponents/NavigateBlocker";
import { setProcessData, setFormPreviosData, setFormProcessesData } from "../../../actions/processActions.js";
Expand Down Expand Up @@ -522,11 +522,14 @@ const EditComponent = () => {
: [],
},
};
const updatepath = MULTITENANCY_ENABLED
? addTenantkey(formDetails.path, tenantKey)
: formDetails.path;

const formData = {
title: formDetails.title,
display: formDetails.display,
path: formDetails.path,
path: updatepath,
submissionAccess: accessDetails.submissionAccess,
access: accessDetails.formAccess,
};
Expand Down
28 changes: 25 additions & 3 deletions forms-flow-web/src/components/Form/EditForm/FormSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
} from "@formsflow/components";

import MultiSelectComponent from "../../CustomComponents/MultiSelect";
import { MULTITENANCY_ENABLED } from "../../../constants/constants";
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 @@ -65,8 +67,10 @@ const FormSettings = forwardRef((props, ref) => {
const [submissionAccessCopy, setSubmissionAccessCopy] = useState(
_cloneDeep(submissionAccess)
);
const tenantKey = useSelector((state) => state.tenants?.tenantId);

const publicUrlPath = `${window.location.origin}/public/form/`;
const [urlPath,setUrlPath] = useState(publicUrlPath);
const setSelectedOption = (roles, option)=> roles.length ? "specifiedRoles" : option;
/* ------------------------- authorization variables ------------------------ */
const [rolesState, setRolesState] = useState({
Expand All @@ -89,6 +93,21 @@ const FormSettings = forwardRef((props, ref) => {

});

/* --------Updating path if multitenant enabled-------------------------- */
useEffect(()=>{
if(MULTITENANCY_ENABLED){
const updatedDisplayPath = removeTenantKeyFromPath(formDetails.path,tenantKey);
setFormDetails((prev) => {
return {
...prev,
path: updatedDisplayPath
};
});
const updatedUrlPath = addTenantkeyAsSuffix(publicUrlPath,tenantKey);
setUrlPath(updatedUrlPath);
}
},[MULTITENANCY_ENABLED]);

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

const validateField = async (field, value) => {
Expand Down Expand Up @@ -132,7 +151,10 @@ const FormSettings = forwardRef((props, ref) => {
};

const handleBlur = (field, value) => {
validateField(field, value);
const updatedValue = MULTITENANCY_ENABLED
? addTenantkey(value, tenantKey)
: value;
validateField(field, updatedValue);
};


Expand Down Expand Up @@ -184,7 +206,7 @@ const FormSettings = forwardRef((props, ref) => {

const copyPublicUrl = async () => {
try {
await copyText(`${publicUrlPath}${formDetails.path}`);
await copyText(`${urlPath}${formDetails.path}`);
setCopied(true);
setTimeout(() => {
setCopied(false);
Expand Down Expand Up @@ -387,7 +409,7 @@ const FormSettings = forwardRef((props, ref) => {
<Form.Label className="field-label">{t("URL Path")}</Form.Label>
<InputGroup className="url-input">
<InputGroup.Text className="url-non-edit">
{publicUrlPath}
{urlPath}
</InputGroup.Text>

<FormControl
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 3ea8c26

Please sign in to comment.