Skip to content

Commit

Permalink
Merge branch 'CE-230-add-reference-number-to-complaint' of https://gi…
Browse files Browse the repository at this point in the history
…thub.com/bcgov/nr-compliance-enforcement into CE-230-add-reference-number-to-complaint
  • Loading branch information
gregorylavery committed Oct 28, 2024
2 parents 4b43288 + 41092c7 commit bad672b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
6 changes: 3 additions & 3 deletions frontend/cypress/e2e/complaint-export.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ describe("Export Complaint Functionality", () => {
it(`Can export complaint: ${index === 0 ? "HWCR" : "ERS"}`, () => {
let fileName = "";

const date = fns.format(new Date(), "yyyy-MM-dd");
const date = fns.format(new Date(), "yyMMdd");

if ("#hwcr-tab".includes(complaintTypes[index])) {
fileName = `Complaint-23-000076-HWCR-${date}.pdf`;
fileName = `HWC_23-000076_${date}.pdf`;
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-000076", true);
} else {
fileName = `Complaint-23-006888-ERS-${date}.pdf`;
fileName = `EC_23-006888_${date}.pdf`;
cy.navigateToDetailsScreen(COMPLAINT_TYPES.ERS, "23-006888", true);
}

Expand Down
31 changes: 28 additions & 3 deletions frontend/src/app/store/reducers/documents-thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { RootState } from "../store";
import config from "../../../config";
import { format } from "date-fns";
import axios, { AxiosRequestConfig } from "axios";
import { AUTH_TOKEN } from "../../service/user-service";
import { AUTH_TOKEN, getUserAgency } from "../../service/user-service";
import { AgencyType } from "../../types/app/agency-types";

//--
//-- exports a complaint as a pdf document
Expand All @@ -12,7 +13,31 @@ export const exportComplaint =
(type: string, id: string): ThunkAction<Promise<string | undefined>, RootState, unknown, Action<string>> =>
async (dispatch) => {
try {
const fileName = `Complaint-${id}-${type}-${format(new Date(), "yyyy-MM-dd")}.pdf`;
const agency = getUserAgency();
let tailored_filename = "";
if (agency != null) {
switch (agency) {
case AgencyType.CEEB: {
tailored_filename = `${format(new Date(), "yyyy-MM-dd")} Complaint ${id}.pdf`;
break;
}
case AgencyType.COS:
default: {
let typeName = type;
if (type === "ERS") {
typeName = "EC";
} else if (type === "HWCR") {
typeName = "HWC";
}
tailored_filename = `${typeName}_${id}_${format(new Date(), "yyMMdd")}.pdf`;
break;
}
}
} else {
// Can't find any agency information - use previous standard
tailored_filename = `Complaint-${id}-${type}-${format(new Date(), "yyyy-MM-dd")}.pdf`;
}

const tz: string = encodeURIComponent(Intl.DateTimeFormat().resolvedOptions().timeZone);

const axiosConfig: AxiosRequestConfig = {
Expand All @@ -33,7 +58,7 @@ export const exportComplaint =
let link = document.createElement("a");
link.id = "hidden-details-screen-export-complaint";
link.href = fileURL;
link.download = fileName;
link.download = tailored_filename;

document.body.appendChild(link);
link.click();
Expand Down

0 comments on commit bad672b

Please sign in to comment.