@ncds/ui-admin 0.0.37 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.RangeDatePicker = void 0;
7
7
  var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _react = require("react");
9
- var _lodash = require("lodash");
10
9
  var _moment = _interopRequireDefault(require("moment"));
11
10
  var _DatePicker = require("./DatePicker");
12
11
  var _utils = require("./utils");
@@ -26,34 +25,29 @@ var RangeDatePicker = exports.RangeDatePicker = /*#__PURE__*/(0, _react.forwardR
26
25
  endDateOptions = _a.endDateOptions,
27
26
  validationOption = _a.validationOption,
28
27
  onDateValidation = _a.onDateValidation;
29
- var resetDateAndAlert = (0, _react.useCallback)(function (type) {
30
- var _a, _b;
31
- var newDate = type === 'start' ? ((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate) || '' : ((_b = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _b === void 0 ? void 0 : _b.endDate) || '';
32
- if (type === 'start') {
33
- startDateOptions.onChangeDate(newDate);
34
- } else {
35
- endDateOptions.onChangeDate(newDate);
36
- }
37
- onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
38
- type: type,
39
- errorType: 'reset',
40
- newDate: newDate,
41
- currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
42
- });
43
- }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
44
28
  var changeSettingDateAndAlert = (0, _react.useCallback)(function (type, isOverPeriod) {
45
29
  if (isOverPeriod === void 0) {
46
30
  isOverPeriod = false;
47
31
  }
48
32
  if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting)) {
49
- var newDate_1 = type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate;
50
- var currentDate = type === 'start' ? endDateOptions.currentDate : startDateOptions.currentDate;
51
- onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
52
- type: type,
53
- errorType: 'overlap',
54
- newDate: newDate_1,
55
- currentDate: currentDate
56
- });
33
+ if (type === 'start' && (0, _moment.default)(startDateOptions.currentDate).isAfter(endDateOptions.currentDate)) {
34
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
35
+ type: type,
36
+ errorType: 'overlap',
37
+ newDate: endDateOptions.currentDate,
38
+ currentDate: startDateOptions.currentDate
39
+ });
40
+ return;
41
+ }
42
+ if (type === 'end' && (0, _moment.default)(endDateOptions.currentDate).isBefore(startDateOptions.currentDate)) {
43
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
44
+ type: type,
45
+ errorType: 'overlap',
46
+ newDate: startDateOptions.currentDate,
47
+ currentDate: endDateOptions.currentDate
48
+ });
49
+ return;
50
+ }
57
51
  return;
58
52
  }
59
53
  var _a = validationOption.setting,
@@ -61,27 +55,28 @@ var RangeDatePicker = exports.RangeDatePicker = /*#__PURE__*/(0, _react.forwardR
61
55
  period = _a.period;
62
56
  var newDate = '';
63
57
  if (type === 'start') {
64
- newDate = (0, _utils.getDateFormat)((0, _moment.default)(endDateOptions.currentDate).subtract(period, unit).toDate());
58
+ if (isOverPeriod) {
59
+ newDate = (0, _utils.getDateFormat)((0, _moment.default)(endDateOptions.currentDate).subtract(period, unit).toDate());
60
+ } else if ((0, _moment.default)(startDateOptions.currentDate).isAfter(endDateOptions.currentDate)) {
61
+ newDate = endDateOptions.currentDate;
62
+ }
65
63
  } else {
66
- newDate = (0, _utils.getDateFormat)((0, _moment.default)(startDateOptions.currentDate).add(period, unit).toDate());
64
+ if (isOverPeriod) {
65
+ newDate = (0, _utils.getDateFormat)((0, _moment.default)(startDateOptions.currentDate).add(period, unit).toDate());
66
+ } else if ((0, _moment.default)(endDateOptions.currentDate).isBefore(startDateOptions.currentDate)) {
67
+ newDate = startDateOptions.currentDate;
68
+ }
69
+ }
70
+ if (newDate) {
71
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
72
+ type: type,
73
+ errorType: isOverPeriod ? 'period' : 'overlap',
74
+ newDate: newDate,
75
+ currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
76
+ });
67
77
  }
