171 lines
5.2 KiB
TypeScript
171 lines
5.2 KiB
TypeScript
// * Packages
|
|
import { ArrowLeftIcon, CheckIcon, MailIcon, XIcon } from "lucide-react";
|
|
import { usePage } from "@inertiajs/react";
|
|
import { route } from "ziggy-js";
|
|
// * Components shadcn
|
|
import { Badge } from "@/components/ui/badge";
|
|
// * Other
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
import DetailsTable from "@/back/Components/Table/DetailsTable";
|
|
import ModelActions from "@/back/Components/ModelActions";
|
|
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
|
import Views from "@/back/lib/actions";
|
|
import { GetFormatedDate, GetTranslation } from "@/lib/utils";
|
|
import { AuthProp, SingleResource, UserModel } from "@/back/types/global";
|
|
import str from "@/hooks/use-string";
|
|
import useTrans from "@/hooks/use-translations";
|
|
|
|
const getColumns = () => {
|
|
return [
|
|
{
|
|
accessorKey: "first_name",
|
|
header: str(
|
|
GetTranslation("uwil-backend::validation.attributes.first_name"),
|
|
)
|
|
.ucFirst()
|
|
.value(),
|
|
},
|
|
{
|
|
accessorKey: "last_name",
|
|
header: str(
|
|
GetTranslation("uwil-backend::validation.attributes.last_name"),
|
|
)
|
|
.ucFirst()
|
|
.value(),
|
|
},
|
|
{
|
|
accessorKey: "email",
|
|
header: str(GetTranslation("uwil-backend::validation.attributes.email"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<a
|
|
href={`mailto:${value}`}
|
|
className="inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 text-dark underline-offset-4 hover:underline"
|
|
>
|
|
<MailIcon />
|
|
{value}
|
|
</a>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "role",
|
|
header: str(GetTranslation(`uwil-backend::validation.attributes.role`))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: UserModel["role"] }) => (
|
|
<Badge variant="outline">
|
|
{str(String(value?.label ?? '')).ucFirst().value()}
|
|
</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "published",
|
|
header: str(GetTranslation("uwil-backend::validation.custom.published"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: boolean }) => (
|
|
<Badge
|
|
variant="outline"
|
|
className={`border-0 ${
|
|
value
|
|
? "bg-green-200 dark:bg-green-900"
|
|
: "bg-red-200 dark:bg-red-900"
|
|
}`}
|
|
>
|
|
{value ? (
|
|
<CheckIcon size={15} className="mr-1" />
|
|
) : (
|
|
<XIcon size={15} className="mr-1" />
|
|
)}
|
|
{str(
|
|
GetTranslation(
|
|
value ? "uwil-backend::back.yes" : "uwil-backend::back.no",
|
|
),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "published_at",
|
|
header: str(
|
|
GetTranslation("uwil-backend::validation.custom.published_at"),
|
|
)
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{GetFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "created_at",
|
|
header: str(
|
|
GetTranslation("uwil-backend::validation.attributes.created_at"),
|
|
)
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{GetFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "updated_at",
|
|
header: str(
|
|
GetTranslation("uwil-backend::validation.attributes.updated_at"),
|
|
)
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{GetFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
];
|
|
};
|
|
|
|
export default function Show({ data }: { data: SingleResource }) {
|
|
const { auth } = usePage().props as unknown as {
|
|
auth: AuthProp;
|
|
};
|
|
const { viewAny } = auth.policies.users;
|
|
const userModel = data.data as UserModel;
|
|
const actionModels = [Views.EDITION, Views.DUPLICATION, Views.DELETION];
|
|
|
|
const columns = getColumns();
|
|
|
|
const transCrudBackList = useTrans("uwil-backend::back.crud_back_to_list");
|
|
const beforeNode = () => {
|
|
return (
|
|
viewAny && (
|
|
<div className="flex justify-end items-center gap-x-1.5">
|
|
<BtnOptionnalLinkWithTooltip
|
|
link={route("back.users.index")}
|
|
content={<ArrowLeftIcon />}
|
|
tooltipContent={<p>{transCrudBackList}</p>}
|
|
/>
|
|
</div>
|
|
)
|
|
);
|
|
};
|
|
|
|
return (
|
|
<AuthenticatedLayout
|
|
title={useTrans("uwil-backend::crud.helpers.visualization_model", {
|
|
params: {
|
|
model: useTrans("uwil-backend::models.classes.users", { choice: 1 }),
|
|
},
|
|
})}
|
|
beforeNode={beforeNode()}
|
|
>
|
|
<ModelActions
|
|
actions={actionModels}
|
|
modelRoute="users"
|
|
model={userModel}
|
|
modelUpdatedAt={userModel.updated_at.toString()}
|
|
/>
|
|
{/* @ts-expect-error Weird error type on cell. */}
|
|
<DetailsTable columns={columns} model={userModel} />
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|