1- import React , { useState } from ' react' ;
2- import { Navbar , Nav , NavDropdown , Container , Dropdown } from ' react-bootstrap' ;
3- import styles from ' ../styles/Menubar.module.css' ;
4- import { RocketChatAuthMenuButton } from ' ./auth/rocketchat' ;
1+ import React , { useState } from " react" ;
2+ import { Navbar , Nav , NavDropdown , Container , Dropdown } from " react-bootstrap" ;
3+ import styles from " ../styles/Menubar.module.css" ;
4+ import { RocketChatAuthMenuButton } from " ./auth/rocketchat" ;
55import BrandLogo from "./brandlogo" ;
6- import RocketChatLinkButton from './rocketchatlinkbutton' ;
7- import Cookies from 'js-cookie' ;
8- import Link from 'next/link'
6+ import RocketChatLinkButton from "./rocketchatlinkbutton" ;
7+ import Cookies from "js-cookie" ;
8+ import Link from "next/link" ;
9+ import { DummyLoginButton } from "./auth/dummy" ;
910
1011const CustomToggle = React . forwardRef ( ( { children, onClick } , ref ) => (
1112 < a
1213 className = { styles . elipses }
1314 href = ""
1415 ref = { ref }
15- onClick = { e => {
16+ onClick = { ( e ) => {
1617 e . preventDefault ( ) ;
1718 onClick ( e ) ;
1819 } }
@@ -24,28 +25,36 @@ const CustomToggle = React.forwardRef(({ children, onClick }, ref) => (
2425
2526export default function Menubar ( props ) {
2627 const [ collapsed , setCollapsed ] = useState ( true ) ;
27-
28+ const userCookie = Cookies . get ( "user" ) ;
29+ const hasAllRequiredCreds =
30+ process . env . NEXTAUTH_URL &&
31+ process . env . ROCKETCHAT_CLIENT_ID &&
32+ process . env . ROCKETCHAT_CLIENT_SECRET &&
33+ process . env . ROCKETCHAT_URL ;
34+ if ( ! hasAllRequiredCreds ) console . log ( "RC4Community is now using a dummy Auth Component! If you wish to use a robust Auth component, provide all the credentials first (https://github.com/RocketChat/RC4Community/tree/master/app/components/auth)" )
2835 return (
29- < Container fluid className = 'border-bottom ' >
30- < Navbar expand = 'lg' className = ' bg-white mx-4 my-2' >
31- < BrandLogo
32- brandLink = { '/' }
33- logoLink = { 'https://global-uploads.webflow.com/611a19b9853b7414a0f6b3f6/611bbb87319adfd903b90f24_logoRC.svg' }
34- imageTitle = { 'Rocket.Chat' }
35- brandName = { 'Rocket.Chat Community' }
36+ < Container fluid className = "border-bottom " >
37+ < Navbar expand = "lg" className = " bg-white mx-4 my-2" >
38+ < BrandLogo
39+ brandLink = { "/" }
40+ logoLink = {
41+ "https://global-uploads.webflow.com/611a19b9853b7414a0f6b3f6/611bbb87319adfd903b90f24_logoRC.svg"
42+ }
43+ imageTitle = { "Rocket.Chat" }
44+ brandName = { "Rocket.Chat Community" }
3645 height = { 21 }
3746 width = { 124 }
3847 />
3948 < Navbar . Toggle
40- aria-controls = 'basic-navbar-nav'
41- className = { styles . default_toggler + " ms-auto" }
49+ aria-controls = "basic-navbar-nav"
50+ className = { styles . default_toggler + " ms-auto" }
51+ onClick = { ( ) => {
52+ setCollapsed ( ! collapsed ) ;
53+ } }
4254 >
4355 < button
4456 className = { `${ styles . navbar_toggler } navbar-toggler collapsed d-flex d-lg-none flex-column justify-content-around bg-white` }
45- type = 'button'
46- onClick = { ( ) => {
47- setCollapsed ( ! collapsed ) ;
48- } }
57+ type = "button"
4958 >
5059 < span
5160 className = { `${ styles . toggler_icon } ${
@@ -54,16 +63,16 @@ export default function Menubar(props) {
5463 />
5564 </ button >
5665 </ Navbar . Toggle >
57- < Navbar . Collapse id = ' basic-navbar-nav' >
58- < Nav className = ' mx-auto' >
59- { props . menu ?. data ?. attributes ?. body ?. map ( ( item , index ) => {
66+ < Navbar . Collapse id = " basic-navbar-nav" >
67+ < Nav className = " mx-auto" >
68+ { props . menu ?. data ?. attributes ?. body ?. map ( ( item , index ) => {
6069 return item . sub_menus && item ?. sub_menus ?. data ?. length ? (
6170 < NavDropdown
62- key = { item . id || item . _id || `NavDropDown_${ index } ` }
71+ key = { `NavDropDown_${ index } ` }
6372 title = { item . label }
6473 className = { `ml-4 fw-normal ${ styles . navbarItem } ` }
6574 >
66- { item . sub_menus . data . map ( ( sub , index ) => (
75+ { item . sub_menus . data . map ( ( sub , index ) => (
6776 < NavDropdown . Item
6877 key = { sub . id || sub . _id || `NavDropDownItem_${ index } ` }
6978 href = { sub . attributes . url }
@@ -73,33 +82,43 @@ export default function Menubar(props) {
7382 ) ) }
7483 </ NavDropdown >
7584 ) : (
76- < Nav . Link href = { item . url } className = 'fw-normal' key = { item . id || item . _id || `NavLink_${ index } ` } >
85+ < Nav . Link
86+ href = { item . url }
87+ className = "fw-normal"
88+ key = { item . id || item . _id || `NavLink_${ index } ` }
89+ >
7790 { item . label }
7891 </ Nav . Link >
7992 ) ;
8093 } ) }
8194 </ Nav >
82- < RocketChatLinkButton className = { `bg-danger bg-gradient p-2 text-white ${ styles . chat } ` } >
95+ < RocketChatLinkButton
96+ className = { `bg-danger bg-gradient p-2 text-white ${ styles . chat } ` }
97+ >
8398 Click to Chat
8499 </ RocketChatLinkButton >
85100 </ Navbar . Collapse >
86101 < div className = "mx-3" >
87- { Cookies . get ( 'user' ) ?
88- < Dropdown
89- align = "end"
90- className = { styles . dropdown_menu } >
91- < Dropdown . Toggle as = { CustomToggle } / >
92- < Dropdown . Menu size = "sm" title = "" >
93- < Dropdown . Header > RC4Community Profile </ Dropdown . Header >
94- < Dropdown . Item > < Link href = { `/profile/ ${ Cookies . get ( 'user' ) } ` } > < a className = { styles . dropdown_menu_item } > Profile</ a > </ Link > </ Dropdown . Item >
95- </ Dropdown . Menu >
96- </ Dropdown >
97- :
98- ""
99- }
100- </ div >
102+ { userCookie && (
103+ < Dropdown align = "end" className = { styles . dropdown_menu } >
104+ < Dropdown . Toggle as = { CustomToggle } />
105+ < Dropdown . Menu size = "sm" title = "" >
106+ < Dropdown . Header > RC4Community Profile </ Dropdown . Header >
107+ < Dropdown . Item >
108+ < Link href = { `/profile/ ${ userCookie } ` } >
109+ < a className = { styles . dropdown_menu_item } > Profile</ a >
110+ </ Link >
111+ </ Dropdown . Item >
112+ </ Dropdown . Menu >
113+ </ Dropdown >
114+ ) }
115+ </ div >
101116 < div className = "mx-2" >
102- < RocketChatAuthMenuButton />
117+ { hasAllRequiredCreds ? (
118+ < RocketChatAuthMenuButton />
119+ ) : (
120+ < DummyLoginButton />
121+ ) }
103122 </ div >
104123 </ Navbar >
105124 </ Container >
0 commit comments