Skip to content

Commit

Permalink
code smells, small refactor, adding toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
cnesmithsalus committed Oct 17, 2023
1 parent f9cecd8 commit 177cc65
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
} from "../../../../store/reducers/complaints";
import { from } from "linq-to-typescript";
import { Complaint } from "../../../../types/complaints/complaint";
import { ToggleError } from "../../../../common/toast";
import { ToastContainer } from "react-toastify";

export const CreateComplaint: FC = () => {
const dispatch = useAppDispatch();
Expand All @@ -65,9 +67,9 @@ export const CreateComplaint: FC = () => {
display_order: "",
active_ind: "",
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null
},
location_geometry_point: {
type: "",
Expand Down Expand Up @@ -106,9 +108,9 @@ export const CreateComplaint: FC = () => {
display_order: 0,
active_ind: false,
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null,
},
cos_geo_org_unit: {
zone_code: "",
Expand Down Expand Up @@ -306,9 +308,9 @@ export const CreateComplaint: FC = () => {
const { violation_code: source } = update;
const updatedEntity = {
...source,
short_description: value as string,
short_description: value,
long_description: label as string,
violation_code: value as string,
violation_code: value,
};

update.violation_code = updatedEntity;
Expand Down Expand Up @@ -536,9 +538,9 @@ export const CreateComplaint: FC = () => {
display_order: "",
active_ind: "",
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null,
};
hwcrComplaint.complaint_identifier.cos_geo_org_unit.area_code =
selectedOption.value;
Expand All @@ -558,9 +560,9 @@ export const CreateComplaint: FC = () => {
display_order: "",
active_ind: "",
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null,
};
allegationComplaint.complaint_identifier.cos_geo_org_unit.area_code =
selectedOption.value;
Expand Down Expand Up @@ -787,9 +789,9 @@ export const CreateComplaint: FC = () => {
display_order: 0,
active_ind: true,
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null,
};

const updatedParent = {
Expand Down Expand Up @@ -999,13 +1001,16 @@ export const CreateComplaint: FC = () => {
navigate("/complaint/" + complaintType + "/" + complaintId);
}
}
setErrorNotificationClass("comp-complaint-error display-none");
} else {
ToggleError("Errors in form");
setErrorNotificationClass("comp-complaint-error");
}
};

return (
<div className="comp-complaint-details">
<ToastContainer />
<CreateComplaintHeader
complaintType={COMPLAINT_TYPES.HWCR}
cancelButtonClick={cancelButtonClick}
Expand Down Expand Up @@ -1105,7 +1110,6 @@ export const CreateComplaint: FC = () => {
<div className="comp-details-edit-column comp-details-right-column">
<div className="comp-details-label-input-pair"></div>
{complaintType === COMPLAINT_TYPES.HWCR && (
<>
<div
className="comp-details-label-input-pair"
id="species-pair-id"
Expand All @@ -1123,7 +1127,6 @@ export const CreateComplaint: FC = () => {
errMsg={speciesErrorMsg}
/>
</div>
</>
)}
<div
className="comp-details-label-input-pair"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
const complaintStatusCodes = useSelector(
selectComplaintStatusCodeDropdown,
) as Option[];
console.log(JSON.stringify(complaintStatusCodes));
const speciesCodes = useSelector(selectSpeciesCodeDropdown) as Option[];
const hwcrNatureOfComplaintCodes = useSelector(
selectHwcrNatureOfComplaintCodeDropdown,
Expand Down Expand Up @@ -341,19 +340,21 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
const handleViolationTypeChange = (selected: Option | null) => {
if (selected) {
const { label, value } = selected;
if(value)
{
let update = { ...updateComplaint } as AllegationComplaint;

let update = { ...updateComplaint } as AllegationComplaint;

const { violation_code: source } = update;
const updatedEntity = {
...source,
short_description: value as string,
long_description: label as string,
violation_code: value as string,
};
const { violation_code: source } = update;
const updatedEntity = {
...source,
short_description: value,
long_description: label as string,
violation_code: value,
};

update.violation_code = updatedEntity;
setUpdateComplaint(update);
update.violation_code = updatedEntity;
setUpdateComplaint(update);
}
}
};

Expand Down Expand Up @@ -608,9 +609,9 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
display_order: "",
active_ind: "",
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null,
};
hwcrComplaint.complaint_identifier.cos_geo_org_unit.area_code =
selectedOption.value;
Expand All @@ -630,9 +631,9 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
display_order: "",
active_ind: "",
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null,
};
allegationComplaint.complaint_identifier.cos_geo_org_unit.area_code =
selectedOption.value;
Expand Down Expand Up @@ -859,9 +860,9 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
display_order: 0,
active_ind: true,
create_user_id: "",
create_utc_timestamp: "",
create_utc_timestamp: null,
update_user_id: "",
update_utc_timestamp: "",
update_utc_timestamp: null,
};

const updatedParent = {
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/app/store/reducers/complaints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ export const createAllegationComplaint =
newComplaintId =
newAllegationComplaint.complaint_identifier.complaint_identifier;
});
console.log();
ToggleSuccess("Complaint has been saved");
return newComplaintId;
} catch (error) {
console.log(error);
ToggleError("Unable to create complaint");
//-- add error handling
} finally {
dispatch(toggleLoading(false));
Expand Down Expand Up @@ -473,7 +473,6 @@ export const updateAllegationComplaint =
ToggleSuccess("Updates have been saved");
} catch (error) {
ToggleError("Unable to update complaint");
console.log(error);
} finally {
dispatch(toggleLoading(false));
}
Expand Down Expand Up @@ -520,10 +519,10 @@ export const createWildlifeComplaint =
newComplaintId =
newHwcrComplaint.complaint_identifier.complaint_identifier;
});
console.log();
ToggleSuccess("Complaint has been saved");
return newComplaintId;
} catch (error) {
console.log(error);
ToggleError("Unable to create complaint");
//-- add error handling
} finally {
dispatch(toggleLoading(false));
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/types/code-tables/agency-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface AgencyCode {
display_order: number;
active_ind: boolean;
create_user_id: string;
create_utc_timestamp: string;
create_utc_timestamp: Date | null;
update_user_id: string;
update_utc_timestamp: string;
update_utc_timestamp: Date | null;
}
4 changes: 2 additions & 2 deletions frontend/src/app/types/code-tables/attractant-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface AttractantCode {
display_order: string;
active_ind: string;
create_user_id: string;
create_utc_timestamp: string;
create_utc_timestamp: Date | null;
update_user_id: string;
update_utc_timestamp: string;
update_utc_timestamp: Date | null;
}
4 changes: 2 additions & 2 deletions frontend/src/app/types/code-tables/complaint-status-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ComplaintStatusCode {
display_order: number;
active_ind: boolean;
create_user_id: string;
create_utc_timestamp: string;
create_utc_timestamp: Date | null;
update_user_id: string;
update_utc_timestamp: string;
update_utc_timestamp: Date | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface GeoOrganizationUnitCode
display_order: string,
active_ind: string,
create_user_id: string,
create_utc_timestamp: string,
create_utc_timestamp: Date | null,
update_user_id: string,
update_utc_timestamp: string
update_utc_timestamp: Date | null
}
4 changes: 2 additions & 2 deletions frontend/src/app/types/code-tables/geo-orginaization-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface GeoOrganizationCode {
display_order: number;
active_ind: boolean;
create_user_id: string;
create_utc_timestamp: string;
create_utc_timestamp: Date | null;
update_user_id: string;
update_utc_timestamp: string;
update_utc_timestamp: Date | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface HwcrNatureOfComplaintCode
display_order: string,
active_ind: string,
create_user_id: string,
create_utc_timestamp: string,
create_utc_timestamp: Date | null,
update_user_id: string,
update_utc_timestamp: string
update_utc_timestamp: Date | null
}

0 comments on commit 177cc65

Please sign in to comment.