feat: Integrate translation support in FieldWithHistory component and update i18n strings

This commit is contained in:
2025-10-02 09:57:51 +02:00
parent a59dc83678
commit 50760ab099
2 changed files with 22 additions and 8 deletions

View File

@@ -3,6 +3,7 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import Tooltip from "@/components/ui/Tooltip"; import Tooltip from "@/components/ui/Tooltip";
import { formatDate } from "@/lib/utils"; import { formatDate } from "@/lib/utils";
import { useTranslation } from "@/lib/i18n";
export default function FieldWithHistory({ export default function FieldWithHistory({
tableName, tableName,
@@ -13,6 +14,7 @@ export default function FieldWithHistory({
label = null, label = null,
className = "", className = "",
}) { }) {
const { t } = useTranslation();
const [hasHistory, setHasHistory] = useState(false); const [hasHistory, setHasHistory] = useState(false);
const [history, setHistory] = useState([]); const [history, setHistory] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
@@ -52,28 +54,28 @@ export default function FieldWithHistory({
return value; return value;
} }
} }
return value || "N/A"; return value || t("common.na");
}; };
// Create tooltip content // Create tooltip content
const tooltipContent = history.length > 0 && ( const tooltipContent = history.length > 0 && (
<div className="space-y-2"> <div className="space-y-2">
<div className="font-medium text-white mb-2">Change History:</div> <div className="font-medium text-white mb-2">{t("common.changeHistory")}:</div>
{history.map((change, index) => ( {history.map((change, index) => (
<div key={change.id} className="text-xs border-b border-gray-600 pb-1 last:border-b-0"> <div key={change.id} className="text-xs border-b border-gray-600 pb-1 last:border-b-0">
<div className="flex justify-between items-start gap-2"> <div className="flex justify-between items-start gap-2">
<div className="flex-1"> <div className="flex-1">
<div className="text-white font-medium"> <div className="text-white font-medium">
Changed to: {getDisplayValue(change.new_value)} {t("common.changedTo")}: {getDisplayValue(change.new_value)}
</div> </div>
{change.old_value && ( {change.old_value && (
<div className="text-gray-400 text-xs"> <div className="text-gray-400 text-xs">
From: {getDisplayValue(change.old_value)} {t("common.from")}: {getDisplayValue(change.old_value)}
</div> </div>
)} )}
{change.changed_by_name && ( {change.changed_by_name && (
<div className="text-gray-300"> <div className="text-gray-300">
by {change.changed_by_name} {t("common.by")} {change.changed_by_name}
</div> </div>
)} )}
</div> </div>
@@ -83,7 +85,7 @@ export default function FieldWithHistory({
</div> </div>
{change.change_reason && ( {change.change_reason && (
<div className="text-gray-400 text-xs mt-1"> <div className="text-gray-400 text-xs mt-1">
Reason: {change.change_reason} {t("common.reason")}: {change.change_reason}
</div> </div>
)} )}
</div> </div>

View File

@@ -74,7 +74,13 @@ const translations = {
clearAll: "Wyczyść", clearAll: "Wyczyść",
clearAllFilters: "Wyczyść wszystkie filtry", clearAllFilters: "Wyczyść wszystkie filtry",
sortBy: "Sortuj według", sortBy: "Sortuj według",
days: "dni" days: "dni",
changeHistory: "Historia zmian",
changedTo: "Zmieniono na",
from: "Z",
by: "przez",
reason: "Powód",
na: "N/D"
}, },
// Dashboard // Dashboard
@@ -636,7 +642,13 @@ const translations = {
clearAll: "Clear", clearAll: "Clear",
clearAllFilters: "Clear all filters", clearAllFilters: "Clear all filters",
sortBy: "Sort by", sortBy: "Sort by",
days: "days" days: "days",
changeHistory: "Change History",
changedTo: "Changed to",
from: "From",
by: "by",
reason: "Reason",
na: "N/A"
}, },
dashboard: { dashboard: {