wwf
2025-05-20 938c3e5a587ce950a94964ea509b9e7f8834dfae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { type FC } from 'react'
import Button from '@/app/components/base/button'
import { useTranslation } from 'react-i18next'
import { getKeyboardKeyCodeBySystem, getKeyboardKeyNameBySystem } from '@/app/components/workflow/utils'
import { useKeyPress } from 'ahooks'
 
type AdvancedActionsProps = {
  isConfirmDisabled: boolean
  onCancel: () => void
  onConfirm: () => void
}
 
const Key = (props: { keyName: string }) => {
  const { keyName } = props
  return (
    <kbd className='system-kbd flex h-4 min-w-4 items-center justify-center rounded-[4px] bg-components-kbd-bg-white px-px text-text-primary-on-surface'>
      {keyName}
    </kbd>
  )
}
 
const AdvancedActions: FC<AdvancedActionsProps> = ({
  isConfirmDisabled,
  onCancel,
  onConfirm,
}) => {
  const { t } = useTranslation()
 
  useKeyPress([`${getKeyboardKeyCodeBySystem('ctrl')}.enter`], (e) => {
    e.preventDefault()
    onConfirm()
  }, {
    exactMatch: true,
    useCapture: true,
  })
 
  return (
    <div className='flex items-center gap-x-1'>
      <Button size='small' variant='secondary' onClick={onCancel}>
        {t('common.operation.cancel')}
      </Button>
      <Button
        className='flex items-center gap-x-1'
        disabled={isConfirmDisabled}
        size='small'
        variant='primary'
        onClick={onConfirm}
      >
        <span>{t('common.operation.confirm')}</span>
        <div className='flex items-center gap-x-0.5'>
          <Key keyName={getKeyboardKeyNameBySystem('ctrl')} />
          <Key keyName='⏎' />
        </div>
      </Button>
    </div>
  )
}
 
export default React.memo(AdvancedActions)