Disable save button until something changed
[MAILPOET-2592]
This commit is contained in:
committed by
Rostislav Wolný
parent
34203b3d69
commit
f8c2120e6a
@@ -28,7 +28,14 @@ const CustomFieldSettings = ({
|
|||||||
checkboxLabel: localCheckboxLabel,
|
checkboxLabel: localCheckboxLabel,
|
||||||
})}
|
})}
|
||||||
isBusy={isSaving}
|
isBusy={isSaving}
|
||||||
disabled={isSaving}
|
disabled={
|
||||||
|
isSaving
|
||||||
|
|| (
|
||||||
|
localMandatory === mandatory
|
||||||
|
&& localIsChecked === isChecked
|
||||||
|
&& localCheckboxLabel === checkboxLabel
|
||||||
|
)
|
||||||
|
}
|
||||||
className="button-on-top"
|
className="button-on-top"
|
||||||
>
|
>
|
||||||
{MailPoet.I18n.t('customFieldSaveCTA')}
|
{MailPoet.I18n.t('customFieldSaveCTA')}
|
||||||
|
@@ -51,7 +51,15 @@ const CustomFieldSettings = ({
|
|||||||
defaultToday: localDefaultToday,
|
defaultToday: localDefaultToday,
|
||||||
})}
|
})}
|
||||||
isBusy={isSaving}
|
isBusy={isSaving}
|
||||||
disabled={isSaving}
|
disabled={
|
||||||
|
isSaving
|
||||||
|
|| (
|
||||||
|
localMandatory === mandatory
|
||||||
|
&& localDefaultToday === defaultToday
|
||||||
|
&& localDateType === dateType
|
||||||
|
&& localDateFormat === dateFormat
|
||||||
|
)
|
||||||
|
}
|
||||||
className="button-on-top"
|
className="button-on-top"
|
||||||
>
|
>
|
||||||
{MailPoet.I18n.t('customFieldSaveCTA')}
|
{MailPoet.I18n.t('customFieldSaveCTA')}
|
||||||
|
@@ -5,6 +5,7 @@ import {
|
|||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
|
import { isEmpty, isEqual, xorWith } from 'lodash';
|
||||||
|
|
||||||
import SettingsPreview from './settings_preview.jsx';
|
import SettingsPreview from './settings_preview.jsx';
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ const CustomFieldSettings = ({
|
|||||||
onSave,
|
onSave,
|
||||||
}) => {
|
}) => {
|
||||||
const [localMandatory, setLocalMandatory] = useState(mandatory);
|
const [localMandatory, setLocalMandatory] = useState(mandatory);
|
||||||
const [localValues, setLocalValues] = useState(values);
|
const [localValues, setLocalValues] = useState(JSON.parse(JSON.stringify(values)));
|
||||||
|
|
||||||
const update = (value) => {
|
const update = (value) => {
|
||||||
setLocalValues(localValues.map((valueInSelection) => {
|
setLocalValues(localValues.map((valueInSelection) => {
|
||||||
@@ -42,7 +43,13 @@ const CustomFieldSettings = ({
|
|||||||
values: localValues,
|
values: localValues,
|
||||||
})}
|
})}
|
||||||
isBusy={isSaving}
|
isBusy={isSaving}
|
||||||
disabled={isSaving}
|
disabled={
|
||||||
|
isSaving
|
||||||
|
|| (
|
||||||
|
localMandatory === mandatory
|
||||||
|
&& isEmpty(xorWith(values, localValues, isEqual))
|
||||||
|
)
|
||||||
|
}
|
||||||
className="button-on-top"
|
className="button-on-top"
|
||||||
>
|
>
|
||||||
{MailPoet.I18n.t('customFieldSaveCTA')}
|
{MailPoet.I18n.t('customFieldSaveCTA')}
|
||||||
|
@@ -81,7 +81,7 @@ const PreviewItem = ({
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
onChange={(event) => onCheck(value.id, event.target.value)}
|
onChange={(event) => onCheck(value.id, event.target.checked)}
|
||||||
key={`check-${value.id}`}
|
key={`check-${value.id}`}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
|
@@ -26,7 +26,7 @@ const CustomFieldSettings = ({
|
|||||||
validate: localValidate,
|
validate: localValidate,
|
||||||
})}
|
})}
|
||||||
isBusy={isSaving}
|
isBusy={isSaving}
|
||||||
disabled={isSaving}
|
disabled={isSaving || (localMandatory === mandatory && localValidate === validate)}
|
||||||
className="button-on-top"
|
className="button-on-top"
|
||||||
>
|
>
|
||||||
{MailPoet.I18n.t('customFieldSaveCTA')}
|
{MailPoet.I18n.t('customFieldSaveCTA')}
|
||||||
|
Reference in New Issue
Block a user