implemented first version of non-intrusive notes in the app

This commit is contained in:
Khalim Conn-Kowlessar 2024-04-13 18:33:35 +01:00
parent b212d198a4
commit cab3eae6ef
5 changed files with 66 additions and 10 deletions

View file

@ -16,17 +16,22 @@ import {
TableRow,
} from "@/app/shadcn_components/ui/table";
import { Feature, GeneralFeature } from "@/app/db/schema/property";
import {
Feature,
GeneralFeature,
NonInstrusiveFeature,
} from "@/app/db/schema/property";
interface DataTableProps<T extends Feature | GeneralFeature> {
interface DataTableProps<
T extends Feature | GeneralFeature | NonInstrusiveFeature
> {
columns: ColumnDef<T>[];
data: T[];
}
export default function FeatureTable<T extends Feature | GeneralFeature>({
data,
columns,
}: DataTableProps<T>) {
export default function FeatureTable<
T extends Feature | GeneralFeature | NonInstrusiveFeature
>({ data, columns }: DataTableProps<T>) {
// Initialise the table
const table = useReactTable({

View file

@ -1,6 +1,11 @@
"use client";
import { Feature, GeneralFeature, Rating } from "@/app/db/schema/property";
import {
Feature,
GeneralFeature,
NonInstrusiveFeature,
Rating,
} from "@/app/db/schema/property";
import { Badge } from "@/app/shadcn_components/ui/badge";
import { ColumnDef } from "@tanstack/react-table";
@ -48,3 +53,14 @@ export const generalColumns: ColumnDef<GeneralFeature>[] = [
header: "Description",
},
];
export const nonInstrusiveColumns: ColumnDef<NonInstrusiveFeature>[] = [
{
accessorKey: "title",
header: "Feature",
},
{
accessorKey: "note",
header: "Recorded Observation",
},
];

View file

@ -456,6 +456,13 @@
"when": 1713028155621,
"tag": "0064_icy_blue_shield",
"breakpoints": true
},
{
"idx": 65,
"version": "5",
"when": 1713028260577,
"tag": "0065_watery_korvac",
"breakpoints": true
}
]
}

View file

@ -52,6 +52,11 @@ export interface GeneralFeature {
description: string | number;
}
export interface NonInstrusiveFeature {
title: string;
note: string;
}
export interface ConditionReportData {
id: number;
lastUpdated: string;
@ -219,8 +224,8 @@ export const nonIntrusiveSurveyNotes = pgTable("non_intrusive_survey_notes", {
surveyId: bigint("survey_id", { mode: "bigint" })
.notNull()
.references(() => nonInstrusiveSurvey.id),
title: text("title"),
note: text("note"),
title: text("title").notNull(),
note: text("note").notNull(),
});
export type Property = InferModel<typeof property, "select">;

View file

@ -9,6 +9,7 @@ import {
import { formatDateTime } from "@/app/utils";
import {
generalColumns,
nonInstrusiveColumns,
retrofitColumns,
} from "@/app/components/building-passport/FeatureTableColumns";
import {
@ -117,6 +118,16 @@ function PropertyDetailsCard({
);
}
const formatDate = (dateString: Date) => {
const date = new Date(dateString);
return date.toLocaleDateString("en-GB", {
weekday: "long", // "Monday" through "Sunday"
year: "numeric", // "2024"
month: "long", // "January" through "December"
day: "numeric", // "1", "2", ..., "31"
});
};
export default async function PreAssessmentReport({
params,
}: {
@ -131,7 +142,6 @@ export default async function PreAssessmentReport({
);
const nonIntrusiveSurvey = await getNonIntrusiveSurvey(propertyMeta.uprn);
console.log(nonIntrusiveSurvey);
const retrofitFeatures = formatRetrofitFeatures(conditionReportData);
@ -158,6 +168,19 @@ export default async function PreAssessmentReport({
</div>
</div>
{nonIntrusiveSurvey && (
<div>
<div className="flex py-8 text-lg">Non-Intrusive Survey</div>
<div className="flex mb-2 text-sm text-gray-500">
Conducted by: {nonIntrusiveSurvey.surveyor} on{" "}
{formatDate(nonIntrusiveSurvey.surveyDate)}
</div>
<FeatureTable
data={nonIntrusiveSurvey.notes}
columns={nonInstrusiveColumns}
/>
</div>
)}
<div className="flex py-8 text-lg">General Features</div>
<FeatureTable data={generalFeatures} columns={generalColumns} />
<div className="flex py-8 text-lg">Existing Property Features</div>