158 lines
6.1 KiB
TypeScript
158 lines
6.1 KiB
TypeScript
import { Link } from '@inertiajs/react';
|
||
import { Frame, button, card } from './shared';
|
||
import { businessModalities } from './business-types';
|
||
import PartnershipSourceLinks from '@/components/partnership-source-links';
|
||
import SimilarBusinesses, {
|
||
BusinessLocationSource,
|
||
} from '@/components/similar-businesses';
|
||
import { downloadPublicBusinessOffline } from '@/lib/public-business-offline';
|
||
import { useState } from 'react';
|
||
import {
|
||
ClassificationSummary,
|
||
type PublicClassification,
|
||
} from '@/components/opportunity-classification';
|
||
|
||
type Business = {
|
||
multidimensional?: PublicClassification[];
|
||
id: string;
|
||
slug: string;
|
||
title: string;
|
||
modality: string;
|
||
objective?: string | null;
|
||
stage?: string | null;
|
||
activity_code?: string | null;
|
||
amount_min?: string | null;
|
||
amount_max?: string | null;
|
||
available_percentage?: string | null;
|
||
currency?: string | null;
|
||
province?: string | null;
|
||
district?: string | null;
|
||
locality?: string | null;
|
||
sector?: { name: string; slug: string } | null;
|
||
published_at?: string | null;
|
||
location_recorded_at?: string | null;
|
||
location_source_reference?: string | null;
|
||
location_source_date?: string | null;
|
||
};
|
||
|
||
export default function BusinessOpportunity({
|
||
record,
|
||
returnUrl = '/negocios',
|
||
interestUrl = `/negocios/${record.slug}/manifestar-interesse`,
|
||
similarCatalogueUrl,
|
||
similarRadiusAvailable = false,
|
||
}: {
|
||
record: Business;
|
||
returnUrl?: string;
|
||
interestUrl?: string;
|
||
similarCatalogueUrl?: string;
|
||
similarRadiusAvailable?: boolean;
|
||
}) {
|
||
const [offlineMessage, setOfflineMessage] = useState('');
|
||
return (
|
||
<Frame title={record.title}>
|
||
<Link
|
||
className={button}
|
||
href={'/investimentos/iniciar?source=business:' + record.id}
|
||
>
|
||
Iniciar ou continuar investimento com este negócio
|
||
</Link>
|
||
<PartnershipSourceLinks type="business" id={record.id} />
|
||
<Link href={returnUrl} className="underline">
|
||
Voltar às oportunidades
|
||
</Link>
|
||
<section className={`${card} space-y-4`}>
|
||
{!!record.multidimensional?.length && (
|
||
<ClassificationSummary rows={record.multidimensional} />
|
||
)}
|
||
<p>{businessModalities[record.modality] ?? record.modality}</p>
|
||
<p>
|
||
{[record.sector?.name, record.stage, record.activity_code]
|
||
.filter(Boolean)
|
||
.join(' · ')}
|
||
</p>
|
||
{(record.province || record.district || record.locality) && (
|
||
<p>
|
||
{[record.locality, record.district, record.province]
|
||
.filter(Boolean)
|
||
.join(', ')}
|
||
</p>
|
||
)}
|
||
<BusinessLocationSource record={record} showRecorded />
|
||
{(record.amount_min || record.amount_max) && (
|
||
<p>
|
||
Montante indicativo: {record.amount_min ?? '—'} –{' '}
|
||
{record.amount_max ?? '—'} {record.currency}
|
||
</p>
|
||
)}
|
||
{record.available_percentage && (
|
||
<p>Participação indicada: {record.available_percentage}%</p>
|
||
)}
|
||
{record.objective && (
|
||
<div>
|
||
<h2 className="font-bold">Objectivo</h2>
|
||
<p className="whitespace-pre-wrap">
|
||
{record.objective}
|
||
</p>
|
||
</div>
|
||
)}
|
||
<p className="text-sm">
|
||
A publicação não constitui garantia de titularidade,
|
||
avaliação, transmissibilidade ou retorno.
|
||
</p>
|
||
<Link className={button} href={interestUrl}>
|
||
Manifestar interesse
|
||
</Link>
|
||
<div className="space-y-2">
|
||
<button
|
||
type="button"
|
||
className="underline"
|
||
onClick={() => {
|
||
try {
|
||
downloadPublicBusinessOffline(
|
||
record,
|
||
businessModalities[record.modality] ??
|
||
record.modality,
|
||
);
|
||
setOfflineMessage(
|
||
'Ficheiro preparado. Guarde-o e abra-o para consultar esta ficha sem rede.',
|
||
);
|
||
} catch {
|
||
setOfflineMessage(
|
||
'Não foi possível preparar o ficheiro. Tente novamente.',
|
||
);
|
||
}
|
||
}}
|
||
>
|
||
Guardar ficha para consulta offline (.html)
|
||
</button>
|
||
<p role="status" aria-live="polite">
|
||
{offlineMessage}
|
||
</p>
|
||
</div>
|
||
</section>
|
||
{similarCatalogueUrl && (
|
||
<SimilarBusinesses
|
||
currentId={record.id}
|
||
classifications={record.multidimensional}
|
||
catalogueUrl={similarCatalogueUrl}
|
||
radiusAvailable={similarRadiusAvailable}
|
||
areaLabel={
|
||
record.province &&
|
||
new URL(
|
||
similarCatalogueUrl,
|
||
'https://portal.invalid',
|
||
).searchParams.has('province_id')
|
||
? record.province
|
||
: undefined
|
||
}
|
||
criteria={[
|
||
businessModalities[record.modality] ?? record.modality,
|
||
...(record.sector ? [record.sector.name] : []),
|
||
]}
|
||
/>
|
||
)}
|
||
</Frame>
|
||
);
|
||
}
|