From 2195fe45284136165d0072529c318e7b4cac6984 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 21 Aug 2023 19:44:22 +0100 Subject: [PATCH] Adding basic portfolio plan table --- .../components/portfolio/plan/PlanTable.tsx | 11 ++--- .../portfolio/plan/PlanTableColumns.tsx | 48 +++++++++++++++++-- .../[slug]/(portfolio)/plan/page.tsx | 15 +++++- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/app/components/portfolio/plan/PlanTable.tsx b/src/app/components/portfolio/plan/PlanTable.tsx index d711dbc1..fc3c9566 100644 --- a/src/app/components/portfolio/plan/PlanTable.tsx +++ b/src/app/components/portfolio/plan/PlanTable.tsx @@ -16,17 +16,16 @@ import { TableRow, } from "@/app/shadcn_components/ui/table"; -import { Feature, GeneralFeature } from "@/app/db/schema/property"; +import { PortfolioPlanRecommendation } from "@/app/db/schema/recommendations"; -interface DataTableProps { +interface DataTableProps { columns: ColumnDef[]; data: T[]; } -export default function FeatureTable({ - data, - columns, -}: DataTableProps) { +export default function PortfolioPlanTable< + T extends PortfolioPlanRecommendation +>({ data, columns }: DataTableProps) { // Initialise the table const table = useReactTable({ diff --git a/src/app/components/portfolio/plan/PlanTableColumns.tsx b/src/app/components/portfolio/plan/PlanTableColumns.tsx index da705e2b..dee5a59e 100644 --- a/src/app/components/portfolio/plan/PlanTableColumns.tsx +++ b/src/app/components/portfolio/plan/PlanTableColumns.tsx @@ -1,24 +1,62 @@ "use client"; import { PortfolioPlanRecommendation } from "@/app/db/schema/recommendations"; -import { Badge } from "@/app/shadcn_components/ui/badge"; +import { formatNumber } from "@/app/utils"; import { ColumnDef } from "@tanstack/react-table"; -export const retrofitColumns: ColumnDef[] = [ +const formattedQuantity = { + m2: "m²", +}; + +const formattedMeasure = { + internal_wall_insulation: "Internal Wall Insulation", + external_wall_insulation: "External Wall Insulation", +}; + +export const portfolioPlanColumns: ColumnDef[] = [ { accessorKey: "materialType", header: "Retrofit Measure", + cell: ({ row }) => { + return ( +
+ { + formattedMeasure[ + row.original.materialType as keyof typeof formattedMeasure + ] + } +
+ ); + }, }, { - accessorKey: "Number o", - header: "Number of Properties", + accessorKey: "numberOfProperties", + header: "Number of properties", + cell: ({ row }) => { + return ( +
{row.original.numberOfProperties}
+ ); + }, }, { accessorKey: "quantity", - header: "Number of Properties", + header: "Quantity required", + cell: ({ row }) => { + return ( +
+ {row.original.quantity + + formattedQuantity[ + row.original.quantityUnit as keyof typeof formattedQuantity + ]} +
+ ); + }, }, { accessorKey: "estimatedCost", header: "Estimated Cost", + cell: ({ row }) => { + return
{"£" + formatNumber(row.original.estimatedCost)}
; + }, }, ]; diff --git a/src/app/portfolio/[slug]/(portfolio)/plan/page.tsx b/src/app/portfolio/[slug]/(portfolio)/plan/page.tsx index 866d18b2..74e8b329 100644 --- a/src/app/portfolio/[slug]/(portfolio)/plan/page.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/plan/page.tsx @@ -1,4 +1,6 @@ +import PortfolioPlanTable from "@/app/components/portfolio/plan/PlanTable"; import { getPortfolioPlan } from "../../utils"; +import { portfolioPlanColumns } from "@/app/components/portfolio/plan/PlanTableColumns"; export default async function PortfolioPlan({ params, @@ -8,5 +10,16 @@ export default async function PortfolioPlan({ const portfolioId = params.slug; const portfolioPlan = await getPortfolioPlan(portfolioId); - return
{String(portfolioPlan)}
; + return ( + <> +
+ { + + } +
+ + ); }