'use client'; import { Image } from '@akinon/next/components'; import { useGetWidgetQuery } from '@akinon/next/data/client/misc'; import { useLocalization } from '@akinon/next/hooks'; import { WidgetResultType } from '@akinon/next/types'; import { LoaderSpinner } from '@theme/components'; import { formatDateToMonthYear } from '@theme/utils/formatDate'; interface BlogImageData { value: string; data_type: 'image'; url: string; } interface BlogItemValue { link: string; image: string; title: string; description: string; date: string; } interface BlogItemKwargs { value: { image: BlogImageData; }; data_type: 'nested'; } interface BlogItem { value: BlogItemValue; kwargs: BlogItemKwargs; } interface BlogListAttributes { blogs: BlogItem[]; } export default function BlogList() { const { locale, t } = useLocalization(); const { data, isLoading } = useGetWidgetQuery('blog-list') as ReturnType< typeof useGetWidgetQuery >; const blogData = data as WidgetResultType | undefined; if (isLoading) { return (
); } if (!blogData) { return (

{t('blog.no_blog_posts')}

); } return (
{blogData.attributes?.blogs?.length ? (
{blogData.attributes.blogs.map((blogItem, index) => (
{blogItem.value.title} {blogItem.value.title}

{blogItem.value.title}

{formatDateToMonthYear( blogItem.value.date, locale as any )}

{blogItem.value.description}

))}
) : (

{t('blog.no_blog_posts')}

)}
); }