generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into dependabot/npm_and_yarn/next-13.5.0
- Loading branch information
Showing
18 changed files
with
285 additions
and
57 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,28 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import fetchMock from 'jest-fetch-mock'; | ||
import IsAuthenticated from '@/hooks/isAuthenticated'; | ||
import { userData } from '../../fixtures/users'; | ||
|
||
beforeAll(() => { | ||
fetchMock.enableMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
fetchMock.resetMocks(); | ||
}); | ||
|
||
it('should return isLoggedIn as true and userData if the request is successful', async () => { | ||
const userDataMock = userData; | ||
fetchMock.mockResponseOnce(JSON.stringify(userDataMock), { status: 200 }); | ||
const { result, waitForNextUpdate } = renderHook(() => IsAuthenticated()); | ||
await waitForNextUpdate(); | ||
expect(result.current.isLoggedIn).toBe(true); | ||
expect(result.current.userData).toEqual(userDataMock.data); | ||
}); | ||
|
||
it('should return isLoggedIn as false if the request is unsuccessful', async () => { | ||
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 401 }); | ||
const { result } = renderHook(() => IsAuthenticated()); | ||
expect(result.current.isLoggedIn).toBe(false); | ||
expect(result.current.userData).toBeNull(); | ||
}); |
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,13 @@ | ||
export const userData = { | ||
data: { | ||
Id: 1, | ||
Username: 'Sunny Sahsi', | ||
Email: 'sunnysahsi@gmail.com', | ||
Password: '', | ||
IsVerified: false, | ||
IsOnboarding: true, | ||
CreatedAt: '2023-11-04T10:02:26.582699Z', | ||
UpdatedAt: '2023-11-04T10:02:26.582699Z', | ||
}, | ||
message: 'user fetched successfully', | ||
}; |
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,13 @@ | ||
const DownArrow = () => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
className="h-5 w-5 inline-block ml-1 transform group-hover:rotate-180 transition-transform" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
> | ||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" /> | ||
</svg> | ||
); | ||
|
||
export default DownArrow; |
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,23 @@ | ||
const GoogleIcon = () => ( | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="28px" height="28px"> | ||
<title>Google</title> | ||
<path | ||
fill="#fbc02d" | ||
d="M43.611,20.083H42V20H24v8h11.303c-1.649,4.657-6.08,8-11.303,8c-6.627,0-12-5.373-12-12 s5.373-12,12-12c3.059,0,5.842,1.154,7.961,3.039l5.657-5.657C34.046,6.053,29.268,4,24,4C12.955,4,4,12.955,4,24s8.955,20,20,20 s20-8.955,20-20C44,22.659,43.862,21.35,43.611,20.083z" | ||
/> | ||
<path | ||
fill="#e53935" | ||
d="M6.306,14.691l6.571,4.819C14.655,15.108,18.961,12,24,12c3.059,0,5.842,1.154,7.961,3.039 l5.657-5.657C34.046,6.053,29.268,4,24,4C16.318,4,9.656,8.337,6.306,14.691z" | ||
/> | ||
<path | ||
fill="#4caf50" | ||
d="M24,44c5.166,0,9.86-1.977,13.409-5.192l-6.19-5.238C29.211,35.091,26.715,36,24,36 c-5.202,0-9.619-3.317-11.283-7.946l-6.522,5.025C9.505,39.556,16.227,44,24,44z" | ||
/> | ||
<path | ||
fill="#1565c0" | ||
d="M43.611,20.083L43.595,20L42,20H24v8h11.303c-0.792,2.237-2.231,4.166-4.087,5.571 c0.001-0.001,0.002-0.001,0.003-0.002l6.19,5.238C36.971,39.205,44,34,44,24C44,22.659,43.862,21.35,43.611,20.083z" | ||
/> | ||
</svg> | ||
); | ||
|
||
export default GoogleIcon; |
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
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,3 @@ | ||
export const TINY_API_URL = 'https://api-tinysite.onrender.com/v1'; | ||
export const TINY_API_GOOGLE_LOGIN = `${TINY_API_URL}/auth/google/login`; | ||
export const TINY_API_LOGOUT = `${TINY_API_URL}/auth/logout`; |
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 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { TINY_API_URL } from '@/constants/url'; | ||
import { UserTypes } from '@/types/user.types'; | ||
|
||
const IsAuthenticated = () => { | ||
const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
const [userData, setUserData] = useState<UserTypes | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch(`${TINY_API_URL}/users/self`, { | ||
method: 'GET', | ||
credentials: 'include', | ||
}); | ||
if (response.status === 200) { | ||
const userData = await response.json(); | ||
setUserData(userData.data); | ||
setIsLoggedIn(true); | ||
} else { | ||
setIsLoggedIn(false); | ||
} | ||
} catch (err) { | ||
setIsLoggedIn(false); | ||
console.error(err); | ||
} | ||
}; | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
return { isLoggedIn, userData }; | ||
}; | ||
|
||
export default IsAuthenticated; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface ButtonProps { | ||
type?: 'button' | 'submit' | 'reset'; | ||
className: string; | ||
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
children: React.ReactNode; | ||
disabled?: boolean; | ||
testId?: string; | ||
} |
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,5 @@ | ||
export interface ProfileIconProps { | ||
firstName: string; | ||
lastName: string; | ||
size: number; | ||
} |
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 @@ | ||
export interface UserTypes { | ||
id: number; | ||
Username: string; | ||
email: string; | ||
password: string; | ||
isVerified: boolean; | ||
isOnboarding: boolean; | ||
createdAt: string; | ||
updatedAt: string; | ||
} |
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,2 @@ | ||
export const alphanumicUnderscore = /^[a-zA-Z0-9_]+$/; | ||
export const randomString = Math.random().toString(36).substring(2, 7); |
Oops, something went wrong.