@marinoscar/vault-web 0.0.0-bootstrap → 0.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/agent/headless/agentActivity.d.ts +53 -0
- package/dist/agent/headless/agentActivity.js +58 -0
- package/dist/agent/headless/index.d.ts +2 -0
- package/dist/agent/headless/index.js +3 -0
- package/dist/agent/headless/useAgentActivity.d.ts +9 -0
- package/dist/agent/headless/useAgentActivity.js +30 -0
- package/dist/agent/ui/components/AgentActivityTable.d.ts +25 -0
- package/dist/agent/ui/components/AgentActivityTable.js +114 -0
- package/dist/agent/ui/index.d.ts +3 -0
- package/dist/agent/ui/index.js +4 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.d.ts +7 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.js +70 -0
- package/dist/agent/ui/pages/AgentActivityPage.d.ts +6 -0
- package/dist/agent/ui/pages/AgentActivityPage.js +61 -0
- package/dist/backups/headless/backupContents.d.ts +69 -0
- package/dist/backups/headless/backupContents.js +133 -0
- package/dist/backups/headless/backupPassword.d.ts +34 -0
- package/dist/backups/headless/backupPassword.js +80 -0
- package/dist/backups/headless/backupSchedule.d.ts +56 -0
- package/dist/backups/headless/backupSchedule.js +189 -0
- package/dist/backups/headless/index.d.ts +4 -0
- package/dist/backups/headless/index.js +5 -0
- package/dist/backups/headless/useBackupRunHistory.d.ts +36 -0
- package/dist/backups/headless/useBackupRunHistory.js +83 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.d.ts +20 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.js +65 -0
- package/dist/backups/ui/components/BackupContentsGroup.d.ts +17 -0
- package/dist/backups/ui/components/BackupContentsGroup.js +21 -0
- package/dist/backups/ui/components/BackupPasswordFields.d.ts +18 -0
- package/dist/backups/ui/components/BackupPasswordFields.js +40 -0
- package/dist/backups/ui/components/BackupRunsTable.d.ts +44 -0
- package/dist/backups/ui/components/BackupRunsTable.js +61 -0
- package/dist/backups/ui/components/DataBackup.d.ts +14 -0
- package/dist/backups/ui/components/DataBackup.js +169 -0
- package/dist/backups/ui/components/ScheduledBackups.d.ts +13 -0
- package/dist/backups/ui/components/ScheduledBackups.js +304 -0
- package/dist/backups/ui/index.d.ts +8 -0
- package/dist/backups/ui/index.js +9 -0
- package/dist/backups/ui/pages/BackupSettingsPage.d.ts +8 -0
- package/dist/backups/ui/pages/BackupSettingsPage.js +19 -0
- package/dist/backups/ui/pages/MyBackupsPage.d.ts +8 -0
- package/dist/backups/ui/pages/MyBackupsPage.js +19 -0
- package/dist/brand/BrandLockup.d.ts +14 -0
- package/dist/brand/BrandLockup.js +13 -0
- package/dist/brand/assets/vault-mark.png +0 -0
- package/dist/brand/contrast.d.ts +8 -0
- package/dist/brand/contrast.js +21 -0
- package/dist/brand/index.d.ts +7 -0
- package/dist/brand/index.js +8 -0
- package/dist/brand/mark.d.ts +6 -0
- package/dist/brand/mark.js +7 -0
- package/dist/brand/theme.d.ts +25 -0
- package/dist/brand/theme.js +84 -0
- package/dist/brand/tokens.d.ts +52 -0
- package/dist/brand/tokens.js +54 -0
- package/dist/cards/headless/cardExpiry.d.ts +57 -0
- package/dist/cards/headless/cardExpiry.js +138 -0
- package/dist/cards/headless/cardFormat.d.ts +60 -0
- package/dist/cards/headless/cardFormat.js +135 -0
- package/dist/cards/headless/cardImage.d.ts +293 -0
- package/dist/cards/headless/cardImage.js +518 -0
- package/dist/cards/headless/index.d.ts +6 -0
- package/dist/cards/headless/index.js +7 -0
- package/dist/cards/headless/useCardImport.d.ts +137 -0
- package/dist/cards/headless/useCardImport.js +391 -0
- package/dist/cards/headless/useCardRenewal.d.ts +102 -0
- package/dist/cards/headless/useCardRenewal.js +305 -0
- package/dist/cards/headless/useCards.d.ts +80 -0
- package/dist/cards/headless/useCards.js +114 -0
- package/dist/cards/ui/components/AiEgressNotice.d.ts +13 -0
- package/dist/cards/ui/components/AiEgressNotice.js +18 -0
- package/dist/cards/ui/components/CardCaptureStep.d.ts +59 -0
- package/dist/cards/ui/components/CardCaptureStep.js +96 -0
- package/dist/cards/ui/components/CardCropAdjuster.d.ts +43 -0
- package/dist/cards/ui/components/CardCropAdjuster.js +215 -0
- package/dist/cards/ui/components/CardCropReview.d.ts +51 -0
- package/dist/cards/ui/components/CardCropReview.js +88 -0
- package/dist/cards/ui/components/CardExpiryBadge.d.ts +8 -0
- package/dist/cards/ui/components/CardExpiryBadge.js +43 -0
- package/dist/cards/ui/components/CardFieldDiff.d.ts +37 -0
- package/dist/cards/ui/components/CardFieldDiff.js +66 -0
- package/dist/cards/ui/components/CardFlowStepper.d.ts +24 -0
- package/dist/cards/ui/components/CardFlowStepper.js +23 -0
- package/dist/cards/ui/components/CardReviewForm.d.ts +44 -0
- package/dist/cards/ui/components/CardReviewForm.js +102 -0
- package/dist/cards/ui/components/CardScanModelSection.d.ts +23 -0
- package/dist/cards/ui/components/CardScanModelSection.js +81 -0
- package/dist/cards/ui/components/CardTile.d.ts +40 -0
- package/dist/cards/ui/components/CardTile.js +94 -0
- package/dist/cards/ui/index.d.ts +15 -0
- package/dist/cards/ui/index.js +16 -0
- package/dist/cards/ui/pages/AiSettingsPage.d.ts +12 -0
- package/dist/cards/ui/pages/AiSettingsPage.js +24 -0
- package/dist/cards/ui/pages/CardsPage.d.ts +26 -0
- package/dist/cards/ui/pages/CardsPage.js +160 -0
- package/dist/cards/ui/pages/ImportCardPage.d.ts +24 -0
- package/dist/cards/ui/pages/ImportCardPage.js +343 -0
- package/dist/cards/ui/pages/RenewCardPage.d.ts +35 -0
- package/dist/cards/ui/pages/RenewCardPage.js +350 -0
- package/dist/core/headless/api.d.ts +272 -0
- package/dist/core/headless/api.js +425 -0
- package/dist/core/headless/cardScanAvailability.d.ts +20 -0
- package/dist/core/headless/cardScanAvailability.js +27 -0
- package/dist/core/headless/clipboard.d.ts +60 -0
- package/dist/core/headless/clipboard.js +101 -0
- package/dist/core/headless/http.d.ts +41 -0
- package/dist/core/headless/http.js +50 -0
- package/dist/core/headless/index.d.ts +12 -0
- package/dist/core/headless/index.js +13 -0
- package/dist/core/headless/relativeTime.d.ts +7 -0
- package/dist/core/headless/relativeTime.js +28 -0
- package/dist/core/headless/saveBlob.d.ts +6 -0
- package/dist/core/headless/saveBlob.js +21 -0
- package/dist/core/headless/types.d.ts +441 -0
- package/dist/core/headless/types.js +49 -0
- package/dist/core/headless/useAiStatus.d.ts +41 -0
- package/dist/core/headless/useAiStatus.js +42 -0
- package/dist/core/headless/useCopyToClipboard.d.ts +20 -0
- package/dist/core/headless/useCopyToClipboard.js +52 -0
- package/dist/core/headless/useDashboardResource.d.ts +22 -0
- package/dist/core/headless/useDashboardResource.js +52 -0
- package/dist/core/headless/useSystemSettings.d.ts +17 -0
- package/dist/core/headless/useSystemSettings.js +106 -0
- package/dist/core/headless/useUserSettings.d.ts +13 -0
- package/dist/core/headless/useUserSettings.js +103 -0
- package/dist/core/ui/ErrorBoundary.d.ts +15 -0
- package/dist/core/ui/ErrorBoundary.js +27 -0
- package/dist/core/ui/LoadingSpinner.d.ts +6 -0
- package/dist/core/ui/LoadingSpinner.js +14 -0
- package/dist/core/ui/SettingsPageFrame.d.ts +19 -0
- package/dist/core/ui/SettingsPageFrame.js +12 -0
- package/dist/core/ui/StorageSettingsLink.d.ts +19 -0
- package/dist/core/ui/StorageSettingsLink.js +26 -0
- package/dist/core/ui/index.d.ts +4 -0
- package/dist/core/ui/index.js +5 -0
- package/dist/home/headless/homeLinks.d.ts +24 -0
- package/dist/home/headless/homeLinks.js +24 -0
- package/dist/home/headless/index.d.ts +1 -0
- package/dist/home/headless/index.js +2 -0
- package/dist/home/ui/components/BackupStatusPanel.d.ts +28 -0
- package/dist/home/ui/components/BackupStatusPanel.js +99 -0
- package/dist/home/ui/components/DashboardPanel.d.ts +33 -0
- package/dist/home/ui/components/DashboardPanel.js +21 -0
- package/dist/home/ui/components/ExpiringCardsPanel.d.ts +31 -0
- package/dist/home/ui/components/ExpiringCardsPanel.js +35 -0
- package/dist/home/ui/components/FirstRunPanel.d.ts +7 -0
- package/dist/home/ui/components/FirstRunPanel.js +21 -0
- package/dist/home/ui/components/QuickActions.d.ts +14 -0
- package/dist/home/ui/components/QuickActions.js +40 -0
- package/dist/home/ui/components/RecentSecretsPanel.d.ts +19 -0
- package/dist/home/ui/components/RecentSecretsPanel.js +20 -0
- package/dist/home/ui/components/StatsRow.d.ts +19 -0
- package/dist/home/ui/components/StatsRow.js +46 -0
- package/dist/home/ui/components/WelcomeHeader.d.ts +11 -0
- package/dist/home/ui/components/WelcomeHeader.js +15 -0
- package/dist/home/ui/index.d.ts +9 -0
- package/dist/home/ui/index.js +10 -0
- package/dist/home/ui/pages/HomePage.d.ts +14 -0
- package/dist/home/ui/pages/HomePage.js +121 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/media/headless/index.d.ts +2 -0
- package/dist/media/headless/index.js +3 -0
- package/dist/media/headless/useMediaFiles.d.ts +20 -0
- package/dist/media/headless/useMediaFiles.js +82 -0
- package/dist/media/headless/useMediaFolders.d.ts +22 -0
- package/dist/media/headless/useMediaFolders.js +81 -0
- package/dist/media/ui/components/FolderList.d.ts +19 -0
- package/dist/media/ui/components/FolderList.js +36 -0
- package/dist/media/ui/components/MediaList.d.ts +20 -0
- package/dist/media/ui/components/MediaList.js +55 -0
- package/dist/media/ui/components/MediaPlayer.d.ts +7 -0
- package/dist/media/ui/components/MediaPlayer.js +361 -0
- package/dist/media/ui/index.d.ts +10 -0
- package/dist/media/ui/index.js +11 -0
- package/dist/media/ui/pages/CreateFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/CreateFolderPage.js +39 -0
- package/dist/media/ui/pages/EditFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/EditFolderPage.js +59 -0
- package/dist/media/ui/pages/MediaFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFolderPage.js +68 -0
- package/dist/media/ui/pages/MediaFoldersPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFoldersPage.js +58 -0
- package/dist/media/ui/pages/MediaPlayerPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaPlayerPage.js +76 -0
- package/dist/media/ui/pages/MediaUploadPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaUploadPage.js +88 -0
- package/dist/media/ui/pages/RenameMediaFilePage.d.ts +1 -0
- package/dist/media/ui/pages/RenameMediaFilePage.js +63 -0
- package/dist/navigation/destinations.d.ts +50 -0
- package/dist/navigation/destinations.js +109 -0
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +4 -0
- package/dist/secrets/headless/fieldOptionsValidation.d.ts +45 -0
- package/dist/secrets/headless/fieldOptionsValidation.js +79 -0
- package/dist/secrets/headless/index.d.ts +6 -0
- package/dist/secrets/headless/index.js +7 -0
- package/dist/secrets/headless/secretFields.d.ts +86 -0
- package/dist/secrets/headless/secretFields.js +190 -0
- package/dist/secrets/headless/useSecretDetail.d.ts +33 -0
- package/dist/secrets/headless/useSecretDetail.js +87 -0
- package/dist/secrets/headless/useSecretTypes.d.ts +16 -0
- package/dist/secrets/headless/useSecretTypes.js +62 -0
- package/dist/secrets/headless/useSecrets.d.ts +24 -0
- package/dist/secrets/headless/useSecrets.js +59 -0
- package/dist/secrets/headless/useTotpCode.d.ts +24 -0
- package/dist/secrets/headless/useTotpCode.js +116 -0
- package/dist/secrets/ui/components/CardImages.d.ts +31 -0
- package/dist/secrets/ui/components/CardImages.js +208 -0
- package/dist/secrets/ui/components/DynamicSecretFields.d.ts +10 -0
- package/dist/secrets/ui/components/DynamicSecretFields.js +90 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.d.ts +13 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.js +114 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.d.ts +15 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.js +45 -0
- package/dist/secrets/ui/components/SecretAttachments.d.ts +15 -0
- package/dist/secrets/ui/components/SecretAttachments.js +106 -0
- package/dist/secrets/ui/components/SecretForm.d.ts +34 -0
- package/dist/secrets/ui/components/SecretForm.js +83 -0
- package/dist/secrets/ui/components/SecretFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretFormDialog.js +95 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.js +92 -0
- package/dist/secrets/ui/components/SecretTypeIcon.d.ts +8 -0
- package/dist/secrets/ui/components/SecretTypeIcon.js +16 -0
- package/dist/secrets/ui/components/SecretTypesList.d.ts +10 -0
- package/dist/secrets/ui/components/SecretTypesList.js +13 -0
- package/dist/secrets/ui/components/SecretValueField.d.ts +20 -0
- package/dist/secrets/ui/components/SecretValueField.js +52 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.d.ts +22 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.js +131 -0
- package/dist/secrets/ui/components/SecretsTable.d.ts +49 -0
- package/dist/secrets/ui/components/SecretsTable.js +174 -0
- package/dist/secrets/ui/components/TotpCodeCard.d.ts +8 -0
- package/dist/secrets/ui/components/TotpCodeCard.js +34 -0
- package/dist/secrets/ui/index.d.ts +20 -0
- package/dist/secrets/ui/index.js +21 -0
- package/dist/secrets/ui/pages/CreateSecretPage.d.ts +2 -0
- package/dist/secrets/ui/pages/CreateSecretPage.js +25 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.js +62 -0
- package/dist/secrets/ui/pages/EditSecretPage.d.ts +5 -0
- package/dist/secrets/ui/pages/EditSecretPage.js +55 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.js +88 -0
- package/dist/secrets/ui/pages/SecretDetailPage.d.ts +7 -0
- package/dist/secrets/ui/pages/SecretDetailPage.js +182 -0
- package/dist/secrets/ui/pages/SecretTypesPage.d.ts +1 -0
- package/dist/secrets/ui/pages/SecretTypesPage.js +23 -0
- package/dist/secrets/ui/pages/SecretsPage.d.ts +6 -0
- package/dist/secrets/ui/pages/SecretsPage.js +179 -0
- package/dist/settings/ui/components/FeatureFlagsList.d.ts +7 -0
- package/dist/settings/ui/components/FeatureFlagsList.js +46 -0
- package/dist/settings/ui/components/ImageUpload.d.ts +6 -0
- package/dist/settings/ui/components/ImageUpload.js +61 -0
- package/dist/settings/ui/components/ProfileSettings.d.ts +11 -0
- package/dist/settings/ui/components/ProfileSettings.js +55 -0
- package/dist/settings/ui/components/ThemeSettings.d.ts +7 -0
- package/dist/settings/ui/components/ThemeSettings.js +24 -0
- package/dist/settings/ui/components/UISettings.d.ts +9 -0
- package/dist/settings/ui/components/UISettings.js +25 -0
- package/dist/settings/ui/components/UserProfileCard.d.ts +1 -0
- package/dist/settings/ui/components/UserProfileCard.js +39 -0
- package/dist/settings/ui/components/UserSettingsSection.d.ts +23 -0
- package/dist/settings/ui/components/UserSettingsSection.js +29 -0
- package/dist/settings/ui/index.d.ts +10 -0
- package/dist/settings/ui/index.js +11 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.js +11 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.d.ts +9 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.js +41 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.js +11 -0
- package/package.json +146 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { Alert, Box, Button, Chip, Container, Grid, InputAdornment, Paper, Skeleton, TextField, Typography, } from '@mui/material';
|
|
5
|
+
import { AddCardOutlined as AddIcon, CreditCardOutlined as CardIcon, DocumentScannerOutlined as ScanIcon, Search as SearchIcon, } from '@mui/icons-material';
|
|
6
|
+
import { CardTile } from '../components/CardTile.js';
|
|
7
|
+
import { useAiStatus } from '../../../core/headless/useAiStatus.js';
|
|
8
|
+
import { useCards } from '../../headless/useCards.js';
|
|
9
|
+
import { EXPIRING_SOON_DAYS, isNeedsAttention } from '../../headless/cardExpiry.js';
|
|
10
|
+
const FILTERS = [
|
|
11
|
+
{ value: 'all', label: 'All' },
|
|
12
|
+
{ value: 'attention', label: 'Needs attention' },
|
|
13
|
+
{ value: 'expiring_soon', label: 'Expiring soon' },
|
|
14
|
+
{ value: 'expired', label: 'Expired' },
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Read `?filter=` (all | attention | expiring_soon | expired; `expiring` is
|
|
18
|
+
* accepted for expiring_soon). Anything else, or nothing, is `all`.
|
|
19
|
+
*/
|
|
20
|
+
export function parseCardFilter(raw) {
|
|
21
|
+
switch (raw) {
|
|
22
|
+
case 'attention':
|
|
23
|
+
case 'expiring_soon':
|
|
24
|
+
case 'expired':
|
|
25
|
+
return raw;
|
|
26
|
+
case 'expiring':
|
|
27
|
+
return 'expiring_soon';
|
|
28
|
+
default:
|
|
29
|
+
return 'all';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function matchesFilter(card, filter) {
|
|
33
|
+
if (filter === 'all')
|
|
34
|
+
return true;
|
|
35
|
+
if (filter === 'attention')
|
|
36
|
+
return isNeedsAttention(card.status);
|
|
37
|
+
return card.status === filter;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The Cards destination: a gallery of the user's payment cards (E10.5, #96).
|
|
41
|
+
*
|
|
42
|
+
* Cards previously sat undifferentiated in the secrets list, so an expiry was
|
|
43
|
+
* only discovered when a payment failed. Everything here is derived from values
|
|
44
|
+
* the user already has; since #118 they arrive in one paged
|
|
45
|
+
* `GET /api/secrets/cards/summary` (display fields only) instead of
|
|
46
|
+
* one decrypted detail request per card.
|
|
47
|
+
*
|
|
48
|
+
* Layout: a header with the two ways to add a card (scan, gated on AI; manual),
|
|
49
|
+
* a toolbar with search and the status filter chips, then a responsive grid of
|
|
50
|
+
* `CardTile`s (one column on a phone, two from `sm`, three from `md`). The
|
|
51
|
+
* shell's `<main>` already pads the page, so the container adds no gutters of
|
|
52
|
+
* its own (no double padding on a phone).
|
|
53
|
+
*/
|
|
54
|
+
export default function CardsPage() {
|
|
55
|
+
const navigate = useNavigate();
|
|
56
|
+
const { cards, isTruncated, totalItems, isLoading, error, fetchCards } = useCards();
|
|
57
|
+
const { cardExtractEnabled, isLoading: isAiStatusLoading } = useAiStatus();
|
|
58
|
+
const [search, setSearch] = useState('');
|
|
59
|
+
// The filter lives in the URL (`?filter=`), so the Home dashboard can link
|
|
60
|
+
// straight to a filtered gallery and the choice survives a reload or Back.
|
|
61
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
62
|
+
const filter = parseCardFilter(searchParams.get('filter'));
|
|
63
|
+
const setFilter = (next) => {
|
|
64
|
+
setSearchParams((prev) => {
|
|
65
|
+
const params = new URLSearchParams(prev);
|
|
66
|
+
if (next === 'all')
|
|
67
|
+
params.delete('filter');
|
|
68
|
+
else
|
|
69
|
+
params.set('filter', next);
|
|
70
|
+
return params;
|
|
71
|
+
}, { replace: true });
|
|
72
|
+
};
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
fetchCards();
|
|
75
|
+
}, [fetchCards]);
|
|
76
|
+
// Counts describe the whole wallet, not the filtered view, so choosing a
|
|
77
|
+
// filter never changes the headline numbers or the chip counts.
|
|
78
|
+
const counts = useMemo(() => ({
|
|
79
|
+
all: cards.length,
|
|
80
|
+
attention: cards.filter((card) => isNeedsAttention(card.status)).length,
|
|
81
|
+
expiring_soon: cards.filter((card) => card.status === 'expiring_soon').length,
|
|
82
|
+
expired: cards.filter((card) => card.status === 'expired').length,
|
|
83
|
+
}), [cards]);
|
|
84
|
+
// `cards` arrives already sorted soonest-expiry-first from the hook; filtering
|
|
85
|
+
// preserves that order.
|
|
86
|
+
const visibleCards = useMemo(() => {
|
|
87
|
+
const term = search.trim().toLowerCase();
|
|
88
|
+
return cards.filter((card) => {
|
|
89
|
+
if (!matchesFilter(card, filter))
|
|
90
|
+
return false;
|
|
91
|
+
if (!term)
|
|
92
|
+
return true;
|
|
93
|
+
return [card.name, card.last4 ?? '', card.network, card.issuingBank, card.cardholderName]
|
|
94
|
+
.filter(Boolean)
|
|
95
|
+
.some((field) => field.toLowerCase().includes(term));
|
|
96
|
+
});
|
|
97
|
+
}, [cards, filter, search]);
|
|
98
|
+
const attentionTotal = counts.expired + counts.expiring_soon;
|
|
99
|
+
// Nothing is shown while the status is in flight, so the button never appears
|
|
100
|
+
// and then vanishes under a user who is reaching for it. Gated on
|
|
101
|
+
// GET /api/ai/config (`useAiStatus`, `isCardScanAvailable`): with card scanning
|
|
102
|
+
// unavailable the wizard can only end in a 503 the user cannot act on. The
|
|
103
|
+
// check fails closed.
|
|
104
|
+
const isScanAvailable = !isAiStatusLoading && cardExtractEnabled;
|
|
105
|
+
const goScan = () => navigate('/cards/import');
|
|
106
|
+
const goManual = () => navigate('/secrets/new');
|
|
107
|
+
// Null when there is nothing worth saying: the empty state below already
|
|
108
|
+
// spells out that there are no cards, and repeating it here reads as a bug.
|
|
109
|
+
const summaryLine = (() => {
|
|
110
|
+
if (isLoading || cards.length === 0)
|
|
111
|
+
return null;
|
|
112
|
+
const total = `${cards.length} card${cards.length === 1 ? '' : 's'}`;
|
|
113
|
+
if (attentionTotal === 0)
|
|
114
|
+
return `${total}, none expiring soon.`;
|
|
115
|
+
const parts = [];
|
|
116
|
+
if (counts.expired > 0)
|
|
117
|
+
parts.push(`${counts.expired} expired`);
|
|
118
|
+
if (counts.expiring_soon > 0)
|
|
119
|
+
parts.push(`${counts.expiring_soon} expiring soon`);
|
|
120
|
+
return `${total} — ${parts.join(', ')}.`;
|
|
121
|
+
})();
|
|
122
|
+
const hasCards = !isLoading && cards.length > 0;
|
|
123
|
+
return (_jsxs(Container, { maxWidth: "lg", disableGutters: true, children: [_jsxs(Box, { sx: {
|
|
124
|
+
display: 'flex',
|
|
125
|
+
flexWrap: 'wrap',
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
justifyContent: 'space-between',
|
|
128
|
+
gap: 2,
|
|
129
|
+
mb: 2,
|
|
130
|
+
}, children: [_jsxs(Box, { sx: { minWidth: 0 }, children: [_jsx(Typography, { variant: "h4", component: "h1", children: "Cards" }), _jsx(Typography, { variant: "body2", sx: { color: 'text.secondary', mt: 0.5 }, children: isLoading ? 'Loading cards…' : summaryLine ?? 'Your payment cards and when they expire.' })] }), hasCards && (_jsxs(Box, { sx: { display: 'flex', gap: 1, flexWrap: 'wrap', width: { xs: '100%', sm: 'auto' } }, children: [_jsx(Button, { variant: "outlined", startIcon: _jsx(AddIcon, {}), onClick: goManual, sx: { flex: { xs: 1, sm: 'none' } }, children: "Add manually" }), isScanAvailable && (_jsx(Button, { variant: "contained", startIcon: _jsx(ScanIcon, {}), onClick: goScan, sx: { flex: { xs: 1, sm: 'none' } }, children: "Scan a card" }))] }))] }), error && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, children: error })), isTruncated && (_jsxs(Alert, { severity: "info", sx: { mb: 2 }, children: ["Showing the first ", cards.length, " of ", totalItems, " cards."] })), hasCards && (_jsxs(Box, { sx: {
|
|
131
|
+
display: 'flex',
|
|
132
|
+
flexDirection: { xs: 'column', sm: 'row' },
|
|
133
|
+
alignItems: { xs: 'stretch', sm: 'center' },
|
|
134
|
+
gap: 1.5,
|
|
135
|
+
mb: 2.5,
|
|
136
|
+
}, children: [_jsx(TextField, { label: "Search cards", placeholder: "Name, last 4, network, bank or holder", size: "small", value: search, onChange: (e) => setSearch(e.target.value), sx: { flexGrow: 1, maxWidth: { sm: 420 } }, slotProps: {
|
|
137
|
+
input: {
|
|
138
|
+
startAdornment: (_jsx(InputAdornment, { position: "start", children: _jsx(SearchIcon, { fontSize: "small" }) })),
|
|
139
|
+
},
|
|
140
|
+
} }), _jsx(Box, { role: "group", "aria-label": "Filter cards by expiry", sx: { display: 'flex', gap: 1, flexWrap: 'wrap' }, children: FILTERS.map(({ value, label }) => {
|
|
141
|
+
const selected = filter === value;
|
|
142
|
+
return (_jsx(Chip, { label: `${label} (${counts[value]})`, clickable: true, color: selected ? 'primary' : 'default', variant: selected ? 'filled' : 'outlined', "aria-pressed": selected, onClick: () => setFilter(value), sx: { fontWeight: selected ? 600 : 500 } }, value));
|
|
143
|
+
}) })] })), isLoading ? (_jsx(Grid, { container: true, spacing: 2, "aria-busy": "true", "aria-label": "Loading cards", children: [0, 1, 2].map((i) => (_jsx(Grid, { size: { xs: 12, sm: 6, md: 4 }, children: _jsx(Skeleton, { variant: "rounded", sx: { aspectRatio: '1.45', height: 'auto', borderRadius: 2 } }) }, i))) })) : cards.length === 0 ? (_jsxs(Paper, { variant: "outlined", sx: { py: { xs: 5, sm: 7 }, px: 3, textAlign: 'center', borderStyle: 'dashed' }, children: [_jsx(Box, { "aria-hidden": "true", sx: {
|
|
144
|
+
width: 64,
|
|
145
|
+
height: 64,
|
|
146
|
+
mx: 'auto',
|
|
147
|
+
mb: 2,
|
|
148
|
+
borderRadius: '50%',
|
|
149
|
+
display: 'flex',
|
|
150
|
+
alignItems: 'center',
|
|
151
|
+
justifyContent: 'center',
|
|
152
|
+
bgcolor: 'secondary.main',
|
|
153
|
+
color: 'secondary.contrastText',
|
|
154
|
+
}, children: _jsx(CardIcon, { sx: { fontSize: 32 } }) }), _jsx(Typography, { variant: "h6", component: "h2", gutterBottom: true, children: "No cards yet" }), _jsxs(Typography, { variant: "body2", sx: { color: 'text.secondary', maxWidth: 420, mx: 'auto' }, children: [isScanAvailable
|
|
155
|
+
? 'Scan a card with your camera and check the details, or type them in yourself. '
|
|
156
|
+
: 'Add a card and type its details in. ', "Vault warns you ", EXPIRING_SOON_DAYS, " days before a card expires."] }), _jsxs(Box, { sx: { mt: 3, display: 'flex', gap: 1, justifyContent: 'center', flexWrap: 'wrap' }, children: [isScanAvailable && (_jsx(Button, { variant: "contained", startIcon: _jsx(ScanIcon, {}), onClick: goScan, children: "Scan a card" })), _jsx(Button, { variant: "outlined", startIcon: _jsx(AddIcon, {}), onClick: goManual, children: "Add manually" })] })] })) : visibleCards.length === 0 ? (_jsxs(Box, { sx: { py: 6, textAlign: 'center' }, children: [_jsx(Typography, { sx: { color: 'text.secondary', mb: 1.5 }, children: "No cards match your filters." }), _jsx(Button, { onClick: () => {
|
|
157
|
+
setSearch('');
|
|
158
|
+
setFilter('all');
|
|
159
|
+
}, children: "Show all cards" })] })) : (_jsx(Grid, { container: true, spacing: 2, children: visibleCards.map((card) => (_jsx(Grid, { size: { xs: 12, sm: 6, md: 4 }, children: _jsx(CardTile, { card: card, onClick: (id) => navigate(`/secrets/${id}`), onRenew: (id) => navigate(`/cards/${id}/renew`) }) }, card.id))) }))] }));
|
|
160
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI-assisted card import.
|
|
3
|
+
*
|
|
4
|
+
* Capture (front, then the optional back) -> Crop (the AI reads the card and
|
|
5
|
+
* locates it; the user checks the crop) -> Review (AI-read fields marked, CVV
|
|
6
|
+
* typed by hand) -> Save. The stepper shows those four steps (E10.5, #96).
|
|
7
|
+
*
|
|
8
|
+
* The capture steps collect FULL photos — no cropping happens there. The
|
|
9
|
+
* prepared full frames go to the extraction endpoint, which locates the card
|
|
10
|
+
* and returns a bounding box per side; the stored attachment is then cropped
|
|
11
|
+
* from that box (or the centred auto-fit when no box came back) and can be
|
|
12
|
+
* adjusted manually on the review step. Only the cropped version is ever
|
|
13
|
+
* uploaded to storage — the full photo goes to the AI and nowhere else.
|
|
14
|
+
*
|
|
15
|
+
* Two invariants shape the whole flow:
|
|
16
|
+
*
|
|
17
|
+
* 1. A card cannot be saved without a CVV — the Card secret type marks it
|
|
18
|
+
* required — and the CVV is only ever typed by hand: it is never seeded
|
|
19
|
+
* from the extraction (`toReviewValues`), whatever the provider returned.
|
|
20
|
+
* 2. A failed extraction is not a dead end. Any failure still lands on the
|
|
21
|
+
* review step with the captured photos and an empty form, so the card can
|
|
22
|
+
* be entered manually instead of starting over.
|
|
23
|
+
*/
|
|
24
|
+
export default function ImportCardPage(): import("react").JSX.Element;
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Link as RouterLink, useNavigate } from 'react-router-dom';
|
|
4
|
+
import { Alert, AlertTitle, Box, Breadcrumbs, Button, CircularProgress, Container, Link, Paper, TextField, Typography, } from '@mui/material';
|
|
5
|
+
import { AutoAwesomeOutlined as AiIcon } from '@mui/icons-material';
|
|
6
|
+
import { AiEgressNotice } from '../components/AiEgressNotice.js';
|
|
7
|
+
import { CardCaptureStep } from '../components/CardCaptureStep.js';
|
|
8
|
+
import { CardCropReview } from '../components/CardCropReview.js';
|
|
9
|
+
import { CardFlowStepper } from '../components/CardFlowStepper.js';
|
|
10
|
+
import { CardReviewForm } from '../components/CardReviewForm.js';
|
|
11
|
+
import { useAiStatus } from '../../../core/headless/useAiStatus.js';
|
|
12
|
+
import { AI_SETTINGS_PATH, LOW_CONFIDENCE_THRESHOLD, aiSeededFields, buildDefaultCardName, toReviewValues, useCardImport, } from '../../headless/useCardImport.js';
|
|
13
|
+
import { usePermissions } from '@marinoscar/platform-web/identity/headless';
|
|
14
|
+
import { cropImageFileToBox, cropImageFileToCard, prepareCardPhoto, } from '../../headless/cardImage.js';
|
|
15
|
+
/** Where each stage sits on the Capture → Crop → Review → Save stepper. */
|
|
16
|
+
const STAGE_STEP = {
|
|
17
|
+
front: 'capture',
|
|
18
|
+
back: 'capture',
|
|
19
|
+
processing: 'crop',
|
|
20
|
+
crop: 'crop',
|
|
21
|
+
review: 'review',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* AI-assisted card import.
|
|
25
|
+
*
|
|
26
|
+
* Capture (front, then the optional back) -> Crop (the AI reads the card and
|
|
27
|
+
* locates it; the user checks the crop) -> Review (AI-read fields marked, CVV
|
|
28
|
+
* typed by hand) -> Save. The stepper shows those four steps (E10.5, #96).
|
|
29
|
+
*
|
|
30
|
+
* The capture steps collect FULL photos — no cropping happens there. The
|
|
31
|
+
* prepared full frames go to the extraction endpoint, which locates the card
|
|
32
|
+
* and returns a bounding box per side; the stored attachment is then cropped
|
|
33
|
+
* from that box (or the centred auto-fit when no box came back) and can be
|
|
34
|
+
* adjusted manually on the review step. Only the cropped version is ever
|
|
35
|
+
* uploaded to storage — the full photo goes to the AI and nowhere else.
|
|
36
|
+
*
|
|
37
|
+
* Two invariants shape the whole flow:
|
|
38
|
+
*
|
|
39
|
+
* 1. A card cannot be saved without a CVV — the Card secret type marks it
|
|
40
|
+
* required — and the CVV is only ever typed by hand: it is never seeded
|
|
41
|
+
* from the extraction (`toReviewValues`), whatever the provider returned.
|
|
42
|
+
* 2. A failed extraction is not a dead end. Any failure still lands on the
|
|
43
|
+
* review step with the captured photos and an empty form, so the card can
|
|
44
|
+
* be entered manually instead of starting over.
|
|
45
|
+
*/
|
|
46
|
+
export default function ImportCardPage() {
|
|
47
|
+
const navigate = useNavigate();
|
|
48
|
+
const { hasPermission } = usePermissions();
|
|
49
|
+
const { config: aiConfig, cardExtractEnabled, canUseAi, isLoading: isStatusLoading, } = useAiStatus();
|
|
50
|
+
const canOpenAiSettings = hasPermission('ai_config:read');
|
|
51
|
+
const { cardType, isTypeLoading, typeError, extraction, extractionError, isExtracting, runExtraction, isSaving, saveError, saveCard, abandonImport, } = useCardImport();
|
|
52
|
+
const [stage, setStage] = useState('front');
|
|
53
|
+
const [frontPhoto, setFrontPhoto] = useState(null);
|
|
54
|
+
const [backPhoto, setBackPhoto] = useState(null);
|
|
55
|
+
const [frontCrop, setFrontCrop] = useState(null);
|
|
56
|
+
const [backCrop, setBackCrop] = useState(null);
|
|
57
|
+
const [isPreparing, setIsPreparing] = useState(false);
|
|
58
|
+
const [captureError, setCaptureError] = useState(null);
|
|
59
|
+
const [name, setName] = useState('');
|
|
60
|
+
const [values, setValues] = useState(() => toReviewValues(null));
|
|
61
|
+
const [fieldErrors, setFieldErrors] = useState({});
|
|
62
|
+
const [editedFields, setEditedFields] = useState(new Set());
|
|
63
|
+
const [savedNotice, setSavedNotice] = useState(null);
|
|
64
|
+
// Object URLs (full-photo previews AND crop previews) are revoked
|
|
65
|
+
// explicitly. They are held in a ref as well as state so the unmount cleanup
|
|
66
|
+
// sees the current set rather than a stale closure, which is the difference
|
|
67
|
+
// between releasing the blobs and leaking them for the life of the document.
|
|
68
|
+
const previewUrlsRef = useRef(new Set());
|
|
69
|
+
const trackUrl = useCallback((url) => {
|
|
70
|
+
previewUrlsRef.current.add(url);
|
|
71
|
+
}, []);
|
|
72
|
+
const releaseUrl = useCallback((url) => {
|
|
73
|
+
if (!url)
|
|
74
|
+
return;
|
|
75
|
+
previewUrlsRef.current.delete(url);
|
|
76
|
+
URL.revokeObjectURL(url);
|
|
77
|
+
}, []);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const urls = previewUrlsRef.current;
|
|
80
|
+
return () => {
|
|
81
|
+
urls.forEach((url) => URL.revokeObjectURL(url));
|
|
82
|
+
urls.clear();
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
// What gets uploaded on save: the CROPPED images, never the full photos.
|
|
86
|
+
const capturedSides = useMemo(() => {
|
|
87
|
+
const sides = [];
|
|
88
|
+
if (frontCrop)
|
|
89
|
+
sides.push({ role: 'card_front', image: frontCrop.image });
|
|
90
|
+
if (backCrop)
|
|
91
|
+
sides.push({ role: 'card_back', image: backCrop.image });
|
|
92
|
+
return sides;
|
|
93
|
+
}, [frontCrop, backCrop]);
|
|
94
|
+
const handleFileSelected = async (side, file) => {
|
|
95
|
+
setCaptureError(null);
|
|
96
|
+
if (!file.type.startsWith('image/')) {
|
|
97
|
+
setCaptureError('Please choose an image file.');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
setIsPreparing(true);
|
|
101
|
+
try {
|
|
102
|
+
// Full frame only: downscaled if huge, but never cropped or rotated —
|
|
103
|
+
// the AI locates the card, and its box fractions apply to this image.
|
|
104
|
+
const prepared = await prepareCardPhoto(file);
|
|
105
|
+
const previewUrl = URL.createObjectURL(file);
|
|
106
|
+
trackUrl(previewUrl);
|
|
107
|
+
const photo = { file, prepared, previewUrl };
|
|
108
|
+
if (side === 'front') {
|
|
109
|
+
releaseUrl(frontPhoto?.previewUrl);
|
|
110
|
+
setFrontPhoto(photo);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
releaseUrl(backPhoto?.previewUrl);
|
|
114
|
+
setBackPhoto(photo);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
setCaptureError(err instanceof Error ? err.message : 'That photo could not be processed.');
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
setIsPreparing(false);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const handleRetake = (side) => {
|
|
125
|
+
setCaptureError(null);
|
|
126
|
+
if (side === 'front') {
|
|
127
|
+
releaseUrl(frontPhoto?.previewUrl);
|
|
128
|
+
setFrontPhoto(null);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
releaseUrl(backPhoto?.previewUrl);
|
|
132
|
+
setBackPhoto(null);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Render the initial stored-attachment crop for one side: from the AI's box
|
|
137
|
+
* when one came back, otherwise the legacy centred auto-fit. A failed box
|
|
138
|
+
* crop falls back to the auto-fit rather than losing the side.
|
|
139
|
+
*/
|
|
140
|
+
const renderInitialCrop = useCallback(async (side, photo, box) => {
|
|
141
|
+
const fileName = `card-${side}.jpg`;
|
|
142
|
+
if (box) {
|
|
143
|
+
try {
|
|
144
|
+
const image = await cropImageFileToBox(photo.file, box, { fileName });
|
|
145
|
+
trackUrl(image.previewUrl);
|
|
146
|
+
return { image, box, adjustments: null };
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// Degenerate or unusable box — fall through to the auto-fit crop.
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const image = await cropImageFileToCard(photo.file, { fileName });
|
|
154
|
+
trackUrl(image.previewUrl);
|
|
155
|
+
return { image, box: null, adjustments: null };
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}, [trackUrl]);
|
|
161
|
+
const goToReview = async (front, back) => {
|
|
162
|
+
setStage('processing');
|
|
163
|
+
const result = await runExtraction({
|
|
164
|
+
front: front.prepared.dataUrl,
|
|
165
|
+
back: back?.prepared.dataUrl,
|
|
166
|
+
});
|
|
167
|
+
const nextFront = await renderInitialCrop('front', front, result?.crops?.front ?? null);
|
|
168
|
+
const nextBack = back
|
|
169
|
+
? await renderInitialCrop('back', back, result?.crops?.back ?? null)
|
|
170
|
+
: null;
|
|
171
|
+
releaseUrl(frontCrop?.image.previewUrl);
|
|
172
|
+
releaseUrl(backCrop?.image.previewUrl);
|
|
173
|
+
setFrontCrop(nextFront);
|
|
174
|
+
setBackCrop(nextBack);
|
|
175
|
+
const seeded = toReviewValues(result);
|
|
176
|
+
setValues(seeded);
|
|
177
|
+
setName(buildDefaultCardName(seeded.card_network, seeded.number));
|
|
178
|
+
setEditedFields(new Set());
|
|
179
|
+
setFieldErrors({});
|
|
180
|
+
// The Crop step only exists when there is a photo to crop.
|
|
181
|
+
setStage(nextFront || nextBack ? 'crop' : 'review');
|
|
182
|
+
};
|
|
183
|
+
/** The user re-cropped a side in the review step's adjuster. */
|
|
184
|
+
const handleCropChange = (side, image, adjustments) => {
|
|
185
|
+
trackUrl(image.previewUrl);
|
|
186
|
+
if (side === 'front') {
|
|
187
|
+
releaseUrl(frontCrop?.image.previewUrl);
|
|
188
|
+
setFrontCrop((prev) => ({ image, box: prev?.box ?? null, adjustments }));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
releaseUrl(backCrop?.image.previewUrl);
|
|
192
|
+
setBackCrop((prev) => ({ image, box: prev?.box ?? null, adjustments }));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const handleCancel = async () => {
|
|
196
|
+
await abandonImport();
|
|
197
|
+
navigate('/cards');
|
|
198
|
+
};
|
|
199
|
+
const handleFieldChange = (field, value) => {
|
|
200
|
+
setValues((prev) => ({ ...prev, [field]: value }));
|
|
201
|
+
setEditedFields((prev) => new Set(prev).add(field));
|
|
202
|
+
setFieldErrors((prev) => {
|
|
203
|
+
if (!prev[field])
|
|
204
|
+
return prev;
|
|
205
|
+
const next = { ...prev };
|
|
206
|
+
delete next[field];
|
|
207
|
+
return next;
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
const lowConfidenceFields = useMemo(() => {
|
|
211
|
+
const flagged = new Set();
|
|
212
|
+
if (!extraction?.confidence)
|
|
213
|
+
return flagged;
|
|
214
|
+
for (const [field, score] of Object.entries(extraction.confidence)) {
|
|
215
|
+
// A field the user has already corrected no longer needs checking, and an
|
|
216
|
+
// empty field is covered by required-field validation instead.
|
|
217
|
+
if (editedFields.has(field))
|
|
218
|
+
continue;
|
|
219
|
+
if ((values[field] ?? '') === '')
|
|
220
|
+
continue;
|
|
221
|
+
if (score <= LOW_CONFIDENCE_THRESHOLD)
|
|
222
|
+
flagged.add(field);
|
|
223
|
+
}
|
|
224
|
+
return flagged;
|
|
225
|
+
}, [extraction, values, editedFields]);
|
|
226
|
+
// Fields whose value the AI supplied and the user has not touched since.
|
|
227
|
+
const aiFields = useMemo(() => {
|
|
228
|
+
const seeded = aiSeededFields(extraction);
|
|
229
|
+
for (const field of editedFields)
|
|
230
|
+
seeded.delete(field);
|
|
231
|
+
return seeded;
|
|
232
|
+
}, [extraction, editedFields]);
|
|
233
|
+
const cvvEntered = (values.cvv ?? '').trim() !== '';
|
|
234
|
+
const handleSave = async () => {
|
|
235
|
+
if (!cardType)
|
|
236
|
+
return;
|
|
237
|
+
const errors = {};
|
|
238
|
+
if (!name.trim())
|
|
239
|
+
errors.__name = 'A name is required';
|
|
240
|
+
for (const field of cardType.fields) {
|
|
241
|
+
if (field.required && (values[field.name] ?? '').trim() === '') {
|
|
242
|
+
errors[field.name] = `${field.label} is required`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (Object.keys(errors).length > 0) {
|
|
246
|
+
setFieldErrors(errors);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const outcome = await saveCard({ name, values, images: capturedSides });
|
|
250
|
+
if (!outcome)
|
|
251
|
+
return;
|
|
252
|
+
if (outcome.attachmentWarning) {
|
|
253
|
+
// Do not swallow this by navigating away — the user chose to attach
|
|
254
|
+
// photos and needs to know they are not there.
|
|
255
|
+
setSavedNotice({ secretId: outcome.secretId, warning: outcome.attachmentWarning });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
navigate(`/secrets/${outcome.secretId}`);
|
|
259
|
+
};
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// Gating
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
if (isStatusLoading) {
|
|
264
|
+
return (_jsx(Container, { maxWidth: "md", sx: { py: 6, textAlign: 'center' }, children: _jsx(CircularProgress, {}) }));
|
|
265
|
+
}
|
|
266
|
+
if (!cardExtractEnabled) {
|
|
267
|
+
// Three reasons, three messages: the viewer may not use AI (no `ai:use`, a
|
|
268
|
+
// Viewer), AI is switched off, or it is on but card scanning is not set up.
|
|
269
|
+
// There is deliberately no API key input anywhere on this page for any role:
|
|
270
|
+
// the key is set on the Console's AI page, behind `ai_config:write`, and
|
|
271
|
+
// nowhere else. Only a viewer who can open that page is offered the link.
|
|
272
|
+
const reason = !canUseAi
|
|
273
|
+
? 'forbidden'
|
|
274
|
+
: aiConfig.enabled === true
|
|
275
|
+
? 'not_set_up'
|
|
276
|
+
: 'off';
|
|
277
|
+
const text = {
|
|
278
|
+
forbidden: {
|
|
279
|
+
title: 'Card scanning is not available to you',
|
|
280
|
+
detail: 'Your role does not include AI features. You can still add a card by typing its details.',
|
|
281
|
+
},
|
|
282
|
+
off: {
|
|
283
|
+
title: 'AI is off',
|
|
284
|
+
detail: 'AI is off — an admin can turn it on in Console → AI.',
|
|
285
|
+
},
|
|
286
|
+
not_set_up: {
|
|
287
|
+
title: 'AI is not set up yet',
|
|
288
|
+
detail: 'AI is not set up yet — an administrator needs to add the OpenAI key and choose the card scanning model in Console → AI.',
|
|
289
|
+
},
|
|
290
|
+
}[reason];
|
|
291
|
+
return (_jsxs(Container, { maxWidth: "md", disableGutters: true, children: [_jsxs(Breadcrumbs, { sx: { mb: 2 }, children: [_jsx(Link, { color: "inherit", href: "/cards", onClick: (e) => {
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
navigate('/cards');
|
|
294
|
+
}, children: "Cards" }), _jsx(Typography, { sx: {
|
|
295
|
+
color: "text.primary"
|
|
296
|
+
}, children: "Import" })] }), _jsxs(Alert, { severity: "info", children: [_jsx(AlertTitle, { children: text.title }), text.detail, _jsxs(Box, { sx: { mt: 2, display: 'flex', gap: 1, flexWrap: 'wrap' }, children: [canOpenAiSettings && reason !== 'forbidden' && (_jsx(Button, { variant: "contained", onClick: () => navigate(AI_SETTINGS_PATH), children: "Open Console \u2192 AI" })), _jsx(Button, { variant: "outlined", onClick: () => navigate('/secrets/new'), children: "Add a card manually" }), _jsx(Button, { color: "inherit", onClick: () => navigate('/cards'), children: "Back to cards" })] })] })] }));
|
|
297
|
+
}
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
// Wizard
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
const photoSides = [
|
|
302
|
+
...(frontPhoto ? [{ side: 'front', file: frontPhoto.file, crop: frontCrop }] : []),
|
|
303
|
+
...(backPhoto ? [{ side: 'back', file: backPhoto.file, crop: backCrop }] : []),
|
|
304
|
+
];
|
|
305
|
+
const activeStep = isSaving || savedNotice ? 'save' : STAGE_STEP[stage];
|
|
306
|
+
const readCount = aiSeededFields(extraction).size;
|
|
307
|
+
return (_jsxs(Container, { maxWidth: "md", disableGutters: true, children: [_jsxs(Breadcrumbs, { sx: { mb: 1 }, children: [_jsx(Link, { color: "inherit", href: "/cards", onClick: (e) => {
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
navigate('/cards');
|
|
310
|
+
}, children: "Cards" }), _jsx(Typography, { sx: { color: 'text.primary' }, children: "Scan a card" })] }), _jsx(Typography, { variant: "h4", component: "h1", sx: { fontSize: { xs: '1.75rem', sm: '2.125rem' } }, children: "Scan a card" }), _jsx(CardFlowStepper, { active: activeStep, done: Boolean(savedNotice) }), typeError && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, children: typeError })), savedNotice ? (_jsxs(Paper, { variant: "outlined", sx: { p: { xs: 2, md: 3 } }, children: [_jsxs(Alert, { severity: "warning", sx: { mb: 2 }, children: [_jsx(AlertTitle, { children: "Card saved, photos not attached" }), savedNotice.warning] }), _jsx(Button, { variant: "contained", onClick: () => navigate(`/secrets/${savedNotice.secretId}`), children: "View the card" })] })) : stage === 'front' || stage === 'back' ? (_jsxs(_Fragment, { children: [_jsx(AiEgressNotice, {}), stage === 'front' ? (_jsx(CardCaptureStep, { side: "front", photo: frontPhoto, isProcessing: isPreparing, error: captureError, onFileSelected: (file) => void handleFileSelected('front', file), onRetake: () => handleRetake('front'), onContinue: () => setStage('back'), onCancel: () => void handleCancel() })) : (_jsx(CardCaptureStep, { side: "back", photo: backPhoto, isProcessing: isPreparing, error: captureError, onFileSelected: (file) => void handleFileSelected('back', file), onRetake: () => handleRetake('back'), onContinue: () => {
|
|
311
|
+
if (frontPhoto)
|
|
312
|
+
void goToReview(frontPhoto, backPhoto);
|
|
313
|
+
}, onSkip: () => {
|
|
314
|
+
releaseUrl(backPhoto?.previewUrl);
|
|
315
|
+
setBackPhoto(null);
|
|
316
|
+
if (frontPhoto)
|
|
317
|
+
void goToReview(frontPhoto, null);
|
|
318
|
+
}, onCancel: () => void handleCancel() }))] })) : stage === 'processing' ? (_jsxs(Paper, { variant: "outlined", sx: { p: 4, textAlign: 'center' }, "aria-live": "polite", children: [_jsx(CircularProgress, { sx: { mb: 2 } }), _jsx(Typography, { variant: "h6", component: "h2", gutterBottom: true, children: "Reading the card\u2026" }), _jsx(Typography, { variant: "body2", sx: { color: 'text.secondary' }, children: isExtracting
|
|
319
|
+
? 'Your photos have been sent to OpenAI, which locates the card and reads the printed details. This usually takes a few seconds.'
|
|
320
|
+
: 'Cropping the photos to the card…' })] })) : stage === 'crop' ? (_jsxs(Paper, { variant: "outlined", sx: { p: { xs: 2, md: 3 } }, children: [_jsx(Typography, { variant: "h6", component: "h2", gutterBottom: true, children: "Check the crop" }), extractionError || extraction?.partial ? (_jsx(Alert, { severity: "info", sx: { mb: 2 }, children: "The details could not be read automatically. You can type them in on the next step; your photos are kept." })) : readCount > 0 ? (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 2, color: 'text.secondary' }, children: [_jsx(AiIcon, { fontSize: "small", sx: { color: 'primary.main' } }), _jsxs(Typography, { variant: "body2", children: [readCount, " detail", readCount === 1 ? '' : 's', " read from the photo. You will check them on the next step."] })] })) : null, _jsx(CardCropReview, { sides: photoSides, onCropChange: handleCropChange }), _jsxs(Box, { sx: { display: 'flex', flexDirection: { xs: 'column', sm: 'row' }, gap: 1 }, children: [_jsx(Button, { variant: "contained", onClick: () => setStage('review'), sx: { minHeight: 44 }, children: "Continue to details" }), _jsx(Button, { variant: "outlined", onClick: () => setStage('front'), sx: { minHeight: 44 }, children: "Retake photos" }), _jsx(Box, { sx: { flexGrow: 1, display: { xs: 'none', sm: 'block' } } }), _jsx(Button, { color: "inherit", onClick: () => void handleCancel(), sx: { minHeight: 44 }, children: "Cancel" })] })] })) : (_jsxs(Paper, { variant: "outlined", sx: { p: { xs: 2, md: 3 } }, children: [_jsx(Typography, { variant: "h6", component: "h2", gutterBottom: true, children: "Check the details" }), extractionError && (_jsxs(Alert, { severity: extractionError.adminActionRequired ? 'warning' : 'error', sx: { mb: 2 }, action: extractionError.retryable ? (_jsx(Button, { color: "inherit", size: "small", onClick: () => {
|
|
321
|
+
if (frontPhoto)
|
|
322
|
+
void goToReview(frontPhoto, backPhoto);
|
|
323
|
+
}, children: "Try again" })) : undefined, children: [_jsx(AlertTitle, { children: extractionError.title }), extractionError.detail, extractionError.adminLink && canOpenAiSettings && (_jsx(Box, { sx: { mt: 1 }, children: _jsx(Link, { component: RouterLink, to: extractionError.adminLink.to, children: extractionError.adminLink.label }) })), _jsx(Typography, { variant: "body2", sx: { mt: 1 }, children: "Your photos were kept \u2014 fill the details in below and they will be attached to the card." })] })), extraction?.partial && !extractionError && (_jsx(Alert, { severity: "warning", sx: { mb: 2 }, children: "Nothing legible came back from the photos. Enter the details below." })), saveError && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, children: saveError })), _jsx(CardCropReview, { compact: true, sides: photoSides, disabled: isSaving, onEdit: () => setStage('crop'), onCropChange: handleCropChange }), aiFields.size > 0 && (_jsxs(Box, { sx: {
|
|
324
|
+
display: 'flex',
|
|
325
|
+
alignItems: 'flex-start',
|
|
326
|
+
gap: 1,
|
|
327
|
+
mb: 2,
|
|
328
|
+
p: 1.5,
|
|
329
|
+
borderRadius: 1,
|
|
330
|
+
borderLeft: 3,
|
|
331
|
+
borderColor: 'primary.main',
|
|
332
|
+
bgcolor: 'action.hover',
|
|
333
|
+
}, children: [_jsx(AiIcon, { fontSize: "small", sx: { color: 'primary.main', mt: 0.25 } }), _jsxs(Typography, { variant: "body2", children: ["Fields marked ", _jsx("strong", { children: "AI" }), " were read from your photo; fields marked ", _jsx("strong", { children: "Check" }), " were hard to read. Compare them with the card. The CVV is never read from the photo \u2014 type it yourself."] })] })), _jsx(TextField, { fullWidth: true, required: true, label: "Name", value: name, onChange: (e) => {
|
|
334
|
+
setName(e.target.value);
|
|
335
|
+
setFieldErrors((prev) => {
|
|
336
|
+
if (!prev.__name)
|
|
337
|
+
return prev;
|
|
338
|
+
const next = { ...prev };
|
|
339
|
+
delete next.__name;
|
|
340
|
+
return next;
|
|
341
|
+
});
|
|
342
|
+
}, error: Boolean(fieldErrors.__name), helperText: fieldErrors.__name ?? 'Shown in your card list.', disabled: isSaving, sx: { mb: 2 } }), isTypeLoading ? (_jsx(Box, { sx: { display: 'flex', justifyContent: 'center', py: 4 }, children: _jsx(CircularProgress, {}) })) : (_jsx(CardReviewForm, { fields: cardType?.fields ?? [], values: values, onChange: handleFieldChange, lowConfidenceFields: lowConfidenceFields, aiFields: aiFields, warnings: extraction?.warnings ?? [], errors: fieldErrors, disabled: isSaving })), !cvvEntered && (_jsx(Alert, { severity: "info", sx: { mt: 2 }, children: "Enter the CVV / CVC to save this card. It is never read from the photo, so type it from the card yourself." })), _jsxs(Box, { sx: { display: 'flex', flexDirection: { xs: 'column', sm: 'row' }, gap: 1, mt: 3 }, children: [_jsx(Button, { variant: "contained", onClick: () => void handleSave(), disabled: isSaving || !cvvEntered || !cardType, sx: { minHeight: 44 }, children: isSaving ? 'Saving…' : 'Save card' }), _jsx(Box, { sx: { flexGrow: 1, display: { xs: 'none', sm: 'block' } } }), _jsx(Button, { color: "inherit", onClick: () => void handleCancel(), disabled: isSaving, sx: { minHeight: 44 }, children: "Cancel" })] })] }))] }));
|
|
343
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renew a card in place, creating a new version.
|
|
3
|
+
*
|
|
4
|
+
* Capture (both photos optional) -> Crop (only when a photo was taken; the AI
|
|
5
|
+
* reads the new card first when it is on) -> Review (per-field diff) -> Save.
|
|
6
|
+
* The same four-step stepper as the import wizard (E10.5, #96).
|
|
7
|
+
*
|
|
8
|
+
* The capture steps collect FULL photos, exactly as the import wizard now
|
|
9
|
+
* does: the prepared full frame goes to the extraction endpoint, the AI
|
|
10
|
+
* returns a bounding box per side, and the stored attachment is cropped from
|
|
11
|
+
* that box (adjustable on the diff step). With AI off, any photo is cropped by
|
|
12
|
+
* the centred auto-fit instead — still adjustable. Only the cropped version is
|
|
13
|
+
* ever uploaded to storage.
|
|
14
|
+
*
|
|
15
|
+
* Three things separate this from the import wizard, and each one is load-bearing:
|
|
16
|
+
*
|
|
17
|
+
* 1. THE DIFF. The user is not entering a card, they are replacing one they
|
|
18
|
+
* already hold. The review step therefore shows current-vs-proposed per
|
|
19
|
+
* field, so what changes (number, expiry, code) and what does not
|
|
20
|
+
* (cardholder, network) is visible before anything is committed.
|
|
21
|
+
* 2. IT WORKS WITHOUT AI. Only the extraction step is gated on `useAiStatus`.
|
|
22
|
+
* A reissued card arrives whether or not an administrator has configured an
|
|
23
|
+
* OpenAI key, so with AI off the same wizard runs with the photo steps
|
|
24
|
+
* optional and every value typed by hand. Gating the page itself would make
|
|
25
|
+
* the feature unreachable for exactly the users who cannot fix it.
|
|
26
|
+
* 3. PHOTOS ARE OPTIONAL THROUGHOUT. A renewal with no new photos carries the
|
|
27
|
+
* old version's images forward server-side, which is what keeps the old
|
|
28
|
+
* card readable in its own version of the history.
|
|
29
|
+
*
|
|
30
|
+
* The CVV is typed by hand, always: the OUTGOING card's code is never carried
|
|
31
|
+
* forward (a reissued card always has a new one) and nothing read from the new
|
|
32
|
+
* card's photo seeds it either. Saving stays blocked until the field holds
|
|
33
|
+
* something.
|
|
34
|
+
*/
|
|
35
|
+
export default function RenewCardPage(): import("react").JSX.Element;
|