index.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use client'
  2. import { useState } from 'react'
  3. import { useContext } from 'use-context-selector'
  4. import { XMarkIcon } from '@heroicons/react/24/outline'
  5. import { useTranslation } from 'react-i18next'
  6. import s from './index.module.css'
  7. import Modal from '@/app/components/base/modal'
  8. import Button from '@/app/components/base/button'
  9. import { inviteMember } from '@/service/common'
  10. import { emailRegex } from '@/config'
  11. import { ToastContext } from '@/app/components/base/toast'
  12. type IInviteModalProps = {
  13. onCancel: () => void
  14. onSend: (url: string) => void
  15. }
  16. const InviteModal = ({
  17. onCancel,
  18. onSend,
  19. }: IInviteModalProps) => {
  20. const { t } = useTranslation()
  21. const [email, setEmail] = useState('')
  22. const { notify } = useContext(ToastContext)
  23. const handleSend = async () => {
  24. if (emailRegex.test(email)) {
  25. try {
  26. const res = await inviteMember({ url: '/workspaces/current/members/invite-email', body: { email, role: 'admin' } })
  27. if (res.result === 'success') {
  28. onCancel()
  29. onSend(res.invite_url)
  30. }
  31. }
  32. catch (e) {}
  33. }
  34. else {
  35. notify({ type: 'error', message: t('common.members.emailInvalid') })
  36. }
  37. }
  38. return (
  39. <div className={s.wrap}>
  40. <Modal isShow onClose={() => {}} className={s.modal}>
  41. <div className='flex justify-between mb-2'>
  42. <div className='text-xl font-semibold text-gray-900'>{t('common.members.inviteTeamMember')}</div>
  43. <XMarkIcon className='w-4 h-4 cursor-pointer' onClick={onCancel} />
  44. </div>
  45. <div className='mb-7 text-[13px] text-gray-500'>{t('common.members.inviteTeamMemberTip')}</div>
  46. <div>
  47. <div className='mb-2 text-sm font-medium text-gray-900'>{t('common.members.email')}</div>
  48. <input
  49. className='
  50. block w-full py-2 mb-9 px-3 bg-gray-50 outline-none border-none
  51. appearance-none text-sm text-gray-900 rounded-lg
  52. '
  53. value={email}
  54. onChange={e => setEmail(e.target.value)}
  55. placeholder={t('common.members.emailPlaceholder') || ''}
  56. />
  57. <Button
  58. className='w-full text-sm font-medium'
  59. onClick={handleSend}
  60. type='primary'
  61. >
  62. {t('common.members.sendInvite')}
  63. </Button>
  64. </div>
  65. </Modal>
  66. </div>
  67. )
  68. }
  69. export default InviteModal