import { Link, useForm } from '@inertiajs/react'; import { useState } from 'react'; 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; }; type Props = { 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 }; 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)} />
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)} /> ))}