diff --git a/frontend/src/routes/vendors/$slug.tsx b/frontend/src/routes/vendors/$slug.tsx index 09bc445..8aa1db5 100644 --- a/frontend/src/routes/vendors/$slug.tsx +++ b/frontend/src/routes/vendors/$slug.tsx @@ -1,5 +1,149 @@ -import { createFileRoute } from '@tanstack/react-router' +import { useSuspenseQuery } from '@tanstack/react-query' +import { createFileRoute, Link, notFound } from '@tanstack/react-router' +import { iso31661 } from 'iso-3166' +import { Facebook, Globe, Linkedin, Twitter } from 'lucide-react' +import { Helmet } from 'react-helmet-async' + +import { Button } from '~/components/ui/button' +import { assetUrl } from '~/lib/directus' +import { vendorBySlugQuery } from '~/lib/queries' export const Route = createFileRoute('/vendors/$slug')({ - component: () => null, + loader: async ({ context: { queryClient }, params: { slug } }) => { + const vendor = await queryClient.ensureQueryData(vendorBySlugQuery(slug)) + if (!vendor) throw notFound() + }, + component: VendorDetailPage, }) + +function countryName(alpha3: string | null | undefined): string { + if (!alpha3) return '' + return iso31661.find((iso) => iso.alpha3 === alpha3)?.name ?? '' +} + +function VendorDetailPage() { + const { slug } = Route.useParams() + const { data: vendor } = useSuspenseQuery(vendorBySlugQuery(slug)) + if (!vendor) return null + + const country = countryName(vendor.country) + const hasSocial = vendor.website || vendor.facebook || vendor.linkedin || vendor.twitter + const hasAddress = vendor.address_line_1 || vendor.address_line_2 || vendor.city || vendor.state || country + + return ( +
+ + {vendor.name} + + +
+

{vendor.name}

+ {vendor.logo && ( + {vendor.name} + )} +
+ + {vendor.long_description && ( +
+ )} + +
+ {hasAddress && ( +
+

Address

+

+ {vendor.address_line_1 && ( + <> + {vendor.address_line_1} +
+ + )} + {vendor.address_line_2 && ( + <> + {vendor.address_line_2} +
+ + )} + {vendor.city && ( + <> + {vendor.city} +
+ + )} + {vendor.state && ( + <> + {vendor.state} +
+ + )} + {country && <>{country}} +

+
+ )} + + {hasSocial && ( +
+

Social

+ +
+ )} + + {vendor.categories.length > 0 && ( +
+

Categories

+
    + {vendor.categories.map((cat) => ( +
  • + +
  • + ))} +
+
+ )} +
+
+ ) +}