Skip to content

Commit

Permalink
FWF[3820] bugifx : submit button added in default form creation (#2312)
Browse files Browse the repository at this point in the history
* FWF[3820] bugifx : submit button added in default form creation

* validate process moved before comparison of xml
  • Loading branch information
shuhaib-aot authored Oct 29, 2024
1 parent 646b7c0 commit b490881
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 47 deletions.
8 changes: 4 additions & 4 deletions forms-flow-web/src/components/Form/EditForm/FlowEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ const FlowEdit = forwardRef(({isPublished = false}, ref) => {
try{
const bpmnModeler = bpmnRef.current?.getBpmnModeler();
const xml = await createXMLFromModeler(bpmnModeler);

if (!validateProcess(xml,lintErrors,t)) {
return;
}
//if xml is same as existing process data, no need to update
const isEqual = await compareXML(processData?.processData, xml);
if (isEqual) {
toast.success(t("Process updated successfully"));
return;
}
if (!validateProcess(xml,lintErrors)) { //if the validate process is not true
return;
}

setSavingFlow(true);
const response = await updateProcess({ type:"BPMN", id: processData.id, data:xml });
dispatch(setProcessData(response.data));
Expand Down
59 changes: 16 additions & 43 deletions forms-flow-web/src/components/Form/List.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useReducer } from "react";
import React, { useEffect, useState } from "react";
import { connect, useSelector, useDispatch } from "react-redux";
import CreateFormModal from "../Modals/CreateFormModal.js";
import ImportFormModal from "../Modals/ImportFormModal.js";
Expand Down Expand Up @@ -31,44 +31,16 @@ import {
import FormTable from "./constants/FormTable";
import ClientTable from "./constants/ClientTable";
import _ from "lodash";
import { CustomButton } from "@formsflow/components";
import _set from "lodash/set";
import _cloneDeep from "lodash/cloneDeep";
import { CustomButton } from "@formsflow/components";
import _camelCase from "lodash/camelCase";
import { formCreate, formImport,validateFormName } from "../../apiManager/services/FormServices";
import { addHiddenApplicationComponent } from "../../constants/applicationComponent";
import { setFormSuccessData } from "../../actions/formActions";
import { CustomSearch } from "@formsflow/components";
import userRoles from "../../constants/permissions.js";
import FileService from "../../services/FileService";
import {FormBuilderModal} from "@formsflow/components";


const reducer = (form, { type, value }) => {
const formCopy = _cloneDeep(form);
switch (type) {
case "formChange":
for (let prop in value) {
if (Object.prototype.hasOwnProperty.call(value, prop)) {
form[prop] = value[prop];
}
}
return form;
case "replaceForm":
return _cloneDeep(value);
case "title":
if (type === "title" && !form._id) {
formCopy.name = _camelCase(value);
formCopy.path = _camelCase(value).toLowerCase();
}
break;
default:
break;
}
_set(formCopy, type, value);
return formCopy;
};


const List = React.memo((props) => {
const { createDesigns, createSubmissions, viewDesigns } = userRoles();
const { t } = useTranslation();
Expand All @@ -95,8 +67,9 @@ const List = React.memo((props) => {
const submissionAccess = useSelector((state) => state.user?.submissionAccess || []);

const [formSubmitted, setFormSubmitted] = useState(false);
const formData = { display: "form" }; const tenantKey = useSelector((state) => state.tenants?.tenantId);
const [form, dispatchFormAction] = useReducer(reducer, _cloneDeep(formData));

const tenantKey = useSelector((state) => state.tenants?.tenantId);
const [form, setForm] = useState({display:"form", title:"", description:""});
// const roleIds = useSelector((state) => state.user?.roleIds || {});
useEffect(() => {
setSearch(searchText);
Expand Down Expand Up @@ -270,36 +243,36 @@ const List = React.memo((props) => {
const { target } = event;
const value = target.type === "checkbox" ? target.checked : target.value;
value == "" ? setNameError("This field is required") : setNameError("");
dispatchFormAction({ type: path, value });
setForm(prev=>({...prev,[path]:value}));
};

const handleBuild = (formName,formDescription) => {
// TBD: no need to pass formName and formDescription instead of that pass every data in handleChange
setFormSubmitted(true);
const errors = validateForm();
if (Object.keys(errors).length > 0) {
setNameError(errors.title);
return;
}
form.components = [];
const newFormData = addHiddenApplicationComponent(form);

const newForm = {
...newFormData,
...form,
tags: ["common"],
};

newForm.submissionAccess = submissionAccess;
newForm.componentChanged = true;
newForm.newVersion = true;
newForm.access = formAccess;
newForm.path = _camelCase(form.title).toLowerCase();
newForm.name = _camelCase(form.title);
newForm.description = formDescription;
if (MULTITENANCY_ENABLED && tenantKey) {
newForm.tenantKey = tenantKey;
if (newForm.path) {
newForm.tenantKey = tenantKey;
newForm.path = addTenantkey(newForm.path, tenantKey);
}
if (newForm.name) {
newForm.name = addTenantkey(newForm.name, tenantKey);
}
}
}

formCreate(newForm).then((res) => {
const form = res.data;
dispatch(setFormSuccessData("form", form));
Expand Down

0 comments on commit b490881

Please sign in to comment.