Skip to Content
Octopus Energy Packages

Create the Shell

Create the route shell, shared timeframe state, and Coral overview controls

Every measurements overview starts with a timeframe. The selected range controls which records are fetched, and every card on the page should usually use the same resolved timeframe so users can compare like with like.

What you'll build

By the end of this guide, your energy overview page will render a client overview with shared timeframe state and Coral EnergyOverview timeframe controls.

Create the route shell

Keep the route focused on routing concerns. It reads the route params and passes them to the client overview.

app/accounts/[accountNumber]/properties/[propertyId]/consumption/page.tsx
import { ConsumptionOverview } from "./_components/consumption-overview";

export default async function ConsumptionPage({
  params,
}: PageProps<"/accounts/[accountNumber]/properties/[propertyId]/consumption">) {
  const { accountNumber, propertyId } = await params;

  return <ConsumptionOverview accountNumber={accountNumber} propertyId={propertyId} />;
}

The route does not fetch measurements yet. The client component will own the interactive timeframe state and the queries added in the next guide.

Create the shared timeframe

Use useTimeframe when the user can change the selected range in the browser. Without explicit defaults or stored state, useTimeframe starts from today. That is enough for the first working overview.

This example stores timeframe state with createLocalStorageAdapter, so the selected range survives page reloads.

_components/consumption-overview.tsx
"use client";

import { createLocalStorageAdapter } from "@octopus-energy/measurements/storage/local-storage";
import { useTimeframe } from "@octopus-energy/measurements/timeframe";

type Props = {
  accountNumber: string;
  propertyId: string;
};

export function ConsumptionOverview({ accountNumber, propertyId }: Props) {
  const [timeframe, timeframeActions] = useTimeframe({
    storage: createLocalStorageAdapter(),
    timezone: "Europe/London",
  });

  // Use accountNumber, propertyId, timeframe, and timeframeActions below.
}

Render Coral timeframe controls

Use getTimeframeProps to adapt timeframe and timeframeActions to the prop shape expected by Coral's timeframe controls.

_components/consumption-overview.tsx
import { getTimeframeProps } from "@octopus-energy/measurements/compat";

const { navigation, timeframeControls, toggleButton } = getTimeframeProps({
  timeframe,
  timeframeActions,
});

Then render the Coral EnergyOverview shell and controls.

_components/consumption-overview.tsx
import {
  EnergyOverview,
  EnergyOverviewTimeframeControls,
  EnergyOverviewTimeframeNavigation,
  EnergyOverviewTimeframeToggleButton,
  EnergyOverviewTimeframeToggleOption,
  EnergyOverviewTimeframeToggleOptionGroup,
} from "@octopus-energy/coral/molecules";
import { enGB } from "date-fns/locale/en-GB";

return (
  <EnergyOverview dateLocale={enGB}>
    <EnergyOverviewTimeframeControls
      datePickerLabel="Start date"
      intervalLabel="Interval"
      intervalValues={[
        { label: "Day", value: "DAY" },
        { label: "Week", value: "WEEK" },
        { label: "Month", value: "MONTH" },
      ]}
      {...timeframeControls}
    >
      <EnergyOverviewTimeframeToggleButton {...toggleButton}>
        <EnergyOverviewTimeframeToggleOptionGroup>
          <EnergyOverviewTimeframeToggleOption value="DAY">Day</EnergyOverviewTimeframeToggleOption>
          <EnergyOverviewTimeframeToggleOption value="WEEK">
            Week
          </EnergyOverviewTimeframeToggleOption>
          <EnergyOverviewTimeframeToggleOption value="MONTH">
            Month
          </EnergyOverviewTimeframeToggleOption>
          <EnergyOverviewTimeframeToggleOption value="YEAR">
            Year
          </EnergyOverviewTimeframeToggleOption>
          <EnergyOverviewTimeframeToggleOption value="CUSTOM">
            Custom
          </EnergyOverviewTimeframeToggleOption>
        </EnergyOverviewTimeframeToggleOptionGroup>
      </EnergyOverviewTimeframeToggleButton>

      <EnergyOverviewTimeframeNavigation {...navigation} />
    </EnergyOverviewTimeframeControls>
  </EnergyOverview>
);

The next guide adds supply point and measurement queries to this shell.

Implementation checkpoint

At this checkpoint, the route renders a client ConsumptionOverview and passes route params through. The client overview owns shared timeframe state, persists it with localStorage, and adapts the state to Coral timeframe controls.

FAQ

On this page