Operate.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { useTranslation } from 'react-i18next'
  2. import Indicator from '../../indicator'
  3. import type { Status } from './declarations'
  4. type OperateProps = {
  5. isOpen: boolean
  6. status: Status
  7. disabled?: boolean
  8. onCancel: () => void
  9. onSave: () => void
  10. onAdd: () => void
  11. onEdit: () => void
  12. }
  13. const Operate = ({
  14. isOpen,
  15. status,
  16. disabled,
  17. onCancel,
  18. onSave,
  19. onAdd,
  20. onEdit,
  21. }: OperateProps) => {
  22. const { t } = useTranslation()
  23. if (isOpen) {
  24. return (
  25. <div className='flex items-center'>
  26. <div className='
  27. flex items-center
  28. mr-[5px] px-3 h-7 rounded-md cursor-pointer
  29. text-xs font-medium text-gray-700
  30. ' onClick={onCancel} >
  31. {t('common.operation.cancel')}
  32. </div>
  33. <div className='
  34. flex items-center
  35. px-3 h-7 rounded-md cursor-pointer bg-primary-700
  36. text-xs font-medium text-white
  37. ' onClick={onSave}>
  38. {t('common.operation.save')}
  39. </div>
  40. </div>
  41. )
  42. }
  43. if (status === 'add') {
  44. return (
  45. <div className={
  46. `px-3 h-[28px] bg-white border border-gray-200 rounded-md cursor-pointer
  47. text-xs font-medium text-gray-700 flex items-center ${disabled && 'opacity-50 cursor-default'}}`
  48. } onClick={() => !disabled && onAdd()}>
  49. {t('common.provider.addKey')}
  50. </div>
  51. )
  52. }
  53. if (status === 'fail' || status === 'success') {
  54. return (
  55. <div className='flex items-center'>
  56. {
  57. status === 'fail' && (
  58. <div className='flex items-center mr-4'>
  59. <div className='text-xs text-[#D92D20]'>{t('common.provider.invalidApiKey')}</div>
  60. <Indicator color='red' className='ml-2' />
  61. </div>
  62. )
  63. }
  64. {
  65. status === 'success' && (
  66. <Indicator color='green' className='mr-4' />
  67. )
  68. }
  69. <div className={
  70. `px-3 h-[28px] bg-white border border-gray-200 rounded-md cursor-pointer
  71. text-xs font-medium text-gray-700 flex items-center ${disabled && 'opacity-50 cursor-default'}}`
  72. } onClick={() => !disabled && onEdit()}>
  73. {t('common.provider.editKey')}
  74. </div>
  75. </div>
  76. )
  77. }
  78. return null
  79. }
  80. export default Operate