Skip to content

Commit bca9ebd

Browse files
committed
Fixing submit/reset button appearance on create subgroup and relocate group forms.
1 parent a30c539 commit bca9ebd

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed

src/components/forms/EditGroupForm/EditGroupForm.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { reduxForm, Field, FieldArray } from 'redux-form';
55
import { Container, Row, Col } from 'react-bootstrap';
66

77
import Callout from '../../widgets/Callout';
8+
import Button, { TheButtonGroup } from '../../widgets/TheButton';
89
import FormBox from '../../widgets/FormBox';
910
import SubmitButton from '../SubmitButton';
1011
import LocalizedTextsFormField from '../LocalizedTextsFormField';
12+
import { RefreshIcon } from '../../icons';
1113

1214
import { TextField, CheckboxField, NumericTextField } from '../Fields';
1315
import { getLocalizedTextsInitialValues, validateLocalizedTextsFormData } from '../../../helpers/localizedData';
@@ -56,26 +58,36 @@ const EditGroupForm = ({
5658
}
5759
type={submitSucceeded ? 'success' : undefined}
5860
footer={
59-
<div className="text-center">
60-
<SubmitButton
61-
id="editGroup"
62-
handleSubmit={handleSubmit(data => onSubmit(data).then(reset))}
63-
submitting={submitting}
64-
dirty={dirty}
65-
hasSucceeded={submitSucceeded}
66-
hasFailed={submitFailed}
67-
invalid={invalid}
68-
messages={{
69-
submit: createNew ? (
70-
<FormattedMessage id="app.editGroupForm.createGroup" defaultMessage="Create Group" />
71-
) : (
72-
<FormattedMessage id="app.editGroupForm.saveGroup" defaultMessage="Save Group" />
73-
),
74-
submitting: <FormattedMessage id="generic.saving" defaultMessage="Saving..." />,
75-
success: <FormattedMessage id="generic.saved" defaultMessage="Saved" />,
76-
}}
77-
/>
78-
</div>
61+
!createNew || dirty ? (
62+
<div className="text-center">
63+
<TheButtonGroup>
64+
{dirty && (
65+
<Button type="reset" onClick={reset} variant="danger">
66+
<RefreshIcon gapRight />
67+
<FormattedMessage id="generic.reset" defaultMessage="Reset" />
68+
</Button>
69+
)}
70+
<SubmitButton
71+
id="editGroup"
72+
handleSubmit={handleSubmit(data => onSubmit(data).then(reset))}
73+
submitting={submitting}
74+
dirty={dirty}
75+
hasSucceeded={submitSucceeded}
76+
hasFailed={submitFailed}
77+
invalid={invalid}
78+
messages={{
79+
submit: createNew ? (
80+
<FormattedMessage id="app.editGroupForm.createGroup" defaultMessage="Create Group" />
81+
) : (
82+
<FormattedMessage id="app.editGroupForm.saveGroup" defaultMessage="Save Group" />
83+
),
84+
submitting: <FormattedMessage id="generic.saving" defaultMessage="Saving..." />,
85+
success: <FormattedMessage id="generic.saved" defaultMessage="Saved" />,
86+
}}
87+
/>
88+
</TheButtonGroup>
89+
</div>
90+
) : null
7991
}
8092
collapsable={collapsable}
8193
isOpen={isOpen}

src/components/forms/Fields/CheckboxField.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CheckboxField = ({
1717
/* eslint-disable no-unneeded-ternary */
1818
return (
1919
<FormGroup
20-
className={error ? 'text-danger' : warning ? 'text-warning' : dirty && !ignoreDirty ? 'text-success' : undefined}
20+
className={error ? 'text-danger' : warning ? 'text-warning' : dirty && !ignoreDirty ? 'text-primary' : undefined}
2121
controlId={input.name}>
2222
<Component
2323
{...props}

src/components/forms/Fields/RadioField.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const RadioField = ({ input, meta: { error, warning, dirty }, ignoreDirty = fals
1212
'form-check-label': true,
1313
'text-danger': error && input.value === key,
1414
'text-warninig': !error && warning && input.value === key,
15-
'text-success': dirty && !ignoreDirty && input.value === key,
15+
'text-primary': dirty && !ignoreDirty && input.value === key,
1616
})}>
1717
<input type="radio" name={input.name} value={key} checked={input.value === key} onChange={input.onChange} />
1818
{name}

src/components/forms/NiceCheckbox/NiceCheckbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const NiceCheckbox = ({
3737
: warning
3838
? 'text-warning'
3939
: dirty
40-
? 'text-success'
40+
? 'text-primary'
4141
: !checked
4242
? 'text-muted'
4343
: undefined;

src/components/forms/RelocateGroupForm/RelocateGroupForm.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { defaultMemoize } from 'reselect';
77

88
import { SelectField } from '../Fields';
99
import SubmitButton from '../SubmitButton';
10-
import Icon, { WarningIcon } from '../../icons';
10+
import Icon, { RefreshIcon, WarningIcon } from '../../icons';
11+
import Button, { TheButtonGroup } from '../../widgets/TheButton';
1112
import Callout from '../../widgets/Callout';
1213
import { getGroupCanonicalLocalizedName } from '../../../helpers/localizedData';
1314
import { hasPermissions } from '../../../helpers/common';
@@ -22,8 +23,10 @@ const RelocateGroupForm = ({
2223
submitFailed,
2324
submitSucceeded,
2425
invalid,
26+
dirty = false,
2527
groups,
2628
groupsAccessor,
29+
reset,
2730
intl: { locale },
2831
}) => (
2932
<div>
@@ -47,20 +50,28 @@ const RelocateGroupForm = ({
4750
/>
4851

4952
<div className="text-center">
50-
<SubmitButton
51-
id="relocateGroup"
52-
disabled={invalid}
53-
submitting={submitting}
54-
hasSucceeded={submitSucceeded}
55-
hasFailed={submitFailed}
56-
handleSubmit={handleSubmit}
57-
defaultIcon={<Icon icon="people-carry" gapRight />}
58-
messages={{
59-
submit: <FormattedMessage id="app.relocateGroupForm.submit" defaultMessage="Relocate" />,
60-
submitting: <FormattedMessage id="app.relocateGroupForm.submitting" defaultMessage="Relocating..." />,
61-
success: <FormattedMessage id="app.relocateGroupForm.success" defaultMessage="Group Relocated" />,
62-
}}
63-
/>
53+
<TheButtonGroup>
54+
{dirty && (
55+
<Button type="reset" onClick={reset} variant="danger">
56+
<RefreshIcon gapRight />
57+
<FormattedMessage id="generic.reset" defaultMessage="Reset" />
58+
</Button>
59+
)}
60+
<SubmitButton
61+
id="relocateGroup"
62+
disabled={invalid || !dirty}
63+
submitting={submitting}
64+
hasSucceeded={submitSucceeded}
65+
hasFailed={submitFailed}
66+
handleSubmit={handleSubmit}
67+
defaultIcon={<Icon icon="people-carry" gapRight />}
68+
messages={{
69+
submit: <FormattedMessage id="app.relocateGroupForm.submit" defaultMessage="Relocate" />,
70+
submitting: <FormattedMessage id="app.relocateGroupForm.submitting" defaultMessage="Relocating..." />,
71+
success: <FormattedMessage id="app.relocateGroupForm.success" defaultMessage="Group Relocated" />,
72+
}}
73+
/>
74+
</TheButtonGroup>
6475
</div>
6576
</Form>
6677
</div>
@@ -75,10 +86,12 @@ RelocateGroupForm.propTypes = {
7586
submitFailed: PropTypes.bool,
7687
submitSucceeded: PropTypes.bool,
7788
invalid: PropTypes.bool,
89+
dirty: PropTypes.bool,
7890
handleSubmit: PropTypes.func.isRequired,
7991
links: PropTypes.object,
8092
groups: PropTypes.array,
8193
groupsAccessor: PropTypes.func.isRequired,
94+
reset: PropTypes.func,
8295
intl: PropTypes.object,
8396
};
8497

0 commit comments

Comments
 (0)