68
- onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
69
- type: type,
70
- errorType: isOverPeriod ? 'period' : 'overlap',
71
- newDate: newDate,
72
- currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
73
- });
74
78
  }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
75
- var validateDateType = function (date) {
76
- return (0, _moment.default)(date).isValid();
77
- };
78
79
  (0, _react.useEffect)(function () {
79
- var _a;
80
- var needResetDate = validateDateType(startDateOptions.currentDate) && !(0, _lodash.isNil)((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate);
81
- if (needResetDate) {
82
- resetDateAndAlert('start');
83
- return;
84
- }
85
80
  var isOverDate = (0, _moment.default)(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
86
81
  if (isOverDate) {
87
82
  changeSettingDateAndAlert('start');
@@ -90,21 +85,22 @@ var RangeDatePicker = exports.RangeDatePicker = /*#__PURE__*/(0, _react.forwardR
90
85
  if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting)) {
91
86
  return;
92
87
  }
93
- var _b = validationOption.setting,
94
- unit = _b.unit,
95
- period = _b.period;
88
+ var _a = validationOption.setting,
89
+ unit = _a.unit,
90
+ period = _a.period;
96
91
  var isValidPeriod = (0, _moment.default)(startDateOptions.currentDate).isSameOrAfter((0, _moment.default)(endDateOptions.currentDate).subtract(period, unit));
97
92
  if (!isValidPeriod) {
98
93
  changeSettingDateAndAlert('start', true);
94
+ } else {
95
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
96
+ type: 'start',
97
+ errorType: null,
98
+ newDate: startDateOptions.currentDate,
99
+ currentDate: startDateOptions.currentDate
100
+ });
99
101
  }
100
102
  }, [startDateOptions.currentDate]);
101
103
  (0, _react.useEffect)(function () {
102
- var _a;
103
- var needResetDate = validateDateType(endDateOptions.currentDate) && !(0, _lodash.isNil)((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.endDate);
104
- if (needResetDate) {
105
- resetDateAndAlert('end');
106
- return;
107
- }
108
104
  var isNotTodayEndDate = !(0, _moment.default)(endDateOptions.currentDate).isSame((0, _moment.default)(), 'day');
109
105
  if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting) || !isNotTodayEndDate) {
110
106
  return;
@@ -114,12 +110,19 @@ var RangeDatePicker = exports.RangeDatePicker = /*#__PURE__*/(0, _react.forwardR
114
110
  changeSettingDateAndAlert('end');
115
111
  return;
116
112
  }
117
- var _b = validationOption.setting,
118
- unit = _b.unit,
119
- period = _b.period;
113
+ var _a = validationOption.setting,
114
+ unit = _a.unit,
115
+ period = _a.period;
120
116
  var isValidPeriod = (0, _moment.default)(endDateOptions.currentDate).isSameOrBefore((0, _moment.default)(startDateOptions.currentDate).add(period, unit));
121
117
  if (!isValidPeriod) {
122
118
  changeSettingDateAndAlert('end', true);
119
+ } else {
120
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
121
+ type: 'end',
122
+ errorType: null,
123
+ newDate: endDateOptions.currentDate,
124
+ currentDate: endDateOptions.currentDate
125
+ });
123
126
  }
124
127
  }, [endDateOptions.currentDate]);
125
128
  return (0, _jsxRuntime.jsxs)("div", __assign({
@@ -43,5 +43,4 @@ var Divider = exports.Divider = /*#__PURE__*/(0, _react.forwardRef)(function (_a
43
43
  className: "ncua-divider__line"
44
44
  })]
45
45
  }));
46
- });
47
- Divider.displayName = 'Divider';
46
+ });
@@ -10,7 +10,6 @@ var __assign = this && this.__assign || function () {
10
10
  };
11
11
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  import { useCallback, useEffect, forwardRef } from 'react';
13
- import { isNil } from 'lodash';
14
13
  import moment from 'moment';
15
14
  import { DatePicker } from './DatePicker';
