react-admin-base-bootstrap 0.5.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 (70) hide show
  1. package/.yarnrc +1 -0
  2. package/assets/main.css +63 -0
  3. package/lib/esm/Components/ApiSelect.d.ts +3 -0
  4. package/lib/esm/Components/ApiSelect.js +82 -0
  5. package/lib/esm/Components/BootstrapDataTable.d.ts +12 -0
  6. package/lib/esm/Components/BootstrapDataTable.js +141 -0
  7. package/lib/esm/Components/BootstrapPagination.d.ts +9 -0
  8. package/lib/esm/Components/BootstrapPagination.js +13 -0
  9. package/lib/esm/Components/CRUD.d.ts +20 -0
  10. package/lib/esm/Components/CRUD.js +88 -0
  11. package/lib/esm/Components/CheckBox.d.ts +2 -0
  12. package/lib/esm/Components/CheckBox.js +7 -0
  13. package/lib/esm/Components/EntityEditor.d.ts +11 -0
  14. package/lib/esm/Components/EntityEditor.js +61 -0
  15. package/lib/esm/Components/ErrorBoundary.d.ts +12 -0
  16. package/lib/esm/Components/ErrorBoundary.js +25 -0
  17. package/lib/esm/Components/ExcelExportButton.d.ts +8 -0
  18. package/lib/esm/Components/ExcelExportButton.js +8 -0
  19. package/lib/esm/Components/ExternalLoginButton.d.ts +7 -0
  20. package/lib/esm/Components/ExternalLoginButton.js +12 -0
  21. package/lib/esm/Components/FilePickerCore.d.ts +16 -0
  22. package/lib/esm/Components/FilePickerCore.js +82 -0
  23. package/lib/esm/Components/GoToTop.d.ts +11 -0
  24. package/lib/esm/Components/GoToTop.js +34 -0
  25. package/lib/esm/Components/ImagePicker.d.ts +2 -0
  26. package/lib/esm/Components/ImagePicker.js +22 -0
  27. package/lib/esm/Components/LanguageProvider.d.ts +8 -0
  28. package/lib/esm/Components/LanguageProvider.js +42 -0
  29. package/lib/esm/Components/LoadingButton.d.ts +2 -0
  30. package/lib/esm/Components/LoadingButton.js +6 -0
  31. package/lib/esm/Components/MenuState.d.ts +3 -0
  32. package/lib/esm/Components/MenuState.js +20 -0
  33. package/lib/esm/Components/MultiFilePicker.d.ts +11 -0
  34. package/lib/esm/Components/MultiFilePicker.js +22 -0
  35. package/lib/esm/Components/SingleFilePicker.d.ts +12 -0
  36. package/lib/esm/Components/SingleFilePicker.js +20 -0
  37. package/lib/esm/Components/TopProgressBar.d.ts +3 -0
  38. package/lib/esm/Components/TopProgressBar.js +10 -0
  39. package/lib/esm/Components/Validator.d.ts +16 -0
  40. package/lib/esm/Components/Validator.js +33 -0
  41. package/lib/esm/i18n/de.json +34 -0
  42. package/lib/esm/i18n/en.json +35 -0
  43. package/lib/esm/i18n/tr.json +35 -0
  44. package/lib/esm/index.d.ts +19 -0
  45. package/lib/esm/index.js +19 -0
  46. package/package.json +55 -0
  47. package/src/Components/ApiSelect.tsx +122 -0
  48. package/src/Components/BootstrapDataTable.tsx +160 -0
  49. package/src/Components/BootstrapPagination.tsx +35 -0
  50. package/src/Components/CRUD.tsx +117 -0
  51. package/src/Components/CheckBox.tsx +9 -0
  52. package/src/Components/EntityEditor.tsx +67 -0
  53. package/src/Components/ErrorBoundary.tsx +29 -0
  54. package/src/Components/ExcelExportButton.tsx +11 -0
  55. package/src/Components/ExternalLoginButton.tsx +14 -0
  56. package/src/Components/FilePickerCore.tsx +87 -0
  57. package/src/Components/GoToTop.tsx +41 -0
  58. package/src/Components/ImagePicker.tsx +26 -0
  59. package/src/Components/LanguageProvider.tsx +61 -0
  60. package/src/Components/LoadingButton.tsx +7 -0
  61. package/src/Components/MenuState.tsx +24 -0
  62. package/src/Components/MultiFilePicker.tsx +43 -0
  63. package/src/Components/SingleFilePicker.tsx +40 -0
  64. package/src/Components/TopProgressBar.tsx +13 -0
  65. package/src/Components/Validator.tsx +55 -0
  66. package/src/i18n/de.json +34 -0
  67. package/src/i18n/en.json +35 -0
  68. package/src/i18n/tr.json +35 -0
  69. package/src/index.ts +42 -0
  70. package/tsconfig.json +23 -0
