index.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 Modal from '@/app/components/base/modal'
  7. import Button from '@/app/components/base/button'
  8. import s from './index.module.css'
  9. import { inviteMember } from '@/service/common'
  10. import { emailRegex } from '@/config'
  11. import { ToastContext } from '@/app/components/base/toast'
  12. interface IInviteModalProps {
  13. onCancel: () => void,
  14. onSend: () => 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()
  30. }
  31. } catch (e) {
  32. }
  33. } else {
  34. notify({ type: 'error', message: t('common.members.emailInvalid') })
  35. }
  36. }
  37. return (
  38. <div className={s.wrap}>
  39. <Modal isShow onClose={() => {}} className={s.modal}>
  40. <div className='flex justify-between mb-2'>
  41. <div className='text-xl font-semibold text-gray-900'>{t('common.members.inviteTeamMember')}</div>
  42. <XMarkIcon className='w-4 h-4 cursor-pointer' onClick={onCancel} />
  43. </div>
  44. <div className='mb-7 text-[13px] text-gray-500'>{t('common.members.inviteTeamMemberTip')}</div>
  45. <div>
  46. <div className='mb-2 text-sm font-medium text-gray-900'>{t('common.members.email')}</div>
  47. <input
  48. className='
  49. block w-full py-2 mb-9 px-3 bg-gray-50 outline-none border-none
  50. appearance-none text-sm text-gray-900 rounded-lg
  51. '
  52. value={email}
  53. onChange={e => setEmail(e.target.value)}
  54. placeholder={t('common.members.emailPlaceholder') || ''}
  55. />
  56. <Button
  57. className='w-full text-sm font-medium'
  58. onClick={handleSend}
  59. type='primary'
  60. >
  61. {t('common.members.sendInvite')}
  62. </Button>
  63. </div>
  64. </Modal>
  65. </div>
  66. )
  67. }
  68. export default InviteModal