Skip to content

Commit c8937ec

Browse files
committed
feat: add message under the textinput field
1 parent fdf9c7b commit c8937ec

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

admin-ui/app/routes/Apps/Gluu/GluuCommitDialog.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useState, useEffect } from 'react'
22
import {
33
FormGroup,
44
Col,
@@ -28,25 +28,21 @@ const GluuCommitDialog = ({
2828
const { t } = useTranslation()
2929
const [active, setActive] = useState(false)
3030
let [loading, setLoading] = useState(isLoading)
31+
const [userMeggage, setUserMessage] = useState('')
3132
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) {
3535
setActive(true)
3636
} else {
3737
setActive(false)
3838
}
39-
}
40-
39+
}, [userMeggage])
4140
function handleAccept() {
4241
if (formik) {
43-
formik.setFieldValue(
44-
'action_message',
45-
document.getElementById(USER_MESSAGE).value,
46-
)
42+
formik.setFieldValue('action_message', userMeggage)
4743
}
4844
setLoading(true)
49-
onAccept(document.getElementById(USER_MESSAGE).value)
45+
onAccept(userMeggage)
5046
}
5147
return (
5248
<Modal isOpen={modal} toggle={handler} className="modal-outline-primary">
@@ -78,19 +74,25 @@ const GluuCommitDialog = ({
7874
id={USER_MESSAGE}
7975
type={!!inputType ? inputType : 'textarea'}
8076
name={USER_MESSAGE}
81-
onKeyUp={handleStatus}
77+
onChange={(e) => setUserMessage(e.target.value)}
8278
placeholder={
8379
!placeholderLabel || placeholderLabel === ''
8480
? t('placeholders.action_commit_message')
8581
: placeholderLabel
8682
}
8783
defaultValue=""
8884
/>
85+
{userMeggage.length <= 10 && (
86+
<span className="text-danger">
87+
{10 - userMeggage.length} {userMeggage.length ? ' more' : ''}{' '}
88+
characters required
89+
</span>
90+
)}
8991
</Col>
9092
</FormGroup>
9193
</ModalBody>
9294
<ModalFooter>
93-
<ClipLoader loading={loading} size={35} />
95+
{/* <ClipLoader loading={loading} size={35} /> */}
9496
{active && (
9597
<Button
9698
color="primary"

0 commit comments

Comments
 (0)