64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
"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"
|
|
|
|
export default function Positions() {
|
|
const t = useTranslations("MePage.items.positions")
|
|
const locale = useLocale()
|
|
|
|
const [positions, setPositions] = useState<Position[] | null>(null)
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
fetchMyPositions(locale)
|
|
.then(setPositions)
|
|
.finally(() => setLoading(false))
|
|
}, [locale])
|
|
|
|
return (
|
|
<div className="w-full lg:max-w-sm flex flex-col gap-4">
|
|
<h1 className="text-xl">{t("title")}</h1>
|
|
|
|
{loading && (
|
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
<Spinner />
|
|
<span>{t("loading")}</span>
|
|
</div>
|
|
)}
|
|
|
|
{!loading && (
|
|
<div className="space-y-4">
|
|
{positions && positions.length > 0 ? (
|
|
positions.map((position) => (
|
|
<Item key={position.code}>
|
|
<ItemContent>
|
|
<ItemTitle>{position.name}</ItemTitle>
|
|
{position.description && (
|
|
<ItemDescription>{position.description}</ItemDescription>
|
|
)}
|
|
{position.permissions.length > 0 && (
|
|
<div className="flex flex-wrap gap-1 mt-2">
|
|
{position.permissions.map((perm) => (
|
|
<Badge key={perm.code} variant="secondary" className="text-xs font-mono">
|
|
{perm.code}
|
|
</Badge>
|
|
))}
|
|
</div>
|
|
)}
|
|
</ItemContent>
|
|
</Item>
|
|
))
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">{t("empty")}</p>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
} |