'use client' import type { EnvironmentVariable } from '@/app/components/workflow/types' import { AlertDialog, AlertDialogActions, AlertDialogCancelButton, AlertDialogConfirmButton, AlertDialogContent, AlertDialogTitle, } from '@langgenius/dify-ui/alert-dialog' import { Checkbox } from '@langgenius/dify-ui/checkbox' import { cn } from '@langgenius/dify-ui/cn' import * as React from 'react' import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' export type DSLExportConfirmModalProps = { envList: EnvironmentVariable[] onConfirm: (state: boolean) => void | Promise onClose: () => void } type DSLExportConfirmContentProps = DSLExportConfirmModalProps & { onExportingChange?: (isExporting: boolean) => void } export const DSLExportConfirmContent = ({ envList = [], onConfirm, onClose, onExportingChange, }: DSLExportConfirmContentProps) => { const { t } = useTranslation() const [exportSecrets, setExportSecrets] = useState(false) const [isExporting, setIsExporting] = useState(false) const submit = useCallback(async () => { if (isExporting) return setIsExporting(true) onExportingChange?.(true) try { await onConfirm(exportSecrets) onClose() } finally { setIsExporting(false) onExportingChange?.(false) } }, [exportSecrets, isExporting, onClose, onConfirm, onExportingChange]) return (
{t(($) => $['env.export.title'], { ns: 'workflow' })}
{envList.map((env, index) => ( ))}
{t(($) => $['env.export.name'], { ns: 'workflow' })} {t(($) => $['env.export.value'], { ns: 'workflow' })}
{env.value}
{t(($) => $['operation.cancel'], { ns: 'common' })} {isExporting ? t(($) => $['operation.exporting'], { ns: 'common' }) : exportSecrets ? t(($) => $['env.export.export'], { ns: 'workflow' }) : t(($) => $['env.export.ignore'], { ns: 'workflow' })}
) } const DSLExportConfirmModal = (props: DSLExportConfirmModalProps) => { const { envList, onClose } = props const [isExporting, setIsExporting] = useState(false) const isDialogOpen = envList.length > 0 const handleOpenChange = useCallback( (open: boolean) => { if (open || isExporting) return onClose() }, [isExporting, onClose], ) return ( ) } export default DSLExportConfirmModal