Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TICKET 2] 🚀 update project to nextjs13 #5

Merged
merged 4 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// / <reference types="next" />
// / <reference types="next/types/global" />
// / <reference types="next/image-types/global" />
// / <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
10 changes: 0 additions & 10 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,4 @@ module.exports = {
images: {
domains: ['i.imgur.com', 'www.google.com', 'imgur.com'],
},
webpack: config => {
config.module.rules.push({
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
})

return config
},
webpackDevMiddleware: config => config,
}
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"postinstall": "husky install"
},
"dependencies": {
"@chakra-ui/icons": "^1.0.15",
"@chakra-ui/react": "^1.6.7",
"@chakra-ui/theme-tools": "^1.2.0",
"@chakra-ui/icons": "^2.0.19",
"@chakra-ui/next-js": "^2.1.3",
"@chakra-ui/react": "^2.0.0",
"@chakra-ui/theme-tools": "^2.0.16",
"@emotion/react": "^11.4.1",
"@emotion/styled": "^11.3.0",
"@fontsource/inter": "^4.5.14",
Expand All @@ -21,25 +22,26 @@
"graphql-tag": "^2.12.5",
"jsonwebtoken": "^8.5.1",
"mongodb": "^4.1.2",
"next": "latest",
"next-auth": "^3.29.0",
"next": "13.4.2",
"next-auth": "^4.22.1",
"react": "^18.1.0",
"react-dom": "^17.0.2",
"react-dom": "^18.1.0",
"react-hook-form": "^7.15.3",
"react-query": "^3.23.2",
"react-query": "^3.39.3",
"react-table": "^7.7.0"
},
"devDependencies": {
"@next/eslint-plugin-next": "^11.1.2",
"@next/eslint-plugin-next": "^13.4.3",
"@types/jsonwebtoken": "^8.5.5",
"@types/node": "14.14.35",
"@types/react": "^17.0.21",
"@types/react-dom": "^17.0.9",
"@types/react": "^18.1.0",
"@types/react-dom": "^18.1.0",
"@types/react-table": "^7.7.3",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"encoding": "^0.1.13",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary?

Copy link
Collaborator Author

@czhoffmann23 czhoffmann23 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"eslint": "^7.32.0",
"eslint-config-next": "^11.1.2",
"eslint-config-next": "^13.4.2",
"eslint-config-prettier": "^8.3.0",
"eslint-config-rokket-labs": "^0.4.5",
"eslint-plugin-import": "^2.24.2",
Expand All @@ -48,7 +50,7 @@
"husky": "^7.0.2",
"lint-staged": "^11.1.2",
"prettier": "^2.4.1",
"typescript": "^4.4.3"
"typescript": "^5.0.4"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

},
"lint-staged": {
"*.{ts,tsx,js,jsx}": [
Expand Down
14 changes: 14 additions & 0 deletions src/app/api/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client'
import { Flex } from '@chakra-ui/react'

import RenderCards from 'screens/apiexample/RenderCards'

const ApiExample = () => {
return (
<Flex w="100%" flexDir="column">
<RenderCards />
</Flex>
)
}

export default ApiExample
4 changes: 2 additions & 2 deletions src/pages/crud/index.tsx → src/app/crud/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client'
import { Flex, useDisclosure } from '@chakra-ui/react'
import { NextPage } from 'next'

import { RenderDataTable } from 'screens/crud/RenderDataTable'
import RenderHeader from 'screens/crud/RenderHeader'
import RenderModal from 'screens/crud/RenderModal'

const Crud: NextPage = () => {
const Crud = () => {
const { isOpen, onOpen, onClose } = useDisclosure()

return (
Expand Down
Binary file added src/app/favicon.ico
Binary file not shown.
File renamed without changes.
28 changes: 28 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// import AuthContext from 'context/AuthContext'
import { ChakraCustomContextProvider } from 'context/ChakraCustomContext'
import { ReactQueryCustomContextProvider } from 'context/ReactQueryCustomContext'
import { LayoutComponent } from 'layoutcomponent'

// import { headers } from 'next/dist/client/components/headers'
// import getSession from 'lib/getSessionAuth'
import './global.css'

const RootLayout = async ({ children }: { children: React.ReactNode }) => {
// const session = await getSession(headers().get('cookie') ?? '')

return (
<html lang="en">
<body>
<ChakraCustomContextProvider>
{/* <AuthContext session={session}> */}
<ReactQueryCustomContextProvider>
<LayoutComponent>{children}</LayoutComponent>
</ReactQueryCustomContextProvider>
{/* </AuthContext> */}
</ChakraCustomContextProvider>
</body>
</html>
)
}

export default RootLayout
20 changes: 20 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'
import { Flex } from '@chakra-ui/react'

// import { useSession } from 'next-auth/client'
import RenderCards from 'screens/home/RenderCards'
// import RenderFooter from 'screens/home/RenderFooter'

const Index = () => {
// const [session] = useSession()

return (
<Flex w="100%" flexDir="column">
<RenderCards />
<br />
{/* <RenderFooter session={session} /> */}
</Flex>
)
}

export default Index
1 change: 0 additions & 1 deletion src/assets/svg/GithubLogo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const GithubLogo: React.FC = () => {
version="1.1"
width="20"
data-view-component="true"
className="octicon octicon-mark-github v-align-middle"
>
<path
fillRule="evenodd"
Expand Down
13 changes: 13 additions & 0 deletions src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client'

import { Session } from 'next-auth'
import { SessionProvider } from 'next-auth/react'

export interface AuthContextProps {
children: React.ReactNode
session: Session
}

export default function AuthContext({ children }: AuthContextProps) {
return <SessionProvider>{children}</SessionProvider>
}
17 changes: 17 additions & 0 deletions src/context/ChakraCustomContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client'

import { CacheProvider } from '@chakra-ui/next-js'
import { ChakraProvider } from '@chakra-ui/react'
import theme from 'theme/theme'

export const ChakraCustomContextProvider: React.FC<{
children: React.ReactNode
}> = ({ children }) => {
return (
<CacheProvider>
<ChakraProvider resetCSS theme={theme}>
{children}
</ChakraProvider>
</CacheProvider>
)
}
32 changes: 32 additions & 0 deletions src/context/ReactQueryCustomContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
'use client'

import { useState } from 'react'
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query'
import { useToast } from '@chakra-ui/react'

import { queryClient } from 'lib/queryClient'

export const ReactQueryCustomContextProvider = ({
children,
}: {
children: any
}) => {
const toast = useToast()
const [client] = useState(
new QueryClient({
...queryClient,
queryCache: new QueryCache({
onError: (error, query) => {
if (query.state.data !== undefined)
toast({
title: `${(error as any).message} toast`,
status: 'error',
})
},
}),
}),
)

return <QueryClientProvider client={client}>{children}</QueryClientProvider>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useQueryClient } from 'react-query'
// import { useQueryClient } from 'react-query'
import { HamburgerIcon } from '@chakra-ui/icons'
import {
Box,
Expand All @@ -10,29 +10,29 @@ import {
DrawerOverlay,
Flex,
IconButton,
Spinner,
// Spinner,
useBreakpointValue,
useDisclosure,
} from '@chakra-ui/react'
import { useRouter } from 'next/dist/client/router'
import { signIn, signOut, useSession } from 'next-auth/client'
import { useRouter } from 'next/navigation'

// import { signIn, signOut, useSession } from 'next-auth/client'
import { GithubLogo } from 'assets/svg'

export const NavigationButtons: React.FC = () => {
const queryClient = useQueryClient()
const [session, loading] = useSession()
// const queryClient = useQueryClient()
// const [session, loading] = useSession()
const { isOpen, onOpen, onClose } = useDisclosure()
const router = useRouter()
const isMobile = useBreakpointValue({ base: true, sm: true, md: false })

const renderAuthButton = () => {
const buttonText = session ? 'Sign Out' : 'Sign In'
// const buttonText = session ? 'Sign Out' : 'Sign In'

const signOutAndClearData = async () => {
await signOut()
queryClient.clear()
}
// const signOutAndClearData = async () => {
// // await signOut()
// queryClient.clear()
// }

return (
<Box flexGrow={3} mx={2}>
Expand All @@ -41,9 +41,9 @@ export const NavigationButtons: React.FC = () => {
variant="custom-button"
leftIcon={<GithubLogo />}
colorScheme="green"
onClick={() => (session ? signOutAndClearData() : signIn())}
// onClick={() => (session ? signOutAndClearData() : signIn())}
>
{loading ? <Spinner /> : buttonText}
{/* {loading ? <Spinner /> : buttonText} */}
</Button>
</Box>
)
Expand All @@ -70,16 +70,16 @@ export const NavigationButtons: React.FC = () => {
</Button>
<Button
width="100%"
onClick={() => handleRoute(`launches`)}
onClick={() => handleRoute(`api`)}
variant="custom-ghost"
mt={['0.5rem', '0.5rem', '0']}
color="white"
>
Launches
Api
</Button>

<Button
onClick={() => handleRoute(`/crud`)}
onClick={() => handleRoute(`crud`)}
width="100%"
variant="custom-ghost"
mt={['0.5rem', '0.5rem', '0']}
Expand All @@ -93,7 +93,7 @@ export const NavigationButtons: React.FC = () => {

return (
<Flex alignItems="center" h="100%" py={2}>
<Flex d={['flex', 'flex', 'none']}>
<Flex display={['flex', 'flex', 'none']}>
<IconButton
colorScheme="dark"
aria-label="hamburguer"
Expand All @@ -111,7 +111,7 @@ export const NavigationButtons: React.FC = () => {
</DrawerOverlay>
</Drawer>
</Flex>
<Flex d={['none', 'none', 'flex']}>{renderContent()}</Flex>
<Flex display={['none', 'none', 'flex']}>{renderContent()}</Flex>
</Flex>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Flex, Text, useBreakpointValue } from '@chakra-ui/react'
import { useRouter } from 'next/dist/client/router'
import { useRouter } from 'next/navigation'

import { DrimoLogo } from 'assets/svg'

Expand Down
5 changes: 4 additions & 1 deletion src/layout/index.tsx → src/layoutcomponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use client'
import { Box, Flex } from '@chakra-ui/react'
import { AnimateSharedLayout } from 'framer-motion'

import { NavigationButtons } from './NavigationButtons'
import { NavigationLogo } from './NavigationLogo'

export const Layout: React.FC = ({ children }) => {
export const LayoutComponent: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
return (
<AnimateSharedLayout>
<Flex position="relative" w="100%" h="100%">
Expand Down
16 changes: 16 additions & 0 deletions src/lib/getSessionAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const getSession = async (cookie: string) => {
const response = await fetch(
`${process.env.LOCAL_AUTH_URL ?? 'http://localhost:3000'}/api/auth/session`,
{
headers: {
cookie,
},
},
)

const session = await response.json()

return Object.keys(session).length > 0 ? session : null
}

export default getSession
7 changes: 3 additions & 4 deletions src/lib/queryClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { QueryClient } from 'react-query'
import { GraphQLClient } from 'graphql-request'

const graphqlUrl =
process.env.NEXT_PUBLIC_API_URL ?? 'https://api.spacex.land/graphql/'
process.env.NEXT_PUBLIC_API_URL ?? 'https://rickandmortyapi.com/graphql'

export const graphqlClient = async () => {
// Uncomment if you need to get a token
Expand All @@ -17,12 +16,12 @@ export const graphqlClient = async () => {
return client
}

export const queryClient = new QueryClient({
export const queryClient = {
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
refetchOnReconnect: false,
retry: false,
},
},
})
}
Loading