@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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
export const Container = styled.thead`
|
|
5
|
+
background: ${ props => props.theme.background.neutral };
|
|
6
|
+
|
|
7
|
+
& > tr > td:first-of-type > div {
|
|
8
|
+
justify-content: left;
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
interface TdData {
|
|
13
|
+
$width?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Td = styled.td<TdData>`
|
|
17
|
+
${ props => props.$width && css<TdData>`
|
|
18
|
+
width: ${ props => props.$width }%;
|
|
19
|
+
` }
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const Column = styled.div`
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
padding: 8px 16px;
|
|
27
|
+
color: ${ props => props.theme.font.faded };
|
|
28
|
+
font-weight: 700;
|
|
29
|
+
text-transform: uppercase;
|
|
30
|
+
font-size: ${ props => props.theme.size.xs };
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export const Text = styled.span`
|
|
34
|
+
cursor: default;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const LinkHeader = styled(Link)`
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
gap: 5px;
|
|
41
|
+
color: ${ props => props.theme.font.faded };
|
|
42
|
+
transition: all 0.3s ease;
|
|
43
|
+
|
|
44
|
+
&:hover {
|
|
45
|
+
opacity: .7;
|
|
46
|
+
text-decoration: none;
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import Pagination from '../Pagination/Pagination';
|
|
3
|
+
import { ContainerPaginate } from './styles';
|
|
4
|
+
import { PaginationData } from '@modules/Providers/types/pagination';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
data?: PaginationData<any>
|
|
8
|
+
colLength: number
|
|
9
|
+
t: TFunction<'common'>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Paginate = ({ data, colLength, t }: Props): (JSX.Element | null) => {
|
|
13
|
+
if (data === undefined) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (data.last_page < 2) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<tfoot>
|
|
23
|
+
<tr>
|
|
24
|
+
<td colSpan={ colLength }>
|
|
25
|
+
<ContainerPaginate>
|
|
26
|
+
<Pagination pages={ data } t={ t } />
|
|
27
|
+
</ContainerPaginate>
|
|
28
|
+
</td>
|
|
29
|
+
</tr>
|
|
30
|
+
</tfoot>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default Paginate;
|
package/Table/Row.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Td } from './styles';
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
id: number
|
|
5
|
+
data: any[]
|
|
6
|
+
withoutView?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// @todo: de scos id-ul din toate row-urile
|
|
10
|
+
const Row = ({ id, data }: Props): JSX.Element[] => {
|
|
11
|
+
const columns = data.map((item, index) => (
|
|
12
|
+
<Td key={ index }>
|
|
13
|
+
{ item }
|
|
14
|
+
</Td>
|
|
15
|
+
));
|
|
16
|
+
|
|
17
|
+
return columns;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default Row;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { Inline } from '@autobusal/common';
|
|
3
|
+
import { ContainerLoading } from './styles';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
length: number
|
|
7
|
+
t: TFunction<'common'>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const Loading = ({ length, t }: Props): JSX.Element => (
|
|
11
|
+
<tbody>
|
|
12
|
+
<tr>
|
|
13
|
+
<td colSpan={ length }>
|
|
14
|
+
<ContainerLoading>
|
|
15
|
+
<Inline text={ t('table.loading_data', { ns: 'common' }) } />
|
|
16
|
+
</ContainerLoading>
|
|
17
|
+
</td>
|
|
18
|
+
</tr>
|
|
19
|
+
</tbody>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export default Loading;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { RiEmotionUnhappyLine } from 'react-icons/ri';
|
|
3
|
+
import { ContainerNotFound } from './styles';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
length: number
|
|
7
|
+
t: TFunction<'common'>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const NotFound = ({ length, t }: Props): JSX.Element => (
|
|
11
|
+
<tbody>
|
|
12
|
+
<tr>
|
|
13
|
+
<td colSpan={ length }>
|
|
14
|
+
<ContainerNotFound>
|
|
15
|
+
<RiEmotionUnhappyLine />{ t('table.no_data', { ns: 'common' }) }
|
|
16
|
+
</ContainerNotFound>
|
|
17
|
+
</td>
|
|
18
|
+
</tr>
|
|
19
|
+
</tbody>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export default NotFound;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { NavigateFunction } from 'react-router-dom';
|
|
3
|
+
import Loading from './Loading';
|
|
4
|
+
import NotFound from './NotFound';
|
|
5
|
+
import Actions from '../Actions/Actions';
|
|
6
|
+
import { Tr } from './styles';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
url: string
|
|
10
|
+
urlWith?: string
|
|
11
|
+
data?: JSX.Element[]
|
|
12
|
+
loading: boolean
|
|
13
|
+
colLength: number
|
|
14
|
+
t: TFunction<'common'>
|
|
15
|
+
actions?: string[]
|
|
16
|
+
handlers?: any
|
|
17
|
+
navigate: NavigateFunction
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Rows = ({ url, urlWith, data, loading, colLength, t, actions, handlers, navigate }: Props): JSX.Element => {
|
|
21
|
+
if (loading) {
|
|
22
|
+
return <Loading length={ colLength } t={ t } />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (data?.length === 0) {
|
|
26
|
+
return <NotFound length={ colLength } t={ t } />;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const isViewable = actions?.includes('view');
|
|
30
|
+
|
|
31
|
+
const onClick = (id: number): void => {
|
|
32
|
+
if (isViewable) {
|
|
33
|
+
navigate(`${ url }/manage/${ id }${ urlWith ? `?${ urlWith }` : '' }`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const columns = data?.map((item, index) => (
|
|
38
|
+
<Tr key={ index } $viewable={ isViewable } onClick={ () => onClick(item.props.id) }>
|
|
39
|
+
{ item }
|
|
40
|
+
|
|
41
|
+
{ (actions !== undefined && actions.length > 0) && (
|
|
42
|
+
<Actions
|
|
43
|
+
id={ item.props.id }
|
|
44
|
+
url={ url }
|
|
45
|
+
urlWith={ urlWith }
|
|
46
|
+
available={ actions }
|
|
47
|
+
t={ t }
|
|
48
|
+
handlers={ handlers }
|
|
49
|
+
navigate={ navigate }
|
|
50
|
+
/>
|
|
51
|
+
) }
|
|
52
|
+
</Tr>
|
|
53
|
+
));
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<tbody>
|
|
57
|
+
{ columns }
|
|
58
|
+
</tbody>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default Rows;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const ContainerLoading = styled.div`
|
|
4
|
+
padding: 25px 0;
|
|
5
|
+
`;
|
|
6
|
+
|
|
7
|
+
export const ContainerNotFound = styled(ContainerLoading)`
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 8px;
|
|
12
|
+
font-size: ${ props => props.theme.size.s };
|
|
13
|
+
color: ${ props => props.theme.font.faded };
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
export const Tr = styled.tr<{ $viewable?: boolean }>`
|
|
17
|
+
${ props => props.$viewable && css`
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
` }
|
|
20
|
+
|
|
21
|
+
text-align: center;
|
|
22
|
+
|
|
23
|
+
& > td:first-of-type {
|
|
24
|
+
text-align: left;
|
|
25
|
+
font-weight: 700;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&:hover {
|
|
29
|
+
background: ${ props => props.theme.background.neutral };
|
|
30
|
+
}
|
|
31
|
+
`;
|
package/Table/Table.tsx
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import Top from './Top/Top';
|
|
3
|
+
import Header from './Header/Header';
|
|
4
|
+
import Rows from './Rows/Rows';
|
|
5
|
+
import Paginate from './Paginate';
|
|
6
|
+
import { Container, Content, Inner, ContainerTable } from './styles';
|
|
7
|
+
import { ColumnData, SortingData } from './types';
|
|
8
|
+
import { useNavigate } from 'react-router-dom';
|
|
9
|
+
import { PaginationData } from '@modules/Providers/types/pagination';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
url: string
|
|
13
|
+
urlWith?: string
|
|
14
|
+
columns: ColumnData[]
|
|
15
|
+
rows?: JSX.Element[]
|
|
16
|
+
pages?: PaginationData<any>
|
|
17
|
+
sorting?: SortingData
|
|
18
|
+
search?: string | null
|
|
19
|
+
loading: boolean
|
|
20
|
+
t: TFunction<'common'>
|
|
21
|
+
actions?: string[]
|
|
22
|
+
extra?: JSX.Element
|
|
23
|
+
handlers?: any
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const Table = ({ url, urlWith, columns, rows, pages, sorting, search, loading, t, actions, extra, handlers }: Props): JSX.Element => {
|
|
27
|
+
const navigate = useNavigate();
|
|
28
|
+
|
|
29
|
+
const colLength = columns.length + 1;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Container className="box">
|
|
33
|
+
<Top
|
|
34
|
+
url={ url }
|
|
35
|
+
urlWith={ urlWith }
|
|
36
|
+
search={ search }
|
|
37
|
+
t={ t }
|
|
38
|
+
actions={ actions }
|
|
39
|
+
extra={ extra }
|
|
40
|
+
navigate={ navigate }
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
<Content>
|
|
44
|
+
<Inner>
|
|
45
|
+
<ContainerTable cellPadding={ 0 } cellSpacing={ 0 }>
|
|
46
|
+
<Header
|
|
47
|
+
url={ url }
|
|
48
|
+
data={ columns }
|
|
49
|
+
sorting={ sorting }
|
|
50
|
+
t={ t }
|
|
51
|
+
actions={ actions }
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
<Rows
|
|
55
|
+
url={ url }
|
|
56
|
+
urlWith={ urlWith }
|
|
57
|
+
data={ rows }
|
|
58
|
+
loading={ loading }
|
|
59
|
+
colLength={ colLength }
|
|
60
|
+
t={ t }
|
|
61
|
+
actions={ actions }
|
|
62
|
+
handlers={ handlers }
|
|
63
|
+
navigate={ navigate }
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
<Paginate data={ pages } colLength={ colLength } t={ t } />
|
|
67
|
+
</ContainerTable>
|
|
68
|
+
</Inner>
|
|
69
|
+
</Content>
|
|
70
|
+
</Container>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default Table;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FormEvent, useState } from 'react';
|
|
2
|
+
import { NavigateFunction } from 'react-router-dom';
|
|
3
|
+
import { TFunction } from 'i18next';
|
|
4
|
+
import { parseUrl } from '../browseUrl';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
value?: string | null
|
|
8
|
+
url: string
|
|
9
|
+
t: TFunction<'common'>
|
|
10
|
+
navigate: NavigateFunction
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Search = ({ value, url, t, navigate }: Props): JSX.Element => {
|
|
14
|
+
const [ q, setQ ] = useState<string>(String(value ?? ''));
|
|
15
|
+
|
|
16
|
+
const handleSubmit = (event: FormEvent<HTMLFormElement>): void => {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
|
|
19
|
+
const search = parseUrl({ page: 1, q });
|
|
20
|
+
|
|
21
|
+
navigate(`${ url }${ search }`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<form onSubmit={ handleSubmit }>
|
|
26
|
+
<input
|
|
27
|
+
type="text"
|
|
28
|
+
value={ q }
|
|
29
|
+
placeholder={ t('table.search', { ns: 'common' }) }
|
|
30
|
+
onChange={ (event) => setQ(event.target.value) }
|
|
31
|
+
/>
|
|
32
|
+
</form>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default Search;
|
|
@@ -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 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 = (): any => (
|
|
20
|
+
queryString.parse(location.search)
|
|
21
|
+
);
|
package/Table/styles.ts
ADDED
|
@@ -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,106 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
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';
|
|
5
|
+
import { ContainerActions } from './styles';
|
|
6
|
+
import { ActionData } from './types';
|
|
7
|
+
import { Button } from '@autobusal/common';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
id: number
|
|
11
|
+
available: string[]
|
|
12
|
+
loading?: boolean
|
|
13
|
+
t: TFunction<'common'>
|
|
14
|
+
onDelete?: () => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const Actions = ({ id, available, loading, t, onDelete }: Props): JSX.Element => {
|
|
18
|
+
const options: ActionData[] = [];
|
|
19
|
+
|
|
20
|
+
const onAskDelete = (): void => {
|
|
21
|
+
if (window.confirm(t('table.confirm', { ns: 'common' }))) {
|
|
22
|
+
if (onDelete) {
|
|
23
|
+
onDelete();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (available.includes('add')) {
|
|
29
|
+
options.push({
|
|
30
|
+
label: t('table.actions.add', { ns: 'common' }),
|
|
31
|
+
icon: <BsPlusCircleFill />,
|
|
32
|
+
type: 'submit'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (available.includes('save')) {
|
|
37
|
+
options.push({
|
|
38
|
+
label: t('table.actions.save', { ns: 'common' }),
|
|
39
|
+
icon: <RiSave2Line />,
|
|
40
|
+
type: 'submit'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (available.includes('send')) {
|
|
45
|
+
options.push({
|
|
46
|
+
label: t('table.actions.send', { ns: 'common' }),
|
|
47
|
+
icon: <BiSend />,
|
|
48
|
+
type: 'submit'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (available.includes('update')) {
|
|
53
|
+
options.push({
|
|
54
|
+
label: t('table.actions.update', { ns: 'common' }),
|
|
55
|
+
icon: <BiEditAlt />,
|
|
56
|
+
type: 'submit'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (available.includes('approve')) {
|
|
61
|
+
options.push({
|
|
62
|
+
label: t('table.actions.approve', { ns: 'common' }),
|
|
63
|
+
icon: <RiCheckFill />,
|
|
64
|
+
type: 'submit'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
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
|
+
}
|
|
76
|
+
|
|
77
|
+
if (available.includes('search')) {
|
|
78
|
+
options.push({
|
|
79
|
+
label: t('table.actions.search', { ns: 'common' }),
|
|
80
|
+
icon: <RiSearchLine />,
|
|
81
|
+
type: 'submit'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const items = options.map((item, index) => (
|
|
86
|
+
<Button
|
|
87
|
+
key={ index }
|
|
88
|
+
type={ item.type === 'submit' ? 'submit' : 'button' }
|
|
89
|
+
subtype={ item.subtype }
|
|
90
|
+
text={
|
|
91
|
+
<>{ item.icon } { item.label }</>
|
|
92
|
+
}
|
|
93
|
+
loading={ loading }
|
|
94
|
+
noMargin
|
|
95
|
+
onClick={ item.handler }
|
|
96
|
+
/>
|
|
97
|
+
));
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<ContainerActions>
|
|
101
|
+
{ items }
|
|
102
|
+
</ContainerActions>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default Actions;
|