mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Defined visits TS types
This commit is contained in:
parent
f283dc8569
commit
f3a2535e2f
7 changed files with 88 additions and 38 deletions
|
@ -14,6 +14,7 @@ export const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR
|
|||
export const LIST_SHORT_URLS = 'shlink/shortUrlsList/LIST_SHORT_URLS';
|
||||
/* eslint-enable padding-line-between-statements */
|
||||
|
||||
/** @deprecated Use ShortUrl interface instead */
|
||||
export const shortUrlType = PropTypes.shape({
|
||||
shortCode: PropTypes.string,
|
||||
shortUrl: PropTypes.string,
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
export const CREATE_VISIT = 'shlink/visitCreation/CREATE_VISIT';
|
||||
|
||||
export const createNewVisit = ({ shortUrl, visit }) => ({ shortUrl, visit, type: CREATE_VISIT });
|
12
src/visits/reducers/visitCreation.ts
Normal file
12
src/visits/reducers/visitCreation.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { Action } from 'redux';
|
||||
import { CreateVisit } from '../types';
|
||||
|
||||
export const CREATE_VISIT = 'shlink/visitCreation/CREATE_VISIT';
|
||||
|
||||
type CreateVisitAction = Action<typeof CREATE_VISIT> & CreateVisit;
|
||||
|
||||
export const createNewVisit = ({ shortUrl, visit }: CreateVisit): CreateVisitAction => ({
|
||||
type: CREATE_VISIT,
|
||||
shortUrl,
|
||||
visit,
|
||||
});
|
|
@ -1,25 +0,0 @@
|
|||
import PropTypes from 'prop-types';
|
||||
|
||||
export const VisitType = PropTypes.shape({
|
||||
referer: PropTypes.string,
|
||||
date: PropTypes.string,
|
||||
userAgent: PropTypes.string,
|
||||
visitLocations: PropTypes.shape({
|
||||
countryCode: PropTypes.string,
|
||||
countryName: PropTypes.string,
|
||||
regionName: PropTypes.string,
|
||||
cityName: PropTypes.string,
|
||||
latitude: PropTypes.number,
|
||||
longitude: PropTypes.number,
|
||||
timezone: PropTypes.string,
|
||||
isEmpty: PropTypes.bool,
|
||||
}),
|
||||
});
|
||||
|
||||
export const VisitsInfoType = PropTypes.shape({
|
||||
visits: PropTypes.arrayOf(VisitType),
|
||||
loading: PropTypes.bool,
|
||||
loadingLarge: PropTypes.bool,
|
||||
error: PropTypes.bool,
|
||||
progress: PropTypes.number,
|
||||
});
|
59
src/visits/types/index.ts
Normal file
59
src/visits/types/index.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
import PropTypes from 'prop-types';
|
||||
import { ShortUrl } from '../../short-urls/data';
|
||||
|
||||
/** @deprecated Use Visit interface instead */
|
||||
export const VisitType = PropTypes.shape({
|
||||
referer: PropTypes.string,
|
||||
date: PropTypes.string,
|
||||
userAgent: PropTypes.string,
|
||||
visitLocation: PropTypes.shape({
|
||||
countryCode: PropTypes.string,
|
||||
countryName: PropTypes.string,
|
||||
regionName: PropTypes.string,
|
||||
cityName: PropTypes.string,
|
||||
latitude: PropTypes.number,
|
||||
longitude: PropTypes.number,
|
||||
timezone: PropTypes.string,
|
||||
isEmpty: PropTypes.bool,
|
||||
}),
|
||||
});
|
||||
|
||||
/** @deprecated Use VisitsInfo interface instead */
|
||||
export const VisitsInfoType = PropTypes.shape({
|
||||
visits: PropTypes.arrayOf(VisitType),
|
||||
loading: PropTypes.bool,
|
||||
loadingLarge: PropTypes.bool,
|
||||
error: PropTypes.bool,
|
||||
progress: PropTypes.number,
|
||||
});
|
||||
|
||||
export interface VisitsInfo {
|
||||
visits: Visit[];
|
||||
loading: boolean;
|
||||
loadingLarge: boolean;
|
||||
error: boolean;
|
||||
progress: number;
|
||||
}
|
||||
|
||||
interface VisitLocation {
|
||||
countryCode: string | null;
|
||||
countryName: string | null;
|
||||
regionName: string | null;
|
||||
cityName: string | null;
|
||||
latitude: number | null;
|
||||
longitude: number | null;
|
||||
timezone: string | null;
|
||||
isEmpty: boolean;
|
||||
}
|
||||
|
||||
export interface Visit {
|
||||
referer: string;
|
||||
date: string;
|
||||
userAgent: string;
|
||||
visitLocation: VisitLocation | null;
|
||||
}
|
||||
|
||||
export interface CreateVisit {
|
||||
shortUrl: ShortUrl;
|
||||
visit: Visit;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
import { CREATE_VISIT, createNewVisit } from '../../../src/visits/reducers/visitCreation';
|
||||
|
||||
describe('visitCreationReducer', () => {
|
||||
describe('createNewVisit', () => {
|
||||
it('just returns the action with proper type', () =>
|
||||
expect(createNewVisit({ shortUrl: {}, visit: {} })).toEqual(
|
||||
{ type: CREATE_VISIT, shortUrl: {}, visit: {} },
|
||||
));
|
||||
});
|
||||
});
|
16
test/visits/reducers/visitCreation.test.ts
Normal file
16
test/visits/reducers/visitCreation.test.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { Mock } from 'ts-mockery';
|
||||
import { CREATE_VISIT, createNewVisit } from '../../../src/visits/reducers/visitCreation';
|
||||
import { ShortUrl } from '../../../src/short-urls/data';
|
||||
import { Visit } from '../../../src/visits/types';
|
||||
|
||||
describe('visitCreationReducer', () => {
|
||||
describe('createNewVisit', () => {
|
||||
const shortUrl = Mock.all<ShortUrl>();
|
||||
const visit = Mock.all<Visit>();
|
||||
|
||||
it('just returns the action with proper type', () =>
|
||||
expect(createNewVisit({ shortUrl, visit })).toEqual(
|
||||
{ type: CREATE_VISIT, shortUrl, visit },
|
||||
));
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue