|
1 |
| -import React, { useState } from 'react' |
| 1 | +import React, { useState, useEffect } from 'react' |
2 | 2 | import {
|
3 | 3 | FormGroup,
|
4 | 4 | Col,
|
@@ -28,25 +28,21 @@ const GluuCommitDialog = ({
|
28 | 28 | const { t } = useTranslation()
|
29 | 29 | const [active, setActive] = useState(false)
|
30 | 30 | let [loading, setLoading] = useState(isLoading)
|
| 31 | + const [userMeggage, setUserMessage] = useState('') |
31 | 32 | const USER_MESSAGE = 'user_action_message'
|
32 |
| - function handleStatus() { |
33 |
| - var value = document.getElementById(USER_MESSAGE).value |
34 |
| - if (value.length >= 10) { |
| 33 | + useEffect(() => { |
| 34 | + if (userMeggage.length >= 10) { |
35 | 35 | setActive(true)
|
36 | 36 | } else {
|
37 | 37 | setActive(false)
|
38 | 38 | }
|
39 |
| - } |
40 |
| - |
| 39 | + }, [userMeggage]) |
41 | 40 | function handleAccept() {
|
42 | 41 | if (formik) {
|
43 |
| - formik.setFieldValue( |
44 |
| - 'action_message', |
45 |
| - document.getElementById(USER_MESSAGE).value, |
46 |
| - ) |
| 42 | + formik.setFieldValue('action_message', userMeggage) |
47 | 43 | }
|
48 | 44 | setLoading(true)
|
49 |
| - onAccept(document.getElementById(USER_MESSAGE).value) |
| 45 | + onAccept(userMeggage) |
50 | 46 | }
|
51 | 47 | return (
|
52 | 48 | <Modal isOpen={modal} toggle={handler} className="modal-outline-primary">
|
@@ -78,19 +74,25 @@ const GluuCommitDialog = ({
|
78 | 74 | id={USER_MESSAGE}
|
79 | 75 | type={!!inputType ? inputType : 'textarea'}
|
80 | 76 | name={USER_MESSAGE}
|
81 |
| - onKeyUp={handleStatus} |
| 77 | + onChange={(e) => setUserMessage(e.target.value)} |
82 | 78 | placeholder={
|
83 | 79 | !placeholderLabel || placeholderLabel === ''
|
84 | 80 | ? t('placeholders.action_commit_message')
|
85 | 81 | : placeholderLabel
|
86 | 82 | }
|
87 | 83 | defaultValue=""
|
88 | 84 | />
|
| 85 | + {userMeggage.length <= 10 && ( |
| 86 | + <span className="text-danger"> |
| 87 | + {10 - userMeggage.length} {userMeggage.length ? ' more' : ''}{' '} |
| 88 | + characters required |
| 89 | + </span> |
| 90 | + )} |
89 | 91 | </Col>
|
90 | 92 | </FormGroup>
|
91 | 93 | </ModalBody>
|
92 | 94 | <ModalFooter>
|
93 |
| - <ClipLoader loading={loading} size={35} /> |
| 95 | + {/* <ClipLoader loading={loading} size={35} /> */} |
94 | 96 | {active && (
|
95 | 97 | <Button
|
96 | 98 | color="primary"
|
|
0 commit comments