Operate.tsx 2.1 KB

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