summaryrefslogtreecommitdiff
path: root/src/core/components/elements/Navbar/TopBanner.jsx
blob: f9ac70321e478e9ca02e4874bb6e06f8c1508f26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Image from 'next/image';
import { useQuery } from 'react-query';

import odooApi from '@/core/api/odooApi';
import SmoothRender from '~/components/ui/smooth-render';
import Link from '../Link/Link';

const TopBanner = () => {
  const topBanner = useQuery({
    queryKey: 'topBanner',
    queryFn: async () => await odooApi('GET', '/api/v1/banner?type=top-banner'),
    refetchOnWindowFocus: false,
  });

  const backgroundColor = topBanner.data?.[0]?.backgroundColor || 'transparent';
  const hasData = topBanner.data?.length > 0;
  const data = topBanner.data?.[0] || null;

  return (
    <SmoothRender
      isLoaded={hasData}
      height='36px'
      duration='700ms'
      delay='500ms'
      style={{ backgroundColor }}
    >
      <Link href={data?.url}>
        <Image
          src={data?.image}
          alt={data?.name}
          width={1440}
          height={40}
          className='object-cover object-center h-full mx-auto'
        />
      </Link>
    </SmoothRender>
  );
};

export default TopBanner;