"use client" import { useEffect, useState } from "react" import { useLocale, useTranslations } from "next-intl" import type { Position } from "@/types" import { Item, ItemContent, ItemDescription, ItemTitle } from "@/components/ui/item" import { Badge } from "@/components/ui/badge" import { Spinner } from "@/components/ui/spinner" import { fetchMyPositions } from "@/actions/positions" const positionsCache: Record = {} export default function Positions() { const t = useTranslations("MePage.items.positions") const locale = useLocale() const [positions, setPositions] = useState( () => positionsCache[locale] ?? null ) const [loading, setLoading] = useState(!positionsCache[locale]) useEffect(() => { if (positionsCache[locale]) return setLoading(true) fetchMyPositions(locale) .then((data) => { positionsCache[locale] = data setPositions(data) }) .finally(() => setLoading(false)) }, [locale]) return (

{t("title")}

{loading && (
{t("loading")}
)} {!loading && (
{positions && positions.length > 0 ? ( positions.map((position) => ( {position.name} {position.description && ( {position.description} )} {position.permissions.length > 0 && (
{position.permissions.map((perm) => ( {perm.description} ))}
)}
)) ) : (

{t("empty")}

)}
)}
) }