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

[TC-924] fix recommitment program on member profile and dashboard banner #454

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/src/database/entities/emcr/emcr-personnel.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export class EmcrPersonnelEntity {
status: this.status,
travelPreference: this.travelPreference,
newMember:
Status.ACTIVE && differenceInDays(new Date(), this.dateApproved) < 6,
this.status === Status.ACTIVE &&
differenceInDays(new Date(), this.dateApproved) < 6,
icsTraining:
this.trainings?.some((t) => t.name === ICS_TRAINING_NAME) || false,
experiences:
Expand Down
1 change: 1 addition & 0 deletions backend/src/personnel/personnel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export class PersonnelService {
queryBuilder.addOrderBy('personnel.lastName', 'ASC');
queryBuilder.addOrderBy('personnel.firstName', 'ASC');
} else if (status === Status.ACTIVE) {
//TODO - Fix this (not sure if the order by is being added here)
queryBuilder.addSelect(
`CASE WHEN emcr_personnel.dateApproved > current_date - interval '5' day THEN emcr_personnel.dateApproved ELSE null END`,
'new_member',
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ services:
DB_PASSWORD: ${DB_PASSWORD}
MODE: ${MODE}
END_RECOMMITMENT_SCHEDULE: ${END_RECOMMITMENT_SCHEDULE}
TEST_EMAIL: ${TEST_EMAIL}
CHOKIDAR_USEPOLLING: true
ALLOW_EMPTY_PASSWORD: "yes"
ENV: ${ENV}
TEST_EMAIL: ${TEST_EMAIL}
TEST_RUN: ${TEST_RUN}
networks:
- tc
keycloak:
Expand Down Expand Up @@ -128,8 +129,6 @@ services:
HEALTH_ENABLED: "true"
HTTP_ENABLED: "true"
METRICS_ENABLED: "true"
TEST_EMAIL: ${TEST_EMAIL}
TEST_RUN: ${TEST_RUN}
depends_on:
- db
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Banner } from '@/components/ui/Banner';
import type { RecommitmentCycle } from '@/common';
import { Transition } from '@headlessui/react';
import { useState } from 'react';
import { format } from 'date-fns';

// TODO - make me look nice
export const RecommitmentDashBanner = ({
Expand Down Expand Up @@ -34,13 +35,7 @@ export const RecommitmentDashBanner = ({
onClick={hideBanner}
content={
<p>
<span className="font-bold">
{recommitment.year} CORE recommitment reminders have been sent to
members and supervisors.{' '}
</span>
Returning members with supervisor approval will be marked as
Recommitted: {recommitment.year} in the coming weeks. Please monitor
their status for any needed follow-up and ParQ review.
{`The ${new Date(recommitment.endDate)?.getFullYear()} CORE recommitment period has begun and will end on ${format(new Date(recommitment?.endDate), 'MMMM do, yyyy') ?? ''}. Email reminders have been sent to active members and their supervisors. Returning members with supervisor approval will be marked as "Recommitted" in the coming weeks. Please monitor their status in case further communication is needed.`}
</p>
}
onClose={hideBanner}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const InitialRecommitmentDropdown = ({
handleChange,
}: {
initialValue?: string;
program: Program;
program?: Program;
handleChange: (v: string | undefined) => void;
}) => {
const getText = () => {
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/components/recommitment/RecommitmentFormBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

interface RecommitmentFormProps {
program: Program.BCWS | Program.EMCR | Program.ALL;
program?: Program;
personnel: MemberProfile;
onClose: () => void;
}
Expand Down Expand Up @@ -248,11 +248,6 @@
onUpdate={setUnableToJoinReasons}
key="unable"
/>,
<Assertions
program={Program.ALL}
onUpdate={setAssertionsChecked}
key="assertions"
/>,
];
default:
return [
Expand All @@ -274,7 +269,7 @@
}, [recommitmentAnswer]);

const handleSubmitRecommitment = async () => {
const selectedReasons = unableToJoinReasons.selectedReasons.map(

Check warning on line 272 in frontend/src/components/recommitment/RecommitmentFormBase.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'getSteps'. Either include it or remove the dependency array
(r) => reasonDefinitions[r as keyof typeof reasonDefinitions],
);
const reasons = [...selectedReasons, unableToJoinReasons.otherReason].join(', ');
Expand Down Expand Up @@ -345,7 +340,10 @@
}
}

if (currentComponentType === Assertions) {
if (
currentComponentType === Assertions ||
currentComponentType === UnableToJoin && recommitmentAnswer === 'no'
) {
setButtonLoading(true);
handleSubmitRecommitment();
}
Expand Down Expand Up @@ -460,7 +458,10 @@

const getButtonText = () => {
const currentComponentType = currentComponent.type;
if (currentComponentType === Assertions) {
if (
currentComponentType === Assertions ||
currentComponentType === UnableToJoin && recommitmentAnswer === 'no'
) {
return 'Submit Decision';
}
if (currentComponentType === ParQBase && currentParQStep === 3) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/recommitment/SupervisorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ interface SupervisorFormProps {
firstName: string;
lastName: string;
email: string;
phone: string;
phone?: string;
};
onUpdate: (data: {
firstName: string;
lastName: string;
email: string;
phone: string;
phone?: string;
}) => void;
}

Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/table/body/TableBodyCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const TableBodyCell = ({
recommitmentStatus?: RecommitmentStatus;
isRecommitmentCycleOpen?: boolean;
}) => {

switch (cell.columnName) {
case DashboardColumns.NAME:
return (
Expand All @@ -84,13 +85,11 @@ export const TableBodyCell = ({
>
{cell.value}
</Link>
{status && status === Status.NEW && (
{status && status === Status.NEW ? (
<span className="bg-warningBannerLight px-2 rounded-full ml-2">
{StatusNames.NEW}
</span>
)}
{/* Only show Active Persons recommitment status during recommitment period */}
{isRecommitmentCycleOpen &&
</span>) :
isRecommitmentCycleOpen &&
recommitmentStatus &&
status === Status.ACTIVE &&
renderRecommitmentStatus(recommitmentStatus, isRecommitmentCycleOpen)}
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/hooks/useMemberProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import type { MemberProfile, Personnel } from '@/common';
import type { MemberProfile, Personnel, Recommitment } from '@/common';
import type { FormikValues } from 'formik';
import { useAxios } from './useAxios';
import { Program } from '@/common';
Expand All @@ -11,25 +11,39 @@
updatePersonnel: (person: FormikValues | Personnel) => Promise<void>;
loading: boolean;
program?: Program;
recommitmentProgram?: Program;
} => {
const [personnel, setPersonnel] = useState<MemberProfile>();
const { AxiosPrivate } = useAxios();
const [refetch, setRefetch] = useState(false);
const [loading, setIsLoading] = useState(false);
const [program, setProgram] = useState<Program>();
const [recommitmentProgram, setRecommitmentProgram] = useState<Program>();
const [openRecommitmentForm, setOpenRecommitmentForm] = useState(false);

const getProfileDetails = async () => {
setIsLoading(true);
try {
const response = await AxiosPrivate.get(`/personnel`);
response && setPersonnel({ ...response.data });
// set program of personnel for personal data
if (response?.data?.bcws && response?.data?.emcr) {
setProgram(Program.ALL);
} else if (response?.data?.emcr && !response?.data?.bcws) {
setProgram(Program.EMCR);
} else if (response?.data?.bcws && !response?.data?.emcr) {
setProgram(Program.BCWS);
}
const bcwsRecommitment = response?.data?.recommitment?.find((itm: Recommitment) => itm.program === Program.BCWS);
const emcrRecommitment = response?.data?.recommitment?.find((itm: Recommitment) => itm.program === Program.EMCR);
// set program of recommitment for recommitment data
if (bcwsRecommitment && emcrRecommitment) {
setRecommitmentProgram(Program.ALL);
} else if (emcrRecommitment && !response?.data?.recommitment.bcws) {
setRecommitmentProgram(Program.EMCR);
} else if (bcwsRecommitment && !emcrRecommitment) {
setRecommitmentProgram(Program.BCWS);
}
} catch (e) {
console.log(e);
} finally {
Expand All @@ -43,7 +57,7 @@

const updatePersonnel = async (personnel: FormikValues | MemberProfile) => {
try {
await AxiosPrivate.patch(encodeURI(`/personnel`), personnel);

Check warning on line 60 in frontend/src/hooks/useMemberProfile.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'getProfileDetails'. Either include it or remove the dependency array

setRefetch(!refetch);
} catch (e) {
Expand All @@ -62,6 +76,7 @@
loading,
updatePersonnel,
program,
recommitmentProgram
};
};

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/profile/MemberProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const MemberProfile = () => {
const {
personnel,
program,
recommitmentProgram,
loading,
updatePersonnel,
openRecommitmentForm,
Expand Down Expand Up @@ -120,11 +121,11 @@ const MemberProfile = () => {
open={openRecommitmentForm}
onClose={updatePersonnel}
handleOpen={handleOpenRecommitmentForm}
title={`Confirm Recommitment Status for ${program === Program.ALL ? 'BCWS and EMCR' : program.toUpperCase()}`}
title={`Confirm Recommitment Status for ${recommitmentProgram === Program.ALL ? 'BCWS and EMCR' : recommitmentProgram?.toUpperCase()}`}
style={'lg:w-2/3 xl:w-1/2'}
>
<RecommitmentFormBase
program={program}
program={recommitmentProgram}
personnel={personnel}
onClose={handleOpenRecommitmentForm}
/>
Expand Down
Loading