@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,70 @@
1
+ import { useState } from 'react';
2
+ import { TFunction } from 'i18next';
3
+ import { UseFormRegister, UseFormSetValue } from 'react-hook-form';
4
+ import { FaCalendar } from 'react-icons/fa';
5
+ import { RiCloseCircleFill } from 'react-icons/ri';
6
+ import Button from '../../Button/Button';
7
+ import Calendar from '../../Calendar/Calendar';
8
+ import { Picker, ContainerPicker, PickerClose } from './styles';
9
+ import { ViewData } from '../types';
10
+
11
+ interface Props {
12
+ item: ViewData
13
+ t: TFunction<'common'>
14
+ refs: UseFormRegister<any>
15
+ onUpdate: UseFormSetValue<any>
16
+ }
17
+
18
+ const DatePicker = ({ item, t, refs, onUpdate }: Props): JSX.Element => {
19
+ const value = item.value !== null && item.value !== undefined && item.value !== '' ? String(item.value) : undefined;
20
+
21
+ const [ choose, setChoose ] = useState<boolean>(value !== undefined);
22
+
23
+ if (!choose) {
24
+ return (
25
+ <Picker>
26
+ <Button
27
+ type="button"
28
+ subtype="secondary"
29
+ size="small"
30
+ text={
31
+ <>
32
+ <FaCalendar />
33
+ { t('table.date-picker', { ns: 'common' }) }
34
+ </>
35
+ }
36
+ onClick={ () => setChoose(true) }
37
+ noMargin
38
+ />
39
+ </Picker>
40
+ );
41
+ }
42
+
43
+ const name = item.name ?? '';
44
+
45
+ const onCancel = (): void => {
46
+ setChoose(false);
47
+
48
+ onUpdate(name, undefined);
49
+ };
50
+
51
+ return (
52
+ <ContainerPicker>
53
+ <Calendar
54
+ type="date"
55
+ name={ name }
56
+ defaultValue={ value }
57
+ t={ t }
58
+ validation={ item.rules }
59
+ refs={ refs }
60
+ onUpdate={ onUpdate }
61
+ />
62
+
63
+ <PickerClose type="button" onClick={ onCancel }>
64
+ <RiCloseCircleFill />
65
+ </PickerClose>
66
+ </ContainerPicker>
67
+ );
68
+ };
69
+
70
+ export default DatePicker;
@@ -1,6 +1,6 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { UseFormRegister } from 'react-hook-form';
3
- import { validate } from '@autobusal/utilities';
3
+ import { Validate } from '@autobusal/utilities';
4
4
  import { ViewData } from '../types';
5
5
 
