summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-19 15:47:23 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-19 16:03:11 +0200
commit5e5ab63b280eb446db4090733cd3ad2e97d02018 (patch)
tree352766be8a86c78f2aa233bb24db1a2711cc0f21 /opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js
parent54d07120191eb81de91a49cdebf619cfecce2666 (diff)
refactor(ui): Restructure components per page
This change updates the source structure of the OpenDC frontend to follow the page structure.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js')
-rw-r--r--opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js70
1 files changed, 0 insertions, 70 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js b/opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js
deleted file mode 100644
index 392a729e..00000000
--- a/opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import PropTypes from 'prop-types'
-import React, { useRef, useState } from 'react'
-import Modal from './Modal'
-import { Form, FormGroup, TextInput } from '@patternfly/react-core'
-
-function TextInputModal({ title, label, isOpen, callback, initialValue }) {
- const textInput = useRef(null)
- const [isSubmitted, setSubmitted] = useState(false)
- const [isValid, setValid] = useState(true)
-
- const resetState = () => {
- textInput.current.value = ''
- setSubmitted(false)
- setValid(false)
- }
- const onSubmit = (event) => {
- const value = textInput.current.value
- setSubmitted(true)
-
- if (event) {
- event.preventDefault()
- }
-
- if (!value) {
- setValid(false)
- return false
- }
-
- callback(value)
- resetState()
- return true
- }
- const onCancel = () => {
- callback(undefined)
- resetState()
- }
-
- return (
- <Modal title={title} isOpen={isOpen} onSubmit={onSubmit} onCancel={onCancel}>
- <Form onSubmit={onSubmit}>
- <FormGroup
- label={label}
- fieldId="text-input"
- isRequired
- validated={isSubmitted && !isValid ? 'error' : 'default'}
- helperTextInvalid="This field cannot be empty"
- >
- <TextInput
- id="text-input"
- name="text-input"
- isRequired
- type="text"
- ref={textInput}
- defaultValue={initialValue}
- />
- </FormGroup>
- </Form>
- </Modal>
- )
-}
-
-TextInputModal.propTypes = {
- title: PropTypes.string.isRequired,
- label: PropTypes.string.isRequired,
- isOpen: PropTypes.bool.isRequired,
- callback: PropTypes.func.isRequired,
- initialValue: PropTypes.string,
-}
-
-export default TextInputModal