All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.components.ObjectView.ModalEditViewColumn.ModalEditViewColumn.tsx Maven / Gradle / Ivy

The newest version!
/**
 * 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 from '@clayui/form';
import ClayModal from '@clayui/modal';
import {Observer} from '@clayui/modal/lib/types';
import {Input} from '@liferay/object-js-components-web';
import {InputLocalized} from 'frontend-js-components-web';
import React, {FormEvent, useState} from 'react';

import {defaultLanguageId} from '../../../utils/constants';
import {TYPES, useViewContext} from '../objectViewContext';

interface IProps {
	editingObjectFieldName: string;
	observer: Observer;
	onClose: () => void;
}

export function ModalEditViewColumn({
	editingObjectFieldName,
	observer,
	onClose,
}: IProps) {
	const [
		{
			objectView: {objectViewColumns},
		},
		dispatch,
	] = useViewContext();

	const [editingColumn] = objectViewColumns.filter(
		(viewColumn) => viewColumn.objectFieldName === editingObjectFieldName
	);

	const {label} = editingColumn;

	const [translations, setTranslations] = useState(label);

	const onSubmit = (event: FormEvent) => {
		event.preventDefault();

		Object.entries(translations).forEach(([key, value]) => {
			if (value === '' && key !== defaultLanguageId) {
				delete translations[key as Liferay.Language.Locale];
			}
		});

		dispatch({
			payload: {editingObjectFieldName, translations},
			type: TYPES.EDIT_OBJECT_VIEW_COLUMN_LABEL,
		});

		onClose();
	};

	return (
		
			 onSubmit(event)}>
				
					{Liferay.Language.get('rename-column-label')}
				

				
					

					
				

				
							 onClose()}
							>
								{Liferay.Language.get('cancel')}
							

							
								{Liferay.Language.get('edit')}
							
						
					}
				/>
			
		
	);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy