All files / client/components/Admin/User InviteUserForm.tsx

0% Statements 0/17
100% Branches 0/0
0% Functions 0/7
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                                                                                                                                                 
import React, { useState, FC } from 'react'
import { Collapse, Form, FormGroup, FormText, Label, Input, CustomInput, Button, Row, Col } from 'reactstrap'
 
function useForm(invite) {
  const [emails, setEmails] = useState('')
  const [sendEmail, setSendEmail] = useState(true)
 
  const clearForm = () => {
    setEmails('')
    setSendEmail(false)
  }
 
  const onSubmit = e => {
    e.preventDefault()
    invite({ emails, sendEmail })
    clearForm()
  }
 
  return [{ emails, sendEmail }, { setEmails, setSendEmail, onSubmit }] as const
}
 
interface Props {
  invite: ({ emails, sendEmail }: { emails: string; sendEmail: boolean }) => void
}
 
const InviteUserForm: FC<Props> = ({ invite }) => {
  const [collapse, setCollapse] = useState(false)
  const [{ emails, sendEmail }, { setEmails, setSendEmail, onSubmit }] = useForm(invite)
 
  return (
    <>
      <p>
        <Button color="secondary" onClick={() => setCollapse(!collapse)}>
          新規ユーザーの招待
        </Button>
      </p>
      <Form onSubmit={onSubmit}>
        <Collapse isOpen={collapse}>
          <FormGroup>
            <Row>
              <Col xs={{ size: 2, offset: 1 }}>
                <Label for="emails">メールアドレス</Label>
              </Col>
              <Col xs="8">
                <Input type="textarea" id="emails" placeholder="例: user@crowi.wiki" value={emails} onChange={e => setEmails(e.target.value)} />
                <FormText color="muted">複数行入力で複数人招待可能</FormText>
              </Col>
            </Row>
          </FormGroup>
 
          <FormGroup>
            <Row>
              <Col xs={{ size: 8, offset: 3 }}>
                <CustomInput id="sendEmail" type="checkbox" label="招待をメールで送信" checked={sendEmail} onChange={() => setSendEmail(!sendEmail)} inline />
              </Col>
            </Row>
          </FormGroup>
 
          <FormGroup>
            <Row>
              <Col xs={{ size: 8, offset: 3 }}>
                <Button color="primary">招待する</Button>
              </Col>
            </Row>
          </FormGroup>
        </Collapse>
      </Form>
    </>
  )
}
 
export default InviteUserForm