import { Link, router } from '@inertiajs/react'; import { useState } from 'react'; import { Frame, Field, input, button, card, api } from './shared'; import { businessModalities, businessStates } from './business-types'; import type { Business } from './business-types'; import BusinessObjects from './business-objects'; import type { BusinessObject } from './business-objects'; import BusinessVerifications from './business-verifications'; import type { BusinessVerification } from './business-verifications'; import BusinessWizard from './business-wizard'; import type { FormSchema } from './business-wizard'; import type { Country } from '@/components/country-select'; import BusinessPointSummary, { type RegisteredBusinessLocation, } from '@/components/business-point-summary'; import { businessPointTerritoryLabel } from '@/lib/business-locations'; type Props = { countries: Country[]; formSchema: FormSchema; modalityFormType?: string | null; sectors: { id: number; name: string }[]; record: Business; canEdit: boolean; registeredLocation?: RegisteredBusinessLocation | null; pointPublicationAvailable?: boolean; owner: boolean; canReview: boolean; canTriage: boolean; canApproveLevelOne: boolean; canApproveLevelTwo: boolean; canPublish: boolean; modalities: string[]; objects: BusinessObject[]; objectKinds: string[]; verificationChecks: string[]; verifications: BusinessVerification[]; history: { version_no: number; action: string; created_at: string; note: string; }[]; }; export default function BusinessPage(props: Props) { if (props.canEdit) return ( ); return ( ); } function Editor({ record, canEdit, owner, canReview, canTriage, canApproveLevelOne, canApproveLevelTwo, canPublish, modalities, history, objects, objectKinds, verificationChecks, verifications, formSchema, sectors, registeredLocation, pointPublicationAvailable, }: Props) { const [payload, setPayload] = useState(record.payload); const [modality, setModality] = useState(record.modality); const [note, setNote] = useState(''); const [consent, setConsent] = useState(false); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const dirty = JSON.stringify(payload) !== JSON.stringify(record.payload) || modality !== record.modality; const run = async (action?: string) => { setBusy(true); setError(''); try { await api( `/api/v1/existing-business/listings/${record.id}${action ? '/transitions' : ''}`, action ? { action, version_no: record.version_no, note, review_consent: consent, } : { _method: 'PUT', modality, classification: record.classification, payload, reason: note, version_no: record.version_no, }, ); router.reload(); } catch (err) { setError( err instanceof Error ? err.message : 'Não foi possível guardar. Recarregue se a versão mudou.', ); } finally { setBusy(false); } }; return (

Classificação multidimensional deste anúncio

Voltar à lista

{businessStates[record.status]} · versão {record.version_no} · informação reservada

Informação declarada, pendente de validação. Não constitui anúncio público, certificação, avaliação ou autorização de transmissão.

{!canEdit && (
Sector
{sectors.find( (sector) => sector.id === record.sector_id, )?.name ?? '—'}
{Object.entries(formSchema) .filter( ([key, field]) => !key.startsWith('location_point_') && ![ 'location_latitude', 'location_longitude', ].includes(key) && Object.entries(field.when ?? {}).every( ([dependency, values]) => values.includes( record.payload[dependency] ?? '', ), ) && ![ 'title', 'description', 'declared_reason', 'source_reference', 'valid_until', ].includes(key), ) .map(([key, field]) => (
{field.pt}
{record.payload[key] || '—'}
))}
)}
{ e.preventDefault(); void run(); }} >
{( [ ['title', 'Título privado'], ['description', 'Descrição reservada'], ['declared_reason', 'Motivo declarado'], ['source_reference', 'Referência da fonte'], ['valid_until', 'Validade declarada'], ] as const ).map(([key, label]) => ( {key === 'description' ? (