30
loading...
This website collects cookies to deliver better user experience
const Button: React.FC<
ButtonProps & React.ButtonHTMLAttributes<HTMLButtonElement>
> = ({ children, size, color, isLoading, className, ...others }) => (
<button
className={clsx(
"button",
size,
color,
isLoading ? "is-loading" : undefined,
className,
)}
{...others}
>
{children}
</button>
);
const ExportPdfButton: React.FC<ExportPdfButtonProps> = ({
url,
operation,
reference,
className,
}) => {
const { t } = useTranslation();
const [isLoading, setLoading] = useDownloadPdf(url, operation, reference);
const handleClick = (e: React.MouseEvent<HTMLButtonElement | MouseEvent>) => {
e.stopPropagation();
setLoading(true);
};
return (
<Button
className={clsx("has-tooltip-arrow", className)}
onClick={(e) => handleClick(e)}
data-tooltip={uppercaseFirst(t("downloadPdf"))}
>
{isLoading ? (
<FontAwesomeIcon icon={faSpinner} pulse />
) : (
<FontAwesomeIcon icon={faFilePdf} />
)}
</Button>
);
};
const ActionsButton: React.FC<ActionsButtonProps> = ({
title,
label,
type,
modalContent,
}) => {
const { t } = useTranslation();
const openModal = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.stopPropagation();
ModalService.open({
onCancel: () => Promise.resolve(true),
title,
content: <ModalWrapper>{modalContent}</ModalWrapper>,
});
};
return (
<Button className={clsx("action-btn large", type)} onClick={openModal}>
{uppercaseFirst(t(label))}
</Button>
);
};
const ContextWrapper: React.FC<ContextWrapperProps> = ({ children }) => {
const [itemsState, dispatchitems] = useReducer(
itemsReducer,
itemsInitialState,
);
const [filtersState, dispatchFilters] = useReducer(
filtersReducer,
filtersInitialState,
);
return (
<ItemsContext.Provider
value={{ state: itemsState, dispatch: dispatchitems }}
>
<FiltersContext.Provider
value={{ state: filtersState, dispatch: dispatchFilters }}
>
{children}
</FiltersContext.Provider>
</ItemsContext.Provider>
);
};
const Items: React.FC = () => {
const { elementId } = useParams<RouteParams>();
const [element] = useElement(elementId);
return (
<ContextWrapper>
{element && (
<Page
filtersComponent={<Filters />}
actionsPanel={<ItemsActionsPanel element={element} />}
dataTable={<ItemsTable />}
/>
)}
</ContextWrapper>
);
};
const Page: React.FC<PageProps> = ({
filtersComponent,
actionsPanel,
dataTable,
}) => {
const [isVisible, setIsVisible] = useState<boolean>(false);
const { t } = useTranslation();
const toggleSideBar = () => {
setIsVisible(!isVisible);
};
const actionsPanelWithProps = React.Children.map(actionsPanel, (child, i) => {
return React.cloneElement(child, {
toggleSideBar,
index: i,
});
});
return (
<>
<header>
<NavBar />
</header>
<main className="site-content">
<SideBar
title={uppercaseFirst(t("filters"))}
isVisible={isVisible}
toggleSideBar={toggleSideBar}
>
{filtersComponent}
<ResetFiltersButton isFullWidth />
</SideBar>
<div className={Style.container}>
{actionsPanelWithProps}
{dataTable}
</div>
</main>
{filtersComponent ? <ModalProvider /> : null}
</>
);
};