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

META-INF.resources.js.components.ObjectDetails.SeparatorContainer.tsx Maven / Gradle / Ivy

The newest version!
/**
 * SPDX-FileCopyrightText: (c) 2025 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

import {SeparatorFields} from '@liferay/friendly-url-web';
import {FormError} from '@liferay/object-js-components-web';
import React, {useState} from 'react';

import {Error} from '../../utils/errors';

interface SeparatorContainerProps {
	disabled?: boolean;
	errors: FormError;
	onSubmit?: (editedObjectDefinition?: Partial) => void;
	setErrors?: (errors: Error) => void;
	setValues: (values: Partial) => void;
	values: Partial;
}

const SEPARATOR_TEXT = {
	helpText: Liferay.Language.get(
		'modifying-these-values-can-impact-existing-urls-and-seo'
	),
	label: Liferay.Language.get('object-entry-url-separator'),
	url: 'http://www.sitename.com',
	warningMessage: Liferay.Language.get(
		"using-the-l-separator-disables-the-ability-to-override-an-object-entry's-friendly-url"
	),
};

export function hasLegacySeparator(value: any) {
	return value === 'l';
}

export function SeparatorContainer({
	disabled,
	errors,
	onSubmit,
	setErrors,
	setValues,
	values,
}: SeparatorContainerProps) {
	const {helpText, label, url, warningMessage} = SEPARATOR_TEXT;

	const [warnings, setWarnings] = useState({friendlyURLSeparator: ''});

	const handleChange = (value: string) => {
		setValues({friendlyURLSeparator: value});

		if (hasLegacySeparator(value)) {
			setValues({
				enableFriendlyURLCustomization: false,
			});

			setWarnings({friendlyURLSeparator: warningMessage});
		}
		else {
			setWarnings({friendlyURLSeparator: ''});
		}
	};

	const handleOnBlur = (
		event: React.FocusEvent
	) => {
		event.stopPropagation();

		if (setErrors) {
			setErrors({});
		}

		if (onSubmit) {
			onSubmit();
		}
	};

	return (
		<>
			
		
	);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy