-
Notifications
You must be signed in to change notification settings - Fork 2
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 #98 from sopt-makers/feature-admin_authority
[#96][FEATURE] 계정권한 분리, 디버그 툴 구현
- Loading branch information
Showing
14 changed files
with
188 additions
and
21 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
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,44 @@ | ||
import { | ||
createContext, | ||
Dispatch, | ||
ReactNode, | ||
SetStateAction, | ||
useEffect, | ||
useState, | ||
} from 'react'; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
} | ||
|
||
interface AdminStatusContextType { | ||
status: string | null; | ||
setStatus: Dispatch<SetStateAction<string | null>>; | ||
} | ||
|
||
const defaultContextValue: AdminStatusContextType = { | ||
status: 'DEVELOPER', | ||
setStatus: () => {}, | ||
}; | ||
|
||
export const adminStatusContext = | ||
createContext<AdminStatusContextType>(defaultContextValue); | ||
|
||
export const AdminStatusProvider = (props: Props) => { | ||
const { children } = props; | ||
const [status, setStatus] = useState<string | null>('NOT_CERTIFIED'); | ||
|
||
useEffect(() => { | ||
if (typeof window !== 'undefined') { | ||
const savedStatus = | ||
sessionStorage.getItem('adminStatus') ?? 'NOT_CERTIFIED'; | ||
setStatus(savedStatus); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<adminStatusContext.Provider value={{ status, setStatus }}> | ||
{children} | ||
</adminStatusContext.Provider> | ||
); | ||
}; |
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,59 @@ | ||
import { useRouter } from 'next/router'; | ||
import { useContext, useEffect, useState } from 'react'; | ||
|
||
import DropDown from '@/components/common/DropDown'; | ||
import OptionTemplate from '@/components/common/OptionTemplate'; | ||
import Selector from '@/components/common/Selector'; | ||
|
||
import { adminStatusContext } from '../AdminContextProvider'; | ||
import { StAdminStatusContainer } from './style'; | ||
|
||
function AdminStatusDevtools() { | ||
const router = useRouter(); | ||
const [isDropdownOpen, setIsDropdownOpen] = useState<boolean>(false); | ||
const { status, setStatus } = useContext(adminStatusContext); | ||
|
||
const STATUS_SELECTION: ADMIN_STATUS[] = ['SOPT', 'MAKERS']; | ||
|
||
const isAdminStatus = (value: string): value is ADMIN_STATUS => { | ||
return [ | ||
'SUPER_USER', | ||
'SOPT', | ||
'MAKERS', | ||
'NOT_CERTIFIED', | ||
'DEVELOPER', | ||
].includes(value); | ||
}; | ||
|
||
const handleStatusChange = (newStatus: string) => { | ||
if (isAdminStatus(newStatus)) { | ||
setStatus(newStatus); | ||
sessionStorage.setItem('adminStatus', newStatus); | ||
if (newStatus === 'MAKERS') { | ||
router.push('/alarmAdmin'); | ||
} | ||
} else { | ||
console.error('유효하지 않은 권한입니다.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<StAdminStatusContainer> | ||
<OptionTemplate title="권한"> | ||
<Selector | ||
content={status} | ||
onClick={() => setIsDropdownOpen(!isDropdownOpen)} | ||
/> | ||
{isDropdownOpen && ( | ||
<DropDown | ||
type={'select'} | ||
list={STATUS_SELECTION} | ||
onItemSelected={handleStatusChange} | ||
/> | ||
)} | ||
</OptionTemplate> | ||
</StAdminStatusContainer> | ||
); | ||
} | ||
|
||
export default AdminStatusDevtools; |
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 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const StAdminStatusContainer = styled.div` | ||
width: 18.5rem; | ||
`; |
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,16 @@ | ||
import { useRouter } from 'next/router'; | ||
import { useEffect } from 'react'; | ||
|
||
export const useUnauthorizedStatus = (status: ADMIN_STATUS) => { | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
if ( | ||
typeof window !== 'undefined' && | ||
sessionStorage.getItem('adminStatus') === status | ||
) { | ||
alert('접근 권한이 없는 계정입니다.'); | ||
router.back(); | ||
} | ||
}, [router, status]); | ||
}; |
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
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { atom } from 'recoil'; | ||
import { atom, DefaultValue, selector } from 'recoil'; | ||
|
||
export const user = atom<User>({ | ||
key: 'userData', | ||
default: { | ||
id: 0, | ||
adminStatus: 'NOT_CERTIFIED', | ||
name: '', | ||
}, | ||
}); |
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