Skip to content

Commit 03b0ad4

Browse files
authored
Merge pull request #520 from AppQuality/fix-status-info-utils
fix(utils): fix status info utils to use TFunction instead of useTranslation hook to prevent crashes
2 parents daaca9e + 62020b0 commit 03b0ad4

File tree

5 files changed

+36
-26
lines changed

5 files changed

+36
-26
lines changed

src/common/components/meta/StatusMeta.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useTranslation } from 'react-i18next';
12
import { CampaignStatus } from 'src/types';
23
import { Meta } from '../Meta';
34
import { getStatusInfo } from '../utils/getStatusInfo';
@@ -10,7 +11,8 @@ interface StatusMetaArgs extends React.HTMLAttributes<HTMLDivElement> {
1011
}
1112

1213
export const StatusMeta = ({ status, counter, ...props }: StatusMetaArgs) => {
13-
const statusInfo = getStatusInfo(status);
14+
const { t } = useTranslation();
15+
const statusInfo = getStatusInfo(status, t);
1416

1517
return (
1618
<Meta

src/common/components/tag/StatusTag.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Tag } from '@appquality/unguess-design-system';
2+
import { useTranslation } from 'react-i18next';
23
import { theme } from 'src/app/theme';
34
import { CampaignStatus } from 'src/types';
45
import { getStatusInfo } from '../utils/getStatusInfo';
@@ -17,7 +18,8 @@ export const StatusTag = ({
1718
isRound,
1819
...props
1920
}: StatusTagArgs) => {
20-
const statusInfo = getStatusInfo(status);
21+
const { t } = useTranslation();
22+
const statusInfo = getStatusInfo(status, t);
2123

2224
return (
2325
<Tag

src/common/components/utils/getStatusInfo.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ import {
77
CampaignFunctionalIcon,
88
} from '@appquality/unguess-design-system';
99
import { theme } from 'src/app/theme';
10-
import { useTranslation } from 'react-i18next';
10+
import { TFunction } from 'i18next';
1111

1212
type StatusInfo = {
1313
icon?: React.ReactNode;
1414
text?: string;
1515
color?: string;
1616
};
1717

18-
export const getStatusInfo = (status: CampaignStatus): StatusInfo => {
19-
const { t } = useTranslation();
20-
18+
export const getStatusInfo = (
19+
status: CampaignStatus,
20+
t: TFunction
21+
): StatusInfo => {
2122
switch (status.toLowerCase()) {
2223
case 'running':
2324
return {

src/pages/Dashboard/campaigns-list/table.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,29 @@ export const TableList = ({
3939

4040
const items = curr.map((campaign) => {
4141
const statusInfo = getStatusInfo(
42-
campaign.status.name as CampaignStatus
42+
campaign.status.name as CampaignStatus,
43+
t
4344
);
45+
46+
const cpUrl = getLocalizeDashboardRoute({
47+
campaignId: campaign.id,
48+
cpFamily: campaign.family.name,
49+
outputs: campaign.outputs || [],
50+
});
51+
52+
const cpStartDate = new Date(campaign.start_date).toLocaleDateString();
53+
4454
return {
4555
name: (
46-
<Anchor
47-
href={getLocalizeDashboardRoute({
48-
campaignId: campaign.id,
49-
cpFamily: campaign.family.name,
50-
outputs: campaign.outputs || [],
51-
})}
52-
>
56+
<Anchor href={cpUrl}>
5357
<Span isBold style={{ color: theme.palette.grey[800] }}>
5458
{campaign.customer_title ?? campaign.title}
5559
</Span>
5660
</Anchor>
5761
),
5862
type: campaign.family.name,
5963
testType: campaign.type.name,
60-
startDate: new Date(campaign.start_date).toLocaleDateString(),
64+
startDate: cpStartDate,
6165
status: (
6266
<Tooltip
6367
type="light"

src/pages/Dashboard/project-items/table.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const TableList = ({
3232
{ name: t('__CAMPAIGNS_TABLE_COLUMN_STATUS'), field: 'status' },
3333
];
3434

35+
if (!campaigns.length) return null;
36+
3537
return (
3638
<Table isReadOnly style={{ backgroundColor: 'white' }}>
3739
<TableHead>
@@ -43,27 +45,26 @@ export const TableList = ({
4345
</TableHead>
4446
<TableBody>
4547
{campaigns.map((cp) => {
46-
const statusInfo = getStatusInfo(cp.status.name as CampaignStatus);
48+
const statusInfo = getStatusInfo(cp.status.name as CampaignStatus, t);
49+
const cpUrl = getLocalizeDashboardRoute({
50+
campaignId: cp.id,
51+
cpFamily: cp.family.name,
52+
outputs: cp.outputs || [],
53+
});
54+
const cpStartDate = new Date(cp.start_date).toLocaleDateString();
55+
4756
return (
4857
<TableRow key={cp.id}>
4958
<TableCell>
50-
<Anchor
51-
href={getLocalizeDashboardRoute({
52-
campaignId: cp.id,
53-
cpFamily: cp.family.name,
54-
outputs: cp.outputs || [],
55-
})}
56-
>
59+
<Anchor href={cpUrl}>
5760
<Span isBold style={{ color: theme.palette.grey[800] }}>
5861
{cp.customer_title ?? cp.title}
5962
</Span>
6063
</Anchor>
6164
</TableCell>
6265
<TableCell>{cp.family.name}</TableCell>
6366
<TableCell>{cp.type.name}</TableCell>
64-
<TableCell>
65-
{new Date(cp.start_date).toLocaleDateString()}
66-
</TableCell>
67+
<TableCell>{cpStartDate}</TableCell>
6768
<TableCell>
6869
<Tooltip
6970
type="light"

0 commit comments

Comments
 (0)