PostWriteButton.tsx 845 B

123456789101112131415161718192021222324252627282930313233
  1. 'use client';
  2. import '../[code]/style.scss';
  3. import { useRouter } from 'next/navigation';
  4. import { useCallback } from 'react';
  5. import useAuth from '@/hooks/useAuth';
  6. export default function PostWriteButton({ alwaysShowButton, boardCode }: { alwaysShowButton: boolean, boardCode: string }) {
  7. const router = useRouter();
  8. const { isAuthenticated, isLogined } = useAuth();
  9. const handleClick = useCallback(async (e: React.MouseEvent<HTMLButtonElement>) => {
  10. const redirectUrl = e.currentTarget.value;
  11. if (!await isLogined()) {
  12. return;
  13. }
  14. router.push(redirectUrl);
  15. }, []);
  16. if (!alwaysShowButton && !isAuthenticated) {
  17. return;
  18. }
  19. return (
  20. <>
  21. <section aria-label='글쓰기 버튼'>
  22. <button value={`/post/write#${boardCode}`} className='btn btn-submit' onClick={handleClick}>글쓰기</button>
  23. </section>
  24. </>
  25. );
  26. }