import { Link, router, useForm } from '@inertiajs/react'; import { useCallback, useEffect, useState } from 'react'; import { portalRequest, PortalApiError, newSubmissionKey, } from '@/lib/portal-api'; import EducationSubmittedSnapshot, { type EducationDraft, type EducationDraftSummary, } from '@/components/education-submitted-snapshot'; import { Management, Field, control, button, Pagination, } from '../management/shared'; import type { Paginated } from '../management/shared'; import { TerritoryFields, type TerritoryOption, } from '@/components/investment-territory'; type Option = { id: string; name?: string; title?: string; code?: string }; type RecordRow = { id: string; qualification: string; quantity: number; status: string; version_no: number; valid_until: string; period_start: string; period_end: string; source: string; can_review?: boolean; review_unavailable?: 'self' | 'expired' | null; details_url?: string; }; type WorkCounts = { total: number; submitted: number; reviewed: number; rejected: number; expired: number; to_review: number; }; type Props = { workQueue?: { actor_id: number; drafts: number | null; demands: WorkCounts; capacities: WorkCounts; }; draftsAvailable?: boolean; selectedDraft?: EducationDraft | null; ownDrafts?: Paginated | null; demands: Paginated; capacities: Paginated; skills: Option[]; occupations: Option[]; providers: Option[]; courses: Option[]; projects: Option[]; territories: TerritoryOption[]; today: string; filters: { q?: string; status?: string; geo_location_id?: string; scope?: 'all' | 'mine' | 'review'; }; indicators: { demand_records: number; capacity_records: number; expired_demands: number; pending_demands: number; }; }; const territoryLevels = ['province', 'district', 'admin_post', 'locality']; function territoryPath( id: string, territories: TerritoryOption[], ): TerritoryOption[] { const byId = new Map( territories.map((territory) => [territory.id, territory]), ); const path: TerritoryOption[] = []; let current = byId.get(id); while (current && path.length < territoryLevels.length) { if (territoryLevels.includes(current.location_type)) path.unshift(current); current = current.parent_id ? byId.get(current.parent_id) : undefined; } return path; } function Errors({ errors }: { errors: Record }) { return ( <> {Object.entries(errors).map(([key, value]) => (

{value}

))} ); } function Select({ label, value, options, onChange, }: { label: string; value: string; options: Option[]; onChange: (value: string) => void; }) { return ( ); } function Catalog({ kind, title, providers, }: { kind: string; title: string; providers: Option[]; }) { const form = useForm({ name: '', title: '', code: '', provider_id: '' }); return (
{title}
{ e.preventDefault(); form.post(`/management/education/catalog/${kind}`, { onSuccess: () => form.reset(), }); }} > form.setData( kind === 'courses' ? 'title' : 'name', e.target.value, ) } /> {kind !== 'providers' && ( form.setData('code', e.target.value) } /> )} {kind === 'courses' && ( form.setData(demand ? 'project_id' : 'course_id', v) } /> form.setData('skill_id', v)} />
{initial?.payload.geo_location_id && form.data.geo_location_id === initial.payload.geo_location_id && initialPath.length === 0 && (

O local guardado já não consta do cadastro disponível. A referência foi conservada; escolha uma localização actual antes de submeter.

)} form.setData( 'geo_location_id', path[path.length - 1]?.id ?? '', ) } />
{demand && ( form.setData('employer', e.target.value) } /> )} form.setData('qualification', e.target.value) } /> form.setData('quantity', e.target.value) } /> {( [ 'period_start', 'period_end', 'reference_date', 'valid_until', ] as const ).map((key) => ( form.setData(key, e.target.value) } /> ))}