-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from TIHLDE/dev
Merge dev into main
- Loading branch information
Showing
54 changed files
with
4,296 additions
and
269 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2022: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'next/core-web-vitals', | ||
'plugin:react/recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 13, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['react', '@typescript-eslint'], | ||
rules: { | ||
'react/react-in-jsx-scope': 'off', | ||
'@next/next/no-pages-dir': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-unused-vars': 'off', | ||
'@next/next/no-img-element': 'off', | ||
'@typescript-eslint/ban-types': 'off', | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["@/app/**/*.{js,jsx,ts,tsx}"], | ||
}, | ||
], | ||
}; |
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,19 @@ | ||
name: Continuous Integration | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint-and-format: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '20' | ||
|
||
- run: npm install | ||
|
||
- name: Run Prettier | ||
run: npm run prettier |
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,7 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"tabWidth": 2 | ||
} |
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,50 @@ | ||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { getClientCookie } from '@/app/utils/stores/cookieStore'; | ||
|
||
const API_URL = process.env.VITE_API_URL || 'http://localhost:8000/'; | ||
|
||
interface IFetchOptions extends Omit<AxiosRequestConfig, 'url'> { | ||
withAuth?: boolean; | ||
file?: File | File[] | Blob; | ||
} | ||
|
||
export const IFetch = async <T = any>( | ||
endpoint: string, | ||
options?: IFetchOptions, | ||
): Promise<T> => { | ||
const headers: Record<string, string> = {}; | ||
|
||
if (options?.withAuth) { | ||
const token = getClientCookie('tokenDrinking'); | ||
if (token) { | ||
headers.Authorization = `Bearer ${token}`; | ||
} | ||
} | ||
|
||
if (!options?.file) { | ||
headers['Content-Type'] = 'application/json'; | ||
} | ||
|
||
const config: AxiosRequestConfig = { | ||
url: `${API_URL}${endpoint}`, | ||
...options, | ||
}; | ||
|
||
config.headers = { ...headers, ...(options?.headers ?? {}) }; | ||
|
||
if (options?.file) { | ||
const formData = new FormData(); | ||
|
||
if (Array.isArray(options.file)) { | ||
options.file.forEach((file) => formData.append('file', file)); | ||
} else { | ||
formData.append('file', options.file); | ||
} | ||
|
||
config.data = formData; | ||
config.headers['Content-Type'] = 'multipart/form-data'; | ||
} | ||
|
||
const response: AxiosResponse<T> = await axios(config); | ||
return response.data; | ||
}; |
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,28 @@ | ||
import { IFetch } from '@/app/api/fetch'; | ||
|
||
const API_URL = 'http://localhost:8000/'; | ||
const AUTH_ENDPOINT = 'auth'; | ||
|
||
interface LoginRequestResponse { | ||
token?: string; | ||
user?: any; | ||
} | ||
|
||
export const authenticate = async ( | ||
username: string, | ||
password: string, | ||
): Promise<LoginRequestResponse> => { | ||
const endpoint = `${AUTH_ENDPOINT}/login/`; | ||
|
||
const data = { | ||
user_id: username, | ||
password: password, | ||
}; | ||
|
||
const response = await IFetch<LoginRequestResponse>(endpoint, { | ||
method: 'POST', | ||
data: data, | ||
}); | ||
|
||
return response; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react"; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faCog } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
export default function Loading() { | ||
return ( | ||
<div className="flex flex-col"> | ||
<div className="flex flex-col justify-center items-center h-screen"> | ||
<FontAwesomeIcon | ||
icon={faCog} | ||
className="text-primary w-[100px] animate-spin" | ||
/> | ||
<p className="text-2xl mt-4">Please wait while it is loading..</p> | ||
</div> | ||
</div> | ||
); | ||
} |
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,18 @@ | ||
import { useState, useCallback } from 'react'; | ||
import { authenticate } from '@/app/api/user'; | ||
import { setClientCookie } from '@/app/utils/stores/cookieStore'; | ||
|
||
export const useUser = () => { | ||
const [user, setUser] = useState<any | null>(null); | ||
|
||
const login = useCallback(async (username: string, password: string) => { | ||
const data = await authenticate(username, password); | ||
setUser(data.user); | ||
setClientCookie('tokenDrinking', data.token, { expires: 365 }); | ||
}, []); | ||
|
||
return { | ||
user, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
import './globals.css' | ||
import type { Metadata } from 'next' | ||
import { Inter } from 'next/font/google' | ||
'use client'; | ||
import './globals.css'; | ||
import { Inter } from 'next/font/google'; | ||
import { AuthProvider } from '@/app/user/auth/context/AuthContext'; | ||
|
||
// components | ||
import Navbar from './components/defaults/navbar' | ||
import Footer from './components/defaults/footer' | ||
import Navbar from '../components/layout/navbar'; | ||
import Footer from '../components/layout/footer'; | ||
import { ThemeProvider } from 'next-themes'; | ||
|
||
|
||
const inter = Inter({ subsets: ['latin'] }) | ||
|
||
export const metadata: Metadata = { | ||
title: 'Create Next App', | ||
description: 'Generated by create next app', | ||
} | ||
const inter = Inter({ subsets: ['latin'] }); | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body className={inter.className}> | ||
<Navbar /> | ||
{children} | ||
<Footer /> | ||
<AuthProvider> | ||
<html lang="en"> | ||
<body className={inter.className}> | ||
<ThemeProvider | ||
attribute="class" | ||
defaultTheme="system" | ||
enableSystem | ||
disableTransitionOnChange | ||
> | ||
<Navbar /> | ||
{children} | ||
<Footer /> | ||
</ThemeProvider> | ||
</body> | ||
</html> | ||
) | ||
</html> | ||
</AuthProvider> | ||
); | ||
} |
Oops, something went wrong.