"use client"; import { LocationIcon } from "@/assets/icons"; import Breadcrumb from "@/components/Breadcrumbs/Breadcrumb"; import { ShowcaseSection } from "@/components/Layouts/showcase-section"; import Loading from "@/components/loading"; import Status from "@/components/ui/Status"; import { useTenderDetailQuery } from "@/hooks/queries"; import { useGetFlagQuery } from "@/hooks/queries/useFlagsQueries"; import { cn } from "@/lib/utils"; import { isValidAlpha2CountryCode, truncateString, unixToDate, } from "@/utils/shared"; import getSymbolFromCurrency from "currency-symbol-map"; import Link from "next/link"; import { use } from "react"; interface IProps { params: Promise<{ details: string; }>; } const isValidDisplayCountryCode = (code: string) => /^[A-Za-z]{2,3}$/.test(code); function SectionHeading({ children }: { children: React.ReactNode }) { return (

{children}

); } function ExternalLinkIcon({ className }: { className?: string }) { return ( ); } /** Body area only: center content in the card; ShowcaseSection `title` is unchanged */ const SHOWCASE_CENTERED_BODY = { rootClassName: "flex h-full min-h-0 flex-col", className: "flex min-h-0 flex-1 flex-col items-center justify-center text-center", } as const; const TenderDetails = ({ params }: IProps) => { const { details } = use(params); const { data, isLoading, isError } = useTenderDetailQuery(details); const countryCodeNormalized = data?.data.country_code?.trim().toUpperCase() ?? ""; const hasValidCountryCodeForDisplay = isValidDisplayCountryCode(countryCodeNormalized); const canLoadCountryFlag = isValidAlpha2CountryCode(countryCodeNormalized); const { data: flagData } = useGetFlagQuery(countryCodeNormalized, { enabled: canLoadCountryFlag, }); const breadcrumbItems = [ { name: "Dashboard", href: "/" }, { name: "Tenders", href: "/tenders" }, { name: "Tender details", href: `/tenders/${details}` }, ]; if (isLoading) return ; if (isError) { return ( <>

We couldn't load this tender

Check your connection or try again. You can go back to the tender list anytime.

Back to tenders
); } const tender = data!.data; const submissionUrl = tender.submission_url?.trim(); const currencyCode = tender.currency?.trim().toUpperCase() ?? ""; const hasValidCurrency = Boolean(currencyCode); const hasValidEstimatedValue = typeof tender.estimated_value === "number" && Number.isFinite(tender.estimated_value) && tender.estimated_value > 0; const hasValidLocationCurrencyOrValue = hasValidCountryCodeForDisplay || hasValidCurrency || hasValidEstimatedValue; return ( <>

Tender

{tender.title}

{tender.status} {submissionUrl && ( Open submission )}
} className="!p-0" >
Procurement
{tender.tender_id} {tender.buyer_organization.name} {tender.notice_publication_id} {tender.procedure_code} {tender.procurement_type_code}
Timeline
{submissionUrl && ( {truncateString(submissionUrl, 42)} )}
{hasValidLocationCurrencyOrValue && (
Location & currency
{hasValidCountryCodeForDisplay && (

Country

{countryCodeNormalized} {flagData && (
)}
)} {hasValidCurrency && (

Currency

{currencyCode} {getSymbolFromCurrency(currencyCode || "USD")}
)} {hasValidEstimatedValue && (

Estimated value

{new Intl.NumberFormat().format(tender.estimated_value)} {hasValidCurrency && ( {currencyCode} )}
)}
)}
Description

{tender.description || "—"}

); }; export default TenderDetails;