@striae-org/striae 3.0.4
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/.env.example +100 -0
- package/LICENSE +190 -0
- package/NOTICE +18 -0
- package/README.md +133 -0
- package/app/components/actions/case-export/core-export.ts +328 -0
- package/app/components/actions/case-export/data-processing.ts +167 -0
- package/app/components/actions/case-export/download-handlers.ts +900 -0
- package/app/components/actions/case-export/index.ts +41 -0
- package/app/components/actions/case-export/metadata-helpers.ts +107 -0
- package/app/components/actions/case-export/types-constants.ts +56 -0
- package/app/components/actions/case-export/validation-utils.ts +25 -0
- package/app/components/actions/case-export.ts +4 -0
- package/app/components/actions/case-import/annotation-import.ts +35 -0
- package/app/components/actions/case-import/confirmation-import.ts +363 -0
- package/app/components/actions/case-import/image-operations.ts +61 -0
- package/app/components/actions/case-import/index.ts +39 -0
- package/app/components/actions/case-import/orchestrator.ts +420 -0
- package/app/components/actions/case-import/storage-operations.ts +270 -0
- package/app/components/actions/case-import/validation.ts +189 -0
- package/app/components/actions/case-import/zip-processing.ts +413 -0
- package/app/components/actions/case-manage.ts +524 -0
- package/app/components/actions/case-review.ts +4 -0
- package/app/components/actions/confirm-export.ts +351 -0
- package/app/components/actions/generate-pdf.ts +210 -0
- package/app/components/actions/image-manage.ts +385 -0
- package/app/components/actions/notes-manage.ts +33 -0
- package/app/components/actions/signout.module.css +15 -0
- package/app/components/actions/signout.tsx +50 -0
- package/app/components/audit/user-audit-viewer.tsx +975 -0
- package/app/components/audit/user-audit.module.css +568 -0
- package/app/components/auth/auth-provider.tsx +78 -0
- package/app/components/auth/mfa-enrollment.module.css +268 -0
- package/app/components/auth/mfa-enrollment.tsx +398 -0
- package/app/components/auth/mfa-verification.module.css +251 -0
- package/app/components/auth/mfa-verification.tsx +295 -0
- package/app/components/button/button.module.css +63 -0
- package/app/components/button/button.tsx +46 -0
- package/app/components/canvas/box-annotations/box-annotations.module.css +170 -0
- package/app/components/canvas/box-annotations/box-annotations.tsx +634 -0
- package/app/components/canvas/canvas.module.css +314 -0
- package/app/components/canvas/canvas.tsx +449 -0
- package/app/components/canvas/confirmation/confirmation.module.css +187 -0
- package/app/components/canvas/confirmation/confirmation.tsx +214 -0
- package/app/components/colors/colors.module.css +59 -0
- package/app/components/colors/colors.tsx +68 -0
- package/app/components/form/base-form.tsx +21 -0
- package/app/components/form/form-button.tsx +28 -0
- package/app/components/form/form-field.tsx +53 -0
- package/app/components/form/form-message.tsx +17 -0
- package/app/components/form/form-toggle.tsx +23 -0
- package/app/components/form/form.module.css +427 -0
- package/app/components/form/index.ts +6 -0
- package/app/components/icon/icon.module.css +3 -0
- package/app/components/icon/icon.tsx +27 -0
- package/app/components/icon/icons.svg +102 -0
- package/app/components/icon/manifest.json +110 -0
- package/app/components/sidebar/case-export/case-export.module.css +386 -0
- package/app/components/sidebar/case-export/case-export.tsx +317 -0
- package/app/components/sidebar/case-import/case-import.module.css +626 -0
- package/app/components/sidebar/case-import/case-import.tsx +404 -0
- package/app/components/sidebar/case-import/components/CasePreviewSection.tsx +72 -0
- package/app/components/sidebar/case-import/components/ConfirmationDialog.tsx +72 -0
- package/app/components/sidebar/case-import/components/ConfirmationPreviewSection.tsx +71 -0
- package/app/components/sidebar/case-import/components/ExistingCaseSection.tsx +40 -0
- package/app/components/sidebar/case-import/components/FileSelector.tsx +161 -0
- package/app/components/sidebar/case-import/components/ProgressSection.tsx +46 -0
- package/app/components/sidebar/case-import/hooks/useFilePreview.ts +101 -0
- package/app/components/sidebar/case-import/hooks/useImportExecution.ts +152 -0
- package/app/components/sidebar/case-import/hooks/useImportState.ts +88 -0
- package/app/components/sidebar/case-import/index.ts +18 -0
- package/app/components/sidebar/case-import/utils/file-validation.ts +43 -0
- package/app/components/sidebar/cases/case-sidebar.tsx +827 -0
- package/app/components/sidebar/cases/cases-modal.module.css +166 -0
- package/app/components/sidebar/cases/cases-modal.tsx +201 -0
- package/app/components/sidebar/cases/cases.module.css +713 -0
- package/app/components/sidebar/files/files-modal.module.css +209 -0
- package/app/components/sidebar/files/files-modal.tsx +239 -0
- package/app/components/sidebar/hash/hash-utility.module.css +366 -0
- package/app/components/sidebar/hash/hash-utility.tsx +982 -0
- package/app/components/sidebar/notes/notes-modal.tsx +51 -0
- package/app/components/sidebar/notes/notes-sidebar.tsx +491 -0
- package/app/components/sidebar/notes/notes.module.css +360 -0
- package/app/components/sidebar/sidebar-container.tsx +149 -0
- package/app/components/sidebar/sidebar.module.css +321 -0
- package/app/components/sidebar/sidebar.tsx +215 -0
- package/app/components/sidebar/upload/image-upload-zone.module.css +123 -0
- package/app/components/sidebar/upload/image-upload-zone.tsx +330 -0
- package/app/components/theme-provider/theme-provider.tsx +131 -0
- package/app/components/theme-provider/theme.ts +155 -0
- package/app/components/toast/toast.module.css +137 -0
- package/app/components/toast/toast.tsx +56 -0
- package/app/components/toolbar/toolbar-color-selector.module.css +171 -0
- package/app/components/toolbar/toolbar-color-selector.tsx +129 -0
- package/app/components/toolbar/toolbar.module.css +42 -0
- package/app/components/toolbar/toolbar.tsx +167 -0
- package/app/components/user/delete-account.module.css +274 -0
- package/app/components/user/delete-account.tsx +471 -0
- package/app/components/user/inactivity-warning.module.css +145 -0
- package/app/components/user/inactivity-warning.tsx +84 -0
- package/app/components/user/manage-profile.module.css +190 -0
- package/app/components/user/manage-profile.tsx +253 -0
- package/app/components/user/mfa-phone-update.tsx +739 -0
- package/app/config-example/admin-service.json +13 -0
- package/app/config-example/config.json +17 -0
- package/app/config-example/firebase.ts +21 -0
- package/app/config-example/inactivity.ts +13 -0
- package/app/config-example/meta-config.json +6 -0
- package/app/contexts/auth.context.ts +12 -0
- package/app/entry.client.tsx +12 -0
- package/app/entry.server.tsx +44 -0
- package/app/hooks/useInactivityTimeout.ts +110 -0
- package/app/root.tsx +170 -0
- package/app/routes/_index.tsx +16 -0
- package/app/routes/auth/emailActionHandler.module.css +232 -0
- package/app/routes/auth/emailActionHandler.tsx +405 -0
- package/app/routes/auth/emailVerification.tsx +120 -0
- package/app/routes/auth/login.module.css +523 -0
- package/app/routes/auth/login.tsx +654 -0
- package/app/routes/auth/passwordReset.module.css +274 -0
- package/app/routes/auth/passwordReset.tsx +154 -0
- package/app/routes/auth/route.ts +16 -0
- package/app/routes/mobile-prevented/mobilePrevented.module.css +47 -0
- package/app/routes/mobile-prevented/mobilePrevented.tsx +26 -0
- package/app/routes/mobile-prevented/route.ts +14 -0
- package/app/routes/striae/striae.module.css +30 -0
- package/app/routes/striae/striae.tsx +417 -0
- package/app/services/audit-export.service.ts +755 -0
- package/app/services/audit.service.ts +1454 -0
- package/app/services/firebase-errors.ts +106 -0
- package/app/services/firebase.ts +15 -0
- package/app/styles/legal-pages.module.css +113 -0
- package/app/styles/root.module.css +146 -0
- package/app/tailwind.css +225 -0
- package/app/types/annotations.ts +45 -0
- package/app/types/audit.ts +301 -0
- package/app/types/case.ts +90 -0
- package/app/types/export.ts +8 -0
- package/app/types/file.ts +30 -0
- package/app/types/import.ts +107 -0
- package/app/types/index.ts +24 -0
- package/app/types/user.ts +38 -0
- package/app/utils/SHA256.ts +461 -0
- package/app/utils/annotation-timestamp.ts +25 -0
- package/app/utils/audit-export-signature.ts +117 -0
- package/app/utils/auth-action-settings.ts +48 -0
- package/app/utils/auth.ts +34 -0
- package/app/utils/batch-operations.ts +135 -0
- package/app/utils/confirmation-signature.ts +193 -0
- package/app/utils/data-operations.ts +871 -0
- package/app/utils/device-detection.ts +5 -0
- package/app/utils/html-sanitizer.ts +80 -0
- package/app/utils/id-generator.ts +36 -0
- package/app/utils/meta.ts +48 -0
- package/app/utils/mfa-phone.ts +97 -0
- package/app/utils/mfa.ts +79 -0
- package/app/utils/password-policy.ts +28 -0
- package/app/utils/permissions.ts +562 -0
- package/app/utils/signature-utils.ts +160 -0
- package/app/utils/style.ts +83 -0
- package/app/utils/version.ts +5 -0
- package/firebase.json +11 -0
- package/functions/[[path]].ts +10 -0
- package/package.json +138 -0
- package/postcss.config.js +6 -0
- package/public/.well-known/publickey.info@striae.org.asc +17 -0
- package/public/.well-known/security.txt +7 -0
- package/public/_headers +28 -0
- package/public/_routes.json +13 -0
- package/public/assets/striae.jpg +0 -0
- package/public/clear.jpg +0 -0
- package/public/favicon.ico +0 -0
- package/public/favicon.svg +9 -0
- package/public/icon-256.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/logo-dark.png +0 -0
- package/public/manifest.json +25 -0
- package/public/oin-badge.png +0 -0
- package/public/shortcut.png +0 -0
- package/public/social-image.png +0 -0
- package/public/striae-ascii.txt +10 -0
- package/scripts/deploy-all.sh +100 -0
- package/scripts/deploy-config.sh +940 -0
- package/scripts/deploy-pages.sh +34 -0
- package/scripts/deploy-worker-secrets.sh +215 -0
- package/scripts/dev.cjs +23 -0
- package/scripts/install-workers.sh +88 -0
- package/scripts/run-eslint.cjs +35 -0
- package/scripts/update-compatibility-dates.cjs +124 -0
- package/scripts/update-markdown-versions.cjs +43 -0
- package/tailwind.config.ts +22 -0
- package/tsconfig.json +33 -0
- package/vite.config.ts +35 -0
- package/worker-configuration.d.ts +7490 -0
- package/workers/audit-worker/package.json +17 -0
- package/workers/audit-worker/src/audit-worker.example.ts +195 -0
- package/workers/audit-worker/worker-configuration.d.ts +7448 -0
- package/workers/audit-worker/wrangler.jsonc.example +29 -0
- package/workers/data-worker/package.json +17 -0
- package/workers/data-worker/src/data-worker.example.ts +267 -0
- package/workers/data-worker/src/signature-utils.ts +79 -0
- package/workers/data-worker/src/signing-payload-utils.ts +290 -0
- package/workers/data-worker/worker-configuration.d.ts +7448 -0
- package/workers/data-worker/wrangler.jsonc.example +30 -0
- package/workers/image-worker/package.json +17 -0
- package/workers/image-worker/src/image-worker.example.ts +180 -0
- package/workers/image-worker/worker-configuration.d.ts +7447 -0
- package/workers/image-worker/wrangler.jsonc.example +22 -0
- package/workers/keys-worker/package.json +17 -0
- package/workers/keys-worker/src/keys.example.ts +66 -0
- package/workers/keys-worker/src/keys.ts +66 -0
- package/workers/keys-worker/worker-configuration.d.ts +7447 -0
- package/workers/keys-worker/wrangler.jsonc.example +22 -0
- package/workers/pdf-worker/package.json +17 -0
- package/workers/pdf-worker/src/format-striae.ts +534 -0
- package/workers/pdf-worker/src/pdf-worker.example.ts +119 -0
- package/workers/pdf-worker/src/report-types.ts +69 -0
- package/workers/pdf-worker/worker-configuration.d.ts +7448 -0
- package/workers/pdf-worker/wrangler.jsonc.example +26 -0
- package/workers/user-worker/package.json +17 -0
- package/workers/user-worker/src/user-worker.example.ts +636 -0
- package/workers/user-worker/worker-configuration.d.ts +7448 -0
- package/workers/user-worker/wrangler.jsonc.example +29 -0
- package/wrangler.toml.example +8 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
.modalOverlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
background-color: color-mix(in lab, var(--background) 50%, transparent);
|
|
5
|
+
display: flex;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
align-items: center;
|
|
8
|
+
z-index: var(--zIndex5);
|
|
9
|
+
transition: background-color var(--durationM) var(--bezierFastoutSlowin);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.modal {
|
|
13
|
+
background: var(--backgroundLight);
|
|
14
|
+
border-radius: var(--spaceXS);
|
|
15
|
+
width: 90%;
|
|
16
|
+
max-width: var(--maxWidthL);
|
|
17
|
+
max-height: 80vh;
|
|
18
|
+
box-shadow: 0 var(--spaceXS) var(--spaceL) color-mix(in lab, var(--black) 10%, transparent);
|
|
19
|
+
transition: background-color var(--durationM) var(--bezierFastoutSlowin);
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.modalHeader {
|
|
25
|
+
display: flex;
|
|
26
|
+
font-size: var(--fontSizeBodyL);
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
align-items: center;
|
|
29
|
+
padding: var(--spaceL);
|
|
30
|
+
border-bottom: 1px solid color-mix(in lab, var(--text) 10%, transparent);
|
|
31
|
+
color: var(--textTitle);
|
|
32
|
+
flex-shrink: 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.modalContent {
|
|
36
|
+
padding: var(--spaceL);
|
|
37
|
+
overflow-y: auto;
|
|
38
|
+
flex: 1;
|
|
39
|
+
min-height: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.closeButton {
|
|
43
|
+
background: none;
|
|
44
|
+
border: none;
|
|
45
|
+
font-size: var(--fontSizeH5);
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
padding: var(--spaceS);
|
|
48
|
+
color: var(--textLight);
|
|
49
|
+
transition: color var(--durationS) var(--bezierFastoutSlowin);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.closeButton:hover {
|
|
53
|
+
color: var(--text);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.filesList {
|
|
57
|
+
list-style: none;
|
|
58
|
+
padding: 0;
|
|
59
|
+
margin: 0;
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
gap: var(--spaceM);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.fileItem {
|
|
66
|
+
display: flex;
|
|
67
|
+
justify-content: space-between;
|
|
68
|
+
align-items: center;
|
|
69
|
+
padding: var(--spaceM) var(--spaceL);
|
|
70
|
+
border: 1px solid #e9ecef;
|
|
71
|
+
border-radius: var(--spaceXS);
|
|
72
|
+
background: var(--backgroundLight);
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
transition: all var(--durationS) var(--bezierFastoutSlowin);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.fileItem:hover {
|
|
78
|
+
background-color: color-mix(in lab, var(--background) 95%, transparent);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.fileItem.active {
|
|
82
|
+
background-color: color-mix(in lab, var(--background) 90%, transparent);
|
|
83
|
+
font-weight: var(--fontWeightMedium);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.fileInfo {
|
|
87
|
+
flex: 1;
|
|
88
|
+
min-width: 0; /* Allow text truncation */
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.fileName {
|
|
92
|
+
font-weight: var(--fontWeightMedium);
|
|
93
|
+
color: var(--textBody);
|
|
94
|
+
margin-bottom: var(--spaceXS);
|
|
95
|
+
word-break: break-word;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.fileDate {
|
|
99
|
+
font-size: var(--fontSizeBodyS);
|
|
100
|
+
color: var(--textLight);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.deleteButton {
|
|
104
|
+
background: none;
|
|
105
|
+
border: none;
|
|
106
|
+
color: #dc3545;
|
|
107
|
+
font-size: 1.2rem;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
padding: 0.5rem;
|
|
110
|
+
border-radius: var(--spaceXS);
|
|
111
|
+
margin-left: var(--spaceM);
|
|
112
|
+
transition: all var(--durationS) var(--bezierFastoutSlowin);
|
|
113
|
+
flex-shrink: 0;
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: center;
|
|
116
|
+
justify-content: center;
|
|
117
|
+
min-width: 32px;
|
|
118
|
+
height: 32px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.deleteButton:hover:not(:disabled) {
|
|
122
|
+
color: #bd2130;
|
|
123
|
+
background-color: rgba(220, 53, 69, 0.1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.deleteButton:disabled {
|
|
127
|
+
opacity: 0.5;
|
|
128
|
+
cursor: not-allowed;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.errorState,
|
|
132
|
+
.emptyState {
|
|
133
|
+
text-align: center;
|
|
134
|
+
padding: var(--space2XL);
|
|
135
|
+
color: var(--textLight);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.errorState {
|
|
139
|
+
color: var(--error);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.pagination {
|
|
143
|
+
display: flex;
|
|
144
|
+
justify-content: space-between;
|
|
145
|
+
align-items: center;
|
|
146
|
+
padding: var(--spaceL);
|
|
147
|
+
border-top: 1px solid color-mix(in lab, var(--text) 10%, transparent);
|
|
148
|
+
background: var(--backgroundLight);
|
|
149
|
+
flex-shrink: 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.pagination button {
|
|
153
|
+
background: var(--primary);
|
|
154
|
+
color: var(--white);
|
|
155
|
+
border: none;
|
|
156
|
+
padding: var(--spaceS) var(--spaceM);
|
|
157
|
+
border-radius: var(--spaceXS);
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
font-size: var(--fontSizeBodyS);
|
|
160
|
+
transition: all var(--durationS) var(--bezierFastoutSlowin);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.pagination button:hover:not(:disabled) {
|
|
164
|
+
background: color-mix(in lab, var(--primary) 85%, var(--black));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.pagination button:disabled {
|
|
168
|
+
background: color-mix(in lab, var(--text) 20%, transparent);
|
|
169
|
+
color: var(--textLight);
|
|
170
|
+
cursor: not-allowed;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.pagination span {
|
|
174
|
+
font-size: var(--fontSizeBodyS);
|
|
175
|
+
color: var(--textBody);
|
|
176
|
+
font-weight: var(--fontWeightMedium);
|
|
177
|
+
}
|
|
178
|
+
/* Confirmation Status Indicators */
|
|
179
|
+
.fileItemNotConfirmed {
|
|
180
|
+
background-color: color-mix(in lab, var(--warning) 15%, var(--backgroundLight));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.fileItemNotConfirmed:hover {
|
|
184
|
+
background-color: color-mix(in lab, var(--warning) 20%, var(--backgroundLight));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.fileItem.active.fileItemNotConfirmed {
|
|
188
|
+
background-color: color-mix(in lab, var(--warning) 15%, var(--backgroundLight));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.fileItem.active.fileItemNotConfirmed:hover {
|
|
192
|
+
background-color: color-mix(in lab, var(--warning) 20%, var(--backgroundLight));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.fileItemConfirmed {
|
|
196
|
+
background-color: color-mix(in lab, var(--success) 20%, var(--backgroundLight));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.fileItemConfirmed:hover {
|
|
200
|
+
background-color: color-mix(in lab, var(--success) 28%, var(--backgroundLight));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.fileItem.active.fileItemConfirmed {
|
|
204
|
+
background-color: color-mix(in lab, var(--success) 20%, var(--backgroundLight));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.fileItem.active.fileItemConfirmed:hover {
|
|
208
|
+
background-color: color-mix(in lab, var(--success) 28%, var(--backgroundLight));
|
|
209
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import React, { useState, useContext, useEffect } from 'react';
|
|
2
|
+
import { AuthContext } from '~/contexts/auth.context';
|
|
3
|
+
import { deleteFile } from '~/components/actions/image-manage';
|
|
4
|
+
import { getFileAnnotations } from '~/utils/data-operations';
|
|
5
|
+
import { FileData } from '~/types';
|
|
6
|
+
import styles from './files-modal.module.css';
|
|
7
|
+
|
|
8
|
+
interface FilesModalProps {
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
onFileSelect?: (file: FileData) => void;
|
|
12
|
+
currentCase: string | null;
|
|
13
|
+
files: FileData[];
|
|
14
|
+
setFiles: React.Dispatch<React.SetStateAction<FileData[]>>;
|
|
15
|
+
isReadOnly?: boolean;
|
|
16
|
+
selectedFileId?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const FILES_PER_PAGE = 10;
|
|
20
|
+
|
|
21
|
+
// Type to track confirmation status for each file
|
|
22
|
+
interface FileConfirmationStatus {
|
|
23
|
+
[fileId: string]: {
|
|
24
|
+
includeConfirmation: boolean;
|
|
25
|
+
isConfirmed: boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const FilesModal = ({ isOpen, onClose, onFileSelect, currentCase, files, setFiles, isReadOnly = false, selectedFileId }: FilesModalProps) => {
|
|
30
|
+
const { user } = useContext(AuthContext);
|
|
31
|
+
const [error, setError] = useState<string | null>(null);
|
|
32
|
+
const [currentPage, setCurrentPage] = useState(0);
|
|
33
|
+
const [deletingFileId, setDeletingFileId] = useState<string | null>(null);
|
|
34
|
+
const [fileConfirmationStatus, setFileConfirmationStatus] = useState<FileConfirmationStatus>({});
|
|
35
|
+
|
|
36
|
+
const totalPages = Math.ceil(files.length / FILES_PER_PAGE);
|
|
37
|
+
const startIndex = currentPage * FILES_PER_PAGE;
|
|
38
|
+
const endIndex = startIndex + FILES_PER_PAGE;
|
|
39
|
+
const currentFiles = files.slice(startIndex, endIndex);
|
|
40
|
+
|
|
41
|
+
// Fetch confirmation status only for currently visible paginated files
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const fetchConfirmationStatuses = async () => {
|
|
44
|
+
const visibleFiles = currentFiles;
|
|
45
|
+
|
|
46
|
+
if (!isOpen || !currentCase || !user || visibleFiles.length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Fetch annotations in parallel for only visible files
|
|
51
|
+
const annotationPromises = visibleFiles.map(async (file) => {
|
|
52
|
+
try {
|
|
53
|
+
const annotations = await getFileAnnotations(user, currentCase, file.id);
|
|
54
|
+
return {
|
|
55
|
+
fileId: file.id,
|
|
56
|
+
includeConfirmation: annotations?.includeConfirmation ?? false,
|
|
57
|
+
isConfirmed: !!(annotations?.includeConfirmation && annotations?.confirmationData),
|
|
58
|
+
};
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error(`Error fetching annotations for file ${file.id}:`, err);
|
|
61
|
+
return {
|
|
62
|
+
fileId: file.id,
|
|
63
|
+
includeConfirmation: false,
|
|
64
|
+
isConfirmed: false,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Wait for all fetches to complete
|
|
70
|
+
const results = await Promise.all(annotationPromises);
|
|
71
|
+
|
|
72
|
+
// Build the statuses map from results
|
|
73
|
+
const statuses: FileConfirmationStatus = {};
|
|
74
|
+
results.forEach((result) => {
|
|
75
|
+
statuses[result.fileId] = {
|
|
76
|
+
includeConfirmation: result.includeConfirmation,
|
|
77
|
+
isConfirmed: result.isConfirmed,
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
setFileConfirmationStatus(statuses);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
fetchConfirmationStatuses();
|
|
85
|
+
}, [isOpen, currentCase, currentPage, files, user]);
|
|
86
|
+
|
|
87
|
+
const handleFileSelect = (file: FileData) => {
|
|
88
|
+
onFileSelect?.(file);
|
|
89
|
+
onClose();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handleDeleteFile = async (fileId: string, event: React.MouseEvent) => {
|
|
93
|
+
event.stopPropagation(); // Prevent file selection when clicking delete
|
|
94
|
+
|
|
95
|
+
// Don't allow file deletion for read-only cases
|
|
96
|
+
if (isReadOnly) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!user || !currentCase || !window.confirm('Are you sure you want to delete this file?')) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setDeletingFileId(fileId);
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
await deleteFile(user, currentCase, fileId);
|
|
108
|
+
// Remove the deleted file from the list
|
|
109
|
+
const updatedFiles = files.filter(f => f.id !== fileId);
|
|
110
|
+
setFiles(updatedFiles);
|
|
111
|
+
|
|
112
|
+
// Adjust page if needed
|
|
113
|
+
const newTotalPages = Math.ceil(updatedFiles.length / FILES_PER_PAGE);
|
|
114
|
+
if (currentPage >= newTotalPages && newTotalPages > 0) {
|
|
115
|
+
setCurrentPage(newTotalPages - 1);
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.error('Error deleting file:', err);
|
|
119
|
+
setError('Failed to delete file');
|
|
120
|
+
setTimeout(() => setError(null), 3000);
|
|
121
|
+
} finally {
|
|
122
|
+
setDeletingFileId(null);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const handleKeyDown = (event: React.KeyboardEvent) => {
|
|
127
|
+
if (event.key === 'Escape') {
|
|
128
|
+
onClose();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const formatDate = (dateString: string) => {
|
|
133
|
+
try {
|
|
134
|
+
return new Date(dateString).toLocaleDateString();
|
|
135
|
+
} catch {
|
|
136
|
+
return 'Unknown';
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const formatFileName = (filename: string) => {
|
|
141
|
+
if (filename.length <= 30) return filename;
|
|
142
|
+
const lastDotIndex = filename.lastIndexOf('.');
|
|
143
|
+
if (lastDotIndex === -1) {
|
|
144
|
+
return filename.substring(0, 27) + '…';
|
|
145
|
+
}
|
|
146
|
+
const name = filename.substring(0, lastDotIndex);
|
|
147
|
+
const ext = filename.substring(lastDotIndex);
|
|
148
|
+
const maxNameLength = 27 - ext.length;
|
|
149
|
+
if (name.length <= maxNameLength) return filename;
|
|
150
|
+
return name.substring(0, maxNameLength) + '…' + ext;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
if (!isOpen) return null;
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div className={styles.modalOverlay} onKeyDown={handleKeyDown} tabIndex={-1}>
|
|
157
|
+
<div className={styles.modal}>
|
|
158
|
+
<div className={styles.modalHeader}>
|
|
159
|
+
<h2>Files in Case {currentCase}</h2>
|
|
160
|
+
<button
|
|
161
|
+
className={styles.closeButton}
|
|
162
|
+
onClick={onClose}
|
|
163
|
+
aria-label="Close modal"
|
|
164
|
+
>
|
|
165
|
+
×
|
|
166
|
+
</button>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<div className={styles.modalContent}>
|
|
170
|
+
{error ? (
|
|
171
|
+
<div className={styles.errorState}>{error}</div>
|
|
172
|
+
) : files.length === 0 ? (
|
|
173
|
+
<div className={styles.emptyState}>No files in this case</div>
|
|
174
|
+
) : (
|
|
175
|
+
<div className={styles.filesList}>
|
|
176
|
+
{currentFiles.map((file) => {
|
|
177
|
+
const confirmationStatus = fileConfirmationStatus[file.id];
|
|
178
|
+
let confirmationClass = '';
|
|
179
|
+
|
|
180
|
+
if (confirmationStatus?.includeConfirmation) {
|
|
181
|
+
confirmationClass = confirmationStatus.isConfirmed
|
|
182
|
+
? styles.fileItemConfirmed
|
|
183
|
+
: styles.fileItemNotConfirmed;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div
|
|
188
|
+
key={file.id}
|
|
189
|
+
className={`${styles.fileItem} ${selectedFileId === file.id ? styles.active : ''} ${confirmationClass}`}
|
|
190
|
+
onClick={() => handleFileSelect(file)}
|
|
191
|
+
>
|
|
192
|
+
<div className={styles.fileInfo}>
|
|
193
|
+
<div className={styles.fileName} title={file.originalFilename}>
|
|
194
|
+
{formatFileName(file.originalFilename)}
|
|
195
|
+
</div>
|
|
196
|
+
<div className={styles.fileDate}>
|
|
197
|
+
Uploaded: {formatDate(file.uploadedAt)}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
<button
|
|
201
|
+
className={styles.deleteButton}
|
|
202
|
+
onClick={(e) => handleDeleteFile(file.id, e)}
|
|
203
|
+
disabled={isReadOnly || deletingFileId === file.id}
|
|
204
|
+
aria-label={`Delete ${file.originalFilename}`}
|
|
205
|
+
title={isReadOnly ? "Cannot delete files for read-only cases" : "Delete file"}
|
|
206
|
+
style={{ opacity: isReadOnly ? 0.5 : 1, cursor: isReadOnly ? 'not-allowed' : 'pointer' }}
|
|
207
|
+
>
|
|
208
|
+
{deletingFileId === file.id ? '⏳' : '×'}
|
|
209
|
+
</button>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
})}
|
|
213
|
+
</div>
|
|
214
|
+
)}
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
{totalPages > 1 && (
|
|
218
|
+
<div className={styles.pagination}>
|
|
219
|
+
<button
|
|
220
|
+
onClick={() => setCurrentPage(prev => Math.max(0, prev - 1))}
|
|
221
|
+
disabled={currentPage === 0}
|
|
222
|
+
>
|
|
223
|
+
Previous
|
|
224
|
+
</button>
|
|
225
|
+
<span>
|
|
226
|
+
Page {currentPage + 1} of {totalPages} ({files.length} total files)
|
|
227
|
+
</span>
|
|
228
|
+
<button
|
|
229
|
+
onClick={() => setCurrentPage(prev => Math.min(totalPages - 1, prev + 1))}
|
|
230
|
+
disabled={currentPage === totalPages - 1}
|
|
231
|
+
>
|
|
232
|
+
Next
|
|
233
|
+
</button>
|
|
234
|
+
</div>
|
|
235
|
+
)}
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
};
|