6
6
  interface Props {
@@ -14,23 +14,25 @@ const Dropdown = ({ item, refs, t }: Props): (JSX.Element | null) => {
14
14
  return null;
15
15
  }
16
16
 
17
+ if (typeof item.value !== 'string' && typeof item.value !== 'number' && typeof item.value !== 'undefined') {
18
+ return null;
19
+ }
20
+
21
+ const rules = Validate(String(item.rules), t);
22
+
23
+ // we listen for the change
24
+ if (item.onChange !== undefined && item.onChange !== null) {
25
+ rules.onChange = (event: any) => item.onChange!(event.target.value);
26
+ }
27
+
17
28
  const values = item.values?.map((item, index) => (
18
- <option
19
- key={ index }
20
- value={ item.id }
21
- // disabled={ item.disabled === true }
22
- >
29
+ <option key={ index } value={ item.id }>
23
30
  { item.name }
24
31
  </option>
25
32
  ));
26
-
27
- // // add a custom onchange listener
28
- // if (item.onChange) {
29
- // item.validation.onChange = (e) => data.onChange(e.target.value);
30
- // }
31
33
 
32
34
  return (
33
- <select defaultValue={ item.value } { ...refs(item.name, validate(String(item.rules), t)) }>
35
+ <select defaultValue={ item?.value } { ...refs(item.name, rules) }>
34
36
  { values }
35
37
  </select>
36
38
  );
@@ -0,0 +1,27 @@
1
+ import { ContainerLink, LinkMore } from './styles';
2
+
3
+ interface Props {
4
+ id: number
5
+ value?: JSX.Element | string | number
6
+ url?: string
7
+ }
8
+
9
+ const Linked = ({ id, value, url }: Props): JSX.Element => {
10
+ if (id === 0) {
11
+ return (
12
+ <div className="row-data">
13
+ <ContainerLink>-</ContainerLink>
14
+ </div>
15
+ );
16
+ }
17
+
18
+ return (
19
+ <div className="row-data">
20
+ <ContainerLink>
21
+ <LinkMore to={ url ?? '' }>{ value }</LinkMore>
22
+ </ContainerLink>
23
+ </div>
24
+ );
25
+ };
26
+
27
+ export default Linked;
@@ -1,29 +1,56 @@
1
- // import { EditorState, ContentState, convertToRaw } from 'draft-js';
2
- // import { Editor } from 'react-draft-wysiwyg';
3
- // import htmlToDraft from 'html-to-draftjs';
4
- // import draftToHtml from 'draftjs-to-html';
5
- // import '../../../../../node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
1
+ import { useRef } from 'react';
2
+ import { TFunction } from 'i18next';
3
+ import { UseFormRegister, UseFormSetValue } from 'react-hook-form';
4
+ import { Editor } from '@tinymce/tinymce-react';
5
+ import { Editor as TinyMceEditor } from 'tinymce';
6
+ import { Validate } from '@autobusal/utilities/form';
7
+ import { Textarea } from './styles';
6
8
 
7
- // function TextareaHtml({ data, onUpdate, refs }) {
8
- // const [ value, setValue ] = useState('');
9
+ interface Props {
10
+ name: string
11
+ value?: string
12
+ validation?: string
13
+ t: TFunction<'common'>
14
+ refs: UseFormRegister<any>
15
+ onUpdate: UseFormSetValue<any>
16
+ }
9
17
 
10
- // useEffect(() => {
11
- // let html = data.value ?? '';
12
- // const content = htmlToDraft(html);
18
+ const TextareaHtml = ({ name, value, validation, t, refs, onUpdate }: Props): JSX.Element => {
19
+ const editorRef = useRef<TinyMceEditor | null>(null);
13
20
 
14
- // const contentHtml = ContentState.createFromBlockArray(content);
15
- // setValue(EditorState.createWithContent(contentHtml));
16
- // }, []);
21
+ const onChange = (content: string): void => {
22
+ onUpdate(name, content);
23
+ };
17
24
 
18
- // const onEditorChange = (state) => {
19
- // setValue(state);
20
- // onUpdate(data.name, draftToHtml(convertToRaw(value.getCurrentContent())));
21
- // };
25
+ return (
26
+ <div className="row-data">
27
+ <Editor
28
+ onInit={ (_event, editor) => editorRef.current = editor }
29
+ onEditorChange={ onChange }
30
+ initialValue={ value ?? '' }
31
+ tinymceScriptSrc="/tinymce/tinymce.min.js"
32
+ init={{
33
+ height: 350,
34
+ menubar: false,
35
+ license_key: 'gpl',
36
+ plugins: [
37
+ 'autolink', 'link', 'image', 'media', 'table', 'help', 'lists', 'charmap', 'advlist'
38
+ ],
39
+ toolbar: (
40
+ 'bold italic backcolor | alignleft aligncenter ' +
41
+ 'alignright alignjustify | bullist numlist outdent indent | ' +
42
+ 'image media table | ' +
43
+ 'removeformat | help'
44
+ ),
45
+ content_style: 'body { font-family: Helvetica, Arial, sans-serif; font-size: 14px; }',
46
+ promotion: false,
47
+ highlight_on_focus: false
48
+ }}
49
+ />
22
50
 
23
- // return (
24
- // <>
25
- // <Editor editorState={ value } onEditorStateChange={ onEditorChange } />
26
- // <textarea defaultValue={ data.value } { ...refs(data.name, data.validation) } style={{ display: 'none' }}></textarea>
27
- // </>
28
- // );
29
- // }
51
+ <Textarea defaultValue={ value ?? '' } { ...refs(name, Validate(String(validation), t)) }></Textarea>
52
+ </div>
53
+ );
54
+ };
55
+
56
+ export default TextareaHtml;
@@ -0,0 +1,73 @@
1
+ import styled from 'styled-components';
2
+ import { Link } from 'react-router-dom';
3
+
4
+ export const ContainerCheckboxList = styled.div`
5
+ display: flex;
6
+ align-items: center;
7
+ flex-wrap: wrap;
8
+ gap: 3px;
9
+ min-height: 38px;
10
+ `;
11
+
12
+ export const ListLabel = styled.label`
13
+ display: flex;
14
+ gap: 2px;
15
+ padding: 2px 6px 2px 4px;
16
+ font-size: ${ props => props.theme.size.xs };
17
+ background: ${ props => props.theme.background.neutral };
18
+ border-radius: ${ props => props.theme.borderRadius };
19
+ `;
20
+
21
+ export const ContainerLink = styled.div`
22
+ display: flex;
23
+ align-items: center;
24
+ min-height: 38px;
25
+ `;
26
+
27
+ export const LinkMore = styled(Link)`
28
+ display: flex;
29
+ align-items: center;
30
+ gap: 6px;
31
+ height: 26px;
32
+ padding: 0 10px;
33
+ font-weight: 700;
34
+ font-size: calc(${ props => props.theme.size.xs } + 1px);
35
+ background: ${ props => props.theme.background.neutral };
36
+ border-radius: 100px;
37
+ transition: all 0.3s ease;
38
+
39
+ &:hover {
40
+ text-decoration: none;
41
+ box-shadow: 0 4px 15px ${ props => props.theme.background.neutral };
42
+ }
43
+ `;
44
+
45
+ export const Textarea = styled.textarea`
46
+ display: none;
47
+ `;
48
+
49
+ export const Picker = styled.div`
50
+ display: flex;
51
+ height: 38px;
52
+ align-items: center;
53
+ `;
54
+
55
+ export const ContainerPicker = styled.div`
56
+ position: relative;
57
+ `;
58
+
59
+ export const PickerClose = styled.button`
60
+ position: absolute;
61
+ top: 1px;
62
+ right: 1px;
63
+ width: 38px;
64
+ height: 36px;
65
+ display: flex;
66
+ justify-content: center;
67
+ align-items: center;
68
+ font-size: ${ props => props.theme.size.xl };
69
+ background: ${ props => props.theme.inputs.background };
70
+ border-left: 1px solid ${ props => props.theme.inputs.border };
71
+ border-top-right-radius: ${ props => props.theme.borderRadius };
72
+ border-bottom-right-radius: ${ props => props.theme.borderRadius };
73
+ `;
package/Viewer/Viewer.tsx CHANGED
@@ -6,24 +6,23 @@ import { Container } from './styles';
6
6
  import { ViewData } from './types';
7
7
 
8
8
  interface Props {
9
+ id: number
10
+ type?: 'simple'
9
11
  data: ViewData[]
10
- loading?: boolean
12
+ pending?: boolean
11
13
  actions?: string[]
12
14
  t: TFunction<'common'>
13
- onSave: (data: any) => void
15
+ onSave?: (data: any) => void
16
+ onDelete?: (data?: any) => void
14
17
  }
15
18
 
16
- const Viewer = ({ data, loading, actions, t, onSave }: Props): JSX.Element => {
17
- const { register, handleSubmit, formState: { errors }, setValue, reset } = useForm<any>();
18
-
19
- // reset on id change
20
- // useEffect(() => {
21
- // reset();
22
- // }, [id]);
19
+ const Viewer = ({ id, type, data, pending, actions, t, onSave, onDelete }: Props): JSX.Element => {
20
+ const { register, handleSubmit, formState: { errors }, setValue } = useForm<any>();
23
21
 
24
22
  const items = data.map((item, index) => (
25
23
  <Item
26
24
  key={ index }
25
+ id={ id }
27
26
  data={ item }
28
27
  refs={ register }
29
28
  t={ t }
@@ -33,14 +32,20 @@ const Viewer = ({ data, loading, actions, t, onSave }: Props): JSX.Element => {
33
32
  ));
34
33
 
35
34
  const onSubmit = (data: any): void => {
36
- onSave(data);
35
+ if (onSave !== undefined) {
36
+ onSave(data);
37
+ }
37
38
  };
38
-
39
- // return (
40
- // <div className="box">
41
- // { actions.length > 0 ? <form className="form form-viewer" onSubmit={ handleSubmit(onSubmit) }>{ display }</form> : <div className="form form-viewer">{ display }</div> }
42
- // </div>
43
- // );
39
+
40
+ if (type === 'simple') {
41
+ return (
42
+ <div className="box">
43
+ <Container>
44
+ { items }
45
+ </Container>
46
+ </div>
47
+ );
48
+ }
44
49
 
45
50
  return (
46
51
  <div className="box">
@@ -51,9 +56,11 @@ const Viewer = ({ data, loading, actions, t, onSave }: Props): JSX.Element => {
51
56
 
52
57
  { (actions !== undefined && actions.length > 0) && (
53
58
  <Actions
59
+ id={ id }
54
60
  available={ actions }
55
- loading={ loading }
61
+ pending={ pending }
56
62
  t={ t }
63
+ onDelete={ onDelete }
57
64
  />
58
65
  ) }
59
66
  </form>
package/Viewer/styles.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  import styled from 'styled-components';
2
2
 
3
3
  export const Container = styled.div`
4
- @media (min-width: 480px) {
4
+ & > div.row-checkbox {
5
+ flex-direction: row-reverse;
6
+ justify-content: left;
7
+ height: 20px;
8
+ }
9
+
10
+ @media (min-width: 540px) {
5
11
  display: flex;
6
12
  flex-wrap: wrap;
7
13
  gap: 20px;
@@ -31,8 +37,22 @@ export const Container = styled.div`
31
37
  export const ContainerActions = styled.div`
32
38
  display: flex;
33
39
  justify-content: center;
40
+ gap: 10px;
34
41
  margin-top: 25px;
35
42
  padding: 15px 10px;
36
43
  background: ${ props => props.theme.background.neutral };
37
44
  border-radius: ${ props => props.theme.borderRadius };
45
+ `;
46
+
47
+ export const Display = styled.div`
48
+ min-height: 38px;
49
+ padding: 8px 10px;
50
+ background: ${ props => props.theme.background.neutral };
51
+ border-radius: ${ props => props.theme.borderRadius };
52
+ `;
53
+
54
+ export const Notice = styled.div`
55
+ font-size: ${ props => props.theme.size.xxs };
56
+ color: ${ props => props.theme.font.info };
57
+ font-weight: 400;
38
58
  `;
package/Viewer/types.ts CHANGED
@@ -1,19 +1,22 @@
1
+ import { DropdownData } from '@autobusal/providers/types/other';
2
+
1
3
  export interface ViewData {
2
4
  label?: string
3
5
  name?: string
4
- type?: 'text' | 'select' | 'dob' | 'textarea' | 'file'
5
- value?: string | number
6
- values?: ValuesData[]
6
+ type?: 'text' | 'select' | 'date' | 'dob' | 'picker' | 'textarea' | 'textarea-html' | 'file' | 'files' | 'email' | 'password' | 'display' | 'component' | 'checkbox' | 'checkbox-list' | 'checkbox-list-all' | 'link' | 'number' | 'float' | 'date-picker'
7
+ value?: string | number | JSX.Element
8
+ values?: DropdownData[]
9
+ selected?: any[]
7
10
  rules?: string
8
- }
9
-
10
- export interface ValuesData {
11
- id: number
12
- name: string
11
+ notice?: string
12
+ url?: string
13
+ onChange?: (id: 'string' | 'number') => void
13
14
  }
14
15
 
15
16
  export interface ActionData {
16
17
  label: string
17
18
  icon: any
18
19
  type?: 'submit'
20
+ subtype?: 'delete'
21
+ handler?: () => void
19
22
  }
package/index.ts CHANGED
@@ -1,37 +1,56 @@
1
+ import ApiDetails from './ApiDetails/ApiDetails';
1
2
  import Autocomplete from './Autocomplete/Autocomplete';
2
- import BackTo from './BackTo';
3
+ import Avatar from './Avatar';
4
+ import BackTo from './Back/BackTo';
5
+ import BackWithTitle from './Back/BackWithTitle';
3
6
  import BlogItem from './BlogItem/BlogItem';
4
- import BrowseCompanyItem from './BrowseCompanyItem/BrowseCompanyItem';
7
+ import Button from './Button/Button';
5
8
  import Calendar from './Calendar/Calendar';
6
- import CookieNotification from './CookieNotification/CookieNotification';
7
9
  import ChangeLanguage from './ChangeLanguage/ChangeLanguage';
8
10
  import ChooseSeat from './Seats/ChooseSeat';
9
- import { Button } from './Button/Button';
11
+ import CompanyItem from './CompanyItem/CompanyItem';
12
+ import ContactInfo from './ContactInfo/ContactInfo';
13
+ import CookieNotification from './CookieNotification/CookieNotification';
14
+ import File from './File/File';
10
15
  import Gender from './Gender';
11
- import { General, Inline, Paragraph } from './Loading/Loading';
12
- import Modal from './Modal/Modal';
16
+ import { General, Inline, Box, BoxMiddle, GeneralFull } from './Loading/Loading';
17
+ import IpLogs from './IpLogs/IpLogs';
13
18
  import Meta from './Meta';
19
+ import Modal from './Modal/Modal';
14
20
  import Pagination from './Pagination/Pagination';
21
+ import Paragraph from './Loading/Paragraph';
15
22
  import Passengers from './Passengers/Passengers';
16
23
  import Password from './Password/Password';
17
24
  import Policy from './Policy/Policy';
25
+ import Report from './Report/Report';
18
26
  import RouteFeature from './RouteFeature/RouteFeature';
19
27
  import RouteItem from './RouteItem/RouteItem';
28
+ import Row from './Table/Row';
29
+ import Table from './Table/Table';
20
30
  import Viewer from './Viewer/Viewer';
21
31
 
22
32
  export {
33
+ ApiDetails,
23
34
  Autocomplete,
35
+ Avatar,
24
36
  BackTo,
37
+ BackWithTitle,
25
38
  BlogItem,
26
- BrowseCompanyItem,
39
+ Box,
40
+ BoxMiddle,
27
41
  Button,
28
42
  Calendar,
29
- CookieNotification,
30
43
  ChangeLanguage,
31
44
  ChooseSeat,
45
+ CompanyItem,
46
+ ContactInfo,
47
+ CookieNotification,
48
+ File,
32
49
  Gender,
33
50
  General,
51
+ GeneralFull,
34
52
  Inline,
53
+ IpLogs,
35
54
  Meta,
36
55
  Modal,
37
56
  Pagination,
@@ -39,7 +58,10 @@ export {
39
58
  Passengers,
40
59
  Password,
41
60
  Policy,
61
+ Report,
42
62
  RouteFeature,
43
63
  RouteItem,
64
+ Row,
65
+ Table,
44
66
  Viewer
45
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/common",
3
- "version": "0.0.40",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "main": "index.ts"
6
6
  }
@@ -1,12 +0,0 @@
1
- export interface PaginationData<T> {
2
- current_page: number
3
- last_page: number
4
- data: T[]
5
- links: LinkData[]
6
- }
7
-
8
- export interface LinkData {
9
- url: string | null
10
- label: string
11
- active: boolean
12
- }
File without changes