Merge pull request #9623 from overleaf/mf-enter-submit-create-project

Create new project upon pressing 'Enter' key in new project modal

GitOrigin-RevId: 754572613d805e87b6746d5f38e9543e76e617e8
This commit is contained in:
Alexandre Bourdin 2022-09-26 10:57:18 +02:00 committed by Copybot
parent fe164ec6fd
commit c42cedbcdc

View file

@ -1,5 +1,5 @@
import { useState } from 'react' import React, { useState } from 'react'
import { Alert, Button, FormControl, Modal } from 'react-bootstrap' import { Alert, Button, Form, FormControl, Modal } from 'react-bootstrap'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import useAsync from '../../../../shared/hooks/use-async' import useAsync from '../../../../shared/hooks/use-async'
import { import {
@ -54,6 +54,11 @@ function ModalContentNewProjectForm({ onCancel, template = 'none' }: Props) {
setProjectName(e.currentTarget.value) setProjectName(e.currentTarget.value)
} }
const handleSubmit = (e: React.FormEvent<Form>) => {
e.preventDefault()
createNewProject()
}
return ( return (
<> <>
<Modal.Header closeButton> <Modal.Header closeButton>
@ -64,14 +69,16 @@ function ModalContentNewProjectForm({ onCancel, template = 'none' }: Props) {
{isError && ( {isError && (
<Alert bsStyle="danger">{getUserFacingMessage(error)}</Alert> <Alert bsStyle="danger">{getUserFacingMessage(error)}</Alert>
)} )}
<input <Form onSubmit={handleSubmit}>
type="text" <input
className="form-control" type="text"
ref={autoFocusedRef} className="form-control"
placeholder={t('project_name')} ref={autoFocusedRef}
onChange={handleChangeName} placeholder={t('project_name')}
value={projectName} onChange={handleChangeName}
/> value={projectName}
/>
</Form>
</Modal.Body> </Modal.Body>
<Modal.Footer> <Modal.Footer>