Skip to content

Commit

Permalink
fix issues with multiselect changing value onBlur, fix issues with sa…
Browse files Browse the repository at this point in the history
…ving on CORE, and bug on new records
  • Loading branch information
taraepp committed Apr 4, 2024
1 parent 0ca8605 commit 77355b8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 42 deletions.
4 changes: 2 additions & 2 deletions services/common/src/components/forms/RenderMultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const RenderMultiSelect: FC<MultiSelectProps> = (props) => {
((meta.error && <span>{meta.error}</span>) ||
(meta.warning && <span>{meta.warning}</span>))
}
getValueProps={() => input.value !== "" && { value: input.value }}
>
<Select
loading={props.loading}
Expand All @@ -59,8 +60,7 @@ export const RenderMultiSelect: FC<MultiSelectProps> = (props) => {
mode="multiple"
size="small"
placeholder={placeholder}
{...input}
id={props.id}
id={props.id ?? props.input.name}
onSearch={onSearch}
options={data}
value={input.value ?? undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export const AuthorizationsInvolved = () => {
<div key={authorization.code}>
<Typography.Title level={5}>{authorization.description}</Typography.Title>
{authorization.children.map((child) => {
const checked = formValues.authorizationTypes.includes(child.code);
const checked = formValues.authorizationTypes?.includes(child.code);
return (
<div key={child.code}>
<Row gutter={[0, 16]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
InjectedFormProps,
change,
} from "redux-form";
import { Alert, Button, Row, Col, Typography, Popconfirm } from "antd";
import { Alert, Button, Row, Col, Typography, Popconfirm, Form } from "antd";
import { DeleteOutlined, PlusOutlined } from "@ant-design/icons";
import {
maxLength,
Expand Down Expand Up @@ -38,13 +38,12 @@ import ArchivedDocumentsSection from "@common/components/documents/ArchivedDocum
import { MajorMineApplicationDocument } from "@mds/common/models/documents/document";
import ProjectLinks from "@mds/common/components/projects/ProjectLinks";
import { useFeatureFlag } from "@mds/common/providers/featureFlags/useFeatureFlag";
import FormWrapper from "@mds/common/components/forms/FormWrapper";

interface ProjectSummaryFormProps {
project: IProject;
initialValues: Partial<IProject>;
onSubmit: any;
handleSaveData: (event, message: string) => Promise<void>;
handleSaveData: (message: string) => Promise<void>;
removeDocument: (event, documentGuid: string) => Promise<void>;
archivedDocuments: MajorMineApplicationDocument[];
onArchivedDocuments: (mineGuid, projectSummaryGuid) => Promise<void>;
Expand Down Expand Up @@ -429,13 +428,13 @@ const ProjectSummaryForm: FC<InjectedFormProps<IProjectSummary> & ProjectSummary
};

return (
<FormWrapper
name={FORM.ADD_EDIT_PROJECT_SUMMARY}
onSubmit={(e) => {
<Form
layout="vertical"
onFinish={(_values) => {
const message = props.isNewProject
? "Successfully submitted a project description to the Province of British Columbia."
: "Successfully updated the project.";
props.handleSaveData(e, message);
props.handleSaveData(message);
}}
>
<div className="right center-mobile">
Expand Down Expand Up @@ -532,7 +531,7 @@ const ProjectSummaryForm: FC<InjectedFormProps<IProjectSummary> & ProjectSummary
</>
)}
</div>
</FormWrapper>
</Form>
);
};

Expand Down
74 changes: 43 additions & 31 deletions services/core-web/src/components/mine/Projects/ProjectSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import ScrollSideMenu from "@mds/common/components/common/ScrollSideMenu";
import { useFeatureFlag } from "@mds/common/providers/featureFlags/useFeatureFlag";
import LoadingWrapper from "@/components/common/wrappers/LoadingWrapper";
import ProjectSummaryForm from "@/components/Forms/projectSummaries/ProjectSummaryForm";
import { isArray } from "lodash";

export const ProjectSummary: FC = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -127,41 +128,54 @@ export const ProjectSummary: FC = () => {
return payload;
};

const handleTransformPayload = (payload) => {
const values = removeUploadedDocument(payload, uploadedDocuments);
let payloadValues: any = {};
const updatedAuthorizations = [];
const transformAuthorizations = (valuesFromForm: any) => {
const { authorizations = {}, project_summary_guid } = valuesFromForm;

Object.keys(values).forEach((key) => {
// Pull out form properties from request object that match known authorization types
if (values[key] && projectSummaryAuthorizationTypesArray?.includes(key)) {
const project_summary_guid = values?.project_summary_guid;
const authorization = values?.authorizations?.find(
(auth) => auth?.project_summary_authorization_type === key
);
updatedAuthorizations.push({
...values[key],
// Conditionally add project_summary_guid and project_summary_authorization_guid properties if this a pre-existing authorization
// ... otherwise treat it as a new one which won't have those two properties yet.
...(project_summary_guid && { project_summary_guid }),
...(authorization && {
project_summary_authorization_guid: authorization?.project_summary_authorization_guid,
}),
project_summary_authorization_type: key,
project_summary_permit_type:
key === "OTHER" ? ["OTHER"] : values[key]?.project_summary_permit_type,
existing_permits_authorizations:
values[key]?.existing_permits_authorizations?.split(",") || [],
});
delete values[key];
const transformAuthorization = (type, authorization) => {
return { ...authorization, project_summary_authorization_type: type, project_summary_guid };
};

let updatedAuthorizations = [];
let newAmsAuthorizations = [];
let amendAmsAuthorizations = [];

projectSummaryAuthorizationTypesArray.forEach((type) => {
const authsOfType = authorizations[type];
if (authsOfType) {
if (isArray(authsOfType)) {
const formattedAuthorizations = authsOfType.map((a) => {
return transformAuthorization(type, a);
});
updatedAuthorizations = updatedAuthorizations.concat(formattedAuthorizations);
} else {
newAmsAuthorizations = newAmsAuthorizations.concat(
authsOfType?.NEW.map((a) =>
transformAuthorization(type, { ...a, project_summary_permit_type: ["NEW"] })
)
);
amendAmsAuthorizations = amendAmsAuthorizations.concat(
authsOfType?.AMENDMENT.map((a) =>
transformAuthorization(type, { ...a, project_summary_permit_type: ["AMENDMENT"] })
)
);
}
}
});
return {
authorizations: updatedAuthorizations,
ams_authorizations: { amendments: amendAmsAuthorizations, new: newAmsAuthorizations },
};
};

const handleTransformPayload = (payload) => {
const values = removeUploadedDocument(payload, uploadedDocuments);
let payloadValues: any = {};
const updatedAuthorizations = transformAuthorizations(values);
payloadValues = {
...values,
authorizations: updatedAuthorizations,
...updatedAuthorizations,
};
delete payloadValues.authorizationOptions;
delete payloadValues.authorizationTypes;
return payloadValues;
};

Expand Down Expand Up @@ -224,9 +238,7 @@ export const ProjectSummary: FC = () => {
.finally(() => setIsLoaded(true));
};

const handleSaveData = (e, message) => {
e.preventDefault();

const handleSaveData = (message) => {
dispatch(submit(FORM.ADD_EDIT_PROJECT_SUMMARY));
dispatch(touch(FORM.ADD_EDIT_PROJECT_SUMMARY));
const errors = Object.keys(flattenObject(formErrors));
Expand Down

0 comments on commit 77355b8

Please sign in to comment.