META-INF.resources.js.FormFragmentsConfiguration.js Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import ClayButton from '@clayui/button';
import ClayForm, {ClayInput} from '@clayui/form';
import ClayLayout from '@clayui/layout';
import ClayTable from '@clayui/table';
import {
createPortletURL,
getPortletId,
openSelectionModal,
sub,
} from 'frontend-js-web';
import React, {useState} from 'react';
export default function FormFragmentsConfiguration({
formTypes,
portletNamespace,
selectFragmentEntryURL,
updateInputFragmentEntriesURL,
}) {
const [values, setValues] = useState({});
const onClick = (name) => {
openSelectionModal({
onSelect: ({fragmententrykey, fragmententryname, groupkey}) => {
setValues((previousValues) => ({
...previousValues,
[name]: {
fragmentEntryName: fragmententryname,
groupKey: groupkey,
key: fragmententrykey,
},
}));
},
selectEventName: 'selectFragment',
title: sub(
Liferay.Language.get('select-x'),
Liferay.Language.get('fragment')
),
url: createPortletURL(selectFragmentEntryURL, {
inputType: name,
p_p_id: getPortletId(portletNamespace),
}),
});
};
return (
{Liferay.Language.get('form-fragments')}
{Liferay.Language.get(
'define-the-default-form-fragments-for-this-site'
)}
{Liferay.Language.get(
'the-selected-fragments-are-displayed-in-the-forms-created-on-the-pages-by-default'
)}
{Liferay.Language.get('field-type')}
{Liferay.Language.get('form-fragment')}
{formTypes.map(({fragmentName, label, name}) => (
{label}
onClick(name)
}
readOnly
value={
values[name]
?.fragmentEntryName ||
fragmentName
}
/>
onClick(name)
}
size="sm"
>
{Liferay.Language.get(
'select'
)}
))}
{Liferay.Language.get('save')}
{Liferay.Language.get('cancel')}
);
}