feat: add locale support for date formatting in task components
This commit is contained in:
@@ -8,6 +8,7 @@ import Badge from "@/components/ui/Badge";
|
|||||||
import TaskStatusDropdownSimple from "@/components/TaskStatusDropdownSimple";
|
import TaskStatusDropdownSimple from "@/components/TaskStatusDropdownSimple";
|
||||||
import { Input } from "@/components/ui/Input";
|
import { Input } from "@/components/ui/Input";
|
||||||
import { formatDistanceToNow, parseISO } from "date-fns";
|
import { formatDistanceToNow, parseISO } from "date-fns";
|
||||||
|
import { pl, enUS } from "date-fns/locale";
|
||||||
import { formatDate } from "@/lib/utils";
|
import { formatDate } from "@/lib/utils";
|
||||||
import PageContainer from "@/components/ui/PageContainer";
|
import PageContainer from "@/components/ui/PageContainer";
|
||||||
import PageHeader from "@/components/ui/PageHeader";
|
import PageHeader from "@/components/ui/PageHeader";
|
||||||
@@ -17,7 +18,10 @@ import { LoadingState } from "@/components/ui/States";
|
|||||||
import { useTranslation } from "@/lib/i18n";
|
import { useTranslation } from "@/lib/i18n";
|
||||||
|
|
||||||
export default function ProjectTasksPage() {
|
export default function ProjectTasksPage() {
|
||||||
const { t } = useTranslation();
|
const { t, language } = useTranslation();
|
||||||
|
|
||||||
|
// Get locale for date-fns
|
||||||
|
const locale = language === 'pl' ? pl : enUS;
|
||||||
const [allTasks, setAllTasks] = useState([]);
|
const [allTasks, setAllTasks] = useState([]);
|
||||||
const [filteredTasks, setFilteredTasks] = useState([]);
|
const [filteredTasks, setFilteredTasks] = useState([]);
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
@@ -381,6 +385,7 @@ export default function ProjectTasksPage() {
|
|||||||
Added{" "}
|
Added{" "}
|
||||||
{formatDistanceToNow(parseISO(task.date_added), {
|
{formatDistanceToNow(parseISO(task.date_added), {
|
||||||
addSuffix: true,
|
addSuffix: true,
|
||||||
|
locale: locale
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
{task.max_wait_days > 0 && (
|
{task.max_wait_days > 0 && (
|
||||||
|
|||||||
@@ -13,11 +13,17 @@ import {
|
|||||||
parseISO,
|
parseISO,
|
||||||
formatDistanceToNow,
|
formatDistanceToNow,
|
||||||
} from "date-fns";
|
} from "date-fns";
|
||||||
|
import { pl, enUS } from "date-fns/locale";
|
||||||
import { formatDate } from "@/lib/utils";
|
import { formatDate } from "@/lib/utils";
|
||||||
|
import { useTranslation } from "@/lib/i18n";
|
||||||
|
|
||||||
export default function ProjectTasksDashboard() {
|
export default function ProjectTasksDashboard() {
|
||||||
|
const { language } = useTranslation();
|
||||||
const [allTasks, setAllTasks] = useState([]);
|
const [allTasks, setAllTasks] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
// Get locale for date-fns
|
||||||
|
const locale = language === 'pl' ? pl : enUS;
|
||||||
const [filter, setFilter] = useState("all");
|
const [filter, setFilter] = useState("all");
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
|
|
||||||
@@ -283,7 +289,7 @@ export default function ProjectTasksDashboard() {
|
|||||||
const addedDate = task.date_added.includes("T")
|
const addedDate = task.date_added.includes("T")
|
||||||
? parseISO(task.date_added)
|
? parseISO(task.date_added)
|
||||||
: new Date(task.date_added + "T00:00:00");
|
: new Date(task.date_added + "T00:00:00");
|
||||||
return formatDistanceToNow(addedDate, { addSuffix: true });
|
return formatDistanceToNow(addedDate, { addSuffix: true, locale: locale });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return task.date_added;
|
return task.date_added;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,16 @@ import {
|
|||||||
parseISO,
|
parseISO,
|
||||||
formatDistanceToNow,
|
formatDistanceToNow,
|
||||||
} from "date-fns";
|
} from "date-fns";
|
||||||
|
import { pl, enUS } from "date-fns/locale";
|
||||||
import { formatDate } from "@/lib/utils";
|
import { formatDate } from "@/lib/utils";
|
||||||
import { useTranslation } from "@/lib/i18n";
|
import { useTranslation } from "@/lib/i18n";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
|
|
||||||
export default function ProjectTasksList() {
|
export default function ProjectTasksList() {
|
||||||
const { t } = useTranslation();
|
const { t, language } = useTranslation();
|
||||||
|
|
||||||
|
// Get locale for date-fns
|
||||||
|
const locale = language === 'pl' ? pl : enUS;
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const [allTasks, setAllTasks] = useState([]);
|
const [allTasks, setAllTasks] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -366,6 +370,7 @@ export default function ProjectTasksList() {
|
|||||||
const completedDate = new Date(task.date_completed);
|
const completedDate = new Date(task.date_completed);
|
||||||
return formatDistanceToNow(completedDate, {
|
return formatDistanceToNow(completedDate, {
|
||||||
addSuffix: true,
|
addSuffix: true,
|
||||||
|
locale: locale
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return task.date_completed;
|
return task.date_completed;
|
||||||
@@ -380,7 +385,7 @@ export default function ProjectTasksList() {
|
|||||||
{(() => {
|
{(() => {
|
||||||
try {
|
try {
|
||||||
const startedDate = new Date(task.date_started);
|
const startedDate = new Date(task.date_started);
|
||||||
return formatDistanceToNow(startedDate, { addSuffix: true });
|
return formatDistanceToNow(startedDate, { addSuffix: true, locale: locale });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return task.date_started;
|
return task.date_started;
|
||||||
}
|
}
|
||||||
@@ -393,7 +398,7 @@ export default function ProjectTasksList() {
|
|||||||
const addedDate = task.date_added.includes("T")
|
const addedDate = task.date_added.includes("T")
|
||||||
? parseISO(task.date_added)
|
? parseISO(task.date_added)
|
||||||
: new Date(task.date_added);
|
: new Date(task.date_added);
|
||||||
return formatDistanceToNow(addedDate, { addSuffix: true });
|
return formatDistanceToNow(addedDate, { addSuffix: true, locale: locale });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return task.date_added;
|
return task.date_added;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,14 @@ import Button from "./ui/Button";
|
|||||||
import Badge from "./ui/Badge";
|
import Badge from "./ui/Badge";
|
||||||
import { formatDate } from "@/lib/utils";
|
import { formatDate } from "@/lib/utils";
|
||||||
import { formatDistanceToNow, parseISO } from "date-fns";
|
import { formatDistanceToNow, parseISO } from "date-fns";
|
||||||
|
import { pl, enUS } from "date-fns/locale";
|
||||||
import { useTranslation } from "@/lib/i18n";
|
import { useTranslation } from "@/lib/i18n";
|
||||||
|
|
||||||
export default function TaskCommentsModal({ task, isOpen, onClose }) {
|
export default function TaskCommentsModal({ task, isOpen, onClose }) {
|
||||||
const { t } = useTranslation();
|
const { t, language } = useTranslation();
|
||||||
|
|
||||||
|
// Get locale for date-fns
|
||||||
|
const locale = language === 'pl' ? pl : enUS;
|
||||||
const [notes, setNotes] = useState([]);
|
const [notes, setNotes] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [newNote, setNewNote] = useState("");
|
const [newNote, setNewNote] = useState("");
|
||||||
@@ -159,7 +163,7 @@ export default function TaskCommentsModal({ task, isOpen, onClose }) {
|
|||||||
const date = dateString.includes("T") ? parseISO(dateString) : new Date(dateString);
|
const date = dateString.includes("T") ? parseISO(dateString) : new Date(dateString);
|
||||||
return {
|
return {
|
||||||
label,
|
label,
|
||||||
relative: formatDistanceToNow(date, { addSuffix: true }),
|
relative: formatDistanceToNow(date, { addSuffix: true, locale: locale }),
|
||||||
absolute: formatDate(date, { includeTime: true })
|
absolute: formatDate(date, { includeTime: true })
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user