2021-12-27 23:55:38 +05:30
|
|
|
import { Tabs, TabsProps } from 'antd';
|
2022-03-22 12:10:31 +05:30
|
|
|
import history from 'lib/history';
|
2022-03-14 20:12:42 +05:30
|
|
|
import React from 'react';
|
2021-12-27 23:55:38 +05:30
|
|
|
|
|
|
|
|
const { TabPane } = Tabs;
|
|
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
function RouteTab({
|
2021-12-27 23:55:38 +05:30
|
|
|
routes,
|
|
|
|
|
activeKey,
|
|
|
|
|
onChangeHandler,
|
|
|
|
|
...rest
|
2022-03-22 12:10:31 +05:30
|
|
|
}: RouteTabProps & TabsProps): JSX.Element {
|
2022-03-24 12:06:57 +05:30
|
|
|
const onChange = (activeRoute: string): void => {
|
|
|
|
|
if (onChangeHandler) {
|
|
|
|
|
onChangeHandler();
|
|
|
|
|
}
|
2021-12-27 23:55:38 +05:30
|
|
|
|
|
|
|
|
const selectedRoute = routes.find((e) => e.name === activeRoute);
|
|
|
|
|
|
|
|
|
|
if (selectedRoute) {
|
|
|
|
|
history.push(selectedRoute.route);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Tabs
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
destroyInactiveTabPane
|
|
|
|
|
activeKey={activeKey}
|
2022-05-19 21:25:03 +05:30
|
|
|
animated
|
2022-03-24 12:06:57 +05:30
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
2021-12-27 23:55:38 +05:30
|
|
|
{...rest}
|
|
|
|
|
>
|
|
|
|
|
{routes.map(
|
2022-05-19 21:25:03 +05:30
|
|
|
({ Component, name, route }): JSX.Element => (
|
|
|
|
|
<TabPane
|
|
|
|
|
tabKey={route}
|
|
|
|
|
animated
|
|
|
|
|
destroyInactiveTabPane
|
|
|
|
|
tab={name}
|
|
|
|
|
key={name}
|
|
|
|
|
>
|
2021-12-27 23:55:38 +05:30
|
|
|
<Component />
|
|
|
|
|
</TabPane>
|
|
|
|
|
),
|
|
|
|
|
)}
|
|
|
|
|
</Tabs>
|
|
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-12-27 23:55:38 +05:30
|
|
|
|
|
|
|
|
interface RouteTabProps {
|
|
|
|
|
routes: {
|
|
|
|
|
name: string;
|
|
|
|
|
route: string;
|
|
|
|
|
Component: () => JSX.Element;
|
|
|
|
|
}[];
|
|
|
|
|
activeKey: TabsProps['activeKey'];
|
|
|
|
|
onChangeHandler?: VoidFunction;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
RouteTab.defaultProps = {
|
|
|
|
|
onChangeHandler: undefined,
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-27 23:55:38 +05:30
|
|
|
export default RouteTab;
|