META-INF.resources.js.multishipping.DeliveryGroupHeaderCell.tsx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.commerce.order.content.web
Show all versions of com.liferay.commerce.order.content.web
Liferay Commerce Order Content Web
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import {ClayButtonWithIcon} from '@clayui/button';
import DropDown from '@clayui/drop-down';
import ClayLoadingIndicator from '@clayui/loading-indicator';
import {useModal} from '@clayui/modal';
import ClayTable from '@clayui/table';
import {openConfirmModal} from 'frontend-js-web';
import React, {useCallback} from 'react';
import DeliveryGroupModal from './DeliveryGroupModal';
import {IDeliveryGroup} from './Types';
interface IDeliveryGroupHeaderCellProps {
handleDeleteDeliveryGroup(deliveryGroup: IDeliveryGroup): void;
handleSubmitDeliveryGroup(deliveryGroup: IDeliveryGroup): void;
accountId: number;
deliveryGroup: IDeliveryGroup;
disabled?: boolean;
hasManageAddressesPermission?: boolean;
namespace?: string;
readonly?: boolean;
saving?: boolean;
spritemap?: string;
}
const DeliveryGroupHeaderCell = ({
accountId,
deliveryGroup,
disabled = false,
handleDeleteDeliveryGroup,
handleSubmitDeliveryGroup,
hasManageAddressesPermission = true,
namespace = 'DeliveryGroupHeaderCell',
readonly = false,
saving = false,
spritemap = '',
}: IDeliveryGroupHeaderCellProps) => {
const {observer, onOpenChange, open} = useModal();
const handleDeleteDeliveryGroupWrapper = useCallback(
(deliveryGroup: IDeliveryGroup) => {
onOpenChange(false);
handleDeleteDeliveryGroup(deliveryGroup);
},
[handleDeleteDeliveryGroup, onOpenChange]
);
const handleSubmitDeliveryGroupWrapper = useCallback(
(deliveryGroup: IDeliveryGroup) => {
onOpenChange(false);
handleSubmitDeliveryGroup(deliveryGroup);
},
[handleSubmitDeliveryGroup, onOpenChange]
);
return (
{
event.preventDefault();
if (disabled || saving) {
return;
}
onOpenChange(true);
}}
>
{saving ? (
) : (
<>
{deliveryGroup.name}
{!!deliveryGroup.deliveryDate && (
{new Intl.DateTimeFormat(
Liferay.ThemeDisplay.getBCP47LanguageId(),
{dateStyle: 'short'}
).format(
new Date(deliveryGroup.deliveryDate)
)}
)}
{!readonly && (
{
event.preventDefault();
event.stopPropagation();
}}
size="xs"
symbol="ellipsis-v"
/>
}
>
{
onOpenChange(true);
}}
>
{Liferay.Language.get('edit')}
{
openConfirmModal({
message: Liferay.Language.get(
'are-you-sure-you-want-to-delete-this'
),
onConfirm: (isConfirmed) => {
if (isConfirmed) {
handleDeleteDeliveryGroupWrapper(
deliveryGroup
);
}
},
});
}}
>
{Liferay.Language.get('delete')}
)}
>
)}
{open && (
)}
);
};
export default DeliveryGroupHeaderCell;