-
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.
Added service worker for PWA support. Added axios, redux and other ut…
…ils. Added modal and forms. Added auth for user not logged in.
- Loading branch information
Showing
38 changed files
with
9,405 additions
and
1,378 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,25 @@ | ||
'use client' | ||
import React from 'react' | ||
|
||
import { useCookie } from "@hooks/all" | ||
import { useRouter } from 'next/navigation' | ||
import { ArrowLeftStartOnRectangleIcon } from '@heroicons/react/24/solid' | ||
const Logout = () => { | ||
const { removeCookie } = useCookie() | ||
const router = useRouter() | ||
const handleLogout = () => { | ||
removeCookie({ | ||
name: 'user_token', | ||
domain: window.location.hostname | ||
}) | ||
router.push('/') | ||
} | ||
return ( | ||
<div onClick={handleLogout} className="flex flex-row gap-2 mb-0 hover:text-slate-400 text-red-700 dark:text-red-500" role="button"> | ||
<ArrowLeftStartOnRectangleIcon className="h-6 w-6" /> | ||
<div className="">Logout</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default 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
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,30 @@ | ||
'use client' | ||
import { useLayoutEffect, useState } from "react" | ||
import { useCookie } from "@hooks/all" | ||
import { redirect } from 'next/navigation' | ||
|
||
type AuthProps = { | ||
children: React.ReactNode | ||
} | ||
|
||
const Auth = ({ children }: AuthProps) => { | ||
const [hasLoaded, setHasLoaded] = useState<boolean>(false) | ||
|
||
useLayoutEffect(() => { | ||
const { getCookie } = useCookie(); | ||
const listOfPathnames = ["/login", "/"]; | ||
|
||
if (getCookie('user_token') && listOfPathnames.indexOf(window.location.pathname) != -1) { | ||
redirect('/dashboard') | ||
} else if (getCookie('user_token') == '' && listOfPathnames.indexOf(window.location.pathname) == -1) { | ||
redirect('/') | ||
} | ||
|
||
setHasLoaded(true) | ||
|
||
}, []) | ||
|
||
return hasLoaded ? children : <div className="h-screen w-screen"/> | ||
} | ||
|
||
export default Auth |
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,25 @@ | ||
import React from 'react' | ||
import Modal from './Modal' | ||
import XIcon from "@/public/x.png"; | ||
import Image from "next/image" | ||
|
||
type ErrorModalProps = { | ||
children?: React.ReactNode, | ||
message?: string | ||
} | ||
|
||
const ErrorModal = ({ children, message }: ErrorModalProps) => { | ||
|
||
return ( | ||
<Modal id="error-modal" hideHeader={true}> | ||
{message && <div className='flex items-center justify-center flex-col text-black dark:text-white'> | ||
<Image className="object-cover w-[100px] h-[100px] opacity-90" src={XIcon} alt="" /> | ||
<div className="font-bold mt-4">Error</div> | ||
<div className="mb-4 text-[14px]">{message}</div> | ||
</div>} | ||
{children} | ||
</Modal> | ||
) | ||
} | ||
|
||
export default ErrorModal |
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,69 @@ | ||
'use client' | ||
import { createPortal } from 'react-dom'; | ||
import { useSelector, useDispatch } from "@/app/hooks/all" | ||
import { closeModal } from "@/app/store/reducers/modal"; | ||
|
||
type ModalProps = { | ||
id: string, | ||
title?: string, | ||
size?: 'sm' | 'md' | 'lg' | 'xl', | ||
children: React.ReactNode, | ||
hideHeader?: boolean | ||
} | ||
|
||
const Modal = ({ | ||
id, | ||
title, | ||
size = 'sm', | ||
hideHeader, | ||
children | ||
}: ModalProps) => { | ||
|
||
const dispatch = useDispatch() | ||
const openModal = useSelector((state) => state.modal.isOpen) | ||
const modalId = useSelector((state) => state.modal.modalId) | ||
|
||
const handleCloseModal = () => { | ||
dispatch(closeModal()) | ||
} | ||
|
||
const modalSize = { | ||
sm: 'sm:max-w-sm sm:w-full m-3 sm:mx-auto', | ||
md: 'md:max-w-md md:w-full m-3 md:mx-auto', | ||
lg: 'lg:max-w-lg lg:w-full m-3 lg:mx-auto', | ||
xl: 'xl:max-w-4xl xl:w-full m-3 xl:mx-auto', | ||
} | ||
|
||
const show = (): boolean => { | ||
return openModal && modalId === id | ||
} | ||
|
||
return createPortal(<div className="relative"> | ||
<div id="hs-vertically-centered-modal" className={`hs-overlay size-full fixed top-0 start-0 ${show() ? 'z-[80]' : 'z-0 duration-500 ease-out transition-all'} overflow-x-hidden overflow-y-auto pointer-events-none`}> | ||
<div className={`${show() ? ' mt-7 opacity-100 duration-500' : ' opacity-0 mt-0 duration-500'} p-5 ease-out transition-all ${modalSize[size]} min-h-[calc(100%-3.5rem)] flex items-center`}> | ||
<div className=" bg-opacity-90 w-full flex flex-col bg-white border shadow-sm rounded-xl pointer-events-auto dark:bg-neutral-800 dark:border-neutral-700 dark:shadow-neutral-700/70"> | ||
<div className={`justify-between items-center py-3 px-4 border-b dark:border-neutral-700 ${hideHeader ? 'hidden' : 'flex'}`}> | ||
<h3 className="font-bold text-gray-800 dark:text-white"> | ||
{title} | ||
</h3> | ||
<button type="button" onClick={handleCloseModal} className="flex justify-center items-center size-7 text-sm font-semibold rounded-full border border-transparent text-gray-800 hover:bg-gray-100 disabled:opacity-50 disabled:pointer-events-none dark:text-white dark:hover:bg-neutral-700"> | ||
<span className="sr-only">Close</span> | ||
<svg className="flex-shrink-0 size-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> | ||
<path d="M18 6 6 18"></path> | ||
<path d="m6 6 12 12"></path> | ||
</svg> | ||
</button> | ||
</div> | ||
<div className="p-4 overflow-y-auto"> | ||
{children} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
<div className={`transition duration fixed ${show() ? '' : 'hidden'} w-screen h-screen z-[79] inset-0 bg-gray-900 bg-opacity-60 dark:bg-opacity-80 dark:bg-neutral-900 `}></div> | ||
</div> | ||
, document.getElementById('root-modal') as Element) | ||
} | ||
|
||
export default Modal |
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
Oops, something went wrong.