From b50e5415658c42c7102510a01dc66f5080febb9f Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 25 Apr 2025 21:04:32 -0400 Subject: New country; New page; Update packages --- app/enterprises/page.js | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 app/enterprises/page.js (limited to 'app/enterprises/page.js') diff --git a/app/enterprises/page.js b/app/enterprises/page.js new file mode 100644 index 0000000..7d8ce02 --- /dev/null +++ b/app/enterprises/page.js @@ -0,0 +1,133 @@ +import Header from "../components/Header"; +import { google } from "googleapis"; + +const auth = new google.auth.GoogleAuth({ + credentials: { + client_email: process.env.GOOGLE_CLIENT_EMAIL, + private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'), + project_id: process.env.GOOGLE_PROJECT_ID, + }, + scopes: ['https://www.googleapis.com/auth/spreadsheets.readonly'], +}); + + +async function fetchSheetData(spreadsheetId, range) { + const client = await auth.getClient(); + const sheets = google.sheets('v4'); + const response = await sheets.spreadsheets.values.get({ + auth: client, + spreadsheetId, + range, + }); + + const rows = response.data.values; + + // Define the headers + const headers = [ + 'CompanyID', + 'Businesses', + 'ParentCompany', + 'Type', + 'Owner', + 'Status', + 'Notes' + ]; + + // Map rows to objects + const formattedData = rows.slice(1).map(row => { + const obj = {}; + headers.forEach((header, index) => { + let value = row[index] || ''; // Assign empty string if value is missing + if (header === 'Businesses') { + value = value.includes('\n') ? value.split('\n') : [value]; // Split into array if multiple businesses + } + obj[header] = value; + }); + return obj; + }); + + return Object.values( + formattedData.reduce((acc, company) => { + const parent = company.ParentCompany; + if (!acc[parent]) { + acc[parent] = {...company, Businesses: [...company.Businesses]}; + } else { + acc[parent].Businesses = [...acc[parent].Businesses, ...company.Businesses]; + } + return acc; + }, {}) + ); +} + + +export const metadata = { + title: 'Enterprises', + description: 'Registered enterprises in the Alure Regions', +} + +export default async function Services() { + const response = await fetchSheetData('1VWt21lvbqBRmpZPeC87ZXJphibMEATFp48PPW457q38', 'A1:G32'); + + return ( +
+
+
+
+

Want to start a business?

+

Register with the Alure Regions government in order to operate a company.

+
+ {/*
+ +
+
+ +
+ +
+
*/} + +
+ { + response.map((company) => { + return ( +
+

{company.ParentCompany}

+

Business ID: {company.CompanyID} • Owner: {company.Owner}

+

Type: {company.Type}

+

Status: Operational

+

Businesses

+
    + { + company.Businesses.map((business) => { + return ( +
  • + {business} +
  • + ) + }) + } +
+ { + company.Notes && ( + <> +

Notes:

+

{company.Notes}

+ + ) + } +
+ ) + }) + } +
+
+
+ ) +} -- cgit v1.2.3