Skip to content

Commit

Permalink
[MDS-6140] Project Primary Contact on Project Final Application (#3248)
Browse files Browse the repository at this point in the history
* fix bug

* update test, make 2 of them for different use cases
  • Loading branch information
taraepp authored Sep 17, 2024
1 parent 7510526 commit 8b8c7ef
Show file tree
Hide file tree
Showing 9 changed files with 5,349 additions and 515 deletions.
49 changes: 48 additions & 1 deletion services/common/src/redux/selectors/projectSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createSelector } from "reselect";
import { uniq } from "lodash";
import * as projectReducer from "../reducers/projectReducer";
import { IParty, IProjectContact, IProjectSummaryDocument } from "../..";
import {
IParty,
IProjectContact,
IProjectSummaryDocument,
MAJOR_MINES_APPLICATION_DOCUMENT_TYPE_CODE,
} from "../..";
import { getTransformedProjectSummaryAuthorizationTypes } from "./staticContentSelectors";

export const {
Expand Down Expand Up @@ -41,6 +46,22 @@ const formatProjectSummaryDocuments = (documents = []): IProjectSummaryDocument[
return allDocuments;
};

const getContactName = (contact) => {
if (!contact) {
return;
}

const contactName = contact?.name ?? contact?.company_name;
if (contactName) {
return contactName;
}

return [contact?.first_name, contact?.last_name]
.filter(Boolean)
.join(" ")
.trim();
};

const formatProjectContact = (contacts): IProjectContact[] => {
if (!contacts) {
return contacts;
Expand Down Expand Up @@ -90,6 +111,32 @@ export const getAmsAuthorizationTypes = createSelector(
}
);

export const getFormattedProjectApplication = createSelector(
[getMajorMinesApplication, getProject],
(app, project) => {
const allDocuments = app?.documents ?? [];
const primary_documents = allDocuments.filter(
(d) =>
d.major_mine_application_document_type_code ===
MAJOR_MINES_APPLICATION_DOCUMENT_TYPE_CODE.PRIMARY
);
const spatial_documents = allDocuments.filter(
(d) =>
d.major_mine_application_document_type_code ===
MAJOR_MINES_APPLICATION_DOCUMENT_TYPE_CODE.SPATIAL
);
const supporting_documents = allDocuments.filter(
(d) =>
d.major_mine_application_document_type_code ===
MAJOR_MINES_APPLICATION_DOCUMENT_TYPE_CODE.SUPPORTING
);

const primaryContact = project?.contacts?.filter((contact) => contact.is_primary === true)[0];
const primary_contact = getContactName(primaryContact);
return { ...app, primary_documents, spatial_documents, supporting_documents, primary_contact };
}
);

export const getFormattedProjectSummary = createSelector(
[getProjectSummary, getProject, getAmsAuthorizationTypes],
(summary, project, amsAuthTypes) => {
Expand Down

This file was deleted.

Loading

0 comments on commit 8b8c7ef

Please sign in to comment.