Skip to content

Commit a17f673

Browse files
author
Gene Hynson
authored
feat(sub): edit form field validation (#5039)
1 parent c519b00 commit a17f673

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/writeData/subscriptions/components/BrokerDetails.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import BrokerFormContent from 'src/writeData/subscriptions/components/BrokerForm
2828
import {getOrg} from 'src/organizations/selectors'
2929
import {event} from 'src/cloud/utils/reporting'
3030
import {AppSettingContext} from 'src/shared/contexts/app'
31+
import {checkRequiredFields} from 'src/writeData/subscriptions/utils/form'
3132

3233
// Types
3334
import {SUBSCRIPTIONS, LOAD_DATA} from 'src/shared/constants/routes'
@@ -60,6 +61,7 @@ const BrokerDetails: FC<Props> = ({
6061
const history = useHistory()
6162
const org = useSelector(getOrg)
6263
const {navbarMode} = useContext(AppSettingContext)
64+
const requiredFields = checkRequiredFields(currentSubscription)
6365
const navbarOpen = navbarMode === 'expanded'
6466

6567
return (
@@ -106,10 +108,8 @@ const BrokerDetails: FC<Props> = ({
106108
testID="update-sub-form--cancel"
107109
/>
108110
<Button
109-
text="Edit"
110-
color={
111-
edit ? ComponentColor.Success : ComponentColor.Secondary
112-
}
111+
text={edit ? 'Cancel' : 'Edit'}
112+
color={ComponentColor.Secondary}
113113
onClick={() => {
114114
event('edit button clicked', {}, {feature: 'subscriptions'})
115115
setEdit(!edit)
@@ -127,6 +127,11 @@ const BrokerDetails: FC<Props> = ({
127127
saveForm(currentSubscription)
128128
}}
129129
testID="update-sub-form--submit"
130+
status={
131+
requiredFields
132+
? ComponentStatus.Default
133+
: ComponentStatus.Disabled
134+
}
130135
/>
131136
) : (
132137
<Button

src/writeData/subscriptions/components/BrokerFormContent.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ const BrokerFormContent: FC<Props> = ({
184184
validationFunc={() =>
185185
handleValidation('Broker Host', formContent.brokerHost)
186186
}
187+
helpText={
188+
edit
189+
? 'Changing the hostname will require you to provide your password again.'
190+
: ''
191+
}
187192
>
188193
{status => (
189194
<Input
@@ -196,6 +201,11 @@ const BrokerFormContent: FC<Props> = ({
196201
updateForm({
197202
...formContent,
198203
brokerHost: e.target.value,
204+
// clear the password field if broker host is edited
205+
brokerPassword:
206+
className === 'create'
207+
? formContent?.brokerPassword
208+
: '',
199209
})
200210
}}
201211
onBlur={() =>

0 commit comments

Comments
 (0)