UNPKG

@filerobot/approvals

Version:

Asset approvals package for Filerobot

70 lines 2.8 kB
import { useMemo } from 'react'; import { useCore } from '@filerobot/core/lib/hooks'; import { APPROVAL_STATUSES } from '@filerobot/utils/lib/constants'; import CustomDate from '@filerobot/utils/lib/CustomDate'; import { PC } from '@filerobot/common'; import ApprovalStatus from '@filerobot/common/lib/ApprovalStatus'; import { useExplorerI18n } from '@filerobot/explorer/lib/hooks'; import Styled from './Approval.styled'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; var ApprovalDescription = function ApprovalDescription(_ref) { var approval = _ref.approval, labelFontVariant = _ref.labelFontVariant, renderActions = _ref.renderActions, isModalViewMode = _ref.isModalViewMode; var i18n = useExplorerI18n(); // need to use i18n from explorer to use it in explorer and in approvals as explorer exist in both cases var _useCore = useCore(), language = _useCore.opts.language; var isPendingApproval = approval.status === APPROVAL_STATUSES.PENDING; var dueDatePCKey = useMemo(function () { if (isPendingApproval) { var lessDaysLeftTillDate = function lessDaysLeftTillDate(expireDate) { var days = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var date = new Date(expireDate); date.setDate(date.getDate() - days); return date.getTime() < new Date().getTime(); }; if (lessDaysLeftTillDate(approval === null || approval === void 0 ? void 0 : approval.expires_at, 1)) { return PC.TextError; } if (lessDaysLeftTillDate(approval === null || approval === void 0 ? void 0 : approval.expires_at, 7)) { return PC.TextWarning; } } return null; }, [isPendingApproval, approval.expires_at]); var renderDateLabel = function renderDateLabel() { var i18nKey = 'approvalsOnDateLabel'; var date = approval.completed_at || approval.ended_at; if (isPendingApproval) { i18nKey = 'approvalsDueDateLabel'; date = approval.expires_at; } if (!date) { return; } return i18n(i18nKey, { date: new CustomDate(date).getFormattedDate(language) }); }; var renderDate = function renderDate() { var dateLabel = renderDateLabel(); return dateLabel && /*#__PURE__*/_jsx(Styled.DescDate, { paletteColorKey: dueDatePCKey, children: dateLabel }); }; return /*#__PURE__*/_jsxs(Styled.Description, { children: [/*#__PURE__*/_jsx(Styled.DescStatus, { children: /*#__PURE__*/_jsx(ApprovalStatus, { statusCode: approval.status, labelFontVariant: labelFontVariant, renderActions: renderActions, isModalViewMode: isModalViewMode, i18n: i18n, longLabel: true }) }), renderDate()] }); }; export default ApprovalDescription;