package/.yarnrc ADDED
@@ -0,0 +1 @@
1
+ --install.no-lockfile true
@@ -0,0 +1,63 @@
1
+
2
+ @import "~nprogress/nprogress.css";
3
+ @import "~sweetalert2/dist/sweetalert2.css";
4
+ @import "~@fortawesome/fontawesome-free/css/all.min.css";
5
+
6
+ // Image Picker
7
+ @import url('~tingle.js/dist/tingle.css');
8
+ @import url('~cropperjs/dist/cropper.css');
9
+
10
+ .tingle-modal--visible {
11
+ z-index: 10000;
12
+ }
13
+
14
+ @media (max-width: 540px) {
15
+ .tingle-modal-box__footer .tingle-btn.tingle-btn--danger {
16
+ display:none;
17
+ }
18
+
19
+ .tingle-modal-box__content {
20
+ padding: 1.5rem 3rem;
21
+ }
22
+
23
+ .tingle-modal-box {
24
+ width: 100%;
25
+ }
26
+
27
+ .price_in {
28
+ margin-bottom: 24px;
29
+ }
30
+ }
31
+
32
+ .tingle-modal.tingle-modal--visible {
33
+ display: flex;
34
+ flex-direction: column;
35
+ }
36
+
37
+ .tingle-modal-box {
38
+ flex: 1;
39
+ display: flex;
40
+ flex-direction: column;
41
+ }
42
+
43
+ .tingle-modal-box__content {
44
+ flex: 1;
45
+ position: relative;
46
+ }
47
+
48
+ .tingle-modal-box__content > div {
49
+ position: absolute;
50
+ left:0;
51
+ right:0;
52
+ top:0;
53
+ bottom:0;
54
+ }
55
+
56
+ .tingle-modal--overflow {
57
+ overflow-y: hidden !important;
58
+ padding-top: 0 !important;
59
+ }
60
+
61
+ .tingle-modal-box__footer {
62
+ text-align: center;
63
+ }
@@ -0,0 +1,3 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ export default function ApiSelect(props: any): jsx.JSX.Element;
@@ -0,0 +1,82 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /** @jsx jsx */
11
+ import { jsx } from '@emotion/react';
12
+ import React, { useCallback, useMemo, useState } from 'react';
13
+ import { useFetch } from 'react-admin-base';
14
+ import { FormattedMessage, useIntl } from 'react-intl';
15
+ import Select, { components } from "react-select";
16
+ import CreatableSelect from 'react-select/creatable';
17
+ function Option(props) {
18
+ return jsx(components.Option, Object.assign({}, props), (props.selectProps.children && props.selectProps.children(props.data)) || (props.data.__isNew__ ? jsx(FormattedMessage, { id: "CREATE_VALUE", values: { text: props.children } }) : props.children));
19
+ }
20
+ function SingleValue(props) {
21
+ return jsx(components.SingleValue, Object.assign({}, props), (props.selectProps.children && props.selectProps.children(props.data)) || (props.data.__isNew__ ? jsx(FormattedMessage, { id: "CREATE_VALUE", values: { text: props.children } }) : props.children));
22
+ }
23
+ function EditOrAddIndicator(props) {
24
+ const { className, cx, getStyles, innerProps } = props;
25
+ return (jsx("div", Object.assign({}, innerProps, { className: cx({
26
+ indicator: true,
27
+ 'clear-indicator': true
28
+ }, className), css: getStyles('clearIndicator', props), onMouseDown: e => {
29
+ e.stopPropagation();
30
+ e.preventDefault();
31
+ props.selectProps.onAddOrEdit();
32
+ } }),
33
+ jsx("i", { className: "fas " + (props.hasValue ? 'fa-pencil-alt' : 'fa-plus') })));
34
+ }
35
+ function IndicatorsContainer(props) {
36
+ return jsx(components.IndicatorsContainer, Object.assign({}, props),
37
+ props.selectProps.onAddOrEdit && jsx(React.Fragment, null,
38
+ jsx(EditOrAddIndicator, Object.assign({}, props)),
39
+ jsx(components.IndicatorSeparator, Object.assign({}, props))),
40
+ props.children);
41
+ }
42
+ const Components = { Option, SingleValue, IndicatorsContainer };
43
+ export default function ApiSelect(props) {
44
+ const { disabled, url, getOptionLabel, getOptionValue, idKey, nameKey, filter, group, onCreateOption, getNewOptionData, isMulti, onChange, value, placeholder, staticOptions } = props;
45
+ const intl = useIntl();
46
+ const [search, setSearch] = useState('');
47
+ const params = useMemo(() => ({ query: search }), [search]);
48
+ const [isMenuOpen, setIsMenuOpen] = useState(false);
49
+ const [hasMenuOpen, setHasMenuOpen] = useState(false);
50
+ const [data, loading] = useFetch((hasMenuOpen && url) || false, params);
51
+ const [creating, setCreating] = useState(false);
52
+ let options = staticOptions || (data && data.data) || data;
53
+ if (group) {
54
+ options = group(options || []);
55
+ }
56
+ const handleCreateOption = useCallback(function (input) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ setCreating(true);
59
+ try {
60
+ let option = yield onCreateOption(input);
61
+ if (isMulti) {
62
+ onChange((value || []).concat([option]));
63
+ }
64
+ else {
65
+ onChange(option);
66
+ }
67
+ }
68
+ finally {
69
+ setCreating(false);
70
+ }
71
+ });
72
+ }, [onCreateOption, setCreating, isMulti, value]);
73
+ const onMenuOpen = useCallback(function () {
74
+ setIsMenuOpen(true);
75
+ setHasMenuOpen(true);
76
+ }, [setIsMenuOpen, setHasMenuOpen]);
77
+ const onMenuClose = useCallback(function () {
78
+ setIsMenuOpen(false);
79
+ }, [setIsMenuOpen]);
80
+ const Component = onCreateOption ? CreatableSelect : Select;
81
+ return jsx(Component, Object.assign({}, props, { onCreateOption: (onCreateOption && handleCreateOption) || null, getNewOptionData: onCreateOption ? getNewOptionData ? getNewOptionData : (inputValue) => ({ [nameKey || 'name']: inputValue, __isNew__: true }) : null, inputValue: search, onInputChange: a => setSearch(a), components: Components, isLoading: !!loading || creating, getOptionLabel: getOptionLabel || ((row) => row[nameKey || 'name']), getOptionValue: getOptionValue || ((row) => row[idKey || 'id']), isDisabled: !!disabled || creating, isClearable: true, isSearchable: true, placeholder: placeholder || intl.formatMessage({ id: 'SELECT' }), options: !options ? [] : ((filter && options.filter(filter)) || options), isMenuOpen: isMenuOpen, onMenuOpen: onMenuOpen, onMenuClose: onMenuClose }));
82
+ }
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export declare function useDataTableContext(): any;
3
+ export declare function Actions({ edit, del, rowSpan, children }: {
4
+ edit: any;
5
+ del: any;
6
+ rowSpan?: any;
7
+ children?: any;
8
+ }): JSX.Element;
9
+ export declare function IdColumn(): JSX.Element;
10
+ export declare function ActionsColumn(): JSX.Element;
11
+ export declare function Column(props: any): JSX.Element;
12
+ export default function BootstrapTable({ url, bordered, noStrip, defaultParams, add, children, innerRef, body }: any): JSX.Element;
@@ -0,0 +1,141 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
11
+ import { DataContextProvider, useAuth, useDataTable } from 'react-admin-base';
12
+ import { FormattedMessage, useIntl } from "react-intl";
13
+ import { Link } from 'react-router-dom';
14
+ import { Alert, Button, Card, CardFooter, CardHeader, Col, Input, Row, Table } from 'reactstrap';
15
+ import Swal from 'sweetalert2';
16
+ import BootstrapPagination from "./BootstrapPagination";
17
+ const DataTableContext = React.createContext(null);
18
+ export function useDataTableContext() {
19
+ return useContext(DataTableContext);
20
+ }
21
+ export function Actions({ edit, del, rowSpan, children }) {
22
+ const [api] = useAuth();
23
+ const [, setParams] = useContext(DataTableContext);
24
+ const intl = useIntl();
25
+ const [loading, setLoading] = useState(false);
26
+ const delFnc = useCallback(function (e) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ e && e.preventDefault();
29
+ const val = yield Swal.fire({
30
+ title: intl.formatMessage({ id: 'ACTIONS.DELETE.TITLE' }),
31
+ text: intl.formatMessage({ id: 'ACTIONS.DELETE.TEXT' }),
32
+ icon: 'warning',
33
+ showCancelButton: true,
34
+ confirmButtonColor: '#3085d6',
35
+ cancelButtonColor: '#d33',
36
+ confirmButtonText: intl.formatMessage({ id: 'ACTIONS.DELETE.CONFIRM' })
37
+ });
38
+ if (val.value) {
39
+ setLoading(true);
40
+ try {
41
+ yield api.tokenized.delete(del);
42
+ setParams({}, true);
43
+ }
44
+ finally {
45
+ setLoading(false);
46
+ }
47
+ }
48
+ });
49
+ }, [api, del, setParams, intl, setLoading]);
50
+ return React.createElement("td", { className: "min", rowSpan: rowSpan },
51
+ edit && React.createElement(Link, { to: edit },
52
+ React.createElement(Button, { outline: true, color: "primary" },
53
+ React.createElement("i", { className: "fa fa-pencil-alt" }))),
54
+ edit && del && ' ',
55
+ del && React.createElement(Button, { color: "danger", outline: true, onClick: delFnc, disabled: loading },
56
+ React.createElement("i", { className: loading ? "fa fa-spin fa-spinner" : "fa fa-trash" })),
57
+ children);
58
+ }
59
+ export function IdColumn() {
60
+ return React.createElement(Column, { className: "min text-center", sort: "id" },
61
+ React.createElement("i", { className: "fas fa-hashtag" }));
62
+ }
63
+ export function ActionsColumn() {
64
+ return React.createElement(Column, { className: "min text-center" },
65
+ React.createElement("i", { className: "fas fa-water" }));
66
+ }
67
+ export function Column(props) {
68
+ const [params, setParams] = useContext(DataTableContext);
69
+ const { sort } = props;
70
+ return React.createElement("th", Object.assign({}, props, { style: props.sort && { cursor: 'pointer' }, onClick: props.sort && (() => setParams({
71
+ sort: sort,
72
+ desc: params.sort === sort ? !params.desc : true
73
+ })) }),
74
+ props.children,
75
+ " ",
76
+ sort && params.sort && params.sort === sort ? params.desc ?
77
+ React.createElement("i", { className: "fa fa-sort-down" }) :
78
+ React.createElement("i", { className: "fa fa-sort-up" }) : '');
79
+ }
80
+ export default function BootstrapTable({ url, bordered, noStrip, defaultParams, add, children, innerRef, body }) {
81
+ var state = useState(Object.assign({ sort: 'id' }, defaultParams));
82
+ const [params, setParams] = state;
83
+ const [page, lastPage, setPage, data, itemPerPage, setItemPerPage] = useDataTable(url, params, body);
84
+ const intl = useIntl();
85
+ const [api] = useAuth();
86
+ var ref = useRef(defaultParams);
87
+ useEffect(function () {
88
+ if (ref.current !== defaultParams) {
89
+ ref.current = defaultParams;
90
+ setParams(defaultParams);
91
+ }
92
+ }, [defaultParams, ref, setParams]);
93
+ useEffect(function () {
94
+ if (innerRef) {
95
+ innerRef.current = setParams;
96
+ return function () {
97
+ innerRef.current = null;
98
+ };
99
+ }
100
+ }, [setParams, innerRef]);
101
+ const fetchData = useCallback(function (extraParams) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ if (body) {
104
+ const data = yield api.tokenized.post(url, body, { params: Object.assign(Object.assign({}, params), (extraParams || {})) });
105
+ return data.data;
106
+ }
107
+ const data = yield api.tokenized.get(url, { params: Object.assign(Object.assign({}, params), (extraParams || {})) });
108
+ return data.data;
109
+ });
110
+ }, [api, url, params, body]);
111
+ return React.createElement(Card, null,
112
+ React.createElement(DataTableContext.Provider, { value: state },
113
+ React.createElement(DataContextProvider, { value: fetchData },
114
+ React.createElement(CardHeader, null,
115
+ React.createElement(Row, null,
116
+ add && React.createElement(Col, { xs: "12", md: "2" },
117
+ React.createElement(Link, { to: add, className: "btn btn-primary font-xl btn-lg d-block" },
118
+ React.createElement("i", { className: "fa fa-plus" }))),
119
+ React.createElement(Col, { md: "2" },
120
+ React.createElement(Input, { type: "select", bsSize: "lg", value: itemPerPage.toString(), onChange: a => setItemPerPage(+a.currentTarget.value) },
121
+ React.createElement("option", { value: "1" }, "1"),
122
+ React.createElement("option", { value: "20" }, "20"),
123
+ React.createElement("option", { value: "50" }, "50"),
124
+ React.createElement("option", { value: "100" }, "100"),
125
+ React.createElement("option", { value: "150" }, "150"),
126
+ React.createElement("option", { value: "200" }, "200"),
127
+ React.createElement("option", { value: "-1" }, intl.formatMessage({ id: "ALL" })))),
128
+ children[2],
129
+ React.createElement(Col, { md: "3", className: "ms-auto" },
130
+ React.createElement(Input, { placeholder: intl.formatMessage({ id: "SEARCH" }), type: "text", value: params.query || '', bsSize: "lg", onChange: e => setParams(Object.assign(Object.assign({}, params), { query: e.currentTarget.value })) })))),
131
+ data === null ? React.createElement(Alert, { className: "text-center mb-0 ", color: "warning" },
132
+ React.createElement("i", { className: "fas fa-spinner fa-lg fa-spin" })) : !data.length ? React.createElement(Alert, { className: "text-center", color: "danger" },
133
+ React.createElement("i", { className: "far fa-times-circle fa-lg" }),
134
+ " ",
135
+ React.createElement(FormattedMessage, { id: "NO_DATA_IS_AVAILABLE" })) : React.createElement(Table, { hover: true, bordered: bordered, striped: !noStrip, responsive: true, size: "md", className: "mb-0 dataTable" },
136
+ children[0],
137
+ React.createElement("tbody", null, data && data.map(children[1].props.children))),
138
+ lastPage > 1 && React.createElement(CardFooter, null,
139
+ React.createElement("nav", null,
140
+ React.createElement(BootstrapPagination, { currentPage: page, pageCount: lastPage, onPageChange: index => setPage(index) }))))));
141
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ declare type BootstrapPaginationProps = {
3
+ className?: string;
4
+ currentPage: number;
5
+ pageCount: number;
6
+ onPageChange: (page: number) => void;
7
+ };
8
+ export default function BootstrapPagination({ className, currentPage, pageCount, onPageChange }: BootstrapPaginationProps): JSX.Element | null;
9
+ export {};
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import { PaginatorCore } from 'react-admin-base';
3
+ import { Pagination, PaginationItem, PaginationLink } from "reactstrap";
4
+ export default function BootstrapPagination({ className, currentPage, pageCount, onPageChange }) {
5
+ if (pageCount <= 1)
6
+ return null;
7
+ return React.createElement(Pagination, { listClassName: "mb-0", className: className },
8
+ React.createElement(PaginatorCore, { activePage: currentPage, pageCount: pageCount, showPages: 15, prevPage: index => React.createElement(PaginationItem, { onClick: () => onPageChange(index) },
9
+ React.createElement(PaginationLink, { previous: true, tag: "button" }, "\u00AB")), page: index => React.createElement(PaginationItem, { key: index, active: currentPage === index },
10
+ React.createElement(PaginationLink, { tag: "button", onClick: () => onPageChange(index) }, index)), nextPage: index => React.createElement(PaginationItem, { onClick: () => onPageChange(index) },
11
+ React.createElement(PaginationLink, { next: true, tag: "button" }, "\u00BB")), dots: index => React.createElement(PaginationItem, { onClick: () => onPageChange(index), active: currentPage === index },
12
+ React.createElement(PaginationLink, { tag: "button" }, index)) }));
13
+ }
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ declare type ModalEntityEditorParams = {
3
+ entity: any;
4
+ title?: string;
5
+ size?: string;
6
+ url?: string;
7
+ onReload?: any;
8
+ disabled?: Boolean;
9
+ children: React.ReactNode;
10
+ };
11
+ export declare function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children }: ModalEntityEditorParams): JSX.Element;
12
+ declare type CrudActionProps = {
13
+ id: any;
14
+ edit?: Boolean;
15
+ del: string;
16
+ children?: React.ReactNode;
17
+ };
18
+ export declare function CRUDActions({ id, edit, del, children }: CrudActionProps): JSX.Element;
19
+ export default function CRUD(props: any): JSX.Element;
20
+ export {};
@@ -0,0 +1,88 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useCallback, useContext, useRef, useState } from 'react';
11
+ import { ValidatorProvider } from "react-admin-base";
12
+ import { FormattedMessage } from 'react-intl';
13
+ import { Redirect, Route } from 'react-router-dom';
14
+ import { Alert, Button, Form, Modal, ModalFooter, ModalHeader } from "reactstrap";
15
+ import LoadingButton from '../Components/LoadingButton';
16
+ import BootstrapDataTable, { Actions } from './BootstrapDataTable';
17
+ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children }) {
18
+ const [, , save, loading] = entity;
19
+ const [open, setOpen] = useState(true);
20
+ const [saved, setSaved] = useState(false);
21
+ const [error, setError] = useState(false);
22
+ const onSubmit = useCallback(function (e) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ e.stopPropagation();
25
+ e.preventDefault();
26
+ if (saved) {
27
+ setSaved(false);
28
+ }
29
+ if (error) {
30
+ setError(null);
31
+ }
32
+ try {
33
+ let data = yield save();
34
+ if (onReload) {
35
+ yield onReload(data);
36
+ }
37
+ if (url) {
38
+ setSaved(true);
39
+ }
40
+ }
41
+ catch (e) {
42
+ console.error(e);
43
+ setError((e.response && e.response.data && e.response.data.message) || (error.data && error.data.message) || e.data || e.message || e);
44
+ }
45
+ finally {
46
+ }
47
+ });
48
+ }, [save, saved, error, onReload, url]);
49
+ return React.createElement(React.Fragment, null,
50
+ (saved || !open) && url && React.createElement(Redirect, { to: url }),
51
+ React.createElement(Modal, { isOpen: true, size: size, toggle: () => url ? setOpen(false) : onReload(null), fade: false },
52
+ title && React.createElement(ModalHeader, { toggle: () => url ? setOpen(false) : onReload(null) },
53
+ React.createElement("b", null, title)),
54
+ React.createElement(ValidatorProvider, null,
55
+ React.createElement(Form, { onSubmit: onSubmit, disabled: !!loading || disabled },
56
+ React.createElement("fieldset", { disabled: !!loading || !!disabled }, children),
57
+ React.createElement(ModalFooter, null,
58
+ error && React.createElement(Alert, { color: "danger", toggle: () => setError(null), style: { display: 'block', width: '100%' } }, error),
59
+ React.createElement(LoadingButton, { block: true, loading: loading, type: "submit", color: "primary" },
60
+ React.createElement("i", { className: "fas fa-save" }),
61
+ ' ',
62
+ React.createElement(FormattedMessage, { id: "ENTITY.SAVE" })),
63
+ React.createElement(Button, { block: true, outline: true, color: "danger", onClick: (e) => { e.preventDefault(); (url ? setOpen(false) : onReload(null)); } },
64
+ React.createElement("i", { className: "fas fa-times-circle" }),
65
+ ' ',
66
+ React.createElement(FormattedMessage, { id: "ENTITY.CANCEL" })))))));
67
+ }
68
+ const UrlContext = React.createContext(null);
69
+ export function CRUDActions({ id, edit, del, children }) {
70
+ const url = useContext(UrlContext);
71
+ return React.createElement(Actions, { edit: edit && (url + "/" + id + "/edit"), del: del }, children);
72
+ }
73
+ export default function CRUD(props) {
74
+ const ref = useRef(null);
75
+ const { id, url, apiUrl, Component, defaultParams, noAdd } = props;
76
+ var reload = useCallback(function () {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ if (ref.current) {
79
+ ref.current({});
80
+ }
81
+ });
82
+ }, [ref]);
83
+ return React.createElement(UrlContext.Provider, { value: url },
84
+ !noAdd && React.createElement(Route, { path: url + "/create", render: props => React.createElement(Component, Object.assign({ url: url, onReload: reload }, (defaultParams || {}))) }),
85
+ React.createElement(Route, { path: url + "/:id/edit", render: props => React.createElement(Component, Object.assign({ url: url, onReload: reload, id: props.match.params.id }, (defaultParams || {}))) }),
86
+ id && React.createElement(Route, { path: url + "/edit", render: props => React.createElement(Component, Object.assign({ url: url, onReload: reload, id: id }, (defaultParams || {}))) }),
87
+ React.createElement(BootstrapDataTable, Object.assign({ innerRef: ref, add: !noAdd && (url + "/create") }, props, { url: apiUrl || url })));
88
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function CheckBox(props: any): JSX.Element;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import { FormGroup, Input, Label } from "reactstrap";
3
+ export default function CheckBox(props) {
4
+ return React.createElement(FormGroup, { check: true },
5
+ React.createElement(Input, Object.assign({ type: props.type || "checkbox" }, props, { label: undefined })),
6
+ React.createElement(Label, { check: true, for: props.id }, props.children || props.label));
7
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ declare type EntityEditorParams = {
3
+ entity: any;
4
+ onSave?: any;
5
+ saveButtonClassName?: string;
6
+ saveButtonText?: string;
7
+ disabled?: Boolean;
8
+ children: React.ReactNode;
9
+ };
10
+ export default function EntityEditor({ entity, disabled, children, onSave, saveButtonClassName, saveButtonText }: EntityEditorParams): JSX.Element;
11
+ export {};
@@ -0,0 +1,61 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useCallback, useState } from 'react';
11
+ import { ValidatorProvider } from "react-admin-base";
12
+ import { FormattedMessage } from "react-intl";
13
+ import { Alert, Form } from 'reactstrap';
14
+ import LoadingButton from "../Components/LoadingButton";
15
+ import { ValidationErrors } from './Validator';
16
+ export default function EntityEditor({ entity, disabled, children, onSave, saveButtonClassName, saveButtonText }) {
17
+ const [_1, _2, save, loading] = entity;
18
+ const [saved, setSaved] = useState(false);
19
+ const [error, setError] = useState(false);
20
+ const onSubmit = useCallback(function (e) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ e.preventDefault();
23
+ e.stopPropagation();
24
+ if (saved) {
25
+ setSaved(false);
26
+ }
27
+ if (error) {
28
+ setError(null);
29
+ }
30
+ try {
31
+ yield save();
32
+ onSave && onSave();
33
+ setSaved(true);
34
+ }
35
+ catch (e) {
36
+ console.error(e);
37
+ setError((e.response && e.response.data && e.response.data.message) || (error.data && error.data.message) || e.data || e.message || e);
38
+ }
39
+ finally {
40
+ }
41
+ });
42
+ }, [save, saved, error]);
43
+ const savedAlert = saved && React.createElement(Alert, { color: "success", toggle: () => setSaved(false) },
44
+ React.createElement("i", { className: "fas fa-check-circle me-2" }),
45
+ React.createElement(FormattedMessage, { id: "ENTITY.SAVED" }));
46
+ return React.createElement(ValidatorProvider, null,
47
+ React.createElement(Form, { onSubmit: onSubmit, disabled: !!loading || !!disabled },
48
+ loading && React.createElement(Alert, { color: "warning", toggle: () => setSaved(false) },
49
+ React.createElement("i", { className: "fa fa-spin fa-spinner" }),
50
+ ' ',
51
+ React.createElement(FormattedMessage, { id: "PLEASE_WAIT" })),
52
+ savedAlert,
53
+ error && React.createElement(Alert, { color: "danger", toggle: () => setError(null) }, error),
54
+ React.createElement("fieldset", { disabled: !!loading || !!disabled }, children),
55
+ React.createElement(ValidationErrors, null),
56
+ savedAlert,
57
+ React.createElement(LoadingButton, { className: saveButtonClassName || "col-md-12", loading: loading, type: "submit", color: "primary" },
58
+ saveButtonText || React.createElement(FormattedMessage, { id: "ENTITY.SAVE" }),
59
+ " ",
60
+ React.createElement("i", { className: "fas fa-save fa-lg" }))));
61
+ }
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ export default class ErrorBoundary extends React.Component {
3
+ state: {
4
+ hasError: boolean;
5
+ error: null;
6
+ };
7
+ static getDerivedStateFromError(error: any): {
8
+ hasError: boolean;
9
+ error: any;
10
+ };
11
+ render(): React.ReactNode;
12
+ }
@@ -0,0 +1,25 @@
1
+ import { Alert } from 'reactstrap';
2
+ import React from 'react';
3
+ function ErrorHandler({ error }) {
4
+ return React.createElement(Alert, { color: "danger" },
5
+ React.createElement("i", { className: "fas fa-exclamation-circle me-1" }),
6
+ error && ((error.response && error.response.data && error.response.data.message) || error.message));
7
+ }
8
+ export default class ErrorBoundary extends React.Component {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.state = { hasError: false, error: null };
12
+ }
13
+ static getDerivedStateFromError(error) {
14
+ return {
15
+ hasError: true,
16
+ error
17
+ };
18
+ }
19
+ render() {
20
+ if (this.state.hasError) {
21
+ return React.createElement(ErrorHandler, { error: this.state.error });
22
+ }
23
+ return this.props.children;
24
+ }
25
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ export default function ExcelExportButton({ name, header, params, map, extra }: {
3
+ name: any;
4
+ header: any;
5
+ params: any;
6
+ map: any;
7
+ extra: any;
8
+ }): JSX.Element;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { useExporter } from 'react-admin-base';
3
+ import { Button, Col } from "reactstrap";
4
+ export default function ExcelExportButton({ name, header, params, map, extra }) {
5
+ const [handleExport, loading] = useExporter(header, params, map, extra);
6
+ return React.createElement(Col, null,
7
+ React.createElement(Button, { className: "w-100 d-block", type: "button", size: "lg", color: "success", outline: true, disabled: !!loading, onClick: () => handleExport(name) }, loading ? React.createElement("i", { className: "fas fa-spin fa-spinner" }) : React.createElement("i", { className: "fas fa-file-excel" })));
8
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ export default function ExternalLoginButton({ id, icon, name, url }: {
3
+ id: any;
4
+ icon: any;
5
+ name: any;
6
+ url: any;
7
+ }): JSX.Element;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { useApp, useAuth, useLogin } from 'react-admin-base';
3
+ import { FormattedMessage } from 'react-intl';
4
+ export default function ExternalLoginButton({ id, icon, name, url }) {
5
+ const { endpoint } = useApp();
6
+ const [{ client_id }] = useAuth();
7
+ const { login } = useLogin();
8
+ return React.createElement("a", { className: "btn btn-primary d-block w-100 btn-social-" + id, href: endpoint + url + '?client_id=' + client_id + '&callback_url=' + encodeURIComponent(window.location.origin + login) },
9
+ React.createElement("i", { className: "fab fa-" + (icon || id) + " me-2" }),
10
+ " ",
11
+ React.createElement(FormattedMessage, { id: "SIGN_IN_USING", values: { provider: React.createElement("b", null, name) } }));
12
+ }
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ export declare function Relative({ children }: {
3
+ children: any;
4
+ }): React.ReactSVGElement | null;
5
+ export declare function Preview({ value }: {
6
+ value: any;
7
+ }): JSX.Element | null;
8
+ export default function FilePickerCore({ disabled, className, accepts, value, onNotify, children, transform }: {
9
+ disabled?: any;
10
+ className?: any;
11
+ accepts?: any;
12
+ value?: any;
13
+ onNotify?: any;
14
+ children?: any;
15
+ transform?: any;
16
+ }): JSX.Element | null;