Move checkbox settings to custom field settings
[MAILPOET-2592]
This commit is contained in:
committed by
Rostislav Wolný
parent
5cde239dc3
commit
2a70a7cf2f
@@ -10,8 +10,12 @@ const CustomFieldSettings = ({
|
|||||||
mandatory,
|
mandatory,
|
||||||
isSaving,
|
isSaving,
|
||||||
onSave,
|
onSave,
|
||||||
|
isChecked,
|
||||||
|
checkboxLabel,
|
||||||
}) => {
|
}) => {
|
||||||
const [localMandatory, setLocalMandatory] = useState(mandatory);
|
const [localMandatory, setLocalMandatory] = useState(mandatory);
|
||||||
|
const [localIsChecked, setLocalIsChecked] = useState(isChecked);
|
||||||
|
const [localCheckboxLabel, setLocalCheckboxLabel] = useState(checkboxLabel);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="custom-field-settings">
|
<div className="custom-field-settings">
|
||||||
@@ -20,6 +24,8 @@ const CustomFieldSettings = ({
|
|||||||
isDefault
|
isDefault
|
||||||
onClick={() => onSave({
|
onClick={() => onSave({
|
||||||
mandatory: localMandatory,
|
mandatory: localMandatory,
|
||||||
|
isChecked: localIsChecked,
|
||||||
|
checkboxLabel: localCheckboxLabel,
|
||||||
})}
|
})}
|
||||||
isBusy={isSaving}
|
isBusy={isSaving}
|
||||||
disabled={isSaving}
|
disabled={isSaving}
|
||||||
@@ -32,6 +38,17 @@ const CustomFieldSettings = ({
|
|||||||
checked={localMandatory}
|
checked={localMandatory}
|
||||||
onChange={setLocalMandatory}
|
onChange={setLocalMandatory}
|
||||||
/>
|
/>
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={localIsChecked}
|
||||||
|
onChange={(event) => setLocalIsChecked(!!event.target.checked)}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={localCheckboxLabel}
|
||||||
|
onChange={(event) => setLocalCheckboxLabel(event.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -40,11 +57,15 @@ CustomFieldSettings.propTypes = {
|
|||||||
mandatory: PropTypes.bool,
|
mandatory: PropTypes.bool,
|
||||||
onSave: PropTypes.func.isRequired,
|
onSave: PropTypes.func.isRequired,
|
||||||
isSaving: PropTypes.bool,
|
isSaving: PropTypes.bool,
|
||||||
|
isChecked: PropTypes.bool,
|
||||||
|
checkboxLabel: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
CustomFieldSettings.defaultProps = {
|
CustomFieldSettings.defaultProps = {
|
||||||
mandatory: false,
|
mandatory: false,
|
||||||
isSaving: false,
|
isSaving: false,
|
||||||
|
isChecked: false,
|
||||||
|
checkboxLabel: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CustomFieldSettings;
|
export default CustomFieldSettings;
|
||||||
|
@@ -47,15 +47,25 @@ const CustomCheckboxEdit = ({ attributes, setAttributes }) => {
|
|||||||
<CustomFieldSettings
|
<CustomFieldSettings
|
||||||
mandatory={attributes.mandatory}
|
mandatory={attributes.mandatory}
|
||||||
isSaving={isSaving}
|
isSaving={isSaving}
|
||||||
|
isChecked={isChecked()}
|
||||||
|
checkboxLabel={getCheckboxLabel()}
|
||||||
onSave={(params) => saveCustomField({
|
onSave={(params) => saveCustomField({
|
||||||
customFieldId: attributes.customFieldId,
|
customFieldId: attributes.customFieldId,
|
||||||
data: {
|
data: {
|
||||||
params: {
|
params: {
|
||||||
required: params.mandatory ? '1' : undefined,
|
required: params.mandatory ? '1' : undefined,
|
||||||
|
values: [{
|
||||||
|
is_checked: params.isChecked ? '1' : undefined,
|
||||||
|
value: params.checkboxLabel,
|
||||||
|
}],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
onFinish: () => setAttributes({
|
onFinish: () => setAttributes({
|
||||||
mandatory: params.mandatory,
|
mandatory: params.mandatory,
|
||||||
|
values: [{
|
||||||
|
isChecked: params.isChecked,
|
||||||
|
name: params.checkboxLabel,
|
||||||
|
}],
|
||||||
}),
|
}),
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
@@ -74,25 +84,6 @@ const CustomCheckboxEdit = ({ attributes, setAttributes }) => {
|
|||||||
checked={!attributes.hideLabel}
|
checked={!attributes.hideLabel}
|
||||||
onChange={(hideLabel) => (setAttributes({ hideLabel: !hideLabel }))}
|
onChange={(hideLabel) => (setAttributes({ hideLabel: !hideLabel }))}
|
||||||
/>
|
/>
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={isChecked()}
|
|
||||||
onChange={(event) => setAttributes({
|
|
||||||
values: [{
|
|
||||||
name: getCheckboxLabel(),
|
|
||||||
checked: !!event.target.checked,
|
|
||||||
}],
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
value={getCheckboxLabel()}
|
|
||||||
onChange={(event) => setAttributes({
|
|
||||||
values: [{
|
|
||||||
name: event.target.value,
|
|
||||||
checked: isChecked(),
|
|
||||||
}],
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
</PanelBody>
|
</PanelBody>
|
||||||
</Panel>
|
</Panel>
|
||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
|
Reference in New Issue
Block a user