Просмотр исходного кода

Merge pull request #6395 from weseek/imprv/101688-date-range-picker

imprv(auditlog): Date Range Picker
Yuki Takei 3 лет назад
Родитель
Сommit
728958e7dd

+ 28 - 21
packages/app/src/components/Admin/AuditLog/DateRangePicker.tsx

@@ -1,33 +1,42 @@
-import React, {
-  FC, useRef, forwardRef, useCallback,
-} from 'react';
+import React, { FC, forwardRef, useCallback } from 'react';
 
 
+import { addDays, format } from 'date-fns';
 import DatePicker from 'react-datepicker';
 import DatePicker from 'react-datepicker';
 import 'react-datepicker/dist/react-datepicker.css';
 import 'react-datepicker/dist/react-datepicker.css';
 
 
-import { useTranslation } from 'react-i18next';
-
 
 
 type CustomInputProps = {
 type CustomInputProps = {
-  buttonRef: React.Ref<HTMLButtonElement>
-  onClick?: () => void;
+  value?: string
+  onChange?: () => void
+  onFocus?: () => void
 }
 }
 
 
-const CustomInput = forwardRef<HTMLButtonElement, CustomInputProps>((props: CustomInputProps) => {
-  const { t } = useTranslation();
+const CustomInput = forwardRef<HTMLInputElement, CustomInputProps>((props: CustomInputProps, ref) => {
+  const dateFormat = 'MM/dd/yyyy';
+  const date = new Date();
+  const placeholder = `${format(date, dateFormat)} - ${format(addDays(date, 1), dateFormat)}`;
+
   return (
   return (
-    <button
-      type="button"
-      className="btn btn-outline-secondary dropdown-toggle"
-      ref={props.buttonRef}
-      onClick={props.onClick}
-    >
-      <i className="fa fa-fw fa-calendar" /> {t('admin:audit_log_management.date')}
-    </button>
+    <div className="input-group admin-audit-log">
+      <div className="input-group-prepend">
+        <span className="input-group-text">
+          <i className="fa fa-fw fa-calendar" />
+        </span>
+      </div>
+      <input
+        ref={ref}
+        type="text"
+        value={props?.value}
+        onFocus={props?.onFocus}
+        onChange={props?.onChange}
+        placeholder={placeholder}
+        className="form-control date-range-picker"
+        aria-describedby="basic-addon1"
+      />
+    </div>
   );
   );
 });
 });
 
 
-
 type DateRangePickerProps = {
 type DateRangePickerProps = {
   startDate: Date | null
   startDate: Date | null
   endDate: Date | null
   endDate: Date | null
@@ -37,8 +46,6 @@ type DateRangePickerProps = {
 export const DateRangePicker: FC<DateRangePickerProps> = (props: DateRangePickerProps) => {
 export const DateRangePicker: FC<DateRangePickerProps> = (props: DateRangePickerProps) => {
   const { startDate, endDate, onChange } = props;
   const { startDate, endDate, onChange } = props;
 
 
-  const buttonRef = useRef(null);
-
   const changeHandler = useCallback((dateList: Date[] | null[]) => {
   const changeHandler = useCallback((dateList: Date[] | null[]) => {
     if (onChange != null) {
     if (onChange != null) {
       const [start, end] = dateList;
       const [start, end] = dateList;
@@ -59,7 +66,7 @@ export const DateRangePicker: FC<DateRangePickerProps> = (props: DateRangePicker
         startDate={startDate}
         startDate={startDate}
         endDate={endDate}
         endDate={endDate}
         onChange={changeHandler}
         onChange={changeHandler}
-        customInput={<CustomInput buttonRef={buttonRef} />}
+        customInput={<CustomInput />}
       />
       />
     </div>
     </div>
   );
   );

+ 3 - 0
packages/app/src/styles/_admin.scss

@@ -233,6 +233,9 @@ $slack-work-space-name-card-border: #efc1f6;
       max-height: 500px;
       max-height: 500px;
       overflow-y: auto;
       overflow-y: auto;
     }
     }
+    .date-range-picker {
+      width: 188px;
+    }
   }
   }
 
 
   #layoutOptions {
   #layoutOptions {