Skip to content

Commit

Permalink
[프로젝트 페이지] 프로젝트 글쓰기 권한 Admin -> User (#131)
Browse files Browse the repository at this point in the history
* Fix : 프로젝트 글쓰기 권한 전체로 변경

* Fix : local 삭제후 commit

* Fix : 비로그인시 글쓰기 이슈로 User부터 글쓰기 가능
  • Loading branch information
teagu123 authored Oct 6, 2024
1 parent 7cf775b commit da52e6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/pages/project/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ import WriteIcon from '../../../img/project/write.svg';
import { useNavigate } from 'react-router-dom';
import { ProjectAPI } from './ProjectList';
import { Gen } from '../register/RegisterOptions';
import { useAuth } from '../../../hooks/useAuth';
import { RolePriority } from '../../../constants/Role';

interface IHeader {
setProjectApi: React.Dispatch<React.SetStateAction<ProjectAPI>>;
}

function Header({ setProjectApi }: IHeader) {
const { userinfo, isLoading } = useAuth();
const [activeTab, setActiveTab] = useState<number | undefined>();
const [isUser, setIsUser] = useState<boolean>(false);

const handleClick = (index?: number) => {
setActiveTab(index);
};

const isUserInfo =
RolePriority.findIndex(role => role === userinfo.role) >= 1;

useEffect(() => {
if (isUserInfo && !isLoading) {
setIsUser(true);
}
}, [isLoading, isUserInfo]);

useEffect(() => {
// 전체를 클릭할 경우
if (activeTab === undefined) {
Expand Down Expand Up @@ -67,7 +80,7 @@ function Header({ setProjectApi }: IHeader) {
</P.Tab>
</P.TabContainer>

<P.WriteBtn onClick={goRegister}>
<P.WriteBtn isUser={isUser} onClick={goRegister}>
<img src={WriteIcon} alt="write" />
글쓰기
</P.WriteBtn>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/project/components/HeaderStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export const Divider = styled.div`
display: none;
`;

export const WriteBtn = styled.button`
export const WriteBtn = styled.button<{ isUser: boolean }>`
margin-left: 20px;
padding: 8px 20px 8px 14px;
justify-content: center;
align-items: center;
gap: 6px;
display: inline-flex;
display: ${props => (props.isUser ? 'inline-flex' : 'none')};
border-radius: 6px;
border: none;
background: var(--Orange-600, #ff7710);
Expand Down

0 comments on commit da52e6b

Please sign in to comment.