Skip to content

Commit

Permalink
chore(links): fix app links
Browse files Browse the repository at this point in the history
  • Loading branch information
anteqkois committed May 26, 2024
1 parent 82af27f commit 07f0c1a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
14 changes: 9 additions & 5 deletions apps/web/app/(landing)/components/LandingNavButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ import { cn } from '@linkerry/ui-components/utils'
import { useEffect, useState } from 'react'
import { useUser } from '../../../modules/user/useUser'

interface MainNavProps {}

export function LandingNavButtons() {
const { authStatus, logout } = useUser()
const [logoutButton, setLogoutButton] = useState(false)

useEffect(() => {
if (authStatus === AuthStatus.AUTHENTICATED) setLogoutButton(true)
else setLogoutButton(false)
}, [authStatus])

return (
<>
{logoutButton ? (
<Button variant={'outline'} size={'sm'} className="px-4" onClick={logout}>
logout
</Button>
<>
<Button variant={'outline'} size={'sm'} className="px-4" onClick={() => logout({ withRedirect: false })}>
logout
</Button>
<Link href="/app/dashboard" className={cn(buttonVariants({ size: 'sm' }), 'px-4')}>
Dashboard
</Link>
</>
) : (
<>
<Link href="/login" className={cn(buttonVariants({ size: 'sm', variant: 'outline' }), 'px-4')}>
Expand Down
2 changes: 0 additions & 2 deletions apps/web/app/(landing)/components/MianNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { Button, Icons } from '@linkerry/ui-components/server'
// import { useClickOutside } from '@react-hookz/web'
import { useRef, useState } from 'react'
import { useUser } from '../../../modules/user/useUser'
import { MainNavItem } from '../../../types'
import { LandingNavButtons } from './LandingNavButtons'
import { MenuItem } from './MenuItem'
Expand All @@ -29,7 +28,6 @@ interface MainNavProps {

export function MainNav({ items, children }: MainNavProps) {
// const segment = useSelectedLayoutSegment()
const { authStatus, logout } = useUser()
const [showMobileMenu, setShowMobileMenu] = useState(false)
const ref = useRef(null)

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/app/components/LogoutDropDownMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function LogoutDropDownMenuItem() {
const { logout } = useUser()

return (
<DropdownMenuItem onClick={logout}>
<DropdownMenuItem onClick={() => logout()}>
Log out
<DropdownMenuShortcut>
<Icons.Exit />
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default function Page() {
<H5 className="mb-2 pl-1">Dashboard</H5>
<div className="flex gap-2 flex-grow sm:flex-grow-0">
<Link href="/app/connectors">
<Button className="flex-grow" variant={'secondary'}>
<Button className="flex-grow" variant={'outline'}>
Connectors
</Button>
</Link>
<Link href="/app/flows">
<Button className="flex-grow" variant={'secondary'}>
<Button className="flex-grow" variant={'outline'}>
Flows
</Button>
</Link>
Expand Down
16 changes: 12 additions & 4 deletions apps/web/modules/user/useUser.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import { AuthStatus, Cookies, IAuthLogoutResponse, LoginInput, SignUpInput, SignUpResponse, User } from '@linkerry/shared'
import { AuthStatus, Cookies, IAuthLogoutResponse, LoginInput, SignUpInput, SignUpResponse, User, assertNotNullOrUndefined } from '@linkerry/shared'
import { useRouter, useSearchParams } from 'next/navigation'
import { Dispatch, PropsWithChildren, SetStateAction, createContext, useCallback, useContext, useState } from 'react'
import { useCookie } from '../../shared/hooks/useCookie'
Expand All @@ -14,7 +14,7 @@ type ReturnType = {
setUser: Dispatch<SetStateAction<User>>
signUp: (data: SignUpInput) => Promise<SignUpResponse>
login: (data: LoginInput) => Promise<void>
logout: () => Promise<IAuthLogoutResponse>
logout: (data?: { withRedirect?: boolean; redirect?: string }) => Promise<IAuthLogoutResponse>
/* emial verification */
emialVerificationDialog: boolean
setEmailVerificationDialog: Dispatch<SetStateAction<boolean>>
Expand Down Expand Up @@ -57,13 +57,21 @@ export function UserProvider({ children }: PropsWithChildren) {
return push('/app/dashboard')
}, [])

const logout = useCallback(async () => {
const logout = useCallback(async (data?: { withRedirect?: boolean; redirect?: string }) => {
if (typeof data?.withRedirect !== 'boolean') data = { ...data, withRedirect: true }
if (typeof data?.redirect !== 'string') data = { ...data, redirect: '/' }

assertNotNullOrUndefined(data.redirect, 'data.redirect')
assertNotNullOrUndefined(data.withRedirect, 'data.withRedirect')

// const { withRedirect, redirect } = data
const response = await AuthApi.logout()

setUser({} as User)
setAuthStatus(AuthStatus.UNAUTHENTICATED)
// if(response.data.error) // TODO handle error
push('/')

if (data.withRedirect) push(data.redirect)

return response.data
}, [])
Expand Down

0 comments on commit 07f0c1a

Please sign in to comment.