remove unused abonements API configuration and endpoints add escape key handler for drawer component implement text truncation for service descriptions sync swiper navigation between service tabs and content add static gym rental service to services list
96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
import type { servicesSchema } from '@/content.config'
|
|
import type { z } from 'astro/zod'
|
|
import { YCLIENTS_TOKEN, YCLIENTS_API_URL } from 'astro:env/server'
|
|
|
|
type HTML = string
|
|
const currencyFormatter = Intl.NumberFormat('ru', { currency: 'rub' })
|
|
|
|
const RENT_GYM_SERVICE: z.infer<typeof servicesSchema> = {
|
|
title: 'Аренда зала',
|
|
charachteristics: [
|
|
{
|
|
title: 'Разовое посещение',
|
|
description: 'Разовое посещение студии для самостоятельной тренировки',
|
|
price: `${currencyFormatter.format(1500)} ₽`,
|
|
link: {
|
|
title: 'Записаться',
|
|
href: 'https://n1381542.yclients.com/company/1254211/activity/select?o=act',
|
|
},
|
|
},
|
|
],
|
|
}
|
|
|
|
export type YclientsBookinRawResponse = {
|
|
category: {
|
|
id: number
|
|
title: string
|
|
}[]
|
|
services: {
|
|
id: number
|
|
title: string
|
|
price_min: number
|
|
price_max: number
|
|
discount: number
|
|
comment: string
|
|
weight: number
|
|
active: number
|
|
sex: number
|
|
image: string
|
|
category_id: number
|
|
}[]
|
|
}
|
|
|
|
export type YClientsAbonementRawItem = {
|
|
id: number
|
|
image: string
|
|
online_sale_title: string
|
|
online_sale_description: HTML
|
|
online_sale_price: number
|
|
online_sale_image: string
|
|
cost: number
|
|
price: number
|
|
}
|
|
|
|
export type YclientsAbonementsRawResponse = {
|
|
data: {
|
|
loyalty_abonement_types: YClientsAbonementRawItem[]
|
|
}
|
|
}
|
|
|
|
const fetcher = <R>(...[path, options = {}]: Parameters<typeof fetch>): Promise<R> =>
|
|
fetch(path, {
|
|
...options,
|
|
headers: {
|
|
Authorization: `Bearer ${YCLIENTS_TOKEN}`,
|
|
...(options.headers || {}),
|
|
},
|
|
}).then((res) => res.json() as Promise<R>)
|
|
|
|
export const yclientsClient = {
|
|
async getServices(): Promise<z.infer<typeof servicesSchema>[]> {
|
|
const booking = await fetcher<YclientsBookinRawResponse>(
|
|
`${YCLIENTS_API_URL}/book_services/1254211`,
|
|
{
|
|
method: 'GET',
|
|
}
|
|
)
|
|
|
|
const services = booking.category.map((categoryItem) => ({
|
|
title: categoryItem.title,
|
|
charachteristics: booking.services
|
|
.filter((service) => service.category_id === categoryItem.id)
|
|
.map((service) => ({
|
|
title: service.title,
|
|
price: `${currencyFormatter.format(service.price_min)} ₽`,
|
|
description: service.comment,
|
|
link: {
|
|
title: 'Записаться',
|
|
href: `https://n1381542.yclients.com/company/1254211/personal/select-services?o=s${service.id}`,
|
|
},
|
|
})),
|
|
}))
|
|
|
|
return [services[0], RENT_GYM_SERVICE, ...services.slice(1)]
|
|
},
|
|
}
|