@autobusal/common 0.0.40 → 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.
Files changed (77) hide show
  1. package/ApiDetails/ApiDetails.tsx +50 -0
  2. package/ApiDetails/Content.tsx +48 -0
  3. package/ApiDetails/Devpos.tsx +139 -0
  4. package/ApiDetails/services.ts +39 -0
  5. package/ApiDetails/types.ts +13 -0
  6. package/Autocomplete/Autocomplete.tsx +3 -3
  7. package/Avatar.tsx +28 -0
  8. package/{BackTo.tsx → Back/BackTo.tsx} +4 -3
  9. package/Back/BackWithTitle.tsx +30 -0
  10. package/Button/Button.tsx +4 -2
  11. package/Calendar/Calendar.tsx +2 -2
  12. package/{BrowseCompanyItem/BrowseCompanyItem.tsx → CompanyItem/CompanyItem.tsx} +2 -2
  13. package/ContactInfo/ContactInfo.tsx +40 -0
  14. package/ContactInfo/styles.ts +33 -0
  15. package/CookieNotification/CookieNotification.tsx +2 -2
  16. package/File/File.tsx +11 -7
  17. package/IpLogs/IpLogs.tsx +47 -0
  18. package/IpLogs/View.tsx +48 -0
  19. package/IpLogs/services.ts +27 -0
  20. package/IpLogs/styles.ts +10 -0
  21. package/Loading/Loading.tsx +25 -20
  22. package/Loading/Paragraph.tsx +62 -0
  23. package/Loading/styles.ts +34 -1
  24. package/Meta.tsx +1 -1
  25. package/Modal/Modal.tsx +1 -1
  26. package/Pagination/Pagination.tsx +2 -1
  27. package/Passengers/Passengers.tsx +6 -5
  28. package/Passengers/Persons.tsx +7 -7
  29. package/Passengers/{utilities/getText.ts → utilities.ts} +3 -5
  30. package/Password/Password.tsx +4 -3
  31. package/Password/styles.ts +1 -1
  32. package/Policy/services.ts +1 -3
  33. package/Report/Report.tsx +39 -0
  34. package/Report/Send.tsx +52 -0
  35. package/Report/services.ts +19 -0
  36. package/Report/styles.ts +31 -0
  37. package/Report/types.ts +3 -0
  38. package/RouteItem/styles.ts +0 -1
  39. package/Seats/ChooseSeat.tsx +3 -3
  40. package/Seats/Preview.tsx +3 -3
  41. package/Seats/styles.ts +1 -43
  42. package/Table/Actions/Actions.tsx +40 -0
  43. package/Table/Actions/Get.tsx +49 -0
  44. package/Table/Actions/Icon.tsx +54 -0
  45. package/Table/Actions/styles.ts +22 -0
  46. package/Table/Header/Header.tsx +46 -0
  47. package/Table/Header/Sort.tsx +33 -0
  48. package/Table/Header/styles.ts +48 -0
  49. package/Table/Paginate.tsx +34 -0
  50. package/Table/Row.tsx +22 -0
  51. package/Table/Rows/Loading.tsx +22 -0
  52. package/Table/Rows/NotFound.tsx +22 -0
  53. package/Table/Rows/Rows.tsx +63 -0
  54. package/Table/Rows/styles.ts +37 -0
  55. package/Table/Table.tsx +76 -0
  56. package/Table/Top/Search.tsx +36 -0
  57. package/Table/Top/Top.tsx +44 -0
  58. package/Table/Top/styles.ts +32 -0
  59. package/Table/browseUrl.ts +21 -0
  60. package/Table/styles.ts +28 -0
  61. package/Table/types.ts +11 -0
  62. package/Viewer/Actions.tsx +61 -53
  63. package/Viewer/Data.tsx +74 -8
  64. package/Viewer/Item.tsx +10 -81
  65. package/Viewer/Items/CheckboxList.tsx +53 -30
  66. package/Viewer/Items/DatePicker.tsx +70 -0
  67. package/Viewer/Items/Dropdown.tsx +14 -12
  68. package/Viewer/Items/Linked.tsx +27 -0
  69. package/Viewer/Items/TextareaHtml.tsx +51 -24
  70. package/Viewer/Items/styles.ts +73 -0
  71. package/Viewer/Viewer.tsx +24 -17
  72. package/Viewer/styles.ts +21 -1
  73. package/Viewer/types.ts +11 -8
  74. package/index.ts +30 -8
  75. package/package.json +1 -1
  76. package/Pagination/types.ts +0 -12
  77. /package/{BrowseCompanyItem → CompanyItem}/styles.ts +0 -0
