@filerobot/approvals
Version:
Asset approvals package for Filerobot
137 lines (134 loc) • 7.83 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
import { useState, useMemo } from 'react';
import { TooltipV2, SwitcherGroup, DatePicker, InputGroup, Label } from '@scaleflex/ui/core';
import ClockIcon from '@scaleflex/icons/clock';
import CustomDate from '@filerobot/utils/lib/CustomDate';
import { CURRENT_UTC_OFFSET, MIN_DATE, TIMEZONE_LABEL } from './RequestApproval.constants';
import useApprovals from '../../../../hooks/useApprovals';
import Styled from './RequestApprovalContent.styled';
// const MIN_DATE = (() => {
// const date = new Date()
// date.setDate(date.getDate())
// return date.toISOString().slice(0, 10)
// })()
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var DueDateSection = function DueDateSection(_ref) {
var value = _ref.value,
onChange = _ref.onChange,
dueDateEnabled = _ref.dueDateEnabled,
setDueDateEnabled = _ref.setDueDateEnabled,
_ref$tooltipSize = _ref.tooltipSize,
tooltipSize = _ref$tooltipSize === void 0 ? 'sm' : _ref$tooltipSize;
var _useMemo = useMemo(function () {
if (value) {
var _date = new CustomDate(value);
return ["".concat(_date.getFullYear(), "-").concat(_date.getMonthString(), "-").concat(_date.getDateString()), // 2024-02-21
"".concat(_date.getHoursString(), ":").concat(_date.getMinutesString())];
}
return ['', ''];
}, [value]),
_useMemo2 = _slicedToArray(_useMemo, 2),
parsedDate = _useMemo2[0],
parsedTime = _useMemo2[1];
var _useApprovals = useApprovals(),
i18n = _useApprovals.i18n;
var _useState = useState(parsedDate),
_useState2 = _slicedToArray(_useState, 2),
date = _useState2[0],
setDate = _useState2[1];
var _useState3 = useState(parsedTime || '00:00'),
_useState4 = _slicedToArray(_useState3, 2),
time = _useState4[0],
setTime = _useState4[1];
var handleChangeDate = function handleChangeDate(newDate) {
setDate(newDate);
onChange(newDate ? new Date("".concat(newDate, " ").concat(time)).toISOString() : null);
};
var handleChangeTime = function handleChangeTime(newTime) {
setTime(newTime);
onChange(newTime ? new Date("".concat(date, " ").concat(newTime)).toISOString() : null);
};
var handleChangeSwitcher = function handleChangeSwitcher(_ref2) {
var checked = _ref2.target.checked;
setDueDateEnabled(checked);
onChange(null);
};
return /*#__PURE__*/_jsxs(Styled.DueDateSection, {
children: [/*#__PURE__*/_jsx("div", {
children: /*#__PURE__*/_jsx(SwitcherGroup, {
size: "md",
label: /*#__PURE__*/_jsxs(Styled.LabelWithIcon, {
children: [i18n('approvalsRequestModalDueDateLabel'), /*#__PURE__*/_jsx(TooltipV2, {
title: i18n('approvalsRequestModalDueDateTooltip'),
position: "right",
size: tooltipSize,
children: /*#__PURE__*/_jsx(Styled.InfoIcon, {
size: 16
})
})]
}),
checked: dueDateEnabled,
onChange: handleChangeSwitcher
})
}), dueDateEnabled && /*#__PURE__*/_jsxs(Styled.DueDateRow, {
children: [/*#__PURE__*/_jsx(Styled.DueDateRowField, {
children: /*#__PURE__*/_jsx(DatePicker, {
value: date,
onChange: handleChangeDate,
label: i18n('approvalsRequestModalDateLabel'),
calendarStyles: {
position: 'relative',
top: 16,
height: 300
},
minDate: MIN_DATE,
position: "top-start",
fullWidth: true
})
}), /*#__PURE__*/_jsx(Styled.DueDateRowField, {
$showContent: !time,
children: /*#__PURE__*/_jsx(InputGroup, {
value: time,
onChange: function onChange(_ref3) {
var value = _ref3.target.value;
return handleChangeTime(value);
},
label: /*#__PURE__*/_jsx(Label, {
children: /*#__PURE__*/_jsxs(Styled.LabelWithIcon, {
children: [i18n('approvalsRequestModalTimeLabel', {
utc: CURRENT_UTC_OFFSET
}), /*#__PURE__*/_jsx(TooltipV2, {
title: i18n('approvalsRequestModalTimeTooltip', {
utc: CURRENT_UTC_OFFSET,
timezone_label: TIMEZONE_LABEL
}),
position: "right",
size: tooltipSize,
children: /*#__PURE__*/_jsx(Styled.InfoIcon, {})
})]
})
}),
inputProps: {
type: 'time'
},
iconEnd: function iconEnd(iconProps) {
return /*#__PURE__*/_jsx(ClockIcon, _objectSpread({}, iconProps));
},
fullWidth: true
})
})]
})]
});
};
export default DueDateSection;