Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDS-5975] - ams regions #3113

Merged
merged 13 commits into from
May 28, 2024
41 changes: 41 additions & 0 deletions migrations/sql/V2024.05.22.13.00__create_regions_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CREATE TABLE IF NOT EXISTS regions (
regional_district_id INT NOT NULL PRIMARY KEY,
name varchar(255) NOT NULL,
create_user character varying(60) NOT NULL,
create_timestamp timestamp with time zone DEFAULT now() NOT NULL,
update_user character varying(60) NOT NULL,
update_timestamp timestamp with time zone DEFAULT now() NOT NULL
);

INSERT INTO regions (regional_district_id, name, create_user, update_user)
VALUES (4786586, 'Alberni-Clayoquot', 'system-mds', 'system-mds'),
(4786587, 'Bulkley-Nechako', 'system-mds', 'system-mds'),
(4786588, 'Capital', 'system-mds', 'system-mds'),
(4786590, 'Cariboo', 'system-mds', 'system-mds'),
(4786592, 'Central Coast', 'system-mds', 'system-mds'),
(4786597, 'Central Kootenay', 'system-mds', 'system-mds'),
(4786600, 'Central Okanagan', 'system-mds', 'system-mds'),
(4786601, 'Columbia Shuswap', 'system-mds', 'system-mds'),
(4786602, 'Comox Valley', 'system-mds', 'system-mds'),
(51541265, 'Comox-Strathcona (Island)', 'system-mds', 'system-mds'),
(51541257, 'Comox-Strathcona (Mainland)', 'system-mds', 'system-mds'),
(4786603, 'Cowichan Valley', 'system-mds', 'system-mds'),
(4786604, 'East Kootenay', 'system-mds', 'system-mds'),
(4786605, 'Fraser Valley', 'system-mds', 'system-mds'),
(4786636, 'Fraser-Fort George', 'system-mds', 'system-mds'),
(4786650, 'Kitimat-Stikine', 'system-mds', 'system-mds'),
(4786651, 'Kootenay Boundary', 'system-mds', 'system-mds'),
(4786671, 'Metro Vancouver', 'system-mds', 'system-mds'),
(4786672, 'Mount Waddington', 'system-mds', 'system-mds'),
(4786678, 'Nanaimo', 'system-mds', 'system-mds'),
(4786699, 'North Coast', 'system-mds', 'system-mds'),
(4786683, 'North Okanagan', 'system-mds', 'system-mds'),
(4786684, 'Northern Rockies', 'system-mds', 'system-mds'),
(4786686, 'Okanagan-Similkameen', 'system-mds', 'system-mds'),
(4786687, 'Peace River', 'system-mds', 'system-mds'),
(4786690, 'qathet', 'system-mds', 'system-mds'),
(4786712, 'Squamish-Lillooet', 'system-mds', 'system-mds'),
(7043686, 'Stikine', 'system-mds', 'system-mds'),
(4786713, 'Strathcona', 'system-mds', 'system-mds'),
(4786714, 'Sunshine Coast', 'system-mds', 'system-mds'),
(4786722, 'Thompson-Nicola', 'system-mds', 'system-mds');
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE project_summary
ADD regional_district_id integer;

ALTER TABLE project_summary
ADD CONSTRAINT fk_regional_district_id
FOREIGN KEY (regional_district_id)
REFERENCES regions(regional_district_id);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { render } from "@testing-library/react";
import FormWrapper from "@mds/common/components/forms/FormWrapper";
import { FORM } from "@mds/common";
import { FORM } from "@mds/common/constants";
import { PROJECTS } from "@mds/common/constants/reducerTypes";
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper";
import { PROJECT } from "@mds/common/tests/mocks/dataMocks";
Expand Down
16 changes: 16 additions & 0 deletions services/common/src/components/projectSummary/FacilityOperator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ import { getDropdownProvinceOptions } from "@mds/common/redux/selectors/staticCo
import RenderRadioButtons from "../forms/RenderRadioButtons";
import RenderAutoSizeField from "../forms/RenderAutoSizeField";
import { normalizePhone } from "@mds/common/redux/utils/helpers";
import { getRegionOptions } from "@mds/common/redux/slices/regionsSlice";

export const FacilityOperator: FC = () => {
const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY));

const { zoning } = formValues;

const regionOptions = useSelector(getRegionOptions);

const address_type_code = "CAN";

const provinceOptions = useSelector(getDropdownProvinceOptions).filter(
Expand Down Expand Up @@ -49,6 +53,18 @@ export const FacilityOperator: FC = () => {
rows={3}
component={RenderAutoSizeField}
/>
<Row className="margin-large--bottom">
<Col span={12}>
<Field
name="regional_district_id"
required
validate={[required]}
label="Facility's Regional Location"
component={RenderSelect}
data={regionOptions}
/>
</Col>
</Row>
<Typography.Title level={5}>Facility Address</Typography.Title>
<Row gutter={16}>
<Col md={19} sm={24}>
Expand Down
3 changes: 3 additions & 0 deletions services/common/src/constants/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,6 @@ export const DAM = (damGuid) => (damGuid ? `/dams/${damGuid}` : "/dams");

export const DOCUMENTS_COMPRESSION = (mineGuid) => `/mines/${mineGuid}/documents/zip`;
export const POLL_DOCUMENTS_COMPRESSION_PROGRESS = (taskId) => `/mines/documents/zip/${taskId}`;

// Regions
export const REGIONS_LIST = "/regions";
2 changes: 2 additions & 0 deletions services/common/src/redux/reducers/rootReducerShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from "../reducers";
import reportSubmissionReducer from "@mds/common/components/reports/reportSubmissionSlice";
import verifiableCredentialsReducer from "@mds/common/redux/slices/verifiableCredentialsSlice";
import regionsReducer from "@mds/common/redux/slices/regionsSlice";
import complianceCodeReducer, { complianceCodeReducerType } from "../slices/complianceCodesSlice";
export const sharedReducer = {
...activityReducer,
Expand Down Expand Up @@ -77,5 +78,6 @@ export const sharedReducer = {
loadingBar: loadingBarReducer,
reportSubmission: reportSubmissionReducer,
verifiableCredentials: verifiableCredentialsReducer,
regions: regionsReducer,
[complianceCodeReducerType]: complianceCodeReducer,
};
70 changes: 70 additions & 0 deletions services/common/src/redux/slices/regionsSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { createAppSlice } from "@mds/common/redux/createAppSlice";
import { hideLoading, showLoading } from "react-redux-loading-bar";
import CustomAxios from "@mds/common/redux/customAxios";
import { ENVIRONMENT, REGIONS_LIST } from "@mds/common/constants";
import { RootState } from "@mds/common/redux/rootState";

const createRequestHeader = REQUEST_HEADER.createRequestHeader;

const rejectHandler = (action) => {
console.log(action.error);
console.log(action.error.stack);
};

interface Region {
name: string;
regional_district_id: number;
}

interface RegionsState {
regions: Region[];
}

const initialState: RegionsState = {
regions: [],
};

const regionsSlice = createAppSlice({
name: "regionsSlice",
initialState,
reducers: (create) => ({
fetchRegions: create.asyncThunk(
async (_, thunkAPI) => {
const headers = createRequestHeader();
thunkAPI.dispatch(showLoading());

const response = await CustomAxios({
errorToastMessage: "default",
}).get(`${ENVIRONMENT.apiUrl}${REGIONS_LIST}`, headers);

thunkAPI.dispatch(hideLoading());

return response.data;
},
{
fulfilled: (state, action) => {
state.regions = action.payload;
},
rejected: (state: RegionsState, action) => {
rejectHandler(action);
},
}
),
}),
selectors: {
getRegionOptions: (state: RegionsState) => {
return state.regions.map((region) => ({
label: region.name,
value: region.regional_district_id,
}));
},
},
});

export const { fetchRegions } = regionsSlice.actions;
export const { getRegionOptions } = regionsSlice.getSelectors(
(rootState: RootState) => rootState.regions
);

const regionsReducer = regionsSlice.reducer;
export default regionsReducer;
185 changes: 85 additions & 100 deletions services/common/src/tests/mocks/dataMocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7168,7 +7168,31 @@ export const PROJECT = {
project_title: "Test Project Title",
mine_name: "Sample Mine",
mine_guid: "40fb0ca4-4dfb-4660-a184-6d031a21f3e9",
contacts: [],
contacts: [
{
project_contact_guid: "65a02cd8-3edd-491f-acdd-585f9f9742ee",
project_guid: "aa5bbbeb-f8ab-496f-aff2-e71d314bcc3e",
job_title: null,
company_name: null,
email: "test@test.com",
phone_number: "999-999-9999",
phone_extension: null,
is_primary: true,
first_name: "Test",
last_name: "Testerson",
address: [
{
suite_no: null,
address_line_1: "111 street",
address_line_2: null,
city: "Victoria",
sub_division_code: "BC",
post_code: "T5M0V3",
address_type_code: "CAN",
},
],
},
],
project_summary: {
documents: [],
},
Expand Down Expand Up @@ -7277,106 +7301,44 @@ export const PROJECT_SUMMARY = {
"OTHER",
"WATER_LICENCE",
],
authorizations: {
MINES_ACT_PERMIT: [
{
project_summary_authorization_guid: "83053925-c0ab-468e-b41c-32eb1607d1be",
project_summary_guid: "0bfc0d9e-542f-4424-91b5-c563dba02619",
project_summary_permit_type: ["NEW"],
project_summary_authorization_type: "MINES_ACT_PERMIT",
existing_permits_authorizations: [""],
amendment_changes: null,
amendment_severity: null,
is_contaminated: null,
new_type: null,
authorization_description: null,
exemption_requested: null,
},
],
WATER_LICENCE: [
{
project_summary_authorization_guid: "ec3dcc27-cce9-4539-a9cd-1b3faa41fc9f",
project_summary_guid: "0bfc0d9e-542f-4424-91b5-c563dba02619",
project_summary_permit_type: ["AMENDMENT"],
project_summary_authorization_type: "WATER_LICENCE",
existing_permits_authorizations: ["PX-1234", "CX-5678"],
amendment_changes: null,
amendment_severity: null,
is_contaminated: null,
new_type: null,
authorization_description: null,
exemption_requested: null,
},
],
OCCUPANT_CUT_LICENCE: [
{
project_summary_authorization_guid: "0d047eeb-7000-4649-89ae-6d295a12fc6a",
project_summary_guid: "0bfc0d9e-542f-4424-91b5-c563dba02619",
project_summary_permit_type: ["NEW", "NOTIFICATION"],
project_summary_authorization_type: "OCCUPANT_CUT_LICENCE",
existing_permits_authorizations: null,
amendment_changes: null,
amendment_severity: null,
is_contaminated: null,
new_type: null,
authorization_description: null,
exemption_requested: null,
},
],
OTHER: [
{
project_summary_authorization_guid: "5600e1e3-b303-4070-b3e2-9986264c8c38",
project_summary_guid: "0bfc0d9e-542f-4424-91b5-c563dba02619",
project_summary_permit_type: ["OTHER"],
project_summary_authorization_type: "OTHER",
existing_permits_authorizations: null,
amendment_changes: null,
amendment_severity: null,
is_contaminated: null,
new_type: null,
authorization_description: "other legislation details",
exemption_requested: null,
},
],
AIR_EMISSIONS_DISCHARGE_PERMIT: {
types: ["AMENDMENT"],
NEW: [],
AMENDMENT: [
{
project_summary_authorization_guid: "b8c63caa-e6e5-4e2e-80c9-327921f7efbf",
project_summary_guid: "0bfc0d9e-542f-4424-91b5-c563dba02619",
project_summary_permit_type: ["AMENDMENT"],
project_summary_authorization_type: "AIR_EMISSIONS_DISCHARGE_PERMIT",
existing_permits_authorizations: ["1234"],
amendment_changes: ["ILT"],
amendment_severity: "SIG",
is_contaminated: false,
new_type: null,
authorization_description: "adsf",
exemption_requested: true,
},
],
},
MUNICIPAL_WASTEWATER_REGULATION: {
types: ["NEW"],
NEW: [
{
project_summary_authorization_guid: "2ee7161f-7735-40c6-a8a4-ecb6cb79675e",
project_summary_guid: "0bfc0d9e-542f-4424-91b5-c563dba02619",
project_summary_permit_type: ["NEW"],
project_summary_authorization_type: "MUNICIPAL_WASTEWATER_REGULATION",
existing_permits_authorizations: null,
amendment_changes: null,
amendment_severity: null,
is_contaminated: null,
new_type: "APP",
authorization_description: "purpose of application",
exemption_requested: false,
},
],
AMENDMENT: [],
authorizations: [
{
project_summary_authorization_guid: "92e1a34b-c181-4be8-8ad0-f96dcd3ab7cc",
project_summary_guid: "8b4b9781-2e59-43ef-8164-4cc3b964417a",
project_summary_permit_type: ["NEW"],
project_summary_authorization_type: "AIR_EMISSIONS_DISCHARGE_PERMIT",
existing_permits_authorizations: null,
amendment_changes: null,
amendment_severity: null,
is_contaminated: null,
new_type: "PER",
authorization_description: "sdfa",
amendment_documents: [],
exemption_requested: false,
ams_tracking_number: null,
ams_outcome: null,
ams_status_code: null,
ams_submission_timestamp: "2024-05-24T19:10:09.825194+00:00",
},
{
project_summary_authorization_guid: "624d3acc-b62b-491e-82a3-67ef3b1bbf88",
project_summary_guid: "8b4b9781-2e59-43ef-8164-4cc3b964417a",
project_summary_permit_type: ["NEW"],
project_summary_authorization_type: "REFUSE_DISCHARGE_PERMIT",
existing_permits_authorizations: null,
amendment_changes: null,
amendment_severity: null,
is_contaminated: null,
new_type: "PER",
authorization_description: "asdf",
amendment_documents: [],
exemption_requested: false,
ams_tracking_number: null,
ams_outcome: null,
ams_status_code: null,
ams_submission_timestamp: "2024-05-24T19:17:09.212499+00:00",
},
},
],
};

export const AUTHORIZATION_INVOLVED = {
Expand Down Expand Up @@ -8176,3 +8138,26 @@ export const MINES_ACT_PERMITS_VC_LIST = [
cred_rev_id: "1234",
},
];

export const REGIONS = [
{
name: "Alberni-Clayoquot",
regional_district_id: 4786586,
},
{
name: "Bulkley-Nechako",
regional_district_id: 4786587,
},
{
name: "Capital",
regional_district_id: 4786588,
},
{
name: "Cariboo",
regional_district_id: 4786590,
},
{
name: "Central Coast",
regional_district_id: 4786592,
},
];
Loading
Loading