@autobusal/utilities 0.0.9 → 1.0.1
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.
- package/form.tsx +11 -19
- package/index.ts +17 -5
- package/manage.ts +15 -0
- package/map/index.ts +23 -0
- package/map/marker-icon.png +0 -0
- package/map/marker-shadow.png +0 -0
- package/numbers.ts +3 -0
- package/options.ts +31 -0
- package/package.json +1 -1
- package/users.tsx +67 -0
- package/map.ts +0 -14
package/form.tsx
CHANGED
|
@@ -8,12 +8,14 @@ interface ValidateType {
|
|
|
8
8
|
maxLength?: any
|
|
9
9
|
minLength?: any
|
|
10
10
|
min?: any
|
|
11
|
+
max?: any
|
|
12
|
+
onChange?: (event?: any) => void
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export const
|
|
15
|
+
export const Validate = (rules: string, t: TFunction<'common'>): ValidateType => {
|
|
14
16
|
const analyze = rules.split('|');
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
const validation: ValidateType = {};
|
|
17
19
|
|
|
18
20
|
analyze.forEach(rule => {
|
|
19
21
|
const type = rule.split(':');
|
|
@@ -50,23 +52,13 @@ export const validate = (rules: string, t: TFunction<'common'>): ValidateType =>
|
|
|
50
52
|
message: t('errors.min', { ns: 'common', count: type[1] } as any)
|
|
51
53
|
};
|
|
52
54
|
break;
|
|
53
|
-
|
|
54
|
-
// case 'max':
|
|
55
|
-
// validation.max = {
|
|
56
|
-
// value: type[1],
|
|
57
|
-
// message: t('general:errors.max', { count: type[1] })
|
|
58
|
-
// };
|
|
59
|
-
// break;
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// }
|
|
68
|
-
// };
|
|
69
|
-
// break;
|
|
56
|
+
case 'max':
|
|
57
|
+
validation.max = {
|
|
58
|
+
value: Number(type[1]),
|
|
59
|
+
message: t('errors.max', { ns: 'common', count: type[1] } as any)
|
|
60
|
+
};
|
|
61
|
+
break;
|
|
70
62
|
}
|
|
71
63
|
});
|
|
72
64
|
|
|
@@ -79,7 +71,7 @@ const Error = styled.div`
|
|
|
79
71
|
font-size: ${ props => props.theme.size.s };
|
|
80
72
|
`;
|
|
81
73
|
|
|
82
|
-
export const
|
|
74
|
+
export const Display = (err: (FieldError | Merge<FieldError, FieldErrorsImpl<any>> | undefined)): (JSX.Element | null) => {
|
|
83
75
|
if (!err || !err.message) {
|
|
84
76
|
return null;
|
|
85
77
|
}
|
package/index.ts
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import { createDate, prepareDate, getFormattedShort, differenceYears, futureDate } from './date';
|
|
2
|
-
import {
|
|
3
|
-
import getPosition from './map';
|
|
2
|
+
import { Validate, Display } from './form';
|
|
3
|
+
import { getPosition, autobusMarker } from './map';
|
|
4
4
|
import { error, notify, success } from './notify';
|
|
5
|
+
import { getAllowed, getLanguages, getPayments } from './options';
|
|
5
6
|
import { getSex, getOptionsSex } from './passengers';
|
|
7
|
+
import { GetStatus, DisplayStatus } from './users';
|
|
8
|
+
import { getRandomNumber } from './numbers';
|
|
9
|
+
import { getParams } from './manage';
|
|
6
10
|
|
|
7
11
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
Validate,
|
|
13
|
+
Display,
|
|
10
14
|
error,
|
|
11
15
|
notify,
|
|
12
16
|
success,
|
|
13
17
|
getPosition,
|
|
18
|
+
autobusMarker,
|
|
14
19
|
createDate,
|
|
15
20
|
prepareDate,
|
|
16
21
|
getFormattedShort,
|
|
17
22
|
differenceYears,
|
|
23
|
+
DisplayStatus,
|
|
18
24
|
futureDate,
|
|
25
|
+
getAllowed,
|
|
26
|
+
getLanguages,
|
|
27
|
+
getParams,
|
|
28
|
+
getPayments,
|
|
29
|
+
getOptionsSex,
|
|
30
|
+
getRandomNumber,
|
|
19
31
|
getSex,
|
|
20
|
-
|
|
32
|
+
GetStatus
|
|
21
33
|
};
|
package/manage.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const getParams = (searchParams: URLSearchParams, fields: string[], fieldsAll?: string[]) => {
|
|
2
|
+
const params: any = {};
|
|
3
|
+
|
|
4
|
+
fields.forEach(field => {
|
|
5
|
+
params[field] = searchParams.get(field)
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
if (fieldsAll !== undefined) {
|
|
9
|
+
fieldsAll.forEach(field => {
|
|
10
|
+
params[field] = searchParams.getAll(field)
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return params;
|
|
15
|
+
};
|
package/map/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import L, { LatLngExpression } from 'leaflet';
|
|
2
|
+
import markerIcon from './marker-icon.png';
|
|
3
|
+
import markerShadow from './marker-shadow.png';
|
|
4
|
+
|
|
5
|
+
export const getPosition = (position: string[] | undefined): LatLngExpression => {
|
|
6
|
+
if (position === undefined) {
|
|
7
|
+
return [0, 0];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return [
|
|
11
|
+
Number(position[0]),
|
|
12
|
+
Number(position[1])
|
|
13
|
+
];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const autobusMarker = new L.Icon({
|
|
17
|
+
iconUrl: markerIcon,
|
|
18
|
+
iconSize: [25, 41], // icon size
|
|
19
|
+
iconAnchor: [12, 41], // point of the icon which will correspond to marker's location
|
|
20
|
+
popupAnchor: [1, -34], // point from which the popup should open relative to the iconAnchor
|
|
21
|
+
shadowUrl: markerShadow,
|
|
22
|
+
shadowSize: [41, 41] // shadow size
|
|
23
|
+
});
|
|
Binary file
|
|
Binary file
|
package/numbers.ts
ADDED
package/options.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { DropdownData } from '@autobusal/providers/types/other';
|
|
3
|
+
|
|
4
|
+
export const getAllowed = (t: TFunction<'common'>): DropdownData[] => ([{
|
|
5
|
+
name: t('allowed.yes', { ns: 'common' }),
|
|
6
|
+
id: 1
|
|
7
|
+
}, {
|
|
8
|
+
name: t('allowed.no', { ns: 'common' }),
|
|
9
|
+
id: 0
|
|
10
|
+
}
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
export const getLanguages = (): DropdownData[] => ([
|
|
14
|
+
{
|
|
15
|
+
id: 'sq',
|
|
16
|
+
name: 'Sq'
|
|
17
|
+
}, {
|
|
18
|
+
id: 'en',
|
|
19
|
+
name: 'En'
|
|
20
|
+
}
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export const getPayments = (t: TFunction<'common'>): DropdownData[] => ([
|
|
24
|
+
{
|
|
25
|
+
name: t('payments.bkt', { ns: 'common' }),
|
|
26
|
+
id: 'bkt'
|
|
27
|
+
}, {
|
|
28
|
+
name: t('payments.funds', { ns: 'common' }),
|
|
29
|
+
id: 'funds'
|
|
30
|
+
}
|
|
31
|
+
]);
|
package/package.json
CHANGED
package/users.tsx
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
|
+
|
|
4
|
+
export const GetStatus = (t: TFunction<'common'>) => ([
|
|
5
|
+
{
|
|
6
|
+
id: 1,
|
|
7
|
+
name: t('data.statuses.available', { ns: 'common' }),
|
|
8
|
+
}, {
|
|
9
|
+
id: 0,
|
|
10
|
+
name: t('data.statuses.unavailable', { ns: 'common' })
|
|
11
|
+
}
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const Status = styled.span<{ $type: string }>`
|
|
15
|
+
display: inline-block;
|
|
16
|
+
padding: 3px 5px;
|
|
17
|
+
color: #333333;
|
|
18
|
+
font-size: ${ props => props.theme.size.xs };
|
|
19
|
+
border-radius: ${ props => props.theme.borderRadius };
|
|
20
|
+
|
|
21
|
+
${ props => props.$type === 'available' && css`
|
|
22
|
+
background: #4BE763;
|
|
23
|
+
` }
|
|
24
|
+
${ props => props.$type === 'suspended' && css`
|
|
25
|
+
background: #FFC759;
|
|
26
|
+
` }
|
|
27
|
+
${ props => props.$type === 'pending' && css`
|
|
28
|
+
background: #80BCFF;
|
|
29
|
+
` }
|
|
30
|
+
${ props => props.$type === 'unavailable' && css`
|
|
31
|
+
background: #FFB4B4;
|
|
32
|
+
` }
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export const DisplayStatus = (status: number, t: TFunction<'common'>): (JSX.Element | null) => {
|
|
36
|
+
switch (status) {
|
|
37
|
+
case 3:
|
|
38
|
+
return (
|
|
39
|
+
<Status $type="pending">
|
|
40
|
+
{ t('data.statuses.pending', { ns: 'common' }) }
|
|
41
|
+
</Status>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
case 2:
|
|
45
|
+
return (
|
|
46
|
+
<Status $type="suspended">
|
|
47
|
+
{ t('data.statuses.suspended', { ns: 'common' }) }
|
|
48
|
+
</Status>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
case 1:
|
|
52
|
+
return (
|
|
53
|
+
<Status $type="available">
|
|
54
|
+
{ t('data.statuses.available', { ns: 'common' }) }
|
|
55
|
+
</Status>
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
case 0:
|
|
59
|
+
return (
|
|
60
|
+
<Status $type="unavailable">
|
|
61
|
+
{ t('data.statuses.unavailable', { ns: 'common' }) }
|
|
62
|
+
</Status>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
};
|
package/map.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { LatLngExpression } from 'leaflet';
|
|
2
|
-
|
|
3
|
-
const getPosition = (position: string[] | undefined): LatLngExpression => {
|
|
4
|
-
if (position === undefined) {
|
|
5
|
-
return [0, 0];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return [
|
|
9
|
-
Number(position[0]),
|
|
10
|
-
Number(position[1])
|
|
11
|
-
];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default getPosition;
|