'use client'; import React, { useEffect, useState } from 'react'; import { useSearchParams } from 'next/navigation'; import { List, Tag } from 'antd'; import { RightOutlined } from '@ant-design/icons'; import isEqual from 'lodash/isEqual'; import Image from 'next/image'; import { Link, useRouter } from '../../i18n/routing'; import { ExpertsData, Filter, GeneralFilter } from '../../types/experts'; import { getObjectByFilter, getObjectByAdditionalFilter, getSearchParamsString } from '../../utils/filter'; import { getDuration, getPrice } from '../../utils/expert'; import { getExpertsList } from '../../actions/experts'; import { CustomPagination } from '../view/CustomPagination'; import { CustomSpin } from '../view/CustomSpin'; import { i18nText } from '../../i18nKeys'; type ExpertListProps = { data?: ExpertsData; locale: string; baseFilter: Filter; pageSize: number; basePath: string; }; export const ExpertsList = ({ data, locale, baseFilter, pageSize, basePath }: ExpertListProps) => { const searchParams = useSearchParams(); const router = useRouter(); const [experts, setExperts] = useState(); const [loading, setLoading] = useState(true); useEffect(() => { const filter = { ...baseFilter, ...getObjectByFilter(searchParams), ...getObjectByAdditionalFilter(searchParams) }; if (!isEqual(baseFilter, filter)) { setLoading(true); getExpertsList(locale, filter) .then((experts) => { setExperts(experts); }) .finally(() => { setLoading(false); }) ; } else { setLoading(false); setExperts(data); } }, [searchParams]); const onChangePage = (page: number) => { const newFilter: GeneralFilter = { ...getObjectByFilter(searchParams), ...getObjectByAdditionalFilter(searchParams) }; if (page !== 1) { newFilter.page = page; } else { delete newFilter.page; } const search = getSearchParamsString(newFilter); router.push(search ? `${basePath}?${search}#filter` : `${basePath}#filter`); }; const currentPage = searchParams.has('page') ? Number(searchParams.get('page')) : baseFilter.page; return !loading ? experts?.coaches && ( <> ( )} description={(
{`${item.name} ${item?.surname || ''}`}
{getPrice(item?.sessionCost)} / {getDuration(locale, item?.sessionDuration)}
{item?.coachLanguages?.map((lang) => ( {lang} ))}
)} />
{item?.tags?.slice(0, 2).map((skill) => {skill?.name})} {item?.tags?.length > 2 ? ( {`+${item?.tags?.length - 2}`} ) : null}
{item?.speciality}
{item?.specialityDesc}
{item?.description}
{i18nText('details', locale)}
)} /> {experts.total > pageSize && ( )} ) : ; };