@autobusal/utilities 0.0.8 → 1.0.0

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 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 validate = (rules: string, t: TFunction<'common'>) => {
15
+ export const Validate = (rules: string, t: TFunction<'common'>): ValidateType => {
14
16
  const analyze = rules.split('|');
15
17
 
16
- let validation: ValidateType = {};
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'>) => {
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
- // case 'confirm':
62
- // validation.validate = value => {
63
- // if (value == type[1]) {
64
- // return true;
65
- // } else {
66
- // return t('general:errors.confirmed');
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 display = (err: (FieldError | Merge<FieldError, FieldErrorsImpl<any>> | undefined)): (JSX.Element | null) => {
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,12 +1,16 @@
1
1
  import { createDate, prepareDate, getFormattedShort, differenceYears, futureDate } from './date';
2
- import { validate, display } from './form';
2
+ import { Validate, Display } from './form';
3
3
  import getPosition from './map';
4
4
  import { error, notify, success } from './notify';
5
- import { getSex } from './passengers';
5
+ import { getAllowed, getLanguages, getPayments } from './options';
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
- validate,
9
- display,
12
+ Validate,
13
+ Display,
10
14
  error,
11
15
  notify,
12
16
  success,
@@ -15,6 +19,14 @@ export {
15
19
  prepareDate,
16
20
  getFormattedShort,
17
21
  differenceYears,
22
+ DisplayStatus,
18
23
  futureDate,
19
- getSex
24
+ getAllowed,
25
+ getLanguages,
26
+ getParams,
27
+ getPayments,
28
+ getOptionsSex,
29
+ getRandomNumber,
30
+ getSex,
31
+ GetStatus
20
32
  };
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/numbers.ts ADDED
@@ -0,0 +1,3 @@
1
+ export const getRandomNumber = (min: number, max: number): number => (
2
+ Math.floor(Math.random() * (max - min + 1) + min)
3
+ );
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/utilities",
3
- "version": "0.0.8",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "main": "index.ts"
6
6
  }
package/passengers.ts CHANGED
@@ -1,3 +1,15 @@
1
+ import { TFunction } from 'i18next';
2
+
1
3
  export const getSex = (value: number): string => (
2
4
  value === 1 ? 'female' : 'male'
3
- );
5
+ );
6
+
7
+ export const getOptionsSex = (t: TFunction<'common'>) => ([
8
+ {
9
+ id: 0,
10
+ name: t('data.gender.male', { ns: 'common' })
11
+ }, {
12
+ id: 1,
13
+ name: t('data.gender.female', { ns: 'common' })
14
+ }
15
+ ]);
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
+ };