Skip to content

Commit

Permalink
refactor(business-reports): rename report status types for clarity
Browse files Browse the repository at this point in the history
- Update TReportStatus to TReportStatusTranslations
- Adjust types in fetchBusinessReports and useBusinessReportsQuery
- Replace all deprecated references in business reports logic

(These type names are so confusing, it's like translating a secret code in a spy movie)
  • Loading branch information
shanegrouber committed Dec 23, 2024
1 parent 0424927 commit 942e799
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 29 deletions.
9 changes: 3 additions & 6 deletions apps/backoffice-v2/src/domains/business-reports/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { UnknownRecord } from 'type-fest';

import { Method } from '@/common/enums';
import { apiClient } from '@/common/api-client/api-client';
import { TReportStatus, TRiskLevel } from '@/pages/MerchantMonitoring/schemas';
import { TReportStatusTranslations, TRiskLevel } from '@/pages/MerchantMonitoring/schemas';
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';
import {
MERCHANT_REPORT_STATUSES,
Expand Down Expand Up @@ -88,13 +88,11 @@ export const fetchLatestBusinessReport = async ({

export const fetchBusinessReports = async ({
reportType,
riskLevel,
statuses,
...params
}: {
reportType: MerchantReportType | 'All';
riskLevel: TRiskLevel[];
statuses: TReportStatus[];
statuses: TReportStatusTranslations[];
from?: string;
to?: string;
page: {
Expand All @@ -103,12 +101,11 @@ export const fetchBusinessReports = async ({
};
orderBy: string;
}) => {
console.log(params.statuses);
const queryParams = qs.stringify(
{
...params,
...(reportType !== 'All' && { reportType }),
riskLevel,
statuses,
},
{ encode: false },
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useQuery } from '@tanstack/react-query';
import { isString } from '@/common/utils/is-string/is-string';
import { MerchantReportType } from '@/domains/business-reports/constants';
import { businessReportsQueryKey } from '@/domains/business-reports/query-keys';
import { TReportStatus, TRiskLevel } from '@/pages/MerchantMonitoring/schemas';
import { TReportStatusTranslations, TRiskLevel } from '@/pages/MerchantMonitoring/schemas';
import { useIsAuthenticated } from '@/domains/auth/context/AuthProvider/hooks/useIsAuthenticated/useIsAuthenticated';

export const useBusinessReportsQuery = ({
Expand All @@ -26,7 +26,7 @@ export const useBusinessReportsQuery = ({
sortBy: string;
sortDir: string;
riskLevel: TRiskLevel[];
statuses: TReportStatus[];
statuses: TReportStatusTranslations[];
from?: string;
to?: string;
}) => {
Expand All @@ -43,7 +43,7 @@ export const useBusinessReportsQuery = ({
riskLevel,
statuses,
from,
to: to ? dayjs(to).add(1, 'day').format('YYYY-MM-DD') : undefined,
to,
}),
enabled:
isAuthenticated &&
Expand Down
4 changes: 2 additions & 2 deletions apps/backoffice-v2/src/domains/business-reports/query-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
fetchLatestBusinessReport,
} from '@/domains/business-reports/fetchers';
import { MerchantReportType } from '@/domains/business-reports/constants';
import { TReportStatus, TRiskLevel } from '@/pages/MerchantMonitoring/schemas';
import { TReportStatusTranslations, TRiskLevel } from '@/pages/MerchantMonitoring/schemas';

export const businessReportsQueryKey = createQueryKeys('business-reports', {
list: ({
Expand All @@ -23,7 +23,7 @@ export const businessReportsQueryKey = createQueryKeys('business-reports', {
sortBy: string;
sortDir: string;
riskLevel: TRiskLevel[];
statuses: TReportStatus[];
statuses: TReportStatusTranslations[];
from?: string;
to?: string;
}) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SCAN_TYPES = {
} as const;

const REPORT_STATUS_TO_DISPLAY_STATUS = {
[MERCHANT_REPORT_STATUSES_MAP.completed]: 'Manual Review',
[MERCHANT_REPORT_STATUSES_MAP.completed]: 'Ready for Review',
[MERCHANT_REPORT_STATUSES_MAP['quality-control']]: 'Quality Control',
} as const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
REPORT_TYPE_TO_DISPLAY_TEXT,
RISK_LEVEL_FILTER,
STATUS_LEVEL_FILTER,
REPORT_STATUS_TRANSLATIONS,
} from '@/pages/MerchantMonitoring/schemas';

export const useMerchantMonitoringLogic = () => {
Expand All @@ -42,9 +43,11 @@ export const useMerchantMonitoringLogic = () => {
sortBy,
sortDir,
riskLevel: riskLevel ?? [],
statuses: statuses ?? [],
statuses: statuses
?.map(status => REPORT_STATUS_TRANSLATIONS[status])
.flatMap(status => (status === 'quality-control' ? ['quality-control', 'failed'] : [status])),
from,
to,
to: to ? dayjs(to).add(1, 'day').format('YYYY-MM-DD') : undefined,
});

const onReportTypeChange = (reportType: keyof typeof REPORT_TYPE_TO_DISPLAY_TEXT) => {
Expand Down
41 changes: 27 additions & 14 deletions apps/backoffice-v2/src/pages/MerchantMonitoring/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,43 @@ export const DISPLAY_TEXT_TO_MERCHANT_REPORT_TYPE = {
Monitoring: 'ONGOING_MERCHANT_REPORT_T1',
} as const;

export const RISK_LEVELS = ['Critical', 'High', 'Medium', 'Low'] as const;
export const RISK_LEVELS = ['critical', 'high', 'medium', 'low'] as const;

export type TRiskLevel = (typeof RISK_LEVELS)[number];

export const RISK_LEVEL_FILTER = {
title: 'Risk Level',
accessor: 'riskLevel',
options: RISK_LEVELS.map(riskLevel => ({
label: riskLevel,
value: riskLevel.toLowerCase(),
label: riskLevel.charAt(0).toUpperCase() + riskLevel.slice(1),
value: riskLevel,
})),
};

export const REPORT_STATUS = ['In Progress', 'Quality Control', 'Manual Review'] as const;
export const REPORT_STATUS_OPTIONS = [
'In Progress',
'Quality Control',
'Ready for Review',
] as const;
export const REPORT_STATUS_OPTIONS_WITH_FAILED = [...REPORT_STATUS_OPTIONS, 'Failed'] as const;
export const REPORT_STATUS_TRANSLATIONS = {
'In Progress': 'in-progress',
'Quality Control': 'quality-control',
'Ready for Review': 'completed',
Failed: 'failed',
} as const;

export type TReportStatus = (typeof REPORT_STATUS)[number];
export type TReportStatusOptions = (typeof REPORT_STATUS_OPTIONS)[number];
export type TReportStatusOptionsWithFailed = (typeof REPORT_STATUS_OPTIONS_WITH_FAILED)[number];
export type TReportStatusTranslations =
(typeof REPORT_STATUS_TRANSLATIONS)[keyof typeof REPORT_STATUS_TRANSLATIONS];

export const STATUS_LEVEL_FILTER = {
title: 'Status',
accessor: 'status',
options: REPORT_STATUS.map(status => ({
accessor: 'statuses',
options: REPORT_STATUS_OPTIONS.map(status => ({
label: status,
value: status.toLowerCase(),
value: status,
})),
};

Expand Down Expand Up @@ -74,16 +88,15 @@ export const MerchantMonitoringSearchSchema = BaseSearchSchema.extend({
])
.catch('All'),
riskLevel: z
.array(
z.enum(
RISK_LEVELS.map(riskLevel => riskLevel.toLowerCase()) as [TRiskLevel, ...TRiskLevel[]],
),
)
.array(z.enum(RISK_LEVELS.map(riskLevel => riskLevel) as [TRiskLevel, ...TRiskLevel[]]))
.catch([]),
statuses: z
.array(
z.enum(
REPORT_STATUS.map(status => status.toLowerCase()) as [TReportStatus, ...TReportStatus[]],
REPORT_STATUS_OPTIONS.map(status => status) as [
TReportStatusOptions,
...TReportStatusOptions[],
],
),
)
.catch([]),
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations

0 comments on commit 942e799

Please sign in to comment.