mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
feat(mail-ingest): admin card, review mark, inbox events and links, translations
- Admin settings (desktop and phone, self-hosted only): the instance switch,
how mail arrives (IMAP or a signed webhook) with its fields, the address
template, the AI allowance per person and day, a connection test and the
status in counts. Changed fields only are saved; secrets stay masked.
- The review mark of an imported booking takes its mark off: the pill in the
desktop dialog and a row in the phone's transport sheet ('Looks right'),
through the ordinary booking update. Its hint no longer speaks of airports.
- The inbox follows mailInbox:changed and mailInbox:settings, and
?inbox=mail (the 'bookings waiting' notification) opens it.
- mailIngestRepo: the online-only path the views take, answers parsed
against the shared contracts.
- Dropped 'read with AI' and the unused mail-review contract: the server
reads a passing AI failure again on its own.
- mailInbox, mailAdmin and the new reservation, settings and notification
strings in all 28 locales; the pending notice is a plural group.
- The live flight line on the booking cards is one of the card's fields,
full width on the phone; the phone's live card keeps its map to the middle.
- Admin flight and mail cards sit in the left column.
This commit is contained in:
@@ -8,107 +8,71 @@ import type { MailIngestInboxEntry, MailIngestReason } from '@trek/shared';
|
||||
*/
|
||||
|
||||
/** The ways out of an entry, in the order the row offers them. */
|
||||
export type InboxAction = 'add' | 'choose' | 'file' | 'manual' | 'readAi' | 'discard';
|
||||
|
||||
/** Reasons where reading the mail again with AI is worth a try. */
|
||||
const AI_RETRY: ReadonlySet<MailIngestReason> = new Set([
|
||||
'ai_quota_exhausted',
|
||||
'ai_user_cap',
|
||||
'ai_provider_error',
|
||||
'ai_disabled',
|
||||
'not_a_booking',
|
||||
'mail_unreadable',
|
||||
]);
|
||||
export type InboxAction = 'add' | 'choose' | 'file' | 'manual' | 'discard';
|
||||
|
||||
/** Reasons that need no booking decision at all: the entry only informs. */
|
||||
const INFO_ONLY: ReadonlySet<MailIngestReason> = new Set(['forwarding_confirmation', 'newsletter', 'auto_reply']);
|
||||
|
||||
export function actionsOf(entry: MailIngestInboxEntry, aiAvailable: boolean): InboxAction[] {
|
||||
/**
|
||||
* A passing AI failure is read again by the server on its own; an allowance
|
||||
* used up leaves the form and the document, so there is no "read again" here.
|
||||
*/
|
||||
export function actionsOf(entry: MailIngestInboxEntry): InboxAction[] {
|
||||
const reason = entry.reason ?? entry.message.reason;
|
||||
if (reason && INFO_ONLY.has(reason)) return ['discard'];
|
||||
const actions: InboxAction[] = [];
|
||||
if (entry.item) actions.push(entry.suggested_trip ? 'add' : 'choose');
|
||||
if (entry.message.attachments.length > 0 || entry.item) actions.push('file');
|
||||
actions.push('manual');
|
||||
if (aiAvailable && reason && AI_RETRY.has(reason)) actions.push('readAi');
|
||||
actions.push('discard');
|
||||
return actions;
|
||||
}
|
||||
|
||||
type Translate = (key: string) => string;
|
||||
|
||||
/**
|
||||
* A reason in the reader's words. A switch of literal keys rather than a table,
|
||||
* so the i18n check sees every key in use and a new code fails the type check
|
||||
* here first.
|
||||
* A reason in the reader's words. A table of literal keys, so the i18n check
|
||||
* sees every key in use, and typed by the reason codes, so a new code fails
|
||||
* the type check here first.
|
||||
*/
|
||||
export function reasonText(reason: MailIngestReason, t: (key: string) => string): string {
|
||||
switch (reason) {
|
||||
case 'forwarding_confirmation':
|
||||
return t('mailInbox.reason.forwardingConfirmation');
|
||||
case 'newsletter':
|
||||
return t('mailInbox.reason.newsletter');
|
||||
case 'auto_reply':
|
||||
return t('mailInbox.reason.autoReply');
|
||||
case 'empty_mail':
|
||||
return t('mailInbox.reason.emptyMail');
|
||||
case 'mail_unreadable':
|
||||
return t('mailInbox.reason.mailUnreadable');
|
||||
case 'not_a_booking':
|
||||
return t('mailInbox.reason.notABooking');
|
||||
case 'too_large':
|
||||
return t('mailInbox.reason.tooLarge');
|
||||
case 'address_invalid':
|
||||
return t('mailInbox.reason.addressInvalid');
|
||||
case 'address_daily_limit':
|
||||
return t('mailInbox.reason.addressDailyLimit');
|
||||
case 'processing_failed':
|
||||
return t('mailInbox.reason.processingFailed');
|
||||
case 'ai_quota_exhausted':
|
||||
return t('mailInbox.reason.aiQuotaExhausted');
|
||||
case 'ai_disabled':
|
||||
return t('mailInbox.reason.aiDisabled');
|
||||
case 'ai_user_cap':
|
||||
return t('mailInbox.reason.aiUserCap');
|
||||
case 'ai_provider_error':
|
||||
return t('mailInbox.reason.aiProviderError');
|
||||
case 'no_trip_in_range':
|
||||
return t('mailInbox.reason.noTripInRange');
|
||||
case 'trip_ambiguous':
|
||||
return t('mailInbox.reason.tripAmbiguous');
|
||||
case 'trip_without_dates':
|
||||
return t('mailInbox.reason.tripWithoutDates');
|
||||
case 'no_edit_permission':
|
||||
return t('mailInbox.reason.noEditPermission');
|
||||
case 'demo_mode':
|
||||
return t('mailInbox.reason.demoMode');
|
||||
case 'outside_trip_dates':
|
||||
return t('mailInbox.reason.outsideTripDates');
|
||||
case 'source_mismatch':
|
||||
return t('mailInbox.reason.sourceMismatch');
|
||||
case 'implausible':
|
||||
return t('mailInbox.reason.implausible');
|
||||
case 'not_in_text':
|
||||
return t('mailInbox.reason.notInText');
|
||||
case 'image_only':
|
||||
return t('mailInbox.reason.imageOnly');
|
||||
case 'missing_critical_field':
|
||||
return t('mailInbox.reason.missingCriticalField');
|
||||
case 'missing_confirmation':
|
||||
return t('mailInbox.reason.missingConfirmation');
|
||||
case 'too_many_bookings':
|
||||
return t('mailInbox.reason.tooManyBookings');
|
||||
case 'change_or_cancellation':
|
||||
return t('mailInbox.reason.changeOrCancellation');
|
||||
case 'cancelled':
|
||||
return t('mailInbox.reason.cancelled');
|
||||
case 'possible_duplicate':
|
||||
return t('mailInbox.reason.possibleDuplicate');
|
||||
case 'change_available':
|
||||
return t('mailInbox.reason.changeAvailable');
|
||||
case 'conflict':
|
||||
return t('mailInbox.reason.conflict');
|
||||
case 'ask_first':
|
||||
return t('mailInbox.reason.askFirst');
|
||||
}
|
||||
const REASON_TEXT: Record<MailIngestReason, (t: Translate) => string> = {
|
||||
forwarding_confirmation: (t) => t('mailInbox.reason.forwardingConfirmation'),
|
||||
newsletter: (t) => t('mailInbox.reason.newsletter'),
|
||||
auto_reply: (t) => t('mailInbox.reason.autoReply'),
|
||||
empty_mail: (t) => t('mailInbox.reason.emptyMail'),
|
||||
mail_unreadable: (t) => t('mailInbox.reason.mailUnreadable'),
|
||||
not_a_booking: (t) => t('mailInbox.reason.notABooking'),
|
||||
too_large: (t) => t('mailInbox.reason.tooLarge'),
|
||||
address_invalid: (t) => t('mailInbox.reason.addressInvalid'),
|
||||
address_daily_limit: (t) => t('mailInbox.reason.addressDailyLimit'),
|
||||
processing_failed: (t) => t('mailInbox.reason.processingFailed'),
|
||||
ai_quota_exhausted: (t) => t('mailInbox.reason.aiQuotaExhausted'),
|
||||
ai_disabled: (t) => t('mailInbox.reason.aiDisabled'),
|
||||
ai_user_cap: (t) => t('mailInbox.reason.aiUserCap'),
|
||||
ai_provider_error: (t) => t('mailInbox.reason.aiProviderError'),
|
||||
no_trip_in_range: (t) => t('mailInbox.reason.noTripInRange'),
|
||||
trip_ambiguous: (t) => t('mailInbox.reason.tripAmbiguous'),
|
||||
trip_without_dates: (t) => t('mailInbox.reason.tripWithoutDates'),
|
||||
no_edit_permission: (t) => t('mailInbox.reason.noEditPermission'),
|
||||
demo_mode: (t) => t('mailInbox.reason.demoMode'),
|
||||
outside_trip_dates: (t) => t('mailInbox.reason.outsideTripDates'),
|
||||
source_mismatch: (t) => t('mailInbox.reason.sourceMismatch'),
|
||||
implausible: (t) => t('mailInbox.reason.implausible'),
|
||||
not_in_text: (t) => t('mailInbox.reason.notInText'),
|
||||
image_only: (t) => t('mailInbox.reason.imageOnly'),
|
||||
missing_critical_field: (t) => t('mailInbox.reason.missingCriticalField'),
|
||||
missing_confirmation: (t) => t('mailInbox.reason.missingConfirmation'),
|
||||
too_many_bookings: (t) => t('mailInbox.reason.tooManyBookings'),
|
||||
change_or_cancellation: (t) => t('mailInbox.reason.changeOrCancellation'),
|
||||
cancelled: (t) => t('mailInbox.reason.cancelled'),
|
||||
possible_duplicate: (t) => t('mailInbox.reason.possibleDuplicate'),
|
||||
change_available: (t) => t('mailInbox.reason.changeAvailable'),
|
||||
conflict: (t) => t('mailInbox.reason.conflict'),
|
||||
ask_first: (t) => t('mailInbox.reason.askFirst'),
|
||||
};
|
||||
|
||||
export function reasonText(reason: MailIngestReason, t: Translate): string {
|
||||
return REASON_TEXT[reason](t);
|
||||
}
|
||||
|
||||
/** The entry's headline: the booking's title, else the mail's subject, else nothing to show. */
|
||||
|
||||
Reference in New Issue
Block a user