diff --git a/CHANGELOG.md b/CHANGELOG.md index 065c3ce6..13b3e562 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), * [#430](https://github.com/shlinkio/shlink-web-client/pull/430) Added support to set new and existing short URLs as crawlable, when consuming Shlink >=2.7. ### Changed -* *Nothing* +* [#337](https://github.com/shlinkio/shlink-web-client/pull/337) Replaced moment.js with date-fns. ### Deprecated * *Nothing* diff --git a/package-lock.json b/package-lock.json index f0e9a83d..6063c83f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6517,15 +6517,6 @@ "integrity": "sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==", "dev": true }, - "@types/moment": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/@types/moment/-/moment-2.13.0.tgz", - "integrity": "sha1-YE69GJvDvDShVIaJQE5hoqSqyJY=", - "dev": true, - "requires": { - "moment": "*" - } - }, "@types/node": { "version": "12.7.11", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.11.tgz", @@ -12082,9 +12073,9 @@ } }, "date-fns": { - "version": "2.16.1", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz", - "integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==" + "version": "2.22.1", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.22.1.tgz", + "integrity": "sha512-yUFPQjrxEmIsMqlHhAhmxkuH769baF21Kk+nZwZGyrMoyLA+LugaQtC0+Tqf9CBUUULWwUJt6Q5ySI3LJDDCGg==" }, "date-format": { "version": "3.0.0", @@ -24903,11 +24894,6 @@ "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", "integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==" }, - "react-moment": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/react-moment/-/react-moment-1.0.0.tgz", - "integrity": "sha512-J4iIiwUT4oZcL7cp2U7naQKbQtqvmzGXXBMg/DLj+Pi7n9EW0VhBRx/1aJ1Tp2poCqTCAPoadLEoUIkReGnNNg==" - }, "react-onclickoutside": { "version": "6.10.0", "resolved": "https://registry.npmjs.org/react-onclickoutside/-/react-onclickoutside-6.10.0.tgz", diff --git a/package.json b/package.json index b903f58c..911cbd65 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,9 @@ "classnames": "^2.2.6", "compare-versions": "^3.6.0", "csvjson": "^5.1.0", + "date-fns": "^2.22.1", "event-source-polyfill": "^1.0.22", "leaflet": "^1.7.1", - "moment": "^2.29.1", "promise": "^8.1.0", "qs": "^6.9.6", "ramda": "^0.27.1", @@ -48,7 +48,6 @@ "react-dom": "^17.0.1", "react-external-link": "^1.2.0", "react-leaflet": "^3.1.0", - "react-moment": "^1.0.0", "react-redux": "^7.2.2", "react-router-dom": "^5.2.0", "react-swipeable": "^6.0.1", @@ -78,7 +77,6 @@ "@types/enzyme": "^3.10.8", "@types/jest": "^26.0.20", "@types/leaflet": "^1.5.23", - "@types/moment": "^2.13.0", "@types/qs": "^6.9.5", "@types/ramda": "^0.27.38", "@types/react": "^17.0.2", diff --git a/src/short-urls/SearchBar.tsx b/src/short-urls/SearchBar.tsx index 9f78f352..de135dd4 100644 --- a/src/short-urls/SearchBar.tsx +++ b/src/short-urls/SearchBar.tsx @@ -1,7 +1,7 @@ import { faTags as tagsIcon } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { isEmpty, pipe } from 'ramda'; -import moment from 'moment'; +import { parseISO } from 'date-fns'; import SearchField from '../utils/SearchField'; import Tag from '../tags/helpers/Tag'; import { DateRangeSelector } from '../utils/dates/DateRangeSelector'; @@ -16,7 +16,7 @@ interface SearchBarProps { shortUrlsListParams: ShortUrlsListParams; } -const dateOrNull = (date?: string) => date ? moment(date) : null; +const dateOrNull = (date?: string) => date ? parseISO(date) : null; const SearchBar = (colorGenerator: ColorGenerator) => ({ listShortUrls, shortUrlsListParams }: SearchBarProps) => { const selectedTags = shortUrlsListParams.tags ?? []; diff --git a/src/short-urls/ShortUrlForm.tsx b/src/short-urls/ShortUrlForm.tsx index e30b6c7a..7fcfba3e 100644 --- a/src/short-urls/ShortUrlForm.tsx +++ b/src/short-urls/ShortUrlForm.tsx @@ -2,8 +2,8 @@ import { FC, useEffect, useState } from 'react'; import { InputType } from 'reactstrap/lib/Input'; import { Button, FormGroup, Input, Row } from 'reactstrap'; import { isEmpty, pipe, replace, trim } from 'ramda'; -import m from 'moment'; import classNames from 'classnames'; +import { parseISO } from 'date-fns'; import DateInput, { DateInputProps } from '../utils/DateInput'; import { supportsCrawlableVisits, @@ -38,6 +38,7 @@ export interface ShortUrlFormProps { } const normalizeTag = pipe(trim, replace(/ /g, '-')); +const toDate = (date?: string | Date): Date | undefined => typeof date === 'string' ? parseISO(date) : date; export const ShortUrlForm = ( TagsSelector: FC, @@ -74,7 +75,7 @@ export const ShortUrlForm = ( const renderDateInput = (id: DateFields, placeholder: string, props: Partial = {}) => (
setShortUrlData({ ...shortUrlData, [id]: date })} @@ -163,8 +164,8 @@ export const ShortUrlForm = (
{renderOptionalInput('maxVisits', 'Maximum number of visits allowed', 'number', { min: 1 })} - {renderDateInput('validSince', 'Enabled since...', { maxDate: shortUrlData.validUntil ? m(shortUrlData.validUntil) : undefined })} - {renderDateInput('validUntil', 'Enabled until...', { minDate: shortUrlData.validSince ? m(shortUrlData.validSince) : undefined })} + {renderDateInput('validSince', 'Enabled since...', { maxDate: shortUrlData.validUntil ? toDate(shortUrlData.validUntil) : undefined })} + {renderDateInput('validUntil', 'Enabled until...', { minDate: shortUrlData.validSince ? toDate(shortUrlData.validSince) : undefined })}
diff --git a/src/short-urls/data/index.ts b/src/short-urls/data/index.ts index 341f7e8f..c0fded8b 100644 --- a/src/short-urls/data/index.ts +++ b/src/short-urls/data/index.ts @@ -1,12 +1,11 @@ -import * as m from 'moment'; import { Nullable, OptionalString } from '../../utils/utils'; export interface EditShortUrlData { longUrl?: string; tags?: string[]; title?: string; - validSince?: m.Moment | string | null; - validUntil?: m.Moment | string | null; + validSince?: Date | string | null; + validUntil?: Date | string | null; maxVisits?: number | null; validateUrl?: boolean; crawlable?: boolean; diff --git a/src/short-urls/helpers/ShortUrlsRow.tsx b/src/short-urls/helpers/ShortUrlsRow.tsx index 2b57399b..e04710c9 100644 --- a/src/short-urls/helpers/ShortUrlsRow.tsx +++ b/src/short-urls/helpers/ShortUrlsRow.tsx @@ -1,6 +1,5 @@ -import { isEmpty } from 'ramda'; import { FC, useEffect, useRef } from 'react'; -import Moment from 'react-moment'; +import { isEmpty } from 'ramda'; import { ExternalLink } from 'react-external-link'; import ColorGenerator from '../../utils/services/ColorGenerator'; import { StateFlagTimeout } from '../../utils/helpers/hooks'; @@ -8,6 +7,7 @@ import Tag from '../../tags/helpers/Tag'; import { SelectedServer } from '../../servers/data'; import { CopyToClipboardIcon } from '../../utils/CopyToClipboardIcon'; import { ShortUrl } from '../data'; +import { Time } from '../../utils/Time'; import ShortUrlVisitsCount from './ShortUrlVisitsCount'; import { ShortUrlsRowMenuProps } from './ShortUrlsRowMenu'; import './ShortUrlsRow.scss'; @@ -53,7 +53,7 @@ const ShortUrlsRow = ( return ( - {shortUrl.dateCreated} +