Skip to content

Commit

Permalink
refactor: services-data-to-replace namings
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-ivanovvv committed Nov 6, 2024
1 parent afd07a0 commit 3e21ffc
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 70 deletions.
14 changes: 7 additions & 7 deletions globals/data/src/getters/aqsi-data-getter/aqsi-data.getter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { AqsiDataType } from '../../interfaces/index.js'
import type { ServicesDataToReplaceType } from '../../interfaces/index.js'

import { REQUEST_URL } from './aqsi-data.constants.js'
import { NullResponseError } from './error/null-response.error.js'
import { fetchAqsiDataHelper } from './fetch-data/index.js'
import { formatOutputDataHelper } from './format-output-data-helper/index.js'
import { formatPagesDataHelper } from './format-pages-data-helper/index.js'
import { REQUEST_URL } from './aqsi-data.constants.js'
import { NullResponseError } from './error/null-response.error.js'
import { fetchAqsiDataHelper } from './fetch-data/index.js'
import { formatOutputDataHelper } from './format-output-data-helper/index.js'
import { formatPagesDataHelper } from './format-pages-data-helper/index.js'

export const getAqsiData = async (): Promise<AqsiDataType> => {
export const getAqsiData = async (): Promise<ServicesDataToReplaceType> => {
try {
const godsListResponse = await fetchAqsiDataHelper(REQUEST_URL)
const godsListData = await godsListResponse.json()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/* eslint-disable no-continue */

import type { AqsiDataType } from '../../../interfaces/aqsi-data.interface.js'
import type { FormattedPagesDataType } from '../../../interfaces/index.js'
import type { ServicesDataToReplaceType } from '../../../interfaces/aqsi-data.interface.js'
import type { FormattedPagesDataType } from '../../../interfaces/index.js'

import { DataVariants } from './helpers/get-data-variant.constants.js'
import { serviceTitles } from './format-output-data.constants.js'
import { carBodyTitles } from './format-output-data.constants.js'
import { radiiTitles } from './format-output-data.constants.js'
import { getDataVariantHelper } from './helpers/get-data-variant.helper.js'
import { DataVariants } from './helpers/get-data-variant.constants.js'
import { serviceTitles } from './format-output-data.constants.js'
import { carBodyTitles } from './format-output-data.constants.js'
import { radiiTitles } from './format-output-data.constants.js'
import { getDataVariantHelper } from './helpers/get-data-variant.helper.js'

export const formatOutputDataHelper = (aqsiData: FormattedPagesDataType): AqsiDataType => {
export const formatOutputDataHelper = (
aqsiData: FormattedPagesDataType
): ServicesDataToReplaceType => {
const output = []

for (const aqsiDataItem of aqsiData) {
Expand Down
8 changes: 4 additions & 4 deletions globals/data/src/helpers/replace-service-price.helper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable no-continue */

import type { AqsiDataType } from '@globals/data'
import type { ServicesDataToReplaceType } from '@globals/data'

import type { RequiredReplaceServicePriceHelperType } from './replace-service-price.interface.js'

export const replaceServicePriceHelper = <T>(
service: RequiredReplaceServicePriceHelperType & T,
aqsiSwervicesData: AqsiDataType
servicesDataToReplace: ServicesDataToReplaceType
): T => {
if (!aqsiSwervicesData.length) return service
if (!servicesDataToReplace.length) return service

if (!service) return service
if (!(typeof service === 'object')) return service
Expand Down Expand Up @@ -38,7 +38,7 @@ export const replaceServicePriceHelper = <T>(

if (!outputPriceData[radiiKey]) outputPriceData[radiiKey] = {}

const findedAqsiServiceData = aqsiSwervicesData.find((aqsiServiceData) => {
const findedAqsiServiceData = servicesDataToReplace.find((aqsiServiceData) => {
const {
service: aqsiServiceTitle,
radii: aqsiRadiiTitle,
Expand Down
12 changes: 6 additions & 6 deletions globals/data/src/helpers/replace-service-prices.helper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { AqsiDataType } from '@globals/data'
import type { ServicesDataType } from '@globals/data'
import type { ServicesDataToReplaceType } from '@globals/data'
import type { ServicesDataType } from '@globals/data'

import { replaceServicePriceHelper } from '@globals/data'
import { replaceServicePriceHelper } from '@globals/data'

export const replaceServicePricesHelper = (
wpServicesData: ServicesDataType,
aqsiSwervicesData: AqsiDataType
servicesDataToReplace: ServicesDataToReplaceType
): ServicesDataType => {
if (!aqsiSwervicesData.length) return wpServicesData
if (!servicesDataToReplace.length) return wpServicesData

const replacedServicePrices = []

Expand All @@ -18,7 +18,7 @@ export const replaceServicePricesHelper = (
// eslint-disable-next-line no-continue
if (!service?.servicesParams) continue

const outputServiceData = replaceServicePriceHelper(service, aqsiSwervicesData)
const outputServiceData = replaceServicePriceHelper(service, servicesDataToReplace)

replacedServicePrices.push(outputServiceData)
}
Expand Down
2 changes: 1 addition & 1 deletion globals/data/src/interfaces/aqsi-data.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type AqsiDataType = Array<{
export type ServicesDataToReplaceType = Array<{
service: string
carBody: string
radii: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export const runIndexPageServerQueries = async () => {
])

const aqsiServicesData = await getAqsiData()
return { aqsiServicesData }
return { servicesDataToReplace: aqsiServicesData }
}
4 changes: 2 additions & 2 deletions site/pages/index-page/src/index-page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { getCarBodiesData } from '@globals/data'

import { useIndexPageClient } from './hooks/index.js'

export const IndexPageClient: FC<IndexPageClientProps> = ({ aqsiServicesData }) => {
export const IndexPageClient: FC<IndexPageClientProps> = ({ servicesDataToReplace }) => {
const { navigation } = getNavigationData()
const { fragments } = getFragmentsData()
const { contacts } = getContactsData()
Expand All @@ -41,7 +41,7 @@ export const IndexPageClient: FC<IndexPageClientProps> = ({ aqsiServicesData })
const { workResults } = getWorkResultsData()
const { carBodies } = getCarBodiesData()

const services = replaceServicePricesHelper(baseServices, aqsiServicesData)
const services = replaceServicePricesHelper(baseServices, servicesDataToReplace)

const headerRef = useRef<HTMLDivElement | null>(null)
const isLoaded = useRef<boolean>(false)
Expand Down
4 changes: 2 additions & 2 deletions site/pages/index-page/src/index-page.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { IndexPageClient } from './index-page.client.js'
import { runIndexPageServerQueries } from './hooks/run-index-page-server-queries.hook.js'

const IndexPage: FC = async () => {
const { aqsiServicesData } = await runIndexPageServerQueries()
const { servicesDataToReplace } = await runIndexPageServerQueries()
// @ts-expect-error not assignable
return <IndexPageClient aqsiServicesData={aqsiServicesData} />
return <IndexPageClient servicesDataToReplace={servicesDataToReplace} />
}

export default memo(IndexPage)
8 changes: 4 additions & 4 deletions site/pages/index-page/src/index-page.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { SEOInt } from '@globals/data'
import type { DataInt } from '@globals/data'
import type { AqsiDataType } from '@globals/data'
import type { SEOInt } from '@globals/data'
import type { DataInt } from '@globals/data'
import type { ServicesDataToReplaceType } from '@globals/data'

export interface SeoProps {
ogCover: string
SEO: SEOInt
}

export interface IndexPageClientProps {
aqsiServicesData: AqsiDataType
servicesDataToReplace: ServicesDataToReplaceType
ogCover: string
SEO: SEOInt
data: DataInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export const runServicePageServerQueries: ServicePageServerProps = async ({ para
])

const aqsiServicesData = await getAqsiData()
return { aqsiServicesData }
return { servicesDataToReplace: aqsiServicesData }
}
12 changes: 6 additions & 6 deletions site/pages/service-page/src/service-page.client.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable */

'use client'

import type { FC } from 'react'
Expand All @@ -24,8 +22,10 @@ import { getBlogPostsData } from '@globals/data'
import { replaceServicePricesHelper } from '@globals/data'
import { replaceServicePriceHelper } from '@globals/data'

// @ts-expect-error param is not exist
export const ServicePageClient: FC<ServicePageClientProps> = ({ params, aqsiServicesData }) => {
export const ServicePageClient: FC<ServicePageClientProps> = ({
params,
servicesDataToReplace,
}) => {
const { uri } = params

const { navigation } = getNavigationData()
Expand All @@ -37,8 +37,8 @@ export const ServicePageClient: FC<ServicePageClientProps> = ({ params, aqsiServ
const { posts } = getBlogPostsData()
const { contacts } = getContactsData()

const services = replaceServicePricesHelper(baseServices, aqsiServicesData)
const serviceBy = replaceServicePriceHelper(baseServiceBy, aqsiServicesData)
const services = replaceServicePricesHelper(baseServices, servicesDataToReplace)
const serviceBy = replaceServicePriceHelper(baseServiceBy, servicesDataToReplace)

return (
<Column width='100%' alignItems='center'>
Expand Down
8 changes: 2 additions & 6 deletions site/pages/service-page/src/service-page.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ServicePageClient } from './service-page.client.js'
import { runServicePageServerQueries } from './hooks/index.js'

const ServicePage: ServicePageProps = async ({ params }) => {
const { aqsiServicesData } = await runServicePageServerQueries({ params })
const { servicesDataToReplace } = await runServicePageServerQueries({ params })
const { uri } = params
return (
<PreloadQuery
Expand All @@ -20,11 +20,7 @@ const ServicePage: ServicePageProps = async ({ params }) => {
uri,
}}
>
<ServicePageClient
// @ts-expect-error params is not assignable
params={params}
aqsiServicesData={aqsiServicesData}
/>
<ServicePageClient params={params} servicesDataToReplace={servicesDataToReplace} />
</PreloadQuery>
)
}
Expand Down
21 changes: 6 additions & 15 deletions site/pages/service-page/src/service-page.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import type { SEOInt } from '@globals/data'
import type { DataInt } from '@globals/data'
import type { AqsiDataType } from '@globals/data'

export interface ServicePageClientProps {
aqsiServicesData: AqsiDataType
SEO: SEOInt
ogCover: string
data: DataInt
}
import type { ServicesDataToReplaceType } from '@globals/data'

type ParamsType = {
uri: string
}

export interface ServicePageClientProps {
params: ParamsType
servicesDataToReplace: ServicesDataToReplaceType
}

export type ServicePageProps = ({ params }: { params: ParamsType }) => Promise<JSX.Element>

export type ServicePageServerProps = ({
params,
}: {
params: ParamsType
}) => Promise<ServicePageClientProps>

export interface SeoProps {
ogCover: string
SEO: SEOInt
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export const runServicesPageServerQueries: ServicesPageServerProps = async () =>
])

const aqsiServicesData = await getAqsiData()
return { aqsiServicesData }
return { servicesDataToReplace: aqsiServicesData }
}
4 changes: 2 additions & 2 deletions site/pages/services-page/src/services-page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import { getNavigationData } from '@globals/data'
import { getServicesData } from '@globals/data'
import { replaceServicePricesHelper } from '@globals/data'

export const ServicesPageClient: FC<ServicesPageClientProps> = ({ aqsiServicesData }) => {
export const ServicesPageClient: FC<ServicesPageClientProps> = ({ servicesDataToReplace }) => {
const { fragments } = getFragmentsData()
const { contacts } = getContactsData()
const { navigation } = getNavigationData()
const { availableRadii } = getAvailableRadiiData()
const { services: baseServices } = getServicesData()
const { carBodies } = getCarBodiesData()

const services = replaceServicePricesHelper(baseServices, aqsiServicesData)
const services = replaceServicePricesHelper(baseServices, servicesDataToReplace)

return (
<Column width='100%' alignItems='center'>
Expand Down
4 changes: 2 additions & 2 deletions site/pages/services-page/src/services-page.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { ServicesPageClient } from './services-page.client.js'
import { runServicesPageServerQueries } from './hooks/index.js'

const ServicesPage: ServicesPageProps = async () => {
const { aqsiServicesData } = await runServicesPageServerQueries()
const { servicesDataToReplace } = await runServicesPageServerQueries()
// @ts-expect-error incorrect types
return <ServicesPageClient aqsiServicesData={aqsiServicesData} />
return <ServicesPageClient servicesDataToReplace={servicesDataToReplace} />
}

export default ServicesPage
4 changes: 2 additions & 2 deletions site/pages/services-page/src/services-page.interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { AqsiDataType } from '@globals/data'
import type { ServicesDataToReplaceType } from '@globals/data'

export type ServicesPageProps = () => Promise<JSX.Element>

export interface ServicesPageClientProps {
serverQueryData: SeoProps
aqsiServicesData: AqsiDataType
servicesDataToReplace: ServicesDataToReplaceType
}

export type ServicesPageServerProps = () => Promise<ServicesPageClientProps>
Expand Down

0 comments on commit 3e21ffc

Please sign in to comment.