Skip to content

Commit

Permalink
Merge pull request #60 from penguinsufcg/feat/edit-screen
Browse files Browse the repository at this point in the history
Add logout feature
  • Loading branch information
thayannevls authored Feb 2, 2022
2 parents 2dec13a + 4324445 commit d37efdc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/components/Session/SessionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ function SessionProvider({ children }: SessionContextProps): JSX.Element {
router.push('/logout')
}

const logout = () => {
setSessionId(undefined)
setSession(null)
setSessionRef(null)
}

const getSessionLocal = () => {
const sessionId = localStorage.getItem('sessionId')

Expand Down Expand Up @@ -120,6 +126,7 @@ function SessionProvider({ children }: SessionContextProps): JSX.Element {
isLoading,
createNewSession,
joinSession,
logout,
}),
[session, sessionRef, sessionId, isLoading],
)
Expand Down
11 changes: 7 additions & 4 deletions src/components/client/Navbar/components/NavbarOption.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Button } from "@chakra-ui/react"
import Link from "next/link"
import React, { ReactElement } from "react"
import { Button } from '@chakra-ui/react'
import Link from 'next/link'
import React, { ReactElement } from 'react'

type NavbarOptionProps = {
isSelected?: boolean
onClick?: () => void
href: string
icon: ReactElement
}
Expand All @@ -12,11 +13,13 @@ const NavbarOption = ({
href,
icon,
isSelected = false,
onClick,
}: NavbarOptionProps) => (
<Link href={href} passHref>
<Button
variant="ghost"
size="sm"
onClick={onClick}
color={isSelected ? 'primary.400' : 'secondary.400'}
sx={{
boxSize: 10,
Expand All @@ -31,4 +34,4 @@ const NavbarOption = ({
</Link>
)

export default NavbarOption
export default NavbarOption
16 changes: 9 additions & 7 deletions src/components/client/Navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import useSession from "@/hooks/useSession"
import { Flex } from "@chakra-ui/react"
import React from "react"
import { BiHome, BiCartAlt, BiReceipt } from "react-icons/bi"
import NavbarOption from "./components/NavbarOption"
import useSession from '@/hooks/useSession'
import { Flex } from '@chakra-ui/react'
import React from 'react'
import { BiHome, BiCartAlt, BiReceipt, BiLogOut } from 'react-icons/bi'
import NavbarOption from './components/NavbarOption'

const Navbar = () => {
const { underPayment } = useSession()
const { logout, underPayment } = useSession()

return (
<Flex justifyContent="space-around">
<NavbarOption isSelected icon={<BiHome size={24} />} href="/" />
<NavbarOption icon={<BiCartAlt size={24} />} href="/cart" />
<NavbarOption icon={<BiReceipt size={24} />} href={underPayment ? "/bill" : "/receipt"} />
<NavbarOption icon={<BiLogOut size={24} />} href="/" onClick={logout} />
</Flex>
)
}

export default Navbar
export default Navbar
7 changes: 6 additions & 1 deletion src/hooks/useSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ type SessionContextProps = {
sessionRef?: Reference<Session> | null
isLogged: boolean
underPayment: boolean
createNewSession?: (params: { table: string, client: string }) => Promise<string>
createNewSession?: (params: {
table: string
client: string
}) => Promise<string>
joinSession?: (params: { sessionId: string }) => void
logout: () => void
}

export const SessionContext: Context<SessionContextProps> =
Expand All @@ -17,6 +21,7 @@ export const SessionContext: Context<SessionContextProps> =
isLogged: false,
underPayment: false,
isLoading: false,
logout: () => {},
})

const useSession = (): SessionContextProps => {
Expand Down

0 comments on commit d37efdc

Please sign in to comment.