@autobusal/common 0.0.39 → 0.0.41
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/ApiDetails/ApiDetails.tsx +50 -0
- package/ApiDetails/Content.tsx +44 -0
- package/ApiDetails/Devpos.tsx +139 -0
- package/ApiDetails/services.ts +38 -0
- package/ApiDetails/types.ts +13 -0
- package/Autocomplete/Autocomplete.tsx +1 -1
- package/Avatar.tsx +28 -0
- package/BackTo.tsx +28 -4
- package/Calendar/Calendar.tsx +1 -1
- package/ContactInfo/ContactInfo.tsx +40 -0
- package/ContactInfo/styles.ts +33 -0
- package/File/File.tsx +88 -0
- package/File/styles.ts +23 -0
- package/IpLogs/IpLogs.tsx +47 -0
- package/IpLogs/View.tsx +48 -0
- package/IpLogs/services.ts +27 -0
- package/IpLogs/styles.ts +10 -0
- package/Loading/Loading.tsx +29 -14
- package/Loading/styles.ts +9 -0
- package/Modal/Modal.tsx +3 -2
- package/Pagination/Pagination.tsx +2 -1
- package/Passengers/Passengers.tsx +1 -1
- package/Password/Password.tsx +4 -2
- package/Report/Report.tsx +39 -0
- package/Report/Send.tsx +55 -0
- package/Report/services.ts +18 -0
- package/Report/styles.ts +31 -0
- package/Seats/ChooseSeat.tsx +1 -1
- package/Seats/Preview.tsx +2 -2
- package/Seats/styles.ts +1 -43
- package/Table/Actions/Actions.tsx +40 -0
- package/Table/Actions/Get.tsx +49 -0
- package/Table/Actions/Icon.tsx +54 -0
- package/Table/Actions/styles.ts +22 -0
- package/Table/Header/Header.tsx +46 -0
- package/Table/Header/Sort.tsx +33 -0
- package/Table/Header/styles.ts +48 -0
- package/Table/Paginate.tsx +34 -0
- package/Table/Row.tsx +20 -0
- package/Table/Rows/Loading.tsx +22 -0
- package/Table/Rows/NotFound.tsx +22 -0
- package/Table/Rows/Rows.tsx +62 -0
- package/Table/Rows/styles.ts +31 -0
- package/Table/Table.tsx +74 -0
- package/Table/Top/Search.tsx +36 -0
- package/Table/Top/Top.tsx +44 -0
- package/Table/Top/styles.ts +32 -0
- package/Table/browseUrl.ts +21 -0
- package/Table/styles.ts +28 -0
- package/Table/types.ts +11 -0
- package/Viewer/Actions.tsx +106 -0
- package/Viewer/Data.tsx +124 -0
- package/Viewer/Item.tsx +35 -0
- package/Viewer/Items/CheckboxList.tsx +53 -0
- package/Viewer/Items/DatePicker.tsx +70 -0
- package/Viewer/Items/Dropdown.tsx +45 -0
- package/Viewer/Items/Linked.tsx +27 -0
- package/Viewer/Items/TextareaHtml.tsx +56 -0
- package/Viewer/Items/styles.ts +73 -0
- package/Viewer/Viewer.tsx +71 -0
- package/Viewer/styles.ts +58 -0
- package/Viewer/types.ts +22 -0
- package/index.ts +21 -3
- package/package.json +1 -1
- package/Pagination/types.ts +0 -12
package/Viewer/Data.tsx
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { UseFormRegister, UseFormSetValue } from 'react-hook-form';
|
|
3
|
+
import CheckboxList from './Items/CheckboxList';
|
|
4
|
+
import Linked from './Items/Linked';
|
|
5
|
+
import TextareaHtml from './Items/TextareaHtml';
|
|
6
|
+
import Password from '../Password/Password';
|
|
7
|
+
import Dropdown from './Items/Dropdown';
|
|
8
|
+
import DatePicker from './Items/DatePicker';
|
|
9
|
+
import { ViewData } from './types';
|
|
10
|
+
import Calendar from '../Calendar/Calendar';
|
|
11
|
+
import File from '../File/File';
|
|
12
|
+
import { validate } from '@autobusal/utilities';
|
|
13
|
+
import { Display } from './styles';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
id: number
|
|
17
|
+
item: ViewData
|
|
18
|
+
refs: UseFormRegister<any>
|
|
19
|
+
t: TFunction<'common'>
|
|
20
|
+
onUpdate: UseFormSetValue<any>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const Data = ({ id, item, refs, t, onUpdate }: Props): (JSX.Element | null) => {
|
|
24
|
+
if (item.name === undefined) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
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':
|
|
52
|
+
case 'dob':
|
|
53
|
+
case 'picker':
|
|
54
|
+
const value = item.value !== null && item.value !== undefined ? String(item.value) : undefined;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Calendar
|
|
58
|
+
type={ item.type }
|
|
59
|
+
name={ item.name }
|
|
60
|
+
defaultValue={ value }
|
|
61
|
+
t={ t }
|
|
62
|
+
validation={ item.rules }
|
|
63
|
+
refs={ refs }
|
|
64
|
+
onUpdate={ onUpdate }
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
case 'date-picker':
|
|
69
|
+
return <DatePicker item={ item } t={ t } refs={ refs } onUpdate={ onUpdate } />;
|
|
70
|
+
|
|
71
|
+
case 'email':
|
|
72
|
+
return <input type="email" defaultValue={ item.value ? String(item.value) : undefined } { ...refs(item.name, validate(String(item.rules), t)) } />;
|
|
73
|
+
|
|
74
|
+
case 'file':
|
|
75
|
+
case 'files':
|
|
76
|
+
return (
|
|
77
|
+
<File
|
|
78
|
+
name={ item.name }
|
|
79
|
+
value={ item.value ? String(item.value) : undefined }
|
|
80
|
+
validation={ item.rules }
|
|
81
|
+
multiple={ item.type === 'files' }
|
|
82
|
+
t={ t }
|
|
83
|
+
refs={ refs }
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
case 'float':
|
|
88
|
+
return <input type="number" defaultValue={ item.value ? Number(item.value) : undefined } { ...refs(item.name, validate(String(item.rules), t)) } step="0.01" />;
|
|
89
|
+
|
|
90
|
+
case 'link':
|
|
91
|
+
return <Linked id={ id } value={ item.value } url={ item.url } />;
|
|
92
|
+
|
|
93
|
+
case 'number':
|
|
94
|
+
return <input type="number" defaultValue={ item.value ? Number(item?.value) : undefined } { ...refs(item.name, validate(String(item.rules), t)) } />
|
|
95
|
+
|
|
96
|
+
case 'password':
|
|
97
|
+
return <Password name={ item.name } validation={ item.rules } t={ t } refs={ refs } />;
|
|
98
|
+
|
|
99
|
+
case 'select':
|
|
100
|
+
return <Dropdown item={ item } refs={ refs } t={ t } />;
|
|
101
|
+
|
|
102
|
+
case 'text':
|
|
103
|
+
return <input type="text" defaultValue={ item.value ? String(item.value) : undefined } { ...refs(item.name, validate(String(item.rules), t)) } />;
|
|
104
|
+
|
|
105
|
+
case 'textarea':
|
|
106
|
+
return <textarea defaultValue={ item.value ? String(item.value) : undefined } { ...refs(item.name, validate(String(item.rules), t)) }></textarea>;
|
|
107
|
+
|
|
108
|
+
case 'textarea-html':
|
|
109
|
+
return (
|
|
110
|
+
<TextareaHtml
|
|
111
|
+
name={ item.name }
|
|
112
|
+
value={ item.value ? String(item.value) : undefined }
|
|
113
|
+
validation={ item.rules }
|
|
114
|
+
t={ t }
|
|
115
|
+
refs={ refs }
|
|
116
|
+
onUpdate={ onUpdate }
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return null;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default Data;
|
package/Viewer/Item.tsx
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FieldErrors, UseFormRegister, UseFormSetValue } from 'react-hook-form';
|
|
2
|
+
import { display } from '@autobusal/utilities';
|
|
3
|
+
import Data from './Data';
|
|
4
|
+
import { Notice } from './styles';
|
|
5
|
+
import { ViewData } from './types';
|
|
6
|
+
import { TFunction } from 'i18next';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
id: number
|
|
10
|
+
data: ViewData
|
|
11
|
+
refs: UseFormRegister<any>
|
|
12
|
+
t: TFunction<'common'>
|
|
13
|
+
errors: FieldErrors<any>
|
|
14
|
+
onUpdate: UseFormSetValue<any>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const Item = ({ id, data, refs, t, errors, onUpdate }: Props): JSX.Element => (
|
|
18
|
+
<div className={ `row row-${ data.type } ${ data.label === undefined && 'spacer' }` }>
|
|
19
|
+
{ data.label }
|
|
20
|
+
|
|
21
|
+
<Data
|
|
22
|
+
id={ id }
|
|
23
|
+
item={ data }
|
|
24
|
+
refs={ refs }
|
|
25
|
+
t={ t }
|
|
26
|
+
onUpdate={ onUpdate }
|
|
27
|
+
/>
|
|
28
|
+
|
|
29
|
+
{ data.name && display(errors[data.name]) }
|
|
30
|
+
|
|
31
|
+
{ data.notice && <Notice>* { data.notice }</Notice> }
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export default Item;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 '@modules/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;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { TFunction } from 'i18next';
|
|
3
|
+
import { UseFormRegister, UseFormSetValue } from 'react-hook-form';
|
|
4
|
+
import { Button } from '@autobusal/common';
|
|
5
|
+
import { FaCalendar } from 'react-icons/fa';
|
|
6
|
+
import Calendar from '../../Calendar/Calendar';
|
|
7
|
+
import { Picker, ContainerPicker, PickerClose } from './styles';
|
|
8
|
+
import { ViewData } from '../types';
|
|
9
|
+
import { RiCloseCircleFill } from 'react-icons/ri';
|
|
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;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { UseFormRegister } from 'react-hook-form';
|
|
3
|
+
import { validate } from '@autobusal/utilities';
|
|
4
|
+
import { ViewData } from '../types';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
item: ViewData
|
|
8
|
+
refs: UseFormRegister<any>
|
|
9
|
+
t: TFunction<'common'>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Dropdown = ({ item, refs, t }: Props): (JSX.Element | null) => {
|
|
13
|
+
if (item.name === undefined) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
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) {
|
|
25
|
+
rules.onChange = (event: React.EventHandler<any>) => item.onChange(event.target.value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const values = item.values?.map((item, index) => (
|
|
29
|
+
<option
|
|
30
|
+
key={ index }
|
|
31
|
+
value={ item.id }
|
|
32
|
+
// disabled={ item.disabled === true }
|
|
33
|
+
>
|
|
34
|
+
{ item.name }
|
|
35
|
+
</option>
|
|
36
|
+
));
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<select defaultValue={ item?.value } { ...refs(item.name, rules) }>
|
|
40
|
+
{ values }
|
|
41
|
+
</select>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default Dropdown;
|
|
@@ -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;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 '@modules/Utilities/form';
|
|
7
|
+
import { Textarea } from './styles';
|
|
8
|
+
|
|
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
|
+
}
|
|
17
|
+
|
|
18
|
+
const TextareaHtml = ({ name, value, validation, t, refs, onUpdate }: Props): JSX.Element => {
|
|
19
|
+
const editorRef = useRef<TinyMceEditor | null>(null);
|
|
20
|
+
|
|
21
|
+
const onChange = (content: string): void => {
|
|
22
|
+
onUpdate(name, content);
|
|
23
|
+
};
|
|
24
|
+
|
|
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
|
+
/>
|
|
50
|
+
|
|
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 { Link } from 'react-router-dom';
|
|
2
|
+
import styled from 'styled-components';
|
|
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
|
+
`;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useForm } from 'react-hook-form';
|
|
2
|
+
import { TFunction } from 'i18next';
|
|
3
|
+
import Item from './Item';
|
|
4
|
+
import Actions from './Actions';
|
|
5
|
+
import { Container } from './styles';
|
|
6
|
+
import { ViewData } from './types';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
id: number
|
|
10
|
+
type?: 'simple'
|
|
11
|
+
data: ViewData[]
|
|
12
|
+
loading?: boolean
|
|
13
|
+
actions?: string[]
|
|
14
|
+
t: TFunction<'common'>
|
|
15
|
+
onSave?: (data: any) => void
|
|
16
|
+
onDelete?: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const Viewer = ({ id, type, data, loading, actions, t, onSave, onDelete }: Props): JSX.Element => {
|
|
20
|
+
const { register, handleSubmit, formState: { errors }, setValue } = useForm<any>();
|
|
21
|
+
|
|
22
|
+
const items = data.map((item, index) => (
|
|
23
|
+
<Item
|
|
24
|
+
key={ index }
|
|
25
|
+
id={ id }
|
|
26
|
+
data={ item }
|
|
27
|
+
refs={ register }
|
|
28
|
+
t={ t }
|
|
29
|
+
errors={ errors }
|
|
30
|
+
onUpdate={ setValue }
|
|
31
|
+
/>
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
const onSubmit = (data: any): void => {
|
|
35
|
+
if (onSave !== undefined) {
|
|
36
|
+
onSave(data);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (type === 'simple') {
|
|
41
|
+
return (
|
|
42
|
+
<div className="box">
|
|
43
|
+
<Container>
|
|
44
|
+
{ items }
|
|
45
|
+
</Container>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className="box">
|
|
52
|
+
<form onSubmit={ handleSubmit(onSubmit) }>
|
|
53
|
+
<Container>
|
|
54
|
+
{ items }
|
|
55
|
+
</Container>
|
|
56
|
+
|
|
57
|
+
{ (actions !== undefined && actions.length > 0) && (
|
|
58
|
+
<Actions
|
|
59
|
+
id={ id }
|
|
60
|
+
available={ actions }
|
|
61
|
+
loading={ loading }
|
|
62
|
+
t={ t }
|
|
63
|
+
onDelete={ onDelete }
|
|
64
|
+
/>
|
|
65
|
+
) }
|
|
66
|
+
</form>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default Viewer;
|
package/Viewer/styles.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
& > div.row-checkbox {
|
|
5
|
+
flex-direction: row-reverse;
|
|
6
|
+
justify-content: left;
|
|
7
|
+
height: 20px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (min-width: 540px) {
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-wrap: wrap;
|
|
13
|
+
gap: 20px;
|
|
14
|
+
|
|
15
|
+
& > div.row {
|
|
16
|
+
margin-bottom: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
& > div {
|
|
20
|
+
flex-basis: calc(50% - 10px);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
& > div.spacer {
|
|
24
|
+
flex-basis: 100%;
|
|
25
|
+
height: 1px;
|
|
26
|
+
background: ${ props => props.theme.background.neutral };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@media (min-width: 1300px) {
|
|
31
|
+
& > div {
|
|
32
|
+
flex-basis: calc(33.33333% - 14px);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const ContainerActions = styled.div`
|
|
38
|
+
display: flex;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
gap: 10px;
|
|
41
|
+
margin-top: 25px;
|
|
42
|
+
padding: 15px 10px;
|
|
43
|
+
background: ${ props => props.theme.background.neutral };
|
|
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;
|
|
58
|
+
`;
|
package/Viewer/types.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DropdownData } from '@modules/Providers/types/other';
|
|
2
|
+
|
|
3
|
+
export interface ViewData {
|
|
4
|
+
label?: string
|
|
5
|
+
name?: string
|
|
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[]
|
|
10
|
+
rules?: string
|
|
11
|
+
notice?: string
|
|
12
|
+
url?: string
|
|
13
|
+
onChange?: (id: 'string' | 'number') => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ActionData {
|
|
17
|
+
label: string
|
|
18
|
+
icon: any
|
|
19
|
+
type?: 'submit'
|
|
20
|
+
subtype?: 'delete'
|
|
21
|
+
handler?: () => void
|
|
22
|
+
}
|