diff --git a/app/(defaults)/sungrow/plant/page.tsx b/app/(defaults)/sungrow/plant/page.tsx new file mode 100644 index 0000000..16ba0c6 --- /dev/null +++ b/app/(defaults)/sungrow/plant/page.tsx @@ -0,0 +1,105 @@ +"use client"; + +import IconTrashLines from '@/components/icon/icon-trash-lines'; +import PanelCodeHighlight from '@/components/panel-code-highlight'; +import ComponentsTablesSimple from '@/components/tables/components-tables-simple' +import { formatUnixTimestamp } from '@/utils/helpers'; +import Tippy from '@tippyjs/react'; +import axios from 'axios'; +import React, { useEffect, useState } from "react" + +type Props = {} + +const SungrowPlant = (props: Props) => { + const [sites, setSites] = useState([]) + const [loading, setLoading] = useState(true) + + + useEffect(() => { + const fetchSites = async () => { + try { + const res = await fetch("/api/sungrow/site") + const data = await res.json() + console.log("data", data) + setSites(data) + } catch (error) { + console.error("Error fetching inverters:", error) + } finally { + setLoading(false) + } + } + + fetchSites() + }, []) + + const statusLabels: Record = { + 0: "Offline", + 1: "Normal", + } + const plantTypeLabel: Record = { + 3: "Commercial PV", + 4: "Residential PV", + } + + + return ( +
+ {loading ?

Loading...

: ( + +
+ + + + + + + {/* + + + + + + + */} + + + + + {sites.map((data) => ( + + + + + {/* + + + + + + + */} + + + ))} + +
Site NameStatusPlant TypeInstalled PowerReal-time PowerYield TodayMonthly YieldAnnual YieldTotal YieldEquivalent HoursRemarksAction
+
{data.ps_name}
+
+
+ {statusLabels[data.online_status] || "-"} +
+
{plantTypeLabel[data.ps_type] || "-"} + + + +
+
+
+ )} +
+ ) +} + +export default SungrowPlant diff --git a/app/api/sungrow/site/route.ts b/app/api/sungrow/site/route.ts new file mode 100644 index 0000000..aa99e66 --- /dev/null +++ b/app/api/sungrow/site/route.ts @@ -0,0 +1,22 @@ +import { NextResponse } from "next/server"; +import axios from "axios"; + +export async function GET() { + try { + const res = await axios.post("https://gateway.isolarcloud.com.hk/openapi/platform/queryPowerStationList", { + "page": 1, + "size": 10, + "appkey": `${process.env.SUNGROW_APP_KEY}` + } ,{ + headers: { + "Authorization": `Bearer ${process.env.SUNGROW_ACCESS_TOKEN}`, + "x-access-key": `${process.env.SUNGROW_SECRET_KEY}` + } + }) + // console.log("res", res.data) + return NextResponse.json(res.data.result_data.pageList) + } catch (error) { + console.error("API fetch error:", error); + return NextResponse.json({ error: "Failed to fetch inverters" }, { status: 500 }); + } +} diff --git a/app/layout.tsx b/app/layout.tsx index 819a18e..8ba396c 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -24,5 +24,5 @@ export default function RootLayout({ children }: { children: React.ReactNode }) {children} - ); + ) }