-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
106 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createContext, useContext } from 'react'; | ||
|
||
export type SessionData = { | ||
userId: number; | ||
[key: string]: unknown; | ||
}; | ||
|
||
const SessionContext = createContext<SessionData | null>(null); | ||
|
||
export const { Provider: SessionProvider } = SessionContext; | ||
|
||
export const useSession = () => useContext(SessionContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,40 @@ | ||
import { faArrowRightFromBracket as faLogout, faChevronDown as arrowIcon } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { Link } from '@remix-run/react'; | ||
import { useToggle } from '@shlinkio/shlink-frontend-kit'; | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import { Navbar, NavbarBrand } from 'reactstrap'; | ||
import { Collapse, Nav, Navbar, NavbarBrand, NavbarToggler, NavItem, NavLink } from 'reactstrap'; | ||
import { useSession } from '../auth/session-context'; | ||
import { ShlinkLogo } from './ShlinkLogo'; | ||
|
||
export const MainHeader: FC = () => ( | ||
<Navbar color="primary" dark fixed="top" className="main-header" expand="md"> | ||
<NavbarBrand tag={Link} to="/"> | ||
<ShlinkLogo className="tw-inline-block tw-mr-1 tw-w-[26px]" color="white" /> Shlink | ||
</NavbarBrand> | ||
</Navbar> | ||
); | ||
export const MainHeader: FC = () => { | ||
const session = useSession(); | ||
const [isOpen, toggleCollapse] = useToggle(); | ||
|
||
return ( | ||
<Navbar color="primary" dark fixed="top" className="main-header" expand="md"> | ||
<NavbarBrand tag={Link} to="/"> | ||
<ShlinkLogo className="tw-inline-block tw-mr-1 tw-w-[26px]" color="white" /> Shlink | ||
</NavbarBrand> | ||
|
||
{session !== null && ( | ||
<> | ||
<NavbarToggler onClick={toggleCollapse}> | ||
<FontAwesomeIcon icon={arrowIcon} /> | ||
</NavbarToggler> | ||
|
||
<Collapse navbar isOpen={isOpen}> | ||
<Nav navbar className="tw-ml-auto"> | ||
<NavItem> | ||
<NavLink tag={Link} to="/logout"> | ||
<FontAwesomeIcon icon={faLogout} className="tw-w-[26px] tw-inline-block" /> Logout | ||
</NavLink> | ||
</NavItem> | ||
</Nav> | ||
</Collapse> | ||
</> | ||
)} | ||
</Navbar> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { ActionFunctionArgs } from '@remix-run/node'; | ||
import { Authenticator } from 'remix-auth'; | ||
import { serverContainer } from '../container/container.server'; | ||
|
||
export function loader( | ||
{ request }: ActionFunctionArgs, | ||
authenticator: Authenticator = serverContainer[Authenticator.name], | ||
) { | ||
return authenticator.logout(request, { redirectTo: '/login' }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters