updated living space added

This commit is contained in:
2025-12-04 15:46:24 +03:00
parent 56b42bb906
commit 53e1f1e4fc
70 changed files with 1128 additions and 824 deletions

View File

@@ -23,31 +23,62 @@ export function DraggableRow({ row, selectedID }: { row: Row<z.infer<typeof sche
)
}
function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
function getColumns(router: any, deleteHandler: (id: string) => void, buildID: string): ColumnDef<schemaType>[] {
return [
{
accessorKey: "uuid",
header: "UUID",
},
{
accessorKey: "build",
header: "Build",
accessorKey: "person.firstName",
header: "First Name",
},
{
accessorKey: "part",
header: "Part",
accessorKey: "person.middleName",
header: "Middle Name",
},
{
accessorKey: "userType",
accessorKey: "person.surname",
header: "Surname",
},
{
accessorKey: "person.birthDate",
header: "Birth Date",
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
},
{
accessorKey: "build.info.buildName",
header: "Build Name",
},
{
accessorKey: "build.info.buildNo",
header: "Build No",
},
{
accessorKey: "part.no",
header: "Part No",
},
{
accessorKey: "part.level",
header: "Level",
},
{
accessorKey: "part.humanLivability",
header: "Livability",
cell: ({ getValue }) => getValue() ? <div className="text-green-500 px-2 py-1 rounded">Yes</div> : <div className="text-red-500 px-2 py-1 rounded">No</div>
},
{
accessorKey: "person.birthPlace",
header: "Birth Place",
},
{
accessorKey: "userType.description",
header: "User Type",
},
{
accessorKey: "company",
header: "Company",
},
{
accessorKey: "person",
header: "Person",
accessorKey: "userType.isProperty",
header: "Property",
cell: ({ getValue }) => getValue() ? <div className="text-green-500 px-2 py-1 rounded">Yes</div> : <div className="text-red-500 px-2 py-1 rounded">No</div>
},
{
accessorKey: "createdAt",
@@ -75,10 +106,10 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
cell: ({ row }) => {
return (
<div>
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/living-spaces/update?uuid=${row.original.uuid}&buildID=${row.original.build}`) }}>
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/living-spaces/update?uuid=${row.original.uuid}&buildID=${buildID}`) }}>
<Pencil />
</Button>
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(buildID) }}>
<Trash />
</Button>
</div>

View File

@@ -79,6 +79,7 @@ export function LivingSpaceDataTable({
onPageChange,
onPageSizeChange,
refetchTable,
buildID
}: {
data: schemaType[],
totalCount: number,
@@ -87,6 +88,7 @@ export function LivingSpaceDataTable({
onPageChange: (page: number) => void,
onPageSizeChange: (size: number) => void,
refetchTable: () => void,
buildID: string
}) {
const router = useRouter()
@@ -99,7 +101,7 @@ export function LivingSpaceDataTable({
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
const deleteMutation = useDeleteLivingSpacesMutation()
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
const columns = getColumns(router, deleteHandler);
const columns = getColumns(router, deleteHandler, buildID);
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
const totalPages = Math.ceil(totalCount / pageSize)

View File

@@ -18,4 +18,3 @@ export function useDeleteLivingSpacesMutation() {
onError: (error) => { console.error("Delete living space failed:", error) },
})
}