16
15
  import { getDateFormat } from './utils';
@@ -19,34 +18,29 @@ export var RangeDatePicker = /*#__PURE__*/forwardRef(function (_a, ref) {
19
18
  endDateOptions = _a.endDateOptions,
20
19
  validationOption = _a.validationOption,
21
20
  onDateValidation = _a.onDateValidation;
22
- var resetDateAndAlert = useCallback(function (type) {
23
- var _a, _b;
24
- var newDate = type === 'start' ? ((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate) || '' : ((_b = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _b === void 0 ? void 0 : _b.endDate) || '';
25
- if (type === 'start') {
26
- startDateOptions.onChangeDate(newDate);
27
- } else {
28
- endDateOptions.onChangeDate(newDate);
29
- }
30
- onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
31
- type: type,
32
- errorType: 'reset',
33
- newDate: newDate,
34
- currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
35
- });
36
- }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
37
21
  var changeSettingDateAndAlert = useCallback(function (type, isOverPeriod) {
38
22
  if (isOverPeriod === void 0) {
39
23
  isOverPeriod = false;
40
24
  }
41
25
  if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting)) {
42
- var newDate_1 = type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate;
43
- var currentDate = type === 'start' ? endDateOptions.currentDate : startDateOptions.currentDate;
44
- onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
45
- type: type,
46
- errorType: 'overlap',
47
- newDate: newDate_1,
48
- currentDate: currentDate
49
- });
26
+ if (type === 'start' && moment(startDateOptions.currentDate).isAfter(endDateOptions.currentDate)) {
27
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
28
+ type: type,
29
+ errorType: 'overlap',
30
+ newDate: endDateOptions.currentDate,
31
+ currentDate: startDateOptions.currentDate
32
+ });
33
+ return;
34
+ }
35
+ if (type === 'end' && moment(endDateOptions.currentDate).isBefore(startDateOptions.currentDate)) {
36
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
37
+ type: type,
38
+ errorType: 'overlap',
39
+ newDate: startDateOptions.currentDate,
40
+ currentDate: endDateOptions.currentDate
41
+ });
42
+ return;
43
+ }
50
44
  return;
51
45
  }
52
46
  var _a = validationOption.setting,
@@ -54,27 +48,28 @@ export var RangeDatePicker = /*#__PURE__*/forwardRef(function (_a, ref) {
54
48
  period = _a.period;
55
49
  var newDate = '';
56
50
  if (type === 'start') {
57
- newDate = getDateFormat(moment(endDateOptions.currentDate).subtract(period, unit).toDate());
51
+ if (isOverPeriod) {
52
+ newDate = getDateFormat(moment(endDateOptions.currentDate).subtract(period, unit).toDate());
53
+ } else if (moment(startDateOptions.currentDate).isAfter(endDateOptions.currentDate)) {
54
+ newDate = endDateOptions.currentDate;
55
+ }
58
56
  } else {
59
- newDate = getDateFormat(moment(startDateOptions.currentDate).add(period, unit).toDate());
57
+ if (isOverPeriod) {
58
+ newDate = getDateFormat(moment(startDateOptions.currentDate).add(period, unit).toDate());
59
+ } else if (moment(endDateOptions.currentDate).isBefore(startDateOptions.currentDate)) {
60
+ newDate = startDateOptions.currentDate;
61
+ }
62
+ }
63
+ if (newDate) {
64
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
65
+ type: type,
66
+ errorType: isOverPeriod ? 'period' : 'overlap',
67
+ newDate: newDate,
68
+ currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
69
+ });
60
70
  }
61
- onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
62
- type: type,
63
- errorType: isOverPeriod ? 'period' : 'overlap',
64
- newDate: newDate,
65
- currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
66
- });
67
71
  }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
