mirror of
https://github.com/stalwartlabs/webui.git
synced 2026-12-06 16:04:38 +00:00
78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
|
*/
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Button } from '@/components/ui/button';
|
|
import { CopyButton } from '@/components/common/CopyButton';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
|
|
interface CreatedValuesDialogProps {
|
|
values: Record<string, unknown> | null;
|
|
labels: Map<string, string>;
|
|
onContinue: () => void;
|
|
}
|
|
|
|
function displayValue(value: unknown): string {
|
|
if (typeof value === 'string') return value;
|
|
if (value === null || value === undefined) return '';
|
|
if (typeof value === 'object') return JSON.stringify(value);
|
|
return String(value);
|
|
}
|
|
|
|
export function CreatedValuesDialog({ values, labels, onContinue }: CreatedValuesDialogProps) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Dialog open={values !== null}>
|
|
<DialogContent
|
|
showCloseButton={false}
|
|
onInteractOutside={(e) => e.preventDefault()}
|
|
onEscapeKeyDown={(e) => e.preventDefault()}
|
|
>
|
|
<DialogHeader>
|
|
<DialogTitle>{t('form.createdSuccess', 'Created successfully')}</DialogTitle>
|
|
<DialogDescription>
|
|
{t(
|
|
'form.createdServerGenerated',
|
|
'The following values were generated by the server. Please save them now, they may not be retrievable later.',
|
|
)}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="space-y-1 divide-y divide-border rounded-xl bg-muted px-4 py-1">
|
|
{values &&
|
|
Object.entries(values).map(([key, value]) => {
|
|
const text = displayValue(value);
|
|
const label = labels.get(key) ?? key;
|
|
return (
|
|
<div key={key} className="flex flex-col gap-1.5 py-3">
|
|
<span className="text-[13px] font-semibold text-muted-foreground">{label}</span>
|
|
<div className="flex items-start gap-2">
|
|
<code className="flex-1 select-all break-all rounded-lg bg-card px-3 py-2 font-mono text-sm">
|
|
{text}
|
|
</code>
|
|
<CopyButton value={text} label={label} />
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
<DialogFooter>
|
|
<Button type="button" onClick={onContinue}>
|
|
{t('common.continue', 'Continue')}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|