mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-07 15:25:47 +00:00
feat: add ImportPersonalDocumentsModal and related components to support importing document requirements from personal vaults
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Checkbox,
|
||||
Divider,
|
||||
Drawer,
|
||||
Group,
|
||||
MultiSelect,
|
||||
NumberInput,
|
||||
SegmentedControl,
|
||||
@@ -13,10 +14,11 @@ import {
|
||||
Text,
|
||||
TextInput,
|
||||
} from '@mantine/core';
|
||||
import { IconInfoCircle } from '@tabler/icons-react';
|
||||
import { IconCheck, IconDownload, IconInfoCircle } from '@tabler/icons-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { BilingualInput, ModalFooter } from '@ema-platform/ui';
|
||||
import {
|
||||
useGetPersonalDocumentsQuery,
|
||||
useLocalized,
|
||||
type ApplicationKind,
|
||||
type DocumentRequirement,
|
||||
@@ -74,7 +76,7 @@ const MIME_OPTIONS = [
|
||||
/** What a new slot accepts until someone widens it. */
|
||||
const DEFAULT_MIME_TYPES = ['application/pdf', 'image/jpeg', 'image/png'];
|
||||
|
||||
type DraftRequirement = Omit<DocumentRequirement, 'id' | 'licenseTypeId' | 'isActive'>;
|
||||
export type DraftRequirement = Omit<DocumentRequirement, 'id' | 'licenseTypeId' | 'isActive'>;
|
||||
|
||||
/**
|
||||
* Which licences a personal document is asked for.
|
||||
@@ -117,6 +119,7 @@ export function DocumentRequirementEditorDrawer({
|
||||
opened,
|
||||
onClose,
|
||||
requirement,
|
||||
initialDraft,
|
||||
defaultApplicationKind,
|
||||
onSave,
|
||||
palette,
|
||||
@@ -130,6 +133,8 @@ export function DocumentRequirementEditorDrawer({
|
||||
onClose: () => void;
|
||||
/** Null = adding a new requirement. */
|
||||
requirement: DocumentRequirement | null;
|
||||
/** Optional initial prefill when adding a new requirement (e.g. from personal docs). */
|
||||
initialDraft?: Partial<DraftRequirement> | null;
|
||||
defaultApplicationKind: ApplicationKind;
|
||||
onSave: (draft: DraftRequirement, scope: PersonalScope) => void;
|
||||
palette: FormSchemaPalette | undefined;
|
||||
@@ -142,7 +147,7 @@ export function DocumentRequirementEditorDrawer({
|
||||
/** The licence types this document is already scoped to. */
|
||||
scope?: PersonalScope;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const localized = useLocalized();
|
||||
const [draft, setDraft] = useState<DraftRequirement>(
|
||||
emptyDraft(defaultApplicationKind, personal),
|
||||
@@ -150,36 +155,84 @@ export function DocumentRequirementEditorDrawer({
|
||||
const [scopeIds, setScopeIds] = useState<PersonalScope>(scope);
|
||||
const [appliesToAll, setAppliesToAll] = useState(scope.length === 0);
|
||||
const [keyError, setKeyError] = useState<string | null>(null);
|
||||
const [selectedPersonalKey, setSelectedPersonalKey] = useState<string | null>(null);
|
||||
const isNew = !requirement;
|
||||
|
||||
const { data: personalDocsData } = useGetPersonalDocumentsQuery(
|
||||
{ take: 100, locale: i18n.language === 'am' ? 'am' : 'en' },
|
||||
{ skip: !opened || !isNew || personal },
|
||||
);
|
||||
|
||||
const personalDocOptions = useMemo(
|
||||
() =>
|
||||
(personalDocsData?.items ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: `${localized(item.rows[0]?.name) || item.key} (${item.key})`,
|
||||
})),
|
||||
[personalDocsData, localized],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (opened) {
|
||||
setDraft(
|
||||
requirement
|
||||
? {
|
||||
key: requirement.key,
|
||||
name: { ...requirement.name },
|
||||
description: requirement.description ? { ...requirement.description } : undefined,
|
||||
applicationKind: requirement.applicationKind,
|
||||
mode: requirement.mode,
|
||||
conditionExpression: requirement.conditionExpression,
|
||||
allowedMimeTypes: requirement.allowedMimeTypes,
|
||||
maxSizeMb: requirement.maxSizeMb,
|
||||
requiresValidityDates: requirement.requiresValidityDates,
|
||||
allowMultiple: requirement.allowMultiple,
|
||||
isPersonal: requirement.isPersonal ?? personal,
|
||||
maxFiles: requirement.maxFiles ?? null,
|
||||
sortOrder: requirement.sortOrder,
|
||||
}
|
||||
: emptyDraft(defaultApplicationKind, personal),
|
||||
);
|
||||
if (requirement) {
|
||||
setDraft({
|
||||
key: requirement.key,
|
||||
name: { ...requirement.name },
|
||||
description: requirement.description ? { ...requirement.description } : undefined,
|
||||
applicationKind: requirement.applicationKind,
|
||||
mode: requirement.mode,
|
||||
conditionExpression: requirement.conditionExpression,
|
||||
allowedMimeTypes: requirement.allowedMimeTypes,
|
||||
maxSizeMb: requirement.maxSizeMb,
|
||||
requiresValidityDates: requirement.requiresValidityDates,
|
||||
allowMultiple: requirement.allowMultiple,
|
||||
isPersonal: requirement.isPersonal ?? personal,
|
||||
maxFiles: requirement.maxFiles ?? null,
|
||||
sortOrder: requirement.sortOrder,
|
||||
});
|
||||
setSelectedPersonalKey(null);
|
||||
} else if (initialDraft) {
|
||||
setDraft({
|
||||
...emptyDraft(defaultApplicationKind, personal),
|
||||
...initialDraft,
|
||||
});
|
||||
setSelectedPersonalKey(initialDraft.key ?? null);
|
||||
} else {
|
||||
setDraft(emptyDraft(defaultApplicationKind, personal));
|
||||
setSelectedPersonalKey(null);
|
||||
}
|
||||
setScopeIds(scope);
|
||||
setAppliesToAll(scope.length === 0);
|
||||
setKeyError(null);
|
||||
}
|
||||
// `scope` is a fresh array each render; the opened flag is what gates this.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [opened, requirement, defaultApplicationKind, personal]);
|
||||
}, [opened, requirement, initialDraft, defaultApplicationKind, personal]);
|
||||
|
||||
function handleSelectPersonalDoc(key: string | null) {
|
||||
setSelectedPersonalKey(key);
|
||||
if (!key) return;
|
||||
const found = personalDocsData?.items?.find((item) => item.key === key);
|
||||
if (found && found.rows[0]) {
|
||||
const row = found.rows[0];
|
||||
setDraft((d) => ({
|
||||
...d,
|
||||
key: found.key,
|
||||
name: { en: row.name?.en ?? '', am: row.name?.am ?? '' },
|
||||
description: row.description
|
||||
? { en: row.description?.en ?? '', am: row.description?.am ?? '' }
|
||||
: undefined,
|
||||
allowedMimeTypes: row.allowedMimeTypes?.length
|
||||
? [...row.allowedMimeTypes]
|
||||
: d.allowedMimeTypes,
|
||||
maxSizeMb: row.maxSizeMb ?? d.maxSizeMb,
|
||||
maxFiles: row.maxFiles ?? null,
|
||||
requiresValidityDates: row.requiresValidityDates ?? false,
|
||||
allowMultiple: (row.maxFiles ?? 1) !== 1,
|
||||
}));
|
||||
setKeyError(null);
|
||||
}
|
||||
}
|
||||
|
||||
function save() {
|
||||
if (!draft.key.trim()) {
|
||||
@@ -241,6 +294,40 @@ export function DocumentRequirementEditorDrawer({
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{!personal && isNew && (
|
||||
<Stack gap="xs">
|
||||
<Select
|
||||
label={t('certReq.doc.importFromPersonal', 'Import from personal document')}
|
||||
placeholder={t(
|
||||
'certReq.doc.selectPersonalDoc',
|
||||
'Select a personal document to copy details…',
|
||||
)}
|
||||
data={personalDocOptions}
|
||||
value={selectedPersonalKey}
|
||||
onChange={handleSelectPersonalDoc}
|
||||
searchable
|
||||
clearable
|
||||
leftSection={<IconDownload size={15} />}
|
||||
description={t(
|
||||
'certReq.doc.importPersonalDesc',
|
||||
'Select documents configured in Personal Documents to add as requirements for this licence type.',
|
||||
)}
|
||||
/>
|
||||
|
||||
{selectedPersonalKey && (
|
||||
<Alert variant="light" color="teal" icon={<IconCheck size={16} />}>
|
||||
<Text fz="xs">
|
||||
{t(
|
||||
'certReq.doc.importedHelper',
|
||||
'Imported from personal documents. The key matches the vault so uploaded files will link automatically.',
|
||||
)}
|
||||
</Text>
|
||||
</Alert>
|
||||
)}
|
||||
<Divider my="xs" />
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
<TextInput
|
||||
label={t('certReq.doc.key', 'Key')}
|
||||
placeholder="bank_letter"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { ActionIcon, Alert, Badge, Button, Card, Group, Modal, Stack, Text, Title } from '@mantine/core';
|
||||
import { IconAlertCircle, IconEdit, IconPlus, IconTrash } from '@tabler/icons-react';
|
||||
import { IconAlertCircle, IconDownload, IconEdit, IconPlus, IconTrash } from '@tabler/icons-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { EmptyState, ErrorState, ModalFooter, PageLoader } from '@ema-platform/ui';
|
||||
import {
|
||||
@@ -18,7 +18,11 @@ import {
|
||||
import { collectConditionTargets } from '../config/schema-paths';
|
||||
import { useRequirementActions } from '../hooks/useRequirementActions';
|
||||
import { describeCondition } from './ConditionBuilder';
|
||||
import { DocumentRequirementEditorDrawer } from './DocumentRequirementEditorDrawer';
|
||||
import {
|
||||
DocumentRequirementEditorDrawer,
|
||||
type DraftRequirement,
|
||||
} from './DocumentRequirementEditorDrawer';
|
||||
import { ImportPersonalDocumentsModal } from './ImportPersonalDocumentsModal';
|
||||
|
||||
/** Every kind the server validates a document set for, so each can be configured. */
|
||||
const KINDS: ApplicationKind[] = ['NEW', 'RENEWAL', 'REISSUE'];
|
||||
@@ -54,6 +58,8 @@ export function DocumentRequirementsTab({ licenseType }: { licenseType: LicenseT
|
||||
const [deleteRequirement] = useDeleteDocumentRequirementMutation();
|
||||
|
||||
const [editorState, setEditorState] = useState<{ kind: ApplicationKind; requirement: DocumentRequirement | null } | null>(null);
|
||||
const [initialDraft, setInitialDraft] = useState<Partial<DraftRequirement> | null>(null);
|
||||
const [importModalKind, setImportModalKind] = useState<ApplicationKind | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<DocumentRequirement | null>(null);
|
||||
|
||||
const requirements = useMemo(
|
||||
@@ -120,14 +126,27 @@ export function DocumentRequirementsTab({ licenseType }: { licenseType: LicenseT
|
||||
<Card key={kind} withBorder radius="md" p="md">
|
||||
<Group justify="space-between" mb="sm">
|
||||
<Title order={5}>{t(...KIND_LABEL[kind])}</Title>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="light"
|
||||
leftSection={<IconPlus size={13} />}
|
||||
onClick={() => setEditorState({ kind, requirement: null })}
|
||||
>
|
||||
{t('certReq.doc.add', 'Add document requirement')}
|
||||
</Button>
|
||||
<Group gap="xs">
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
leftSection={<IconDownload size={13} />}
|
||||
onClick={() => setImportModalKind(kind)}
|
||||
>
|
||||
{t('certReq.doc.importPersonal', 'Import from personal documents')}
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="light"
|
||||
leftSection={<IconPlus size={13} />}
|
||||
onClick={() => {
|
||||
setInitialDraft(null);
|
||||
setEditorState({ kind, requirement: null });
|
||||
}}
|
||||
>
|
||||
{t('certReq.doc.add', 'Add document requirement')}
|
||||
</Button>
|
||||
</Group>
|
||||
</Group>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
@@ -180,8 +199,12 @@ export function DocumentRequirementsTab({ licenseType }: { licenseType: LicenseT
|
||||
|
||||
<DocumentRequirementEditorDrawer
|
||||
opened={editorState !== null}
|
||||
onClose={() => setEditorState(null)}
|
||||
onClose={() => {
|
||||
setEditorState(null);
|
||||
setInitialDraft(null);
|
||||
}}
|
||||
requirement={editorState?.requirement ?? null}
|
||||
initialDraft={initialDraft}
|
||||
defaultApplicationKind={editorState?.kind ?? 'NEW'}
|
||||
onSave={handleSave}
|
||||
palette={palette}
|
||||
@@ -189,6 +212,28 @@ export function DocumentRequirementsTab({ licenseType }: { licenseType: LicenseT
|
||||
saving={creating || updating}
|
||||
/>
|
||||
|
||||
{importModalKind && (
|
||||
<ImportPersonalDocumentsModal
|
||||
opened={importModalKind !== null}
|
||||
onClose={() => setImportModalKind(null)}
|
||||
licenseType={licenseType}
|
||||
applicationKind={importModalKind}
|
||||
existingKeys={requirements
|
||||
.filter((r) => r.applicationKind === importModalKind)
|
||||
.map((r) => r.key)}
|
||||
currentMaxSortOrder={requirements
|
||||
.filter((r) => r.applicationKind === importModalKind)
|
||||
.reduce((max, r) => Math.max(max, r.sortOrder ?? 0), 0)}
|
||||
onCustomizeAndAdd={(draft) => {
|
||||
setInitialDraft(draft);
|
||||
setEditorState({
|
||||
kind: (draft.applicationKind as ApplicationKind) ?? importModalKind,
|
||||
requirement: null,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Modal opened={deleteTarget !== null} onClose={() => setDeleteTarget(null)} title={t('certReq.doc.delete', 'Delete document requirement')} size="sm">
|
||||
<Stack gap="md">
|
||||
<Alert color="yellow" variant="light">
|
||||
|
||||
@@ -0,0 +1,431 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import {
|
||||
ActionIcon,
|
||||
Alert,
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Checkbox,
|
||||
Group,
|
||||
Loader,
|
||||
Modal,
|
||||
ScrollArea,
|
||||
SegmentedControl,
|
||||
Select,
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
TextInput,
|
||||
Tooltip,
|
||||
} from '@mantine/core';
|
||||
import {
|
||||
IconAdjustments,
|
||||
IconAlertCircle,
|
||||
IconCheck,
|
||||
IconDownload,
|
||||
IconInfoCircle,
|
||||
IconSearch,
|
||||
} from '@tabler/icons-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ModalFooter } from '@ema-platform/ui';
|
||||
import {
|
||||
useCreateDocumentRequirementMutation,
|
||||
useGetLicenseTypesQuery,
|
||||
useGetPersonalDocumentsQuery,
|
||||
useLocalized,
|
||||
type ApplicationKind,
|
||||
type DocumentRequirement,
|
||||
type LicenseType,
|
||||
type PersonalDocumentGroup,
|
||||
} from '@ema-platform/api';
|
||||
import { useRequirementActions } from '../hooks/useRequirementActions';
|
||||
import type { DraftRequirement } from './DocumentRequirementEditorDrawer';
|
||||
|
||||
const MIME_LABELS: Record<string, string> = {
|
||||
'application/pdf': 'PDF',
|
||||
'application/msword': 'DOC',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'DOCX',
|
||||
'application/vnd.ms-excel': 'XLS',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'XLSX',
|
||||
};
|
||||
|
||||
function shortMime(mime: string): string {
|
||||
return MIME_LABELS[mime] ?? mime.split('/')[1]?.toUpperCase() ?? mime;
|
||||
}
|
||||
|
||||
interface ImportPersonalDocumentsModalProps {
|
||||
opened: boolean;
|
||||
onClose: () => void;
|
||||
licenseType: LicenseType;
|
||||
applicationKind: ApplicationKind;
|
||||
existingKeys: string[];
|
||||
currentMaxSortOrder: number;
|
||||
onCustomizeAndAdd: (draft: Partial<DraftRequirement>) => void;
|
||||
}
|
||||
|
||||
export function ImportPersonalDocumentsModal({
|
||||
opened,
|
||||
onClose,
|
||||
licenseType,
|
||||
applicationKind,
|
||||
existingKeys,
|
||||
currentMaxSortOrder,
|
||||
onCustomizeAndAdd,
|
||||
}: ImportPersonalDocumentsModalProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const localized = useLocalized();
|
||||
const run = useRequirementActions();
|
||||
|
||||
const [search, setSearch] = useState('');
|
||||
const [scopeFilter, setScopeFilter] = useState<'all' | 'scoped'>('all');
|
||||
const [importMode, setImportMode] = useState<DocumentRequirement['mode']>('ALWAYS');
|
||||
const [selectedKeys, setSelectedKeys] = useState<string[]>([]);
|
||||
|
||||
const { data: licenseTypes } = useGetLicenseTypesQuery();
|
||||
const { data: personalDocsData, isLoading, isError, refetch } = useGetPersonalDocumentsQuery({
|
||||
take: 100,
|
||||
locale: i18n.language === 'am' ? 'am' : 'en',
|
||||
});
|
||||
|
||||
const [createRequirement, { isLoading: isCreating }] = useCreateDocumentRequirementMutation();
|
||||
|
||||
const groups = useMemo(() => {
|
||||
return (personalDocsData?.items ?? []).map((group) => {
|
||||
const scopeIds = group.rows
|
||||
.map((r) => r.licenseTypeId)
|
||||
.filter((id): id is string => id !== null);
|
||||
const isGlobal = scopeIds.length === 0;
|
||||
const appliesToCurrentType = isGlobal || scopeIds.includes(licenseType.id);
|
||||
const isAlreadyAdded = existingKeys.includes(group.key);
|
||||
|
||||
return {
|
||||
...group,
|
||||
scopeIds,
|
||||
isGlobal,
|
||||
appliesToCurrentType,
|
||||
isAlreadyAdded,
|
||||
mainRow: group.rows[0],
|
||||
};
|
||||
});
|
||||
}, [personalDocsData, licenseType.id, existingKeys]);
|
||||
|
||||
const filteredGroups = useMemo(() => {
|
||||
const q = search.trim().toLowerCase();
|
||||
return groups.filter((item) => {
|
||||
if (scopeFilter === 'scoped' && !item.appliesToCurrentType) {
|
||||
return false;
|
||||
}
|
||||
if (!q) return true;
|
||||
const nameEn = item.mainRow.name.en?.toLowerCase() ?? '';
|
||||
const nameAm = item.mainRow.name.am?.toLowerCase() ?? '';
|
||||
const key = item.key.toLowerCase();
|
||||
return nameEn.includes(q) || nameAm.includes(q) || key.includes(q);
|
||||
});
|
||||
}, [groups, search, scopeFilter]);
|
||||
|
||||
const selectableKeys = useMemo(
|
||||
() => filteredGroups.filter((g) => !g.isAlreadyAdded).map((g) => g.key),
|
||||
[filteredGroups],
|
||||
);
|
||||
|
||||
const allSelected =
|
||||
selectableKeys.length > 0 && selectableKeys.every((k) => selectedKeys.includes(k));
|
||||
const someSelected =
|
||||
selectableKeys.some((k) => selectedKeys.includes(k)) && !allSelected;
|
||||
|
||||
function toggleSelectAll() {
|
||||
if (allSelected) {
|
||||
setSelectedKeys((prev) => prev.filter((k) => !selectableKeys.includes(k)));
|
||||
} else {
|
||||
setSelectedKeys((prev) => Array.from(new Set([...prev, ...selectableKeys])));
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSelectOne(key: string) {
|
||||
setSelectedKeys((prev) =>
|
||||
prev.includes(key) ? prev.filter((k) => k !== key) : [...prev, key],
|
||||
);
|
||||
}
|
||||
|
||||
async function handleBatchImport() {
|
||||
const itemsToImport = groups.filter(
|
||||
(g) => selectedKeys.includes(g.key) && !g.isAlreadyAdded,
|
||||
);
|
||||
if (itemsToImport.length === 0) return;
|
||||
|
||||
const ok = await run(
|
||||
() =>
|
||||
Promise.all(
|
||||
itemsToImport.map((item, index) =>
|
||||
createRequirement({
|
||||
key: item.key,
|
||||
name: item.mainRow.name,
|
||||
description: item.mainRow.description,
|
||||
applicationKind,
|
||||
mode: importMode,
|
||||
allowedMimeTypes:
|
||||
item.mainRow.allowedMimeTypes ?? ['application/pdf', 'image/jpeg', 'image/png'],
|
||||
maxSizeMb: item.mainRow.maxSizeMb ?? 5,
|
||||
requiresValidityDates: item.mainRow.requiresValidityDates ?? false,
|
||||
allowMultiple: (item.mainRow.maxFiles ?? 1) !== 1,
|
||||
isPersonal: false,
|
||||
maxFiles: item.mainRow.maxFiles ?? null,
|
||||
sortOrder: currentMaxSortOrder + index + 1,
|
||||
licenseTypeId: licenseType.id,
|
||||
}).unwrap(),
|
||||
),
|
||||
),
|
||||
t('certReq.doc.importSuccess', 'Imported {{count}} personal document(s)', {
|
||||
count: itemsToImport.length,
|
||||
}),
|
||||
);
|
||||
|
||||
if (ok) {
|
||||
setSelectedKeys([]);
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
function handleCustomizeRow(item: (typeof groups)[number]) {
|
||||
onCustomizeAndAdd({
|
||||
key: item.key,
|
||||
name: { ...item.mainRow.name },
|
||||
description: item.mainRow.description ? { ...item.mainRow.description } : undefined,
|
||||
applicationKind,
|
||||
mode: importMode,
|
||||
allowedMimeTypes: [...item.mainRow.allowedMimeTypes],
|
||||
maxSizeMb: item.mainRow.maxSizeMb,
|
||||
maxFiles: item.mainRow.maxFiles,
|
||||
requiresValidityDates: item.mainRow.requiresValidityDates,
|
||||
allowMultiple: (item.mainRow.maxFiles ?? 1) !== 1,
|
||||
isPersonal: false,
|
||||
sortOrder: currentMaxSortOrder + 1,
|
||||
});
|
||||
onClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={onClose}
|
||||
title={
|
||||
<div>
|
||||
<Text fw={700} fz="lg">
|
||||
{t('certReq.doc.importPersonal', 'Import from personal documents')}
|
||||
</Text>
|
||||
<Text fz="xs" c="dimmed">
|
||||
{localized(licenseType.name)} · {applicationKind}
|
||||
</Text>
|
||||
</div>
|
||||
}
|
||||
size="lg"
|
||||
padding="md"
|
||||
>
|
||||
<Stack gap="md">
|
||||
<Alert
|
||||
variant="light"
|
||||
color="blue"
|
||||
icon={<IconInfoCircle size={16} />}
|
||||
>
|
||||
<Text fz="xs">
|
||||
{t(
|
||||
'certReq.doc.importedHelper',
|
||||
'Imported from personal documents. The key matches the vault so uploaded files will link automatically.',
|
||||
)}
|
||||
</Text>
|
||||
</Alert>
|
||||
|
||||
<Group justify="space-between" align="center" wrap="wrap" gap="sm">
|
||||
<TextInput
|
||||
placeholder={t('certReq.personal.searchPlaceholder', 'Search by name or key')}
|
||||
leftSection={<IconSearch size={14} />}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.currentTarget.value)}
|
||||
size="xs"
|
||||
style={{ flex: 1, minWidth: 200 }}
|
||||
/>
|
||||
|
||||
<SegmentedControl
|
||||
size="xs"
|
||||
value={scopeFilter}
|
||||
onChange={(v) => setScopeFilter(v as 'all' | 'scoped')}
|
||||
data={[
|
||||
{ value: 'all', label: t('certReq.personal.filterAny', 'All personal docs') },
|
||||
{
|
||||
value: 'scoped',
|
||||
label: t('certReq.doc.scopeSelected', 'Relevant to licence'),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Group>
|
||||
|
||||
<Group justify="space-between" align="center" gap="sm">
|
||||
<Select
|
||||
label={t('certReq.doc.importMode', 'Requirement mode for imported documents')}
|
||||
size="xs"
|
||||
w={240}
|
||||
data={[
|
||||
{ value: 'ALWAYS', label: t('certReq.doc.modeAlways', 'Always required') },
|
||||
{ value: 'OPTIONAL', label: t('certReq.doc.modeOptional', 'Optional upload') },
|
||||
{
|
||||
value: 'CONDITIONAL',
|
||||
label: t('certReq.doc.modeConditional', 'Required when condition holds'),
|
||||
},
|
||||
]}
|
||||
value={importMode}
|
||||
onChange={(v) => v && setImportMode(v as DocumentRequirement['mode'])}
|
||||
allowDeselect={false}
|
||||
/>
|
||||
|
||||
<Text fz="xs" c="dimmed" pt="lg">
|
||||
{t('certReq.personal.fileCount', '{{count}} document(s) available', {
|
||||
count: selectableKeys.length,
|
||||
})}
|
||||
</Text>
|
||||
</Group>
|
||||
|
||||
{isLoading ? (
|
||||
<Group justify="center" py="xl">
|
||||
<Loader size="sm" />
|
||||
<Text fz="sm" c="dimmed">
|
||||
{t('certReq.doc.loading', 'Loading personal documents…')}
|
||||
</Text>
|
||||
</Group>
|
||||
) : isError ? (
|
||||
<Alert color="red" icon={<IconAlertCircle size={16} />}>
|
||||
{t('certReq.doc.loadFailed', 'Could not load personal documents')}
|
||||
<Button size="xs" variant="subtle" color="red" ml="sm" onClick={() => refetch()}>
|
||||
{t('landing.retry', 'Retry')}
|
||||
</Button>
|
||||
</Alert>
|
||||
) : filteredGroups.length === 0 ? (
|
||||
<Card withBorder radius="sm" p="lg" ta="center">
|
||||
<Text fz="sm" c="dimmed">
|
||||
{search
|
||||
? t('certReq.personal.noMatch', 'No personal document matches those filters.')
|
||||
: t('certReq.doc.noPersonalDocs', 'No personal documents configured in Configuration yet.')}
|
||||
</Text>
|
||||
</Card>
|
||||
) : (
|
||||
<ScrollArea.Autosize mah={380} type="auto">
|
||||
<Table highlightOnHover verticalSpacing="xs" fz="sm">
|
||||
<Table.Thead>
|
||||
<Table.Tr>
|
||||
<Table.Th w={40}>
|
||||
<Checkbox
|
||||
checked={allSelected}
|
||||
indeterminate={someSelected}
|
||||
onChange={toggleSelectAll}
|
||||
disabled={selectableKeys.length === 0}
|
||||
/>
|
||||
</Table.Th>
|
||||
<Table.Th>{t('certReq.personal.columns.document', 'Document')}</Table.Th>
|
||||
<Table.Th>{t('certReq.doc.allowedTypes', 'Format & Limits')}</Table.Th>
|
||||
<Table.Th>{t('certReq.doc.scope', 'Scope')}</Table.Th>
|
||||
<Table.Th ta="right">{t('certReq.personal.columns.actions', 'Actions')}</Table.Th>
|
||||
</Table.Tr>
|
||||
</Table.Thead>
|
||||
<Table.Tbody>
|
||||
{filteredGroups.map((item) => {
|
||||
const isSelected = selectedKeys.includes(item.key);
|
||||
return (
|
||||
<Table.Tr
|
||||
key={item.key}
|
||||
bg={
|
||||
item.isAlreadyAdded
|
||||
? 'var(--mantine-color-gray-light)'
|
||||
: isSelected
|
||||
? 'var(--mantine-color-blue-light)'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<Table.Td>
|
||||
<Checkbox
|
||||
checked={isSelected || item.isAlreadyAdded}
|
||||
disabled={item.isAlreadyAdded}
|
||||
onChange={() => toggleSelectOne(item.key)}
|
||||
/>
|
||||
</Table.Td>
|
||||
<Table.Td>
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<div>
|
||||
<Group gap={6}>
|
||||
<Text fz="sm" fw={600}>
|
||||
{localized(item.mainRow.name) || item.key}
|
||||
</Text>
|
||||
{item.isAlreadyAdded && (
|
||||
<Badge size="xs" color="gray" variant="light">
|
||||
{t('certReq.doc.alreadyAdded', 'Already added')}
|
||||
</Badge>
|
||||
)}
|
||||
</Group>
|
||||
<Text fz="xs" c="dimmed">
|
||||
{item.key}
|
||||
</Text>
|
||||
</div>
|
||||
</Group>
|
||||
</Table.Td>
|
||||
<Table.Td>
|
||||
<Text fz="xs">
|
||||
{(item.mainRow.allowedMimeTypes ?? []).slice(0, 3).map(shortMime).join(', ')}
|
||||
{(item.mainRow.allowedMimeTypes ?? []).length > 3 && '...'}
|
||||
</Text>
|
||||
<Text fz="xs" c="dimmed">
|
||||
{item.mainRow.maxSizeMb} MB ·{' '}
|
||||
{item.mainRow.maxFiles === null
|
||||
? t('certReq.doc.maxFilesUnlimited', 'No limit')
|
||||
: `${item.mainRow.maxFiles} file(s)`}
|
||||
{item.mainRow.requiresValidityDates && ' · Validity'}
|
||||
</Text>
|
||||
</Table.Td>
|
||||
<Table.Td>
|
||||
{item.isGlobal ? (
|
||||
<Badge size="xs" variant="filled" color="gray">
|
||||
{t('certReq.doc.scopeAll', 'All licences')}
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge size="xs" variant="light" color="blue">
|
||||
{t('certReq.doc.scopeSelected', 'Selected')}
|
||||
</Badge>
|
||||
)}
|
||||
</Table.Td>
|
||||
<Table.Td ta="right">
|
||||
<Tooltip label={t('certReq.doc.customizeAndAdd', 'Customize & add')}>
|
||||
<ActionIcon
|
||||
variant="light"
|
||||
color="blue"
|
||||
size="sm"
|
||||
onClick={() => handleCustomizeRow(item)}
|
||||
>
|
||||
<IconAdjustments size={14} />
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
);
|
||||
})}
|
||||
</Table.Tbody>
|
||||
</Table>
|
||||
</ScrollArea.Autosize>
|
||||
)}
|
||||
|
||||
<ModalFooter>
|
||||
<Button variant="default" onClick={onClose}>
|
||||
{t('certReq.cancel', 'Cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
color="teal"
|
||||
leftSection={<IconDownload size={15} />}
|
||||
disabled={selectedKeys.length === 0}
|
||||
loading={isCreating}
|
||||
onClick={handleBatchImport}
|
||||
>
|
||||
{t('certReq.doc.importSelected', 'Import selected ({{count}})', {
|
||||
count: selectedKeys.length,
|
||||
})}
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</Stack>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -1617,6 +1617,21 @@ export const am: Translations = {
|
||||
maxFilesUnlimited: "ገደብ የለም",
|
||||
sortOrder: "የቅደም ተከተል ቁጥር",
|
||||
when: "መቼ",
|
||||
importPersonal: "ከግል ሰነዶች አስመጣ",
|
||||
importPersonalDesc:
|
||||
"ለዚህ የፈቃድ አይነት እንደ መስፈርት ለማከል በውቅር ገጽ ላይ ከተዋቀሩት የግል ሰነዶች ይምረጡ።",
|
||||
importFromPersonal: "ከግል ሰነድ አስመጣ",
|
||||
selectPersonalDoc: "ዝርዝሩን ለመቅዳት የግል ሰነድ ይምረጡ…",
|
||||
importSelected: "የተመረጡትን አስመጣ ({{count}})",
|
||||
importAction: "አስመጣ",
|
||||
customizeAndAdd: "አስተካክለህ ጨምር",
|
||||
alreadyAdded: "ቀደም ሲል ተጨምሯል",
|
||||
noPersonalDocs: "በውቅር ውስጥ የተዘጋጀ የግል ሰነድ እስካሁን የለም።",
|
||||
importedFromPersonal: "ከግል ሰነድ የመጣ: {{name}}",
|
||||
importedHelper:
|
||||
"ከግል ሰነዶች የመጣ። ቁልፉ ከአመልካቹ ሰነዶች ጋር ስለሚዛመድ ፋይሎች በቀጥታ ይገናኛሉ።",
|
||||
importMode: "ለሚመጡ ሰነዶች የመስፈርት ሁነታ",
|
||||
importSuccess: "{{count}} የግል ሰነድ(ዶች) ገብተዋል",
|
||||
},
|
||||
personal: {
|
||||
title: "የግል ሰነዶች",
|
||||
|
||||
@@ -1624,6 +1624,21 @@ export const en = {
|
||||
maxFilesUnlimited: 'No limit',
|
||||
sortOrder: 'Sort order',
|
||||
when: 'when',
|
||||
importPersonal: 'Import from personal documents',
|
||||
importPersonalDesc:
|
||||
'Select documents configured in Personal Documents to add as requirements for this licence type.',
|
||||
importFromPersonal: 'Import from personal document',
|
||||
selectPersonalDoc: 'Select a personal document to copy details…',
|
||||
importSelected: 'Import selected ({{count}})',
|
||||
importAction: 'Import',
|
||||
customizeAndAdd: 'Customize & add',
|
||||
alreadyAdded: 'Already added',
|
||||
noPersonalDocs: 'No personal documents configured in Configuration yet.',
|
||||
importedFromPersonal: 'Imported from personal document: {{name}}',
|
||||
importedHelper:
|
||||
'Imported from personal documents. The key matches the vault so uploaded files will link automatically.',
|
||||
importMode: 'Requirement mode for imported documents',
|
||||
importSuccess: 'Imported {{count}} personal document(s)',
|
||||
},
|
||||
personal: {
|
||||
title: 'Personal documents',
|
||||
|
||||
Reference in New Issue
Block a user