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

META-INF.resources.js.ScheduleOptions.js Maven / Gradle / Ivy

There is a newer version: 5.0.181
Show 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 ClayAlert from '@clayui/alert';
import ClayDatePicker from '@clayui/date-picker';
import ClayForm, {ClayInput} from '@clayui/form';
import ClayIcon from '@clayui/icon';
import classNames from 'classnames';
import {sub} from 'frontend-js-web';
import moment from 'moment/min/moment-with-locales';
import React, {useEffect} from 'react';

export default function ScheduleOptions({
	displayDate,
	error,
	formId,
	portletNamespace,
	setDisplayDate,
	setError,
	timeZone,
}) {
	const {day, hour, minutes, month, year} = getDate(displayDate);

	useEffect(() => {
		if (displayDate) {
			if (!moment(displayDate, 'yyyy-MM-DD HH:mm', true).isValid()) {
				setError(Liferay.Language.get('please-enter-a-valid-date'));

				return;
			}

			const date = new Date(displayDate);

			if (date.valueOf() <= new Date().valueOf()) {
				setError(
					Liferay.Language.get('the-date-entered-is-in-the-past')
				);
			}
			else {
				setError('');
			}
		}
	}, [setError, displayDate]);

	return (
		<>
			
				

				

				{error ? (
					
{error}
) : null}

{sub(Liferay.Language.get('time-zone-x'), timeZone)}

); } function getDate(value) { const date = new Date(value); if (moment(date).isValid()) { const date = new Date(value); return { day: date.getDate(), hour: date.getHours(), minutes: date.getMinutes(), month: date.getMonth(), year: date.getFullYear(), }; } return {day: '', hour: '', minutes: '', month: '', year: ''}; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy