Skip to content

Commit f22cb52

Browse files
authored
Merge pull request #523 from openclimatefix/staging
Quartz Energy v0.1.1 – Auth + Forecast Horizon Select
2 parents a092635 + b660a4c commit f22cb52

File tree

24 files changed

+783
-186
lines changed

24 files changed

+783
-186
lines changed

apps/nowcasting-app/components/map/deltaMap.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import mapboxgl, { Expression } from "mapbox-gl";
66
import { FailedStateMap, LoadStateMap, Map, MeasuringUnit } from "./";
77
import { ActiveUnit, SelectedData } from "./types";
88
import { DELTA_BUCKET, VIEWS } from "../../constant";
9-
import ButtonGroup from "../../components/button-group";
109
import gspShapeData from "../../data/gsp_regions_20220314.json";
1110
import useGlobalState from "../helpers/globalState";
1211
import { formatISODateString, formatISODateStringHuman } from "../helpers/utils";
@@ -28,7 +27,9 @@ import DeltaColorGuideBar from "./delta-color-guide-bar";
2827
import { safelyUpdateMapData } from "../helpers/mapUtils";
2928
import { generateGeoJsonForecastData } from "../helpers/data";
3029
import { components } from "../../types/quartz-api";
30+
import dynamic from "next/dynamic";
3131
const yellow = theme.extend.colors["ocf-yellow"].DEFAULT;
32+
const ButtonGroup = dynamic(() => import("../../components/button-group"), { ssr: false });
3233

3334
const getRoundedPv = (pv: number, round: boolean = true) => {
3435
if (!round) return Math.round(pv);

apps/nowcasting-app/components/map/pvLatestMap.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import mapboxgl, { Expression } from "mapbox-gl";
66
import { FailedStateMap, LoadStateMap, Map, MeasuringUnit } from "./";
77
import { ActiveUnit, SelectedData } from "./types";
88
import { MAX_POWER_GENERATED, VIEWS } from "../../constant";
9-
import ButtonGroup from "../../components/button-group";
109
import gspShapeData from "../../data/gsp_regions_20220314.json";
1110
import useGlobalState from "../helpers/globalState";
1211
import { formatISODateString, formatISODateStringHuman } from "../helpers/utils";
@@ -17,8 +16,11 @@ import { FeatureCollection } from "geojson";
1716
import { safelyUpdateMapData } from "../helpers/mapUtils";
1817
import { components } from "../../types/quartz-api";
1918
import { generateGeoJsonForecastData } from "../helpers/data";
19+
import dynamic from "next/dynamic";
2020
const yellow = theme.extend.colors["ocf-yellow"].DEFAULT;
2121

22+
const ButtonGroup = dynamic(() => import("../../components/button-group"), { ssr: false });
23+
2224
type PvLatestMapProps = {
2325
className?: string;
2426
combinedData: CombinedData;

apps/nowcasting-app/components/map/sitesMap.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
MAX_POWER_GENERATED,
1111
VIEWS
1212
} from "../../constant";
13-
import ButtonGroup from "../../components/button-group";
1413
import gspShapeData from "../../data/gsp_regions_20220314.json";
1514
import dnoShapeData from "../../data/dno_regions_lat_long_converted.json";
1615
import useGlobalState from "../helpers/globalState";
@@ -26,8 +25,10 @@ import { Feature, FeatureCollection } from "geojson";
2625
import Slider from "./sitesMapFeatures/sitesZoomSlider";
2726
import SitesLegend from "./sitesMapFeatures/sitesLegend";
2827
import { safelyUpdateMapData } from "../helpers/mapUtils";
28+
import dynamic from "next/dynamic";
2929

3030
const yellow = theme.extend.colors["ocf-yellow"].DEFAULT;
31+
const ButtonGroup = dynamic(() => import("../../components/button-group"), { ssr: false });
3132

3233
const getRoundedPv = (pv: number, round: boolean = true) => {
3334
if (!round) return Math.round(pv);

apps/quartz-app/.env.preview

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AUTH0_BASE_URL=https://$VERCEL_URL

apps/quartz-app/.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AUTH0_BASE_URL=https://$VERCEL_URL
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { handleAuth, handleLogout, HandleAuth } from "@auth0/nextjs-auth0";
2+
3+
/**
4+
* This is a GET endpoint that automatically handles authentication using Auth0.
5+
* We're using a logout option override to redirect to "/logout" after logout.
6+
*
7+
* @function GET
8+
* @returns {HandleAuth} A function that handles authentication.
9+
*/
10+
export const GET = handleAuth({
11+
logout: handleLogout({
12+
returnTo: "/logout",
13+
}),
14+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import { getAccessToken, withApiAuthRequired } from "@auth0/nextjs-auth0";
3+
4+
/**
5+
* This is a secured GET endpoint that requires API authentication.
6+
* It retrieves the access token for the authenticated user.
7+
*
8+
* @async
9+
* @function GET
10+
* @param {NextRequest} req - The Next.js API request object.
11+
* @returns {NextResponse} A JSON response containing the access token.
12+
*/
13+
const GET = withApiAuthRequired(async function GET(req: NextRequest) {
14+
const res = new NextResponse();
15+
const { accessToken } = await getAccessToken(req, res);
16+
return NextResponse.json({ accessToken }, res);
17+
});
18+
19+
export { GET };

apps/quartz-app/app/globals.css

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@
1818

1919
body {
2020
color: rgb(var(--foreground-rgb));
21-
background: linear-gradient(
22-
to bottom,
23-
transparent,
24-
rgb(var(--background-end-rgb))
25-
)
26-
rgb(var(--background-start-rgb));
2721
}
2822

2923
@layer utilities {
3024
.text-balance {
3125
text-wrap: balance;
3226
}
3327
}
28+
29+
.fade-out {
30+
opacity: 1;
31+
animation: fade-out 2s ease-in-out forwards;
32+
}
33+
34+
@keyframes fade-out {
35+
from {
36+
opacity: 1;
37+
}
38+
to {
39+
opacity: 0;
40+
}
41+
}

apps/quartz-app/app/layout.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Metadata } from "next";
22
import { Inter } from "next/font/google";
33
import "./globals.css";
4-
import Header from "../src/components/layout/Header";
5-
import Providers from "@/app/providers";
64
import { ReactNode } from "react";
5+
import { UserProvider } from "@auth0/nextjs-auth0/client";
6+
import LayoutWrapper from "@/src/components/layout/LayoutWrapper";
77

88
const inter = Inter({ subsets: ["latin"] });
99

@@ -19,12 +19,11 @@ export default function RootLayout({
1919
}>) {
2020
return (
2121
<html lang="en">
22-
<body className={inter.className}>
23-
<Providers>
24-
<Header />
25-
{children}
26-
</Providers>
27-
</body>
22+
<UserProvider>
23+
<body className={inter.className}>
24+
<LayoutWrapper>{children}</LayoutWrapper>
25+
</body>
26+
</UserProvider>
2827
</html>
2928
);
3029
}

apps/quartz-app/app/logout/page.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"use client";
2+
3+
import { useRouter } from "next/navigation";
4+
import { ChevronRightIcon } from "@heroicons/react/solid";
5+
import { SupportIcon, ViewListIcon } from "@heroicons/react/outline";
6+
7+
const MyPage = () => {
8+
const router = useRouter();
9+
const links = [
10+
// {
11+
// title: "Documentation",
12+
// description: "Learn how to integrate our tools with your app",
13+
// icon: BookOpenIcon,
14+
// url: "https://openclimatefix.notion.site/Quartz-Solar-Documentation-0d718915650e4f098470d695aa3494bf",
15+
// },
16+
{
17+
title: "API Reference",
18+
description: "A complete API reference for our library",
19+
icon: ViewListIcon,
20+
url:
21+
process.env.NEXT_PUBLIC_API_URL + "docs" ||
22+
"https://api.quartz.energy/docs",
23+
},
24+
{
25+
title: "Support",
26+
description: "Get help with any problems you encounter",
27+
icon: SupportIcon,
28+
url: "mailto:[email protected]?subject=Quartz%20Energy%20Support%20Request",
29+
},
30+
];
31+
return (
32+
<div className="container flex-1 flex flex-col gap-6 py-24 items-center">
33+
<div className="flex-1 flex flex-col gap-6 justify-center text-center md:text-left items-center">
34+
<h1 className="text-4xl text-white">See you next time.</h1>
35+
<h2 className="text-xl text-white px-3">
36+
You have been successfully logged out.
37+
</h2>
38+
<button
39+
className="bg-ocf-yellow py-2 px-3 rounded-md"
40+
onClick={() => router.push("/api/auth/login")}
41+
>
42+
Log back in &rarr;
43+
</button>
44+
</div>
45+
<div className="max-w-3xl w-full flex flex-1 flex-col gap-6 justify-center items-center">
46+
<div className="mt-16">
47+
<h2 className="text-sm font-semibold tracking-wide text-gray-300 uppercase">
48+
More from Quartz
49+
</h2>
50+
<ul
51+
role="list"
52+
className="mt-4 border-t border-b border-gray-200 divide-y divide-gray-200"
53+
>
54+
{links.map((link, linkIdx) => (
55+
<li
56+
key={`LogoutLink${linkIdx}`}
57+
className="relative flex items-start py-6 space-x-4"
58+
>
59+
<div className="flex-shrink-0">
60+
<span className="flex items-center justify-center w-12 h-12 rounded-lg">
61+
<link.icon
62+
className="w-6 h-6 text-gray-300"
63+
aria-hidden="true"
64+
/>
65+
</span>
66+
</div>
67+
<div className="flex-1 min-w-0">
68+
<h3 className="text-base font-medium text-gray-100">
69+
<span className="rounded-sm focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-gray-500">
70+
<a href={link.url} className="focus:outline-none">
71+
<span className="absolute inset-0" aria-hidden="true" />
72+
{link.title}
73+
</a>
74+
</span>
75+
</h3>
76+
<p className="text-base text-gray-400">{link.description}</p>
77+
</div>
78+
<div className="self-center flex-shrink-0">
79+
<ChevronRightIcon
80+
className="w-5 h-5 text-gray-400"
81+
aria-hidden="true"
82+
/>
83+
</div>
84+
</li>
85+
))}
86+
</ul>
87+
</div>
88+
</div>
89+
</div>
90+
);
91+
};
92+
93+
export default MyPage;

0 commit comments

Comments
 (0)