Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.tsx 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use client'
  2. import { useCallback, useState } from 'react'
  3. import { useContext } from 'use-context-selector'
  4. import { RiCloseLine } from '@remixicon/react'
  5. import { useTranslation } from 'react-i18next'
  6. import { ReactMultiEmail } from 'react-multi-email'
  7. import { RiErrorWarningFill } from '@remixicon/react'
  8. import RoleSelector from './role-selector'
  9. import s from './index.module.css'
  10. import cn from '@/utils/classnames'
  11. import Modal from '@/app/components/base/modal'
  12. import Button from '@/app/components/base/button'
  13. import { inviteMember } from '@/service/common'
  14. import { emailRegex } from '@/config'
  15. import { ToastContext } from '@/app/components/base/toast'
  16. import type { InvitationResult } from '@/models/common'
  17. import I18n from '@/context/i18n'
  18. import 'react-multi-email/dist/style.css'
  19. import { noop } from 'lodash-es'
  20. type IInviteModalProps = {
  21. isEmailSetup: boolean
  22. onCancel: () => void
  23. onSend: (invitationResults: InvitationResult[]) => void
  24. }
  25. const InviteModal = ({
  26. isEmailSetup,
  27. onCancel,
  28. onSend,
  29. }: IInviteModalProps) => {
  30. const { t } = useTranslation()
  31. const [emails, setEmails] = useState<string[]>([])
  32. const { notify } = useContext(ToastContext)
  33. const { locale } = useContext(I18n)
  34. const [role, setRole] = useState<string>('normal')
  35. const handleSend = useCallback(async () => {
  36. if (emails.map((email: string) => emailRegex.test(email)).every(Boolean)) {
  37. try {
  38. const { result, invitation_results } = await inviteMember({
  39. url: '/workspaces/current/members/invite-email',
  40. body: { emails, role, language: locale },
  41. })
  42. if (result === 'success') {
  43. onCancel()
  44. onSend(invitation_results)
  45. }
  46. }
  47. catch { }
  48. }
  49. else {
  50. notify({ type: 'error', message: t('common.members.emailInvalid') })
  51. }
  52. }, [role, emails, notify, onCancel, onSend, t])
  53. return (
  54. <div className={cn(s.wrap)}>
  55. <Modal overflowVisible isShow onClose={noop} className={cn(s.modal)}>
  56. <div className='mb-2 flex justify-between'>
  57. <div className='text-xl font-semibold text-text-primary'>{t('common.members.inviteTeamMember')}</div>
  58. <RiCloseLine className='h-4 w-4 cursor-pointer text-text-tertiary' onClick={onCancel} />
  59. </div>
  60. <div className='mb-3 text-[13px] text-text-tertiary'>{t('common.members.inviteTeamMemberTip')}</div>
  61. {!isEmailSetup && (
  62. <div className='grow basis-0 overflow-y-auto pb-4'>
  63. <div className='relative mb-1 rounded-xl border border-components-panel-border p-2 shadow-xs'>
  64. <div className='absolute left-0 top-0 h-full w-full rounded-xl opacity-40' style={{ background: 'linear-gradient(92deg, rgba(255, 171, 0, 0.25) 18.12%, rgba(255, 255, 255, 0.00) 167.31%)' }}></div>
  65. <div className='relative flex h-full w-full items-start'>
  66. <div className='mr-0.5 shrink-0 p-0.5'>
  67. <RiErrorWarningFill className='h-5 w-5 text-text-warning' />
  68. </div>
  69. <div className='system-xs-medium text-text-primary'>
  70. <span>{t('common.members.emailNotSetup')}</span>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. )}
  76. <div>
  77. <div className='mb-2 text-sm font-medium text-text-primary'>{t('common.members.email')}</div>
  78. <div className='mb-8 flex h-36 items-stretch'>
  79. <ReactMultiEmail
  80. className={cn('w-full border-components-input-border-active !bg-components-input-bg-normal px-3 pt-2 outline-none',
  81. 'appearance-none overflow-y-auto rounded-lg text-sm !text-text-primary',
  82. )}
  83. autoFocus
  84. emails={emails}
  85. inputClassName='bg-transparent'
  86. onChange={setEmails}
  87. getLabel={(email, index, removeEmail) =>
  88. <div data-tag key={index} className={cn('bg-components-button-secondary-bg')}>
  89. <div data-tag-item>{email}</div>
  90. <span data-tag-handle onClick={() => removeEmail(index)}>
  91. ×
  92. </span>
  93. </div>
  94. }
  95. placeholder={t('common.members.emailPlaceholder') || ''}
  96. />
  97. </div>
  98. <div className='mb-6'>
  99. <RoleSelector value={role} onChange={setRole} />
  100. </div>
  101. <Button
  102. tabIndex={0}
  103. className='w-full'
  104. onClick={handleSend}
  105. disabled={!emails.length}
  106. variant='primary'
  107. >
  108. {t('common.members.sendInvite')}
  109. </Button>
  110. </div>
  111. </Modal>
  112. </div>
  113. )
  114. }
  115. export default InviteModal