Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

알림에 대한 권한을 미 설정시, 알림에 대한 설명을 모달로 표시 #481

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import ROUTES from '@_constants/routes';
import { getInviteCode } from '@_common/inviteCodeManager';
import { kakaoOAuth } from '@_apis/auth';
import { requestPermission } from '@_service/notification';
import { setToken } from '@_utils/tokenManager';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import useServeToken from '@_hooks/mutaions/useServeToken';

export default function KakaoOAuthLoginPage() {
const navigate = useNavigate();
const { mutate: serveToken } = useServeToken();

useEffect(() => {
const loginKakaoOAuth = async () => {
Expand All @@ -23,7 +20,7 @@ export default function KakaoOAuthLoginPage() {

const response = await kakaoOAuth(code);
setToken(response.data.accessToken);
requestPermission(serveToken);

const inviteCode = getInviteCode();
if (inviteCode) {
navigate(`${ROUTES.darakbangInvitationRoute}?code=${inviteCode}`);
Expand All @@ -34,7 +31,7 @@ export default function KakaoOAuthLoginPage() {
};

loginKakaoOAuth();
}, [navigate, serveToken]);
}, [navigate]);

return null;
}
7 changes: 6 additions & 1 deletion frontend/src/pages/MainPage/MainPage.style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { css } from '@emotion/react';
import { css, Theme } from '@emotion/react';

export const headerButton = css`
background: none;
Expand All @@ -11,3 +11,8 @@ export const headerLeft = css`
align-items: center;
font-size: 100%;
`;

export const ModalContent = (props: { theme: Theme }) => css`
${props.theme.typography.s1}
margin: 5rem;
`;
27 changes: 26 additions & 1 deletion frontend/src/pages/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as S from './MainPage.style';

import { Fragment, useMemo, useState } from 'react';
import { Fragment, useEffect, useMemo, useState } from 'react';
import MoimTabBar, { MainPageTab } from '@_components/MoimTabBar/MoimTabBar';
import OptionsPanel, {
OptionsPanelOption,
Expand Down Expand Up @@ -28,10 +28,14 @@ import useMyRoleInDarakbang from '@_hooks/queries/useMyDarakbangRole';
import { useNavigate } from 'react-router-dom';
import useNowDarakbangName from '@_hooks/queries/useNowDarakbangNameById';
import useServeToken from '@_hooks/mutaions/useServeToken';
import Modal from '@_components/Modal/Modal';
import { useTheme } from '@emotion/react';
import Button from '@_components/Button/Button';

export default function MainPage() {
const navigate = useNavigate();
const { mutate } = useServeToken();
const theme = useTheme();
const [currentTab, setCurrentTab] = useState<MainPageTab>('모임목록');
const [isDarakbangMenuOpened, setIsDarakbangMenuOpened] = useState(false);

Expand All @@ -41,6 +45,16 @@ export default function MainPage() {
const nowDarakbangId = getLastDarakbangId();
const { myRoleInDarakbang: myRoleInNowDarakbang } = useMyRoleInDarakbang();

const [isModalOpen, setIsModalOpen] = useState(false);
useEffect(() => {
if (window.Notification && window.Notification.permission === 'default') {
setIsModalOpen(true);
}
}, []);

const handleModalClose = () => {
setIsModalOpen(false);
};
const handleTabClick = (tab: MainPageTab) => {
setCurrentTab(tab);
};
Expand Down Expand Up @@ -169,6 +183,17 @@ export default function MainPage() {

<NavigationBarWrapper>
<NavigationBar />
{isModalOpen && (
<Modal onClose={handleModalClose}>
<div css={S.ModalContent({ theme })}>
알림을 허용하시면 모임에 대한 알림을 받을 수 있습니다.
<br /> 우측 상단에 알림 버튼을 눌러주세요
</div>
<Button shape="bar" onClick={handleModalClose}>
닫기
</Button>
</Modal>
)}
</NavigationBarWrapper>
</Fragment>
);
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/pages/NotificationPage/NotificationPage.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { css, Theme } from '@emotion/react';

export const ModalContent = (props: { theme: Theme }) => css`
${props.theme.typography.s1}
margin: 5rem;
`;
55 changes: 43 additions & 12 deletions frontend/src/pages/NotificationPage/NotificationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,60 @@ import InformationLayout from '@_layouts/InformationLayout/InformationLayout';
import NotificationList from '@_components/NotificationList/NotificationList';
import { useNavigate } from 'react-router-dom';
import useNotification from '@_hooks/queries/useNotification';
import { Fragment, useEffect, useState } from 'react';
import Modal from '@_components/Modal/Modal';
import Button from '@_components/Button/Button';
import { useTheme } from '@emotion/react';
import * as S from './NotificationPage.style';

export default function NotificationPage() {
const navigate = useNavigate();
const theme = useTheme();
const { notifications, isLoading } = useNotification();
const [isModalOpen, setIsModalOpen] = useState(false);
useEffect(() => {
if (window.Notification && window.Notification.permission === 'denied') {
setIsModalOpen(true);
}
}, []);

const handleModalClose = () => {
setIsModalOpen(false);
};
if (isLoading) {
return <div>Loading...</div>;
}
if (!notifications) {
return <div>Failed to load my information.</div>;
}
return (
<InformationLayout>
<InformationLayout.Header>
<InformationLayout.Header.Left>
<div onClick={() => navigate(GET_ROUTES.nowDarakbang.main())}>
<BackLogo />
<Fragment>
<InformationLayout>
<InformationLayout.Header>
<InformationLayout.Header.Left>
<div onClick={() => navigate(GET_ROUTES.nowDarakbang.main())}>
<BackLogo />
</div>
</InformationLayout.Header.Left>
<InformationLayout.Header.Center>
알림
</InformationLayout.Header.Center>
</InformationLayout.Header>
<InformationLayout.ContentContainer>
<NotificationList notifications={notifications} />
</InformationLayout.ContentContainer>
</InformationLayout>
{isModalOpen && (
<Modal onClose={handleModalClose}>
<div css={S.ModalContent({ theme })}>
알림을 허용해야 모임에 대한 알림을 받을 수 있습니다.
<br /> 브라우저 환경에서 알림을 허용해주세요!
</div>
</InformationLayout.Header.Left>
<InformationLayout.Header.Center>알림</InformationLayout.Header.Center>
</InformationLayout.Header>
<InformationLayout.ContentContainer>
<NotificationList notifications={notifications} />
</InformationLayout.ContentContainer>
</InformationLayout>
<Button shape="bar" onClick={handleModalClose}>
닫기
</Button>
</Modal>
)}
</Fragment>
);
}
Loading