From 240aaa81aeb7f037a1987b332d0ffe0e7131e814 Mon Sep 17 00:00:00 2001 From: BunyodL Date: Tue, 29 Apr 2025 01:22:24 +0500 Subject: [PATCH] update: get main-page-data --- src/app/api-utlities/@types/index.ts | 2 +- src/app/api-utlities/@types/main.ts | 18 ++++++++++++++++++ src/app/api-utlities/presenters/index.ts | 2 +- src/app/page.tsx | 9 ++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/app/api-utlities/@types/main.ts diff --git a/src/app/api-utlities/@types/index.ts b/src/app/api-utlities/@types/index.ts index 705be9f..326bc14 100644 --- a/src/app/api-utlities/@types/index.ts +++ b/src/app/api-utlities/@types/index.ts @@ -45,6 +45,6 @@ export type Station = Root<{ _propanCopy: boolean; _zaryadnayaStanci: boolean; _miniMarketCop: boolean; - _region: Select; + _region: Select[]; _foto: Image[]; }>; diff --git a/src/app/api-utlities/@types/main.ts b/src/app/api-utlities/@types/main.ts new file mode 100644 index 0000000..881fcc3 --- /dev/null +++ b/src/app/api-utlities/@types/main.ts @@ -0,0 +1,18 @@ +import { + presentDiscounts, + presentJobs, + presentPartners, + presentStations, +} from '../presenters'; + +export type Partners = ReturnType; +export type Jobs = ReturnType; +export type Discounts = ReturnType; +export type Stations = ReturnType; + +export type MainPageData = { + discounts: Discounts; + jobs: Jobs; + partners: Partners; + stations: Stations; +}; diff --git a/src/app/api-utlities/presenters/index.ts b/src/app/api-utlities/presenters/index.ts index 1333fd2..d623ffe 100644 --- a/src/app/api-utlities/presenters/index.ts +++ b/src/app/api-utlities/presenters/index.ts @@ -28,7 +28,7 @@ export const presentDiscounts = (discounts: Discount) => })); export const presentStations = (stations: Station) => - stations.records.map((station: any) => ({ + stations.records.map((station) => ({ name: station._name, description: station._opisanie, address: station._adress, diff --git a/src/app/page.tsx b/src/app/page.tsx index 95e56b6..5126d32 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -8,7 +8,14 @@ import { PromotionsSection } from '@/widgets/promotions-section'; import { StatsSection } from '@/widgets/stats-section'; import { VacanciesSection } from '@/widgets/vacancies-section'; -export default function Home() { +import { MainPageData } from './api-utlities/@types/main'; + +export default async function Home() { + const mainPageData = (await fetch( + `${process.env.NEXT_PUBLIC_BASE_URL}/api/pages/main`, + { method: 'GET' }, + ).then((res) => res.json())) as MainPageData; + return (