@@ -111,184 +95,26 @@ export default async function Page({
params,
searchParams,
}: {
- params: { slug: string };
+ params: { slug: number };
searchParams: { [key: string]: string | string[] | undefined | number };
}) {
+ // This page is served from the server so we can make calls to the database
+
// This is temp until we retrieve this data from the frontend
// TODO: Update the objects to contains objective + any other required information
- const Portfolios = [
- {
- id: "f290f1ee-6c54-4b01-90e6-d701748f0851",
- properties: [] as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0851",
- title: "Portfolio 1",
- budget: 500000,
- cost: 500000,
- properties: generateProperties(500000, "1", "scoping") as Property[],
- co2Reduction: 5.4,
- totalWorksHours: 45,
- totalValueIncrease: 500000 * 1.2,
- rentalYieldIncrease: 500000 * 0.002,
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0852",
- title: "Portfolio 2",
- budget: 150000,
- cost: 150000,
- co2Reduction: 9.0,
- totalWorksHours: 30,
- totalValueIncrease: 150000 * 1.2,
- rentalYieldIncrease: 150000 * 0.002,
- properties: generateProperties(150000, "2", "assessment") as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0853",
- title: "Portfolio 3",
- budget: 1000000,
- cost: 1000000,
- co2Reduction: 15.4,
- totalWorksHours: 100,
- totalValueIncrease: 1000000 * 1.2,
- rentalYieldIncrease: 1000000 * 0.002,
- properties: generateProperties(1000000, "3", "tendering") as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0854",
- title: "Portfolio 4",
- budget: 2000000,
- cost: 2000000,
- co2Reduction: 3.8,
- totalWorksHours: 150,
- totalValueIncrease: 2000000 * 1.2,
- rentalYieldIncrease: 2000000 * 0.002,
- properties: generateProperties(2000000, "4", "tendering") as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0855",
- title: "Portfolio 5",
- budget: 250000,
- cost: 250000,
- co2Reduction: 1.9,
- totalWorksHours: 15,
- totalValueIncrease: 250000 * 1.2,
- rentalYieldIncrease: 250000 * 0.002,
- properties: generateProperties(
- 250000,
- "5",
- "project underway"
- ) as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0856",
- title: "Portfolio 6",
- budget: 410000,
- cost: 410000,
- co2Reduction: 1.4,
- totalWorksHours: 10,
- totalValueIncrease: 410000 * 1.2,
- rentalYieldIncrease: 410000 * 0.002,
- properties: generateProperties(
- 410000,
- "6",
- "completion; status 'on track'"
- ) as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0857",
- title: "Portfolio 7",
- budget: 233000,
- cost: 233000,
- co2Reduction: 10.4,
- totalWorksHours: 25,
- totalValueIncrease: 233000 * 1.2,
- rentalYieldIncrease: 233000 * 0.002,
- properties: generateProperties(
- 233000,
- "7",
- "completion; status 'delayed'"
- ) as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0858",
- title: "Portfolio 8",
- budget: 670000,
- cost: 670000,
- co2Reduction: 4.5,
- totalWorksHours: 65,
- totalValueIncrease: 670000 * 1.2,
- rentalYieldIncrease: 670000 * 0.002,
- properties: generateProperties(
- 670000,
- "8",
- "completion; status 'at risk'"
- ) as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0859",
- title: "Portfolio 9",
- budget: 240000,
- cost: 240000,
- co2Reduction: 8.4,
- totalWorksHours: 40,
- totalValueIncrease: 240000 * 1.2,
- rentalYieldIncrease: 240000 * 0.002,
- properties: generateProperties(
- 240000,
- "9",
- "completion; status 'completed'"
- ) as Property[],
- },
- {
- id: "d290f1ee-6c54-4b01-90e6-d701748f0860",
- title: "Portfolio 10",
- budget: 93000,
- cost: 93000,
- co2Reduction: 5.4,
- totalWorksHours: 18,
- totalValueIncrease: 93000 * 1.2,
- rentalYieldIncrease: 93000 * 0.002,
- properties: generateProperties(93000, "10", "needs review") as Property[],
- },
- ];
- const demo_id = "f290f1ee-6c54-4b01-90e6-d701748f0851";
- let page_config;
- let pageName;
- let budget;
- let co2Reduction: number;
- let totalWorksHours: number;
- let totalValueIncrease: number;
- let rentalYieldIncrease: number;
- let totalCost: number;
- if (params.slug === demo_id) {
- page_config = {
- properties: [] as Property[],
- ...searchParams,
- };
- pageName = searchParams.name;
- budget = searchParams.budget;
- co2Reduction = 0;
- totalWorksHours = 0;
- totalValueIncrease = 0;
- rentalYieldIncrease = 0;
- totalCost = 0;
- } else {
- page_config = Portfolios.filter((portfolio) => {
- return portfolio.id == params.slug;
- })[0];
- pageName = page_config.title;
- budget = page_config.budget;
- co2Reduction = page_config.co2Reduction as number;
- totalWorksHours = page_config.totalWorksHours as number;
- totalValueIncrease = page_config.totalValueIncrease as number;
- rentalYieldIncrease = page_config.rentalYieldIncrease as number;
- totalCost = page_config.cost as number;
- }
+ const portfolioId = params.slug;
+ const {
+ name: portfolioName,
+ budget,
+ cost: totalCost,
+ co2EquivalentSavings,
+ totalWorkHours,
+ propertyValuationIncrease,
+ rentalYieldIncrease,
+ } = await getPortfolio(portfolioId);
- // TODO: Put this back in for demo
- const properties = page_config.properties;
+ const properties: Property[] = [];
// TODO: Add the porfolio summary information on the left
// Add an empty state for when there are no properties
@@ -298,7 +124,7 @@ export default async function Page({
<>
- Portfolio: {pageName}
+ Portfolio: {portfolioName}
@@ -323,13 +149,13 @@ export default async function Page({
Number of properties: {properties.length}
- Annual Co2 Savings: {co2Reduction} tonnes
+ Annual Co2 Savings: {co2EquivalentSavings} tonnes
- Total Works Time: {totalWorksHours} hours
+ Total Works Time: {totalWorkHours} hours
- Total Value Increase: £{totalValueIncrease}
+ Total Value Increase: £{propertyValuationIncrease}
Annual rental yield Increase: £{rentalYieldIncrease}
@@ -337,7 +163,7 @@ export default async function Page({