mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
56655d53b4
* feat(admin): register AirTrail as an integration addon
Off by default; toggle lives in Admin -> Addons with a Plane icon. The
per-user connection (URL + API key) follows in integration settings.
* feat(integrations): add per-user AirTrail connection
Settings -> Integrations gains an AirTrail section: instance URL + Bearer
API key (encrypted at rest via apiKeyCrypto), a self-signed-TLS opt-in and
a test-connection check. Served by a small Nest controller under
/api/integrations/airtrail, gated on the airtrail addon and SSRF-guarded.
The key is per-user, so it only ever returns that user's own flights.
* feat(transport): import flights from AirTrail
Adds an AirTrail Import button next to Manual Transport that lists the
user's AirTrail flights and highlights the ones inside the trip dates.
Selected flights become reservations linked to their AirTrail origin
(external_* columns), deduped against flights already in the trip, then
broadcast to every member. The mapping resolves airports, airport-local
times and flight metadata; the linkage is what the two-way sync rides on.
* feat(transport): badge AirTrail-linked flights as synced
Linked reservations show an 'AirTrail synced' badge, or 'no longer
synced' once the flight is gone from AirTrail.
* feat(transport): keep TREK and AirTrail flights in sync both ways
A scheduled poll reconciles each connected owner's flights: field edits
(detected by snapshot hash, since AirTrail has no updated_at) flow into
the linked reservation and broadcast live; a flight deleted in AirTrail
keeps the TREK row but stops syncing. Editing a linked flight in TREK
pushes back to AirTrail under the importer's credentials, preserving the
existing seat manifest; if the owner disconnected the link detaches so the
poll can't revert the local edit. Deleting in TREK never touches AirTrail.
* i18n(airtrail): add AirTrail strings across all locales
* test(airtrail): cover flight mapping, timezones and snapshot hashing
* fix(airtrail): reduce airline/aircraft objects to codes
The flight list/get response returns airline and aircraft as joined
objects ({icao, iata, name, ...}), not bare codes. Mapping them straight
through produced '[object Object]' titles and stored objects in metadata,
which crashed reservation rendering. Extract the ICAO/IATA code instead,
and title flights by their flight number.
* fix(airtrail): clear error on non-JSON responses, tolerate /api in URL
A misconfigured instance URL made AirTrail serve its SPA/login HTML, and
the raw JSON.parse failure surfaced as 'Unexpected token <'. Surface an
actionable message instead, and strip a pasted trailing /api so the base
URL still resolves.
* feat(transport): sync AirTrail edits on trip open, not just on the poll
Add a per-user on-demand sync (POST /integrations/airtrail/sync) triggered
when a connected user opens a trip, so AirTrail-side edits appear right away
instead of waiting up to a full poll cycle. Lower the background poll from 15
to 5 minutes as a safety net.
* fix(transport): refresh imported AirTrail flights without a reload
loadTrip doesn't fetch reservations, so a freshly imported flight only
appeared after a full page reload — use loadReservations instead. Also show
flight dates in the user's locale format (e.g. 13.06.2026) rather than the
raw ISO string.
* style(settings): align AirTrail connection with the photo-provider layout
Match the Immich section: stacked URL/key fields, a ToggleSwitch for
self-signed TLS, and a Save / Test-connection row with a status badge.
* feat(transport): add a seat field when editing flights
The transport editor only offered a seat field for trains; flights had
none even though imports store metadata.seat. Show and persist a seat for
flights too.
* style(transport): match the AirTrail button height to Manual Transport
* feat(transport): put the flight seat next to flight number and sync it to AirTrail
Move the seat from a standalone row to the per-leg flight details (beside
the flight number), stored per leg in metadata.legs[].seat with the first
leg mirrored to metadata.seat. On push, set the seat number on the user's
own AirTrail seat (the one with a userId), leaving co-passengers untouched;
import/poll read that same seat back.
* refactor(planner): move the AirTrail trip-open sync into useTripPlanner
Page containers must not own state/effects (lint:pages). Same logic,
relocated from the page into its data hook.
* test(db): pin the region-reconciliation test to its schema version
The test re-ran 'the last migration' assuming the reconciliation is last;
it no longer is once later migrations are appended. Pin to version 135 and
re-run from there (the appended migrations are idempotent).
148 lines
5.7 KiB
TypeScript
148 lines
5.7 KiB
TypeScript
import React, { useEffect, useState } from 'react'
|
|
import { Plane, Save } from 'lucide-react'
|
|
import { useTranslation } from '../../i18n'
|
|
import { useToast } from '../shared/Toast'
|
|
import { airtrailApi } from '../../api/client'
|
|
import Section from './Section'
|
|
import ToggleSwitch from './ToggleSwitch'
|
|
|
|
/**
|
|
* Settings → Integrations → AirTrail. Per-user connection to a self-hosted
|
|
* AirTrail instance (URL + Bearer API key). Mirrors the photo-provider (Immich)
|
|
* connection layout: stacked fields, a toggle, then Save / Test-connection with
|
|
* a status badge. The key is stored encrypted and never prefilled.
|
|
*/
|
|
export default function AirTrailConnectionSection(): React.ReactElement {
|
|
const { t } = useTranslation()
|
|
const toast = useToast()
|
|
|
|
const [url, setUrl] = useState('')
|
|
const [apiKey, setApiKey] = useState('')
|
|
const [allowInsecureTls, setAllowInsecureTls] = useState(false)
|
|
const [connected, setConnected] = useState(false)
|
|
const [loading, setLoading] = useState(true)
|
|
const [saving, setSaving] = useState(false)
|
|
const [testing, setTesting] = useState(false)
|
|
|
|
useEffect(() => {
|
|
airtrailApi
|
|
.getSettings()
|
|
.then(d => {
|
|
setUrl(d.url || '')
|
|
setAllowInsecureTls(!!d.allowInsecureTls)
|
|
setConnected(!!d.connected)
|
|
})
|
|
.catch(() => {})
|
|
.finally(() => setLoading(false))
|
|
}, [])
|
|
|
|
// Send the key only when the user typed a new one — never prefilled, so a blank
|
|
// field means "keep the stored key".
|
|
const keyPayload = (): { apiKey?: string } => {
|
|
const k = apiKey.trim()
|
|
return k ? { apiKey: k } : {}
|
|
}
|
|
|
|
const handleSave = async () => {
|
|
setSaving(true)
|
|
try {
|
|
const d = await airtrailApi.saveSettings({ url: url.trim(), allowInsecureTls, ...keyPayload() })
|
|
const status = await airtrailApi.status().catch(() => ({ connected: false }))
|
|
setConnected(!!status.connected)
|
|
setApiKey('')
|
|
if (d?.warning) toast.warning(d.warning)
|
|
else toast.success(t('settings.airtrail.toast.saved'))
|
|
} catch (err: any) {
|
|
toast.error(err?.response?.data?.error || t('settings.airtrail.toast.saveError'))
|
|
} finally {
|
|
setSaving(false)
|
|
}
|
|
}
|
|
|
|
const handleTest = async () => {
|
|
setTesting(true)
|
|
try {
|
|
const d = await airtrailApi.test({ url: url.trim(), allowInsecureTls, ...keyPayload() })
|
|
setConnected(!!d.connected)
|
|
if (d.connected) toast.success(t('settings.airtrail.test.success', { count: d.flightCount ?? 0 }))
|
|
else toast.error(d.error || t('settings.airtrail.test.failed'))
|
|
} catch {
|
|
toast.error(t('settings.airtrail.test.failed'))
|
|
} finally {
|
|
setTesting(false)
|
|
}
|
|
}
|
|
|
|
const canSave = !!url.trim() && (connected || !!apiKey.trim())
|
|
|
|
return (
|
|
<Section title={t('settings.airtrail.title')} icon={Plane}>
|
|
<div className="space-y-3">
|
|
<div>
|
|
<label className="block text-sm font-medium text-slate-700 mb-1.5">{t('settings.airtrail.url')}</label>
|
|
<input
|
|
type="url"
|
|
value={url}
|
|
onChange={e => setUrl(e.target.value)}
|
|
placeholder="https://airtrail.example.com"
|
|
className="w-full px-3 py-2.5 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-slate-300"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-slate-700 mb-1.5">{t('settings.airtrail.apiKey')}</label>
|
|
<input
|
|
type="password"
|
|
value={apiKey}
|
|
onChange={e => setApiKey(e.target.value)}
|
|
autoComplete="off"
|
|
placeholder={connected && !apiKey ? '••••••••' : t('settings.airtrail.apiKeyPlaceholder')}
|
|
className="w-full px-3 py-2.5 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-slate-300"
|
|
/>
|
|
<p className="mt-1 text-xs text-slate-500">{t('settings.airtrail.apiKeyHint')}</p>
|
|
</div>
|
|
|
|
<div className="flex items-center gap-3">
|
|
<ToggleSwitch on={allowInsecureTls} onToggle={() => setAllowInsecureTls(v => !v)} />
|
|
<span className="text-sm font-medium text-slate-700">{t('settings.airtrail.allowInsecureTls')}</span>
|
|
</div>
|
|
|
|
<div className="flex flex-wrap items-center gap-3">
|
|
<button
|
|
onClick={handleSave}
|
|
disabled={saving || loading || !canSave}
|
|
className="flex items-center gap-2 px-4 py-2 bg-slate-900 text-white rounded-lg text-sm hover:bg-slate-700 disabled:bg-slate-400"
|
|
>
|
|
<Save className="w-4 h-4" /> {t('common.save')}
|
|
</button>
|
|
<button
|
|
onClick={handleTest}
|
|
disabled={testing || loading || !url.trim()}
|
|
className="flex items-center gap-2 px-4 py-2 border border-slate-200 rounded-lg text-sm hover:bg-slate-50"
|
|
>
|
|
{testing ? (
|
|
<div className="w-4 h-4 border-2 border-slate-300 border-t-slate-700 rounded-full animate-spin" />
|
|
) : (
|
|
<Plane className="w-4 h-4" />
|
|
)}
|
|
{t('settings.airtrail.test.button')}
|
|
</button>
|
|
{connected ? (
|
|
<span className="basis-full sm:basis-auto text-xs font-medium text-green-600 flex items-center gap-1">
|
|
<span className="w-2 h-2 bg-green-500 rounded-full" />
|
|
{t('settings.airtrail.connected')}
|
|
</span>
|
|
) : (
|
|
<span className="basis-full sm:basis-auto text-xs font-medium text-slate-400 flex items-center gap-1">
|
|
<span className="w-2 h-2 bg-slate-300 rounded-full" />
|
|
{t('settings.airtrail.notConnected')}
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
<p className="text-xs text-slate-500">{t('settings.airtrail.hint')}</p>
|
|
</div>
|
|
</Section>
|
|
)
|
|
}
|