@omniumretail/component-library 1.1.64 → 1.1.66

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.
@@ -1,6 +1,7 @@
1
1
  export interface MenuItem {
2
2
  name: string;
3
3
  action: () => void;
4
+ targetRoute?: string;
4
5
  dropdownMenu?: MenuItem[];
5
6
  }
6
7
  export interface actionButton {
@@ -12,6 +13,7 @@ export interface HeaderProps {
12
13
  actionButton?: actionButton;
13
14
  menuList?: MenuItem[];
14
15
  logout?: () => void;
15
- homeUrl?: string;
16
- profileUrl?: string;
16
+ homeUrl: string;
17
+ profileUrl: string;
18
+ onLeavingPage?: (targetRoute: string) => void;
17
19
  }
@@ -1,3 +1,3 @@
1
1
  import { HeaderProps } from './Header.types';
2
- export declare const Header: ({ menuList, actionButton, logout, homeUrl, profileUrl }: HeaderProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const Header: ({ menuList, actionButton, logout, homeUrl, profileUrl, onLeavingPage }: HeaderProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Header;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/component-library",
3
- "version": "1.1.64",
3
+ "version": "1.1.66",
4
4
  "private": false,
5
5
  "main": "dist/bundle.js",
6
6
  "typings": "./dist/types/index",
@@ -20,18 +20,22 @@ const mockMenu = [
20
20
  {
21
21
  name: "Ciclos de Avaliação",
22
22
  action: () => mockAction(),
23
+ targetRoute: "cycleslist",
23
24
  },
24
25
  {
25
26
  name: "Questionários",
26
27
  action: () => mockAction(),
28
+ targetRoute: "questionanaire",
27
29
  },
28
30
  {
29
31
  name: "Análises",
30
32
  action: () => mockAction(),
33
+ targetRoute: "analyse",
31
34
  },
32
35
  {
33
36
  name: "Relatórios",
34
37
  action: () => mockAction(),
38
+ targetRoute: "reports",
35
39
  dropdownMenu: [
36
40
  ]
37
41
  }
@@ -1,6 +1,7 @@
1
1
  export interface MenuItem {
2
2
  name: string;
3
3
  action: () => void;
4
+ targetRoute?: string;
4
5
  dropdownMenu?: MenuItem[];
5
6
  }
6
7
 
@@ -14,6 +15,7 @@ export interface HeaderProps {
14
15
  actionButton?: actionButton;
15
16
  menuList?: MenuItem[];
16
17
  logout?: () => void;
17
- homeUrl?: string;
18
- profileUrl?: string;
18
+ homeUrl: string;
19
+ profileUrl: string;
20
+ onLeavingPage?: (targetRoute: string) => void;
19
21
  }
@@ -6,14 +6,14 @@ import classNames from 'classnames';
6
6
  import { HeaderProps, MenuItem } from './Header.types';
7
7
  import { getMenuTopList, getMenuBottomList } from './Header.data';
8
8
 
9
- export const Header = ({ menuList, actionButton, logout, homeUrl, profileUrl }: HeaderProps) => {
9
+ export const Header = ({ menuList, actionButton, logout, homeUrl, profileUrl, onLeavingPage }: HeaderProps) => {
10
10
  const [isMenuOpen, setIsMenuOpen] = useState(false);
11
11
  const [activeDropdown, setActiveDropdown] = useState<number | null>(null);
12
12
  const headerRef = useRef<HTMLDivElement>(null);
13
13
  const overlayRef = useRef<HTMLDivElement>(null);
14
14
 
15
15
  const onLogout = () => {
16
- if(logout) {
16
+ if( logout ) {
17
17
  logout();
18
18
  } else {
19
19
  onHome();
@@ -21,19 +21,11 @@ export const Header = ({ menuList, actionButton, logout, homeUrl, profileUrl }:
21
21
  };
22
22
 
23
23
  const onProfile = () => {
24
- if(profileUrl) {
25
- window.location.href = profileUrl;
26
- } else {
27
- window.location.reload();
28
- }
24
+ window.location.href = profileUrl;
29
25
  };
30
26
 
31
27
  const onHome = () => {
32
- if(homeUrl) {
33
- window.location.href = homeUrl;
34
- } else {
35
- window.location.reload();
36
- }
28
+ window.location.href = homeUrl;
37
29
  };
38
30
 
39
31
  const menuTopList = getMenuTopList(
@@ -68,15 +60,21 @@ export const Header = ({ menuList, actionButton, logout, homeUrl, profileUrl }:
68
60
  >
69
61
  <div
70
62
  className={styles.listName}
71
- onClick={() => link.action()}
63
+ onClick={() => {
64
+ if (onLeavingPage && link.targetRoute) {
65
+ onLeavingPage(link.targetRoute);
66
+ } else {
67
+ link.action();
68
+ }
69
+ }}
72
70
  >
73
71
  {link.name}
74
72
  {
75
- link.dropdownMenu && link.dropdownMenu.length > 0 && <div className={ styles.arrow } onClick={ (event) => handleDropdownClick(event, index) }>
73
+ link.dropdownMenu && link.dropdownMenu.length > 0 && <div className={styles.arrow} onClick={(event) => handleDropdownClick(event, index)}>
76
74
  {
77
- activeDropdown === index ?
78
- <MinusOutlined className={styles.arrowIcon } /> :
79
- <PlusOutlined className={styles.arrowIcon } />
75
+ activeDropdown === index ?
76
+ <MinusOutlined className={styles.arrowIcon} /> :
77
+ <PlusOutlined className={styles.arrowIcon} />
80
78
  }
81
79
  </div>
82
80
  }
@@ -86,7 +84,13 @@ export const Header = ({ menuList, actionButton, logout, homeUrl, profileUrl }:
86
84
  className={styles.dropdownMenu}
87
85
  >
88
86
  {link.dropdownMenu.map((dropdownLink) => (
89
- <li key={dropdownLink.name} onClick={dropdownLink.action} className={styles.listItem}>
87
+ <li key={dropdownLink.name} onClick={() => {
88
+ if (onLeavingPage && dropdownLink.targetRoute) {
89
+ onLeavingPage(dropdownLink.targetRoute);
90
+ } else {
91
+ dropdownLink.action();
92
+ }
93
+ }} className={styles.listItem}>
90
94
  <div className={styles.listName}>{dropdownLink.name}</div>
91
95
  </li>
92
96
  ))}