Skip to content

Commit

Permalink
fix buttons and status
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Szewczyk committed Dec 19, 2024
1 parent 0346708 commit d75f30f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Grid, Typography } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { paymentPlanStatusToColor } from '@utils/utils';
import {
paymentPlanStatusToColor,
targetPopulationStatusDisplayMap,
} from '@utils/utils';
import { ContainerColumnWithBorder } from '@core/ContainerColumnWithBorder';
import { LabelizedField } from '@core/LabelizedField';
import { OverviewContainer } from '@core/OverviewContainer';
Expand Down Expand Up @@ -46,6 +49,7 @@ export function TargetPopulationDetails({
dataCy="target-population-status"
status={targetPopulation.status}
statusToColor={paymentPlanStatusToColor}
statusNameMapping={targetPopulationStatusDisplayMap}
/>
</LabelizedField>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Grid, MenuItem } from '@mui/material';
import { Group, Person } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { PaymentPlanStatus } from '@generated/graphql';
import {
createHandleApplyFilterChange,
paymentPlanStatusMapping,
} from '@utils/utils';
PaymentPlanStatus,
usePaymentPlanStatusChoicesQueryQuery,
} from '@generated/graphql';
import { createHandleApplyFilterChange } from '@utils/utils';
import { DatePickerFilter } from '@core/DatePickerFilter';
import { NumberTextField } from '@core/NumberTextField';
import { SearchTextField } from '@core/SearchTextField';
Expand All @@ -32,7 +32,6 @@ export const TargetPopulationTableFilters = ({
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const isAccountability = location.pathname.includes('accountability');
const { selectedProgram } = useProgramContext();
const beneficiaryGroup = selectedProgram?.beneficiaryGroup;

Expand All @@ -54,9 +53,18 @@ export const TargetPopulationTableFilters = ({
clearFilter();
};

const preparedStatusChoices = isAccountability
? Object.values(PaymentPlanStatus).filter((key) => key !== 'OPEN')
: Object.values(PaymentPlanStatus);
const allowedStatusChoices = [
PaymentPlanStatus.TpOpen,
PaymentPlanStatus.TpLocked,
PaymentPlanStatus.Finished,
];

const { data: statusChoicesData } = usePaymentPlanStatusChoicesQueryQuery();

const preparedStatusChoices =
statusChoicesData?.paymentPlanStatusChoices?.filter((el) =>
allowedStatusChoices.includes(el.value as PaymentPlanStatus),
) || [];

return (
<FiltersSection
Expand All @@ -82,9 +90,9 @@ export const TargetPopulationTableFilters = ({
fullWidth
data-cy="filters-status"
>
{preparedStatusChoices.sort().map((key) => (
<MenuItem key={key} value={key}>
{paymentPlanStatusMapping(key)}
{preparedStatusChoices.map((item) => (
<MenuItem key={item.value} value={item.value}>
{item.name}
</MenuItem>
))}
</SelectFilter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const StatusWrapper = styled.div`
flex-direction: row;
`;

export interface ProgramDetailsPageHeaderPropTypes {
export interface TargetPopulationPageHeaderProps {
paymentPlan;
canEdit: boolean;
canRemove: boolean;
Expand All @@ -48,7 +48,7 @@ export function TargetPopulationPageHeader({
canLock,
canUnlock,
canSend,
}: ProgramDetailsPageHeaderPropTypes): ReactElement {
}: TargetPopulationPageHeaderProps): ReactElement {
const { t } = useTranslation();
const { baseUrl, businessArea } = useBaseUrl();
const { data: businessAreaData, loading: businessAreaDataLoading } =
Expand All @@ -68,7 +68,7 @@ export function TargetPopulationPageHeader({
let buttons;

switch (paymentPlan.status) {
case PaymentPlanStatus.Open:
case PaymentPlanStatus.TpOpen:
buttons = (
<OpenTargetPopulationHeaderButtons
targetPopulation={paymentPlan}
Expand All @@ -79,7 +79,7 @@ export function TargetPopulationPageHeader({
/>
);
break;
case PaymentPlanStatus.Locked:
case PaymentPlanStatus.TpLocked:
case PaymentPlanStatus.SteficonCompleted:
case PaymentPlanStatus.SteficonError:
case PaymentPlanStatus.SteficonRun:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { BlackLink } from '@components/core/BlackLink';
import { StatusBox } from '@components/core/StatusBox';
import { ClickableTableRow } from '@components/core/Table/ClickableTableRow';
import { UniversalMoment } from '@components/core/UniversalMoment';
import { paymentPlanStatusToColor } from '@utils/utils';
import {
paymentPlanStatusToColor,
targetPopulationStatusDisplayMap,
} from '@utils/utils';
import { PaymentPlanNode } from '@generated/graphql';
import { useBaseUrl } from '@hooks/useBaseUrl';
import { ReactElement } from 'react';
Expand Down Expand Up @@ -67,6 +70,7 @@ export function TargetPopulationTableRow({
<StatusBox
status={targetPopulation.status}
statusToColor={paymentPlanStatusToColor}
statusNameMapping={targetPopulationStatusDisplayMap}
/>
</TableCell>
<TableCell align="left">
Expand Down
14 changes: 14 additions & 0 deletions src/frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ export function paymentStatusDisplayMap(status: string): string {
return 'UNSUCCESSFUL';
}
}

export function targetPopulationStatusDisplayMap(status: string): string {
switch (status) {
case PaymentPlanStatus.TpOpen:
return 'OPEN';
case PaymentPlanStatus.TpLocked:
return 'LOCKED';
case PaymentPlanStatus.Finished:
return 'FINISHED';
default:
return 'UNKNOWN STATUS';
}
}

export function paymentVerificationStatusToColor(
theme: typeof themeObj,
status: string,
Expand Down

0 comments on commit d75f30f

Please sign in to comment.