Skip to content

Commit 3e4c662

Browse files
Merge pull request #2207 from AletheiaFact/Refactor/improve-and-refactor-verification-request-page-UI
UI: Standardize translations and extract tag logic to help check requests
2 parents 486b489 + e9bd950 commit 3e4c662

15 files changed

+215
-232
lines changed

public/locales/en/verificationRequest.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"impactAreaPlaceholder": "Select the impact area...",
4444
"publicationDatePlaceholder": "Select the date you saw this...",
4545
"heardFromPlaceholder": "Specify where you saw or heard this...",
46-
"sourcePlaceholder": "Provide the source of the information...",
46+
"sourcePlaceholder": "Provide the source of the information...",
4747
"emailPlaceholder": "Enter your email address here...",
4848
"verificationRequestCreateSuccess": "Verification Request created successfully",
4949
"verificationRequestCreateError": "Error while creating the Verification Request",
@@ -71,10 +71,15 @@
7171
"statusDeclined": "Declined",
7272
"allPriorities": "All Priorities",
7373
"allSourceChannels": "All Source Channels",
74-
"priorityCritical": "Critical",
75-
"priorityHigh": "High",
76-
"priorityMedium": "Medium",
77-
"priorityLow": "Low",
74+
"priority": {
75+
"critical": "Critical",
76+
"high": "High ({{level}})",
77+
"medium": "Medium ({{level}})",
78+
"low": "Low ({{level}})",
79+
"filter_high": "High",
80+
"filter_medium": "Medium",
81+
"filter_low": "Low"
82+
},
7883
"filterByPriority": "Filter by Priority",
7984
"noRequestsInStatus": "No requests in this status",
8085
"impactAreaFilterLabel": "Impact Area:",

public/locales/pt/verificationRequest.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"impactAreaPlaceholder": "Selecione a área de impacto...",
4444
"publicationDatePlaceholder": "Selecione a data em que você viu isso...",
4545
"heardFromPlaceholder": "Especifique onde você viu ou ouviu isso...",
46-
"sourcePlaceholder": "Forneça a fonte da informação...",
46+
"sourcePlaceholder": "Forneça a fonte da informação...",
4747
"emailPlaceholder": "Insira seu endereço de email aqui...",
4848
"verificationRequestCreateSuccess": "Denúncia criada com sucesso",
4949
"verificationRequestCreateError": "Erro ao criar a denúncia",
@@ -71,10 +71,15 @@
7171
"statusDeclined": "Recusado",
7272
"allPriorities": "Todas as Prioridades",
7373
"allSourceChannels": "Todos os Canais de Origem",
74-
"priorityCritical": "Crítica",
75-
"priorityHigh": "Alta",
76-
"priorityMedium": "Média",
77-
"priorityLow": "Baixa",
74+
"priority": {
75+
"critical": "Crítico",
76+
"high": "Alta ({{level}})",
77+
"medium": "Média ({{level}})",
78+
"low": "Baixa ({{level}})",
79+
"filter_high": "Alta",
80+
"filter_medium": "Média",
81+
"filter_low": "Baixa"
82+
},
7883
"filterByPriority": "Filtrar por Prioridade",
7984
"noRequestsInStatus": "Nenhuma solicitação neste status",
8085
"impactAreaFilterLabel": "Área de Impacto:",

src/components/VerificationRequest/SelectFilter.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ interface SelectFilterProps {
2525
const filterActions: Record<string, () => SelectOption[]> = {
2626
filterByPriority: () => [
2727
{ value: "all", labelKey: "allPriorities" },
28-
{ value: "critical", labelKey: "priorityCritical" },
29-
{ value: "high", labelKey: "priorityHigh" },
30-
{ value: "medium", labelKey: "priorityMedium" },
31-
{ value: "low", labelKey: "priorityLow" },
28+
{ value: "critical", labelKey: "priority.critical" },
29+
{ value: "high", labelKey: "priority.filter_high" },
30+
{ value: "medium", labelKey: "priority.filter_medium" },
31+
{ value: "low", labelKey: "priority.filter_low" },
3232
],
3333

3434
filterBySourceChannel: () => {

src/components/VerificationRequest/SourceListVerificationRequest.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from "react";
22
import Link from "next/link";
33
import { VerificationRequestContent } from "./VerificationRequestContent";
4+
import { truncateUrl } from "../../helpers/verificationRequestCardHelper";
45

56
interface SourceListProps {
67
sources: Array<{ href?: string }>;
78
t: (key: string) => string;
8-
truncateUrl: (url: string) => string;
99
id: string;
1010
}
1111

12-
const SourceList: React.FC<SourceListProps> = ({ sources, t, truncateUrl, id }) => {
12+
const SourceList: React.FC<SourceListProps> = ({ sources, t, id }) => {
1313
if (!sources?.length) return null;
1414

1515
const flatSources = sources.flat().filter((source) => !!source.href);

src/components/VerificationRequest/VerificationRequestAlert.tsx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const VerificationRequestAlert = ({ targetId, verificationRequestId }) => {
3535
description: (
3636
<AletheiaButton
3737
href={`/claim/create?verificationRequest=${verificationRequestId}`}
38-
style={{ width: "fit-content", marginTop: 32 }}
38+
className="container-alert"
3939
>
4040
{t("seo:claimCreateTitle")}
4141
</AletheiaButton>
@@ -44,40 +44,19 @@ const VerificationRequestAlert = ({ targetId, verificationRequestId }) => {
4444
}
4545
if (targetId) {
4646
return {
47-
type: "warning",
47+
type: "success",
4848
showIcon: false,
49-
message: (
50-
<div
51-
style={{
52-
display: "flex",
53-
gap: 16,
54-
flexWrap: "wrap",
55-
justifyContent: "space-around",
56-
}}
57-
>
58-
<span
59-
style={{
60-
height: "auto",
61-
fontSize: 18,
62-
lineHeight: "40px",
63-
textAlign: "center",
64-
}}
65-
>
66-
{t(
67-
"verificationRequest:openVerificationRequestClaimLabel"
68-
)}
69-
</span>
49+
message: t("verificationRequest:openVerificationRequestClaimLabel"),
50+
description: (
7051
<AletheiaButton
7152
href={`/claim/${targetId?.slug}`}
72-
style={{ width: "fit-content" }}
53+
className="container-alert"
7354
>
7455
{t(
7556
"verificationRequest:openVerificationRequestClaimButton"
7657
)}
7758
</AletheiaButton>
78-
</div>
7959
),
80-
description: null,
8160
};
8261
}
8362
return null;

src/components/VerificationRequest/VerificationRequestBoardView.tsx

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ import {
1111
} from "@mui/material";
1212
import colors from "../../styles/colors";
1313
import AletheiaButton, { ButtonType } from "../Button";
14-
import { SeverityEnum, VerificationRequestStatus } from "../../../server/verification-request/dto/types";
15-
import { SeverityLevel } from "../../types/VerificationRequest";
14+
import { VerificationRequestStatus } from "../../../server/verification-request/dto/types";
1615
import VerificationRequestDetailDrawer from "./VerificationRequestDetailDrawer";
17-
18-
const SEVERITY_COLOR_MAP: Record<SeverityLevel, string> = {
19-
low: colors.low,
20-
medium: colors.medium,
21-
high: colors.high,
22-
critical: colors.critical,
23-
};
16+
import {
17+
getSeverityColor,
18+
getSeverityLabel,
19+
} from "../../helpers/verificationRequestCardHelper";
2420

2521
const VerificationRequestBoardView = ({ state, actions }) => {
2622
const { loading, filteredRequests, totalVerificationRequests, paginationModel } = state;
@@ -64,33 +60,6 @@ const VerificationRequestBoardView = ({ state, actions }) => {
6460
statuses.map(({ key }) => [key, totalVerificationRequests[key]])
6561
);
6662

67-
const getSeverityColor = (severity: SeverityEnum | undefined): string => {
68-
if (!severity) return colors.neutralSecondary;
69-
70-
const severityStr = String(severity);
71-
72-
let severityLevel: SeverityLevel;
73-
74-
if (severityStr.startsWith("low")) severityLevel = "low";
75-
else if (severityStr.startsWith("medium")) severityLevel = "medium";
76-
else if (severityStr.startsWith("high")) severityLevel = "high";
77-
else if (severityStr === "critical") severityLevel = "critical";
78-
else severityLevel = "low";
79-
80-
return SEVERITY_COLOR_MAP[severityLevel];
81-
};
82-
83-
const formatSeverityLabel = (severity: string) => {
84-
if (!severity) return "N/A";
85-
const parts = severity.split("_");
86-
if (parts.length === 2) {
87-
return `${parts[0].charAt(0).toUpperCase() + parts[0].slice(1)} (${
88-
parts[1]
89-
})`;
90-
}
91-
return severity.charAt(0).toUpperCase() + severity.slice(1);
92-
};
93-
9463
const truncateText = (text: string, maxLength: number) => {
9564
if (!text) return "";
9665
return text.length > maxLength
@@ -179,7 +148,7 @@ const VerificationRequestBoardView = ({ state, actions }) => {
179148
}}
180149
>
181150
<Chip
182-
label={formatSeverityLabel(request.severity)}
151+
label={getSeverityLabel(request.severity, t)}
183152
size="small"
184153
sx={{
185154
backgroundColor: getSeverityColor(
@@ -236,7 +205,13 @@ const VerificationRequestBoardView = ({ state, actions }) => {
236205
<strong>
237206
{t("verificationRequest:tagSourceChannel")}:
238207
</strong>{" "}
239-
{truncateText(request.sourceChannel, 30)}
208+
{truncateText(
209+
t(
210+
`verificationRequest:${request.sourceChannel}`,
211+
{ defaultValue: request.sourceChannel },
212+
),
213+
30,
214+
)}
240215
</Typography>
241216
)}
242217

src/components/VerificationRequest/VerificationRequestCard.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import { MetaChip } from "./MetaChip";
2121
import { VerificationRequestContent } from "./VerificationRequestContent";
2222
import { RequestDates } from "./RequestDates";
2323
import SourceList from "./SourceListVerificationRequest";
24+
import {
25+
getSeverityColor,
26+
getSeverityLabel,
27+
} from "../../helpers/verificationRequestCardHelper";
2428

2529
const ContentWrapper = styled.div`
2630
display: flex;
@@ -44,20 +48,6 @@ const MetaChipContainer = styled(Grid)`
4448

4549
const smallGreyIcon = { fontSize: 18, color: "grey" };
4650

47-
const truncateUrl = (url) => {
48-
try {
49-
const { hostname, pathname } = new URL(url);
50-
const maxLength = 30;
51-
const shortPath =
52-
pathname.length > maxLength
53-
? `${pathname.substring(0, maxLength)}...`
54-
: pathname;
55-
return `${hostname}${shortPath}`;
56-
} catch (e) {
57-
return url;
58-
}
59-
};
60-
6151
const VerificationRequestCard = ({
6252
verificationRequest,
6353
actions = [],
@@ -83,7 +73,11 @@ const VerificationRequestCard = ({
8373
icon: <Share style={{ fontSize: 18 }} />,
8474
key: `${verificationRequest._id}|receptionChannel`,
8575
label: t("verificationRequest:tagSourceChannel"),
86-
label_value: verificationRequest.sourceChannel,
76+
label_value:
77+
t(
78+
`verificationRequest:${verificationRequest.sourceChannel}`,
79+
{ defaultValue: verificationRequest.sourceChannel },
80+
),
8781
style: { backgroundColor: colors.primary, color: colors.white },
8882
},
8983
{
@@ -100,8 +94,11 @@ const VerificationRequestCard = ({
10094
icon: <WarningAmber style={{ fontSize: 18 }} />,
10195
key: `${verificationRequest._id}|severity`,
10296
label: t("verificationRequest:tagSeverity"),
103-
label_value: verificationRequest.severity,
104-
style: { backgroundColor: colors.neutralSecondary, color: colors.white },
97+
label_value: getSeverityLabel(verificationRequest.severity, t),
98+
style: {
99+
backgroundColor: getSeverityColor(verificationRequest.severity),
100+
color: colors.white,
101+
},
105102
},
106103
];
107104

@@ -183,7 +180,6 @@ const VerificationRequestCard = ({
183180
<SourceList
184181
sources={verificationRequest.source}
185182
t={t}
186-
truncateUrl={truncateUrl}
187183
id={verificationRequest._id}
188184
/>
189185
)}

src/components/VerificationRequest/VerificationRequestDetailDrawer.tsx

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import sendReviewNotifications from "../../notifications/sendReviewNotifications
4444
import AletheiaCaptcha from "../AletheiaCaptcha";
4545
import PersonalitiesSection from "./PersonalitiesSection";
4646
import { usePersonalities } from "../../hooks/usePersonalities";
47+
import {
48+
getSeverityColor,
49+
getSeverityLabel,
50+
} from "../../helpers/verificationRequestCardHelper";
4751

4852
interface VerificationRequestDetailDrawerProps {
4953
verificationRequest: any;
@@ -52,41 +56,6 @@ interface VerificationRequestDetailDrawerProps {
5256
onUpdate?: (oldStatus: string, newStatus: string) => void;
5357
}
5458

55-
const getSeverityColor = (severity: string) => {
56-
if (!severity) return colors.neutralSecondary;
57-
const lowerSeverity = severity.toLowerCase();
58-
if (lowerSeverity === "critical") return "#d32f2f";
59-
if (lowerSeverity.startsWith("high")) return "#f57c00";
60-
if (lowerSeverity.startsWith("medium")) return "#fbc02d";
61-
if (lowerSeverity.startsWith("low")) return "#388e3c";
62-
return colors.neutralSecondary;
63-
};
64-
65-
const formatSeverityLabel = (severity: string) => {
66-
if (!severity) return "N/A";
67-
const parts = severity.split("_");
68-
if (parts.length === 2) {
69-
return `${parts[0].charAt(0).toUpperCase() + parts[0].slice(1)} (${
70-
parts[1]
71-
})`;
72-
}
73-
return severity.charAt(0).toUpperCase() + severity.slice(1);
74-
};
75-
76-
const truncateUrl = (url) => {
77-
try {
78-
const { hostname, pathname } = new URL(url);
79-
const maxLength = 30;
80-
const shortPath =
81-
pathname.length > maxLength
82-
? `${pathname.substring(0, maxLength)}...`
83-
: pathname;
84-
return `${hostname}${shortPath}`;
85-
} catch (e) {
86-
return url;
87-
}
88-
};
89-
9059
const VerificationRequestDetailDrawer: React.FC<VerificationRequestDetailDrawerProps> =
9160
({ verificationRequest, open, onClose, onUpdate }) => {
9261
const { t, i18n } = useTranslation();
@@ -243,7 +212,10 @@ const VerificationRequestDetailDrawer: React.FC<VerificationRequestDetailDrawerP
243212
icon: <Share style={{ fontSize: 18 }} />,
244213
key: `${currentRequest._id}|receptionChannel`,
245214
label: t("verificationRequest:tagSourceChannel"),
246-
label_value: currentRequest.sourceChannel,
215+
label_value: t(
216+
`verificationRequest:${currentRequest.sourceChannel}`,
217+
{ defaultValue: currentRequest.sourceChannel },
218+
),
247219
style: {
248220
backgroundColor: colors.primary,
249221
color: colors.white,
@@ -263,12 +235,9 @@ const VerificationRequestDetailDrawer: React.FC<VerificationRequestDetailDrawerP
263235
icon: <WarningAmber style={{ fontSize: 18 }} />,
264236
key: `${currentRequest._id}|severity`,
265237
label: t("verificationRequest:tagSeverity"),
266-
label_value:
267-
formatSeverityLabel(currentRequest.severity) || "N/A",
238+
label_value: getSeverityLabel(currentRequest.severity, t),
268239
style: {
269-
backgroundColor: getSeverityColor(
270-
currentRequest.severity
271-
),
240+
backgroundColor: getSeverityColor(currentRequest.severity),
272241
color: colors.white,
273242
},
274243
},
@@ -419,7 +388,6 @@ const VerificationRequestDetailDrawer: React.FC<VerificationRequestDetailDrawerP
419388
<SourceList
420389
sources={currentRequest.source}
421390
t={t}
422-
truncateUrl={truncateUrl}
423391
id={currentRequest._id}
424392
/>
425393
</Box>

0 commit comments

Comments
 (0)