68
- var validateDateType = function (date) {
69
- return moment(date).isValid();
70
- };
71
72
  useEffect(function () {
72
- var _a;
73
- var needResetDate = validateDateType(startDateOptions.currentDate) && !isNil((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate);
74
- if (needResetDate) {
75
- resetDateAndAlert('start');
76
- return;
77
- }
78
73
  var isOverDate = moment(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
79
74
  if (isOverDate) {
80
75
  changeSettingDateAndAlert('start');
@@ -83,21 +78,22 @@ export var RangeDatePicker = /*#__PURE__*/forwardRef(function (_a, ref) {
83
78
  if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting)) {
84
79
  return;
85
80
  }
86
- var _b = validationOption.setting,
87
- unit = _b.unit,
88
- period = _b.period;
81
+ var _a = validationOption.setting,
82
+ unit = _a.unit,
83
+ period = _a.period;
89
84
  var isValidPeriod = moment(startDateOptions.currentDate).isSameOrAfter(moment(endDateOptions.currentDate).subtract(period, unit));
90
85
  if (!isValidPeriod) {
91
86
  changeSettingDateAndAlert('start', true);
87
+ } else {
88
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
89
+ type: 'start',
90
+ errorType: null,
91
+ newDate: startDateOptions.currentDate,
92
+ currentDate: startDateOptions.currentDate
93
+ });
92
94
  }
93
95
  }, [startDateOptions.currentDate]);
94
96
  useEffect(function () {
95
- var _a;
96
- var needResetDate = validateDateType(endDateOptions.currentDate) && !isNil((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.endDate);
97
- if (needResetDate) {
98
- resetDateAndAlert('end');
99
- return;
100
- }
101
97
  var isNotTodayEndDate = !moment(endDateOptions.currentDate).isSame(moment(), 'day');
102
98
  if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting) || !isNotTodayEndDate) {
103
99
  return;
@@ -107,12 +103,19 @@ export var RangeDatePicker = /*#__PURE__*/forwardRef(function (_a, ref) {
107
103
  changeSettingDateAndAlert('end');
108
104
  return;
109
105
  }
110
- var _b = validationOption.setting,
111
- unit = _b.unit,
112
- period = _b.period;
106
+ var _a = validationOption.setting,
107
+ unit = _a.unit,
108
+ period = _a.period;
113
109
  var isValidPeriod = moment(endDateOptions.currentDate).isSameOrBefore(moment(startDateOptions.currentDate).add(period, unit));
114
110
  if (!isValidPeriod) {
115
111
  changeSettingDateAndAlert('end', true);
112
+ } else {
113
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
114
+ type: 'end',
115
+ errorType: null,
116
+ newDate: endDateOptions.currentDate,
117
+ currentDate: endDateOptions.currentDate
118
+ });
116
119
  }
117
120
  }, [endDateOptions.currentDate]);
118
121
  return _jsxs("div", __assign({
@@ -36,5 +36,4 @@ export var Divider = /*#__PURE__*/forwardRef(function (_a, ref) {
36
36
  className: "ncua-divider__line"
37
37
  })]
38
38
  }));
39
- });
40
- Divider.displayName = 'Divider';
39
+ });
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { unitOfTime } from 'moment';
3
2
  import { DatePickerProps } from './DatePicker';
4
3
  export type RangeDatePickerProps = {
@@ -16,10 +15,10 @@ export type RangeDatePickerProps = {
16
15
  };
17
16
  onDateValidation?: (params: {
18
17
  type: 'start' | 'end';
19
- errorType: 'reset' | 'period' | 'overlap';
18
+ errorType: 'reset' | 'period' | 'overlap' | null;
20
19
  newDate: string;
21
20
  currentDate: string;
22
21
  }) => void;
23
22
  };
24
- export declare const RangeDatePicker: React.ForwardRefExoticComponent<RangeDatePickerProps & React.RefAttributes<HTMLDivElement>>;
23
+ export declare const RangeDatePicker: import("react").ForwardRefExoticComponent<RangeDatePickerProps & import("react").RefAttributes<HTMLDivElement>>;
25
24
  //# sourceMappingURL=RangeDatePicker.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ncds/ui-admin",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "nhn-commerce의 어드민 디자인 시스템입니다.",
5
5
  "scripts": {
6
6
  "barrel": "node barrel.js",