@@ -0,0 +1,44 @@
1
+ import { TFunction } from 'i18next';
2
+ import { NavigateFunction } from 'react-router-dom';
3
+ import { BsPlusCircleFill } from 'react-icons/bs';
4
+ import Search from './Search';
5
+ import { Container, LinkTop } from './styles';
6
+
7
+ interface Props {
8
+ url: string
9
+ urlWith?: string
10
+ search?: string | null
11
+ t: TFunction<'common'>
12
+ actions?: string[]
13
+ extra?: JSX.Element
14
+ navigate: NavigateFunction
15
+ }
16
+
17
+ const Top = ({ url, urlWith, search, t, actions, extra, navigate }: Props): (JSX.Element | null) => {
18
+ if (actions === undefined) {
19
+ return null;
20
+ }
21
+
22
+ return (
23
+ <Container>
24
+ { actions.includes('create') && (
25
+ <LinkTop to={ `${ url }/manage/0${ urlWith ? `?${ urlWith }` : '' }` }>
26
+ <BsPlusCircleFill />{ t('table.actions.new', { ns: 'common' }) }
27
+ </LinkTop>
28
+ ) }
29
+
30
+ { actions.includes('extra') && extra }
31
+
32
+ { actions.includes('search') && (
33
+ <Search
34
+ value={ search }
35
+ url={ url }
36
+ t={ t }
37
+ navigate={ navigate }
38
+ />
39
+ ) }
40
+ </Container>
41
+ );
42
+ };
43
+
44
+ export default Top;
@@ -0,0 +1,32 @@
1
+ import styled from 'styled-components';
2
+ import { Link } from 'react-router-dom';
3
+
4
+ export const Container = styled.div`
5
+ display: flex;
6
+ justify-content: space-between;
7
+ align-items: center;
8
+ flex-wrap: wrap;
9
+ gap: 20px;
10
+ padding: 15px;
11
+ `;
12
+
13
+ export const LinkTop = styled(Link)`
14
+ display: flex;
15
+ gap: 6px;
16
+ height: 38px;
17
+ align-items: center;
18
+ justify-content: center;
19
+ padding: 0 20px;
20
+ font-weight: 700;
21
+ color: ${ props => props.theme.primary.contrast };
22
+ background: ${ props => props.theme.primary.normal };
23
+ border: 1px solid ${ props => props.theme.primary.normal };
24
+ border-radius: 100px;
25
+ cursor: pointer;
26
+ transition: all 0.3s ease;
27
+
28
+ &:hover {
29
+ text-decoration: none;
30
+ box-shadow: 0 4px 15px ${ props => props.theme.primary.normal };
31
+ }
32
+ `;
@@ -0,0 +1,21 @@
1
+ import queryString, { ParsedQuery } from 'query-string';
2
+
3
+ export const parseUrl = (replace: any): string => {
4
+ const query = queryString.parse(location.search);
5
+
6
+ Object.keys(replace).map(param => {
7
+ query[param] = replace[param]
8
+ });
9
+
10
+ const params = Object.keys(query).map(param => (
11
+ `${ param }=${ query[param] }`
12
+ ));
13
+
14
+ const url = params.join('&');
15
+
16
+ return `?${ url }`
17
+ };
18
+
19
+ export const getUrl = (): ParsedQuery<string> => (
20
+ queryString.parse(location.search)
21
+ );
@@ -0,0 +1,28 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const Container = styled.div`
4
+ padding: 0 !important;
5
+ `;
6
+
7
+ export const Content = styled.div`
8
+ overflow-x: auto;
9
+ `;
10
+
11
+ export const Inner = styled.div`
12
+ min-width: 750px;
13
+ `;
14
+
15
+ export const ContainerTable = styled.table`
16
+ width: 100%;
17
+ font-size: ${ props => props.theme.size.s };
18
+ `;
19
+
20
+ export const Td = styled.td`
21
+ padding: 10px 16px;
22
+ border-top: 1px solid ${ props => props.theme.background.neutral };
23
+ `;
24
+
25
+ export const ContainerPaginate = styled.div`
26
+ padding: 10px 16px;
27
+ border-top: 1px solid ${ props => props.theme.background.neutral };
28
+ `;
package/Table/types.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface ColumnData {
2
+ name: string
3
+ width?: number
4
+ slug?: string
5
+ type?: 'az'
6
+ }
7
+
8
+ export interface SortingData {
9
+ slug: string
10
+ order: 'asc' | 'desc'
11
+ }
@@ -1,48 +1,53 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { BiEditAlt, BiTrash, BiSend } from 'react-icons/bi';
3
- // import { RiSave2Line, RiCheckFill, RiSearchLine } from 'react-icons/ri';
4
- // import { BsPlusCircleFill } from 'react-icons/bs';
3
+ import { RiSave2Line, RiCheckFill, RiSearchLine } from 'react-icons/ri';
4
+ import { BsPlusCircleFill } from 'react-icons/bs';
5
+ import Button from '../Button/Button';
5
6
  import { ContainerActions } from './styles';
6
7
  import { ActionData } from './types';
7
- import { Button } from '@autobusal/common';
8
8
 
9
9
  interface Props {
10
+ id: number
10
11
  available: string[]
11
- loading?: boolean
12
+ pending?: boolean
12
13
  t: TFunction<'common'>
14
+ onDelete?: () => void
13
15
  }
14
16
 
15
- const Actions = ({ available, loading, t }: Props): JSX.Element => {
17
+ const Actions = ({ id, available, pending, t, onDelete }: Props): JSX.Element => {
18
+ const options: ActionData[] = [];
16
19
 
17
- // function Actions({ id, actions, status, t, deleter }) {
18
- let options: ActionData[] = [];
19
-
20
- // const askDeletion = () => {
21
- // if (window.confirm(t('general:table.confirm'))) {
22
- // deleter();
23
- // }
24
- // };
20
+ const onAskDelete = (): void => {
21
+ if (window.confirm(t('table.confirm', { ns: 'common' }))) {
22
+ if (onDelete) {
23
+ onDelete();
24
+ }
25
+ }
26
+ };
25
27
 
26
- // if (actions.includes('add')) {
27
- // options.push({
28
- // label: t('general:table.action.add'),
29
- // icon: <BsPlusCircleFill />
30
- // });
31
- // }
28
+ if (available.includes('add')) {
29
+ options.push({
30
+ label: t('table.actions.add', { ns: 'common' }),
31
+ icon: <BsPlusCircleFill />,
32
+ type: 'submit'
33
+ });
34
+ }
32
35
 
33
- // if (actions.includes('save')) {
34
- // options.push({
35
- // label: t('general:table.action.save'),
36
- // icon: <RiSave2Line />
37
- // });
38
- // }
36
+ if (available.includes('save')) {
37
+ options.push({
38
+ label: t('table.actions.save', { ns: 'common' }),
39
+ icon: <RiSave2Line />,
40
+ type: 'submit'
41
+ });
42
+ }
39
43
 
40
- // if (actions.includes('send')) {
41
- // options.push({
42
- // label: t('general:table.action.send'),
43
- // icon: <BiSend />
44
- // });
45
- // }
44
+ if (available.includes('send')) {
45
+ options.push({
46
+ label: t('table.actions.send', { ns: 'common' }),
47
+ icon: <BiSend />,
48
+ type: 'submit'
49
+ });
50
+ }
46
51
 
47
52
  if (available.includes('update')) {
48
53
  options.push({
@@ -52,39 +57,42 @@ const Actions = ({ available, loading, t }: Props): JSX.Element => {
52
57
  });
53
58
  }
54
59
 
55
- // if (actions.includes('approve')) {
56
- // options.push({
57
- // label: t('general:table.action.approve'),
58
- // icon: <RiCheckFill />
59
- // });
60
- // }
60
+ if (available.includes('approve')) {
61
+ options.push({
62
+ label: t('table.actions.approve', { ns: 'common' }),
63
+ icon: <RiCheckFill />,
64
+ type: 'submit'
65
+ });
66
+ }
61
67
 
62
- // if (actions.includes('delete') && id > 0) {
63
- // options.push({
64
- // label: t('general:table.action.delete'),
65
- // icon: <BiTrash />,
66
- // type: 'button',
67
- // className: "delete",
68
- // handler: askDeletion
69
- // });
70
- // }
68
+ if (available.includes('delete') && id > 0) {
69
+ options.push({
70
+ label: t('table.actions.delete', { ns: 'common' }),
71
+ icon: <BiTrash />,
72
+ subtype: 'delete',
73
+ handler: onAskDelete
74
+ });
75
+ }
71
76
 
72
- // if (actions.includes('search')) {
73
- // options.push({
74
- // label: t('general:table.action.search'),
75
- // icon: <RiSearchLine />
76
- // });
77
- // }
77
+ if (available.includes('search')) {
78
+ options.push({
79
+ label: t('table.actions.search', { ns: 'common' }),
80
+ icon: <RiSearchLine />,
81
+ type: 'submit'
82
+ });
83
+ }
78
84
 
79
85
  const items = options.map((item, index) => (
80
86
  <Button
81
87
  key={ index }
82
88
  type={ item.type === 'submit' ? 'submit' : 'button' }
89
+ subtype={ item.subtype }
83
90
  text={
84
91
  <>{ item.icon } { item.label }</>
85
92
  }
86
- loading={ loading }
93
+ loading={ pending }
87
94
  noMargin
95
+ onClick={ item.handler }
88
96
  />
89
97
  ));
90
98
 
package/Viewer/Data.tsx CHANGED
@@ -1,56 +1,122 @@
1
+ import { TFunction } from 'i18next';
1
2
  import { UseFormRegister, UseFormSetValue } from 'react-hook-form';
2
- import Dropdown from './Items/Dropdown';
3
- import { ViewData } from './types';
3
+ import { Validate } from '@autobusal/utilities';
4
+ import Password from '../Password/Password';
4
5
  import Calendar from '../Calendar/Calendar';
5
6
  import File from '../File/File';
6
- import { validate } from '@autobusal/utilities';
7
- import { TFunction } from 'i18next';
7
+ import CheckboxList from './Items/CheckboxList';
8
+ import Linked from './Items/Linked';
9
+ import TextareaHtml from './Items/TextareaHtml';
10
+ import Dropdown from './Items/Dropdown';
11
+ import DatePicker from './Items/DatePicker';
12
+ import { Display } from './styles';
13
+ import { ViewData } from './types';
8
14
 
9
15
  interface Props {
16
+ id: number
10
17
  item: ViewData
11
18
  refs: UseFormRegister<any>
12
19
  t: TFunction<'common'>
13
20
  onUpdate: UseFormSetValue<any>
14
21
  }
15
22
 
16
- const Data = ({ item, refs, t, onUpdate }: Props): (JSX.Element | null) => {
23
+ const Data = ({ id, item, refs, t, onUpdate }: Props): (JSX.Element | null) => {
17
24
  if (item.name === undefined) {
18
25
  return null;
19
26
  }
20
27
 
21
28
  switch (item.type) {
29
+ case 'checkbox':
30
+ return <input type="checkbox" value={ 1 } defaultChecked={ Number(item.value) == 1 } { ...refs(item.name, Validate(String(item.rules), t)) } />;
31
+
32
+ case 'checkbox-list':
33
+ case 'checkbox-list-all':
34
+ return (
35
+ <CheckboxList
36
+ name={ item.name }
37
+ values={ item.values }
38
+ selected={ item.selected }
39
+ withAll={ item.type !== 'checkbox-list' }
40
+ t={ t }
41
+ refs={ refs }
42
+ />
43
+ );
44
+
45
+ case 'component':
46
+ return <div className="row-data">{ item.value }</div>;
47
+
48
+ case 'display':
49
+ return <Display className="row-data">{ item.value }</Display>;
50
+
51
+ case 'date':
22
52
  case 'dob':
53
+ case 'picker': {
54
+ const value = (item.value !== null && item.value !== undefined) ? String(item.value) : undefined;
55
+
23
56
  return (
24
57
  <Calendar
25
58
  type={ item.type }
26
59
  name={ item.name }
27
- defaultValue={ item.value !== null ? String(item.value) : undefined }
60
+ defaultValue={ value }
28
61
  t={ t }
29
62
  validation={ item.rules }
30
63
  refs={ refs }
31
64
  onUpdate={ onUpdate }
32
65
  />
33
66
  );
67
+ }
68
+
69
+ case 'date-picker':
70
+ return <DatePicker item={ item } t={ t } refs={ refs } onUpdate={ onUpdate } />;
71
+
72
+ case 'email':
73
+ return <input type="email" defaultValue={ item.value !== undefined ? String(item.value) : undefined } { ...refs(item.name, Validate(String(item.rules), t)) } />;
34
74
 
35
75
  case 'file':
76
+ case 'files':
36
77
  return (
37
78
  <File
38
79
  name={ item.name }
39
80
  value={ item.value !== undefined ? String(item.value) : undefined }
40
81
  validation={ item.rules }
82
+ multiple={ item.type === 'files' }
41
83
  t={ t }
42
84
  refs={ refs }
43
85
  />
44
86
  );
45
87
 
88
+ case 'float':
89
+ return <input type="number" defaultValue={ item.value !== undefined ? Number(item.value) : undefined } { ...refs(item.name, Validate(String(item.rules), t)) } step="0.01" />;
90
+
91
+ case 'link':
92
+ return <Linked id={ id } value={ item.value } url={ item.url } />;
93
+
94
+ case 'number':
95
+ return <input type="number" defaultValue={ item.value !== undefined ? Number(item?.value) : undefined } { ...refs(item.name, Validate(String(item.rules), t)) } />
96
+
97
+ case 'password':
98
+ return <Password name={ item.name } validation={ item.rules } t={ t } refs={ refs } />;
99
+
46
100
  case 'select':
47
101
  return <Dropdown item={ item } refs={ refs } t={ t } />;
48
102
 
49
103
  case 'text':
50
- return <input type="text" defaultValue={ item.value } { ...refs(item.name, validate(String(item.rules), t)) } />;
104
+ return <input type="text" defaultValue={ item.value !== undefined ? String(item.value) : undefined } { ...refs(item.name, Validate(String(item.rules), t)) } />;
51
105
 
52
106
  case 'textarea':
53
- return <textarea defaultValue={ item.value } { ...refs(item.name, validate(String(item.rules), t)) }></textarea>;
107
+ return <textarea defaultValue={ item.value !== undefined ? String(item.value) : undefined } { ...refs(item.name, Validate(String(item.rules), t)) }></textarea>;
108
+
109
+ case 'textarea-html':
110
+ return (
111
+ <TextareaHtml
112
+ name={ item.name }
113
+ value={ item.value ? String(item.value) : undefined }
114
+ validation={ item.rules }
115
+ t={ t }
116
+ refs={ refs }
117
+ onUpdate={ onUpdate }
118
+ />
119
+ );
54
120
  }
55
121
 
56
122
  return null;
package/Viewer/Item.tsx CHANGED
@@ -1,10 +1,12 @@
1
1
  import { FieldErrors, UseFormRegister, UseFormSetValue } from 'react-hook-form';
2
- import { display } from '@autobusal/utilities';
2
+ import { Display } from '@autobusal/utilities';
3
3
  import Data from './Data';
4
+ import { Notice } from './styles';
4
5
  import { ViewData } from './types';
5
6
  import { TFunction } from 'i18next';
6
7
 
7
8
  interface Props {
9
+ id: number
8
10
  data: ViewData
9
11
  refs: UseFormRegister<any>
10
12
  t: TFunction<'common'>
@@ -12,95 +14,22 @@ interface Props {
12
14
  onUpdate: UseFormSetValue<any>
13
15
  }
14
16
 
15
- const Item = ({ data, refs, t, errors, onUpdate }: Props): JSX.Element => (
16
- <div className={ `row ${ data.label === undefined && 'spacer' }` }>
17
+ const Item = ({ id, data, refs, t, errors, onUpdate }: Props): JSX.Element => (
18
+ <div className={ `row row-${ data.type } ${ data.label === undefined && 'spacer' }` }>
17
19
  { data.label }
18
20
 
19
21
  <Data
22
+ id={ id }
20
23
  item={ data }
21
24
  refs={ refs }
22
25
  t={ t }
23
26
  onUpdate={ onUpdate }
24
27
  />
25
28
 
26
- { data.name && display(errors[data.name]) }
29
+ { data.name && Display(errors[data.name]) }
30
+
31
+ { data.notice && <Notice>* { data.notice }</Notice> }
27
32
  </div>
28
33
  );
29
34
 
30
- export default Item;
31
-
32
- // function Input({ data, refs, onUpdate, errors, t }) {
33
- // let input;
34
-
35
- // switch (data.type) {
36
- // case 'display':
37
- // input = <div className="display">{ data.value }</div>;
38
- // break;
39
-
40
- // case 'email':
41
- // input = <input type="email" defaultValue={ data.value } { ...refs(data.name, data.validation) } />;
42
- // break;
43
-
44
- // case 'number':
45
- // input = <input type="number" defaultValue={ data.value } { ...refs(data.name, data.validation) } />
46
- // break;
47
-
48
- // case 'float':
49
- // input = <input type="number" defaultValue={ data.value } { ...refs(data.name, data.validation) } step="0.01" />
50
- // break;
51
-
52
- // case 'checkbox':
53
- // input = <input type="checkbox" value="1" defaultChecked={ data.value == 1 } { ...refs(data.name, data.validation) } />;
54
- // break;
55
-
56
- // case 'checkbox-list':
57
- // input = <CheckboxList name={ data.name } values={ data.values } selected={ data.selected } hasAll={ data?.hasAll ?? true } refs={ refs } t={ t } />;
58
- // break;
59
-
60
- // case 'textarea-html':
61
- // input = <TextareaHtml data={ data } onUpdate={ onUpdate } refs={ refs } />;
62
- // break;
63
-
64
- // case 'password':
65
- // input = <Password refs={ refs(data.name, data.validation) } />
66
- // break;
67
-
68
- // case 'picker':
69
- //
70
- // case 'date':
71
- // input = (
72
- // <div className="display">
73
- // <Calendar type={ data.type } name={ data.name } value={ data.value } refs={ refs } validation={ data.validation } t={ t } onUpdate={ onUpdate } />
74
- // </div>
75
- // );
76
- // break;
77
-
78
- // case 'extra':
79
- // input = data.value;
80
- // break;
81
- // }
82
-
83
- // let extra;
84
-
85
- // switch (data.type) {
86
- // case 'password':
87
- // extra = ' item-password';
88
- // break;
89
-
90
- // case 'textarea-html':
91
- // extra = ' full';
92
- // break;
93
- // }
94
-
95
- // if (data.extra) {
96
- // extra = ' ' + data.extra;
97
- // }
98
-
99
- // return (
100
- // <div className={ `item${ extra ?? '' }` }>
101
- // { input }
102
-
103
- // { data.notice ? <div className="notice">* { data.notice }</div> : null }
104
- // </div>
105
- // );
106
- // }
35
+ export default Item;
@@ -1,30 +1,53 @@
1
- // function CheckboxList({ name, values, selected, hasAll, refs, t }) {
2
- // const [ all, setAll ] = useState(selected?.includes('all') ?? true);
3
-
4
- // const checkboxes = values.map((item, index) => {
5
- // if (all) {
6
- // return null;
7
- // }
8
-
9
- // return (
10
- // <label key={ index }>
11
- // <input type="checkbox" value={ item.value } defaultChecked={ selected?.includes(item.value + '') } { ...refs(name + '[' + (index + 1) + ']') } /> { item.name }
12
- // </label>
13
- // );
14
- // });
15
-
16
- // const onAll = () => {
17
- // setAll(all ? false : true);
18
- // };
19
-
20
- // return (
21
- // <div className="display list">
22
- // { hasAll ? <label key={ -1 }><input type="checkbox" value="all" defaultChecked={ all } onClick={ () => onAll() } { ...refs(name + '[' + 0 + ']') } /> { t('general:table.checkbox.all') }</label> : null }
23
-
24
- // { checkboxes }
25
-
26
- // <div className="clear"></div>
27
- // </div>
28
- // );
29
- // }
30
- // }
1
+ import { useState } from 'react';
2
+ import { TFunction } from 'i18next';
3
+ import { UseFormRegister } from 'react-hook-form';
4
+ import { ContainerCheckboxList, ListLabel } from './styles';
5
+ import { DropdownData } from '@autobusal/providers/types/other';
6
+
7
+ interface Props {
8
+ name: string
9
+ values?: DropdownData[]
10
+ selected?: any[]
11
+ withAll: boolean
12
+ t: TFunction<'common'>
13
+ refs: UseFormRegister<any>
14
+ }
15
+
16
+ const CheckboxList = ({ name, values, selected, withAll, t, refs }: Props): JSX.Element => {
17
+ const [ all, setAll ] = useState(selected?.includes('all') ?? withAll);
18
+
19
+ const items = values?.map((item, index) => (
20
+ <ListLabel key={ index }>
21
+ <input
22
+ type="checkbox"
23
+ value={ item.id }
24
+ defaultChecked={ selected?.includes(String(item.id)) || selected?.includes(Number(item.id)) }
25
+ { ...refs(`${ name }[${ (index + 1) }]`) }
26
+ />
27
+
28
+ { item.name }
29
+ </ListLabel>
30
+ ));
31
+
32
+ return (
33
+ <ContainerCheckboxList>
34
+ { withAll && (
35
+ <ListLabel>
36
+ <input
37
+ type="checkbox"
38
+ value="all"
39
+ defaultChecked={ all }
40
+ onClick={ () => setAll(!all) }
41
+ { ...refs(`${ name }[0]`) }
42
+ />
43
+
44
+ { t('table.checkbox', { ns: 'common' }) }
45
+ </ListLabel>
46
+ ) }
47
+
48
+ { !all && items }
49
+ </ContainerCheckboxList>
50
+ );
51
+ };
52
+
53
+ export default CheckboxList;