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

feat: push notification 15min Modal and Alert #379

Merged
merged 11 commits into from
Nov 18, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use client';

import { useSession } from 'next-auth/react';
import { useCallback, useEffect, useState } from 'react';

import { NoticeDetail } from '@/api/notice/notice';
import { calculateRemainingTime } from '@/app/[lng]/write/calculateRemainingTime';
import { PropsWithLng } from '@/app/i18next';
import { useTranslation } from '@/app/i18next/client';

interface SendPushNotificationAlertProps
extends Pick<NoticeDetail, 'author' | 'createdAt'> {}

const SendPushNotificationAlert = ({
author,
createdAt,
lng,
}: PropsWithLng<SendPushNotificationAlertProps>): JSX.Element | null => {
const { t } = useTranslation(lng);

const handleSendPushNotification = useCallback(() => {
// TODO: Implement push notification sending
}, []);
enc2586 marked this conversation as resolved.
Show resolved Hide resolved

const { data: user } = useSession();
const isMyNotice = user?.user.uuid === author.uuid;

enc2586 marked this conversation as resolved.
Show resolved Hide resolved
const [timeRemaining, setTimeRemaining] = useState(calculateRemainingTime(createdAt));

useEffect(() => {
const interval = setInterval(() => {
setTimeRemaining(calculateRemainingTime(createdAt));
}, 1000);

return () => clearInterval(interval);
}, []);
enc2586 marked this conversation as resolved.
Show resolved Hide resolved

const isEditable = timeRemaining.minutes > 0 && timeRemaining.seconds > 0;

if (!(isMyNotice && isEditable)) return null;

return (
<div className="inline-flex w-full items-start justify-start gap-1.5 rounded-[15px] bg-[#fff4f0] px-5 py-[15px] font-normal text-primary">
<span>{t('zabo.sentPushNotificationAlert.title')} </span>
<span
className="cursor-pointer font-bold underline"
onClick={handleSendPushNotification}
>
{t('zabo.sentPushNotificationAlert.action')}
</span>
</div>
);
};
enc2586 marked this conversation as resolved.
Show resolved Hide resolved

export default SendPushNotificationAlert;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import AdditionalNotices from './AdditionalNotices';
import Content from './Content';
import ImageStack from './ImageStack';
import NoticeInfo from './NoticeInfo';
import SendPushNotificationAlert from './SendPushNotificationAlert';

export const generateMetadata = async (
{
Expand Down Expand Up @@ -71,6 +72,8 @@ const DetailedNoticePage = async ({
</div>

<div className="flex flex-col gap-[18px] md:w-[60%]">
<SendPushNotificationAlert {...notice} lng={lng} />

<NoticeInfo
{...notice}
currentDeadline={notice.currentDeadline ?? null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ const MypageButtons = ({ lng }: PropsWithLng) => {
<div className="h-[1px] bg-greyLight dark:bg-dark_greyBorder" />

<div className="flex justify-between gap-4">
<CSLink className="flex-1">
{/* <CSLink className="flex-1">
enc2586 marked this conversation as resolved.
Show resolved Hide resolved
<MypageButton
align="right"
icon={<FlagIcon className={ICON_CLASSNAME} />}
buttonText={t('mypage.feedback')}
/>
</CSLink>
</CSLink> */}
</div>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions src/app/[lng]/write/NoticeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ const NoticeEditor = ({
const handleSubmit = async () => {
if (isLoading) return;

await Swal.fire({
text: t('write.alerts.pushWillDelayedNotice'),
icon: 'info',
confirmButtonText: t('alertResponse.confirm'),
});

setIsLoading(true);
const noticeId = await handleNoticeSubmit({
title: state.korean.title,
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/layout/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const Footer = async ({ lng }: PropsWithLng) => {
<div className="flex flex-col gap-2">
{links.map(({ link, name, key }: FooterLink) =>
key === 'bugReport' ? (
<CSLink key={name}>{name}</CSLink>
// <CSLink key={name}>{name}</CSLink>
<></>
enc2586 marked this conversation as resolved.
Show resolved Hide resolved
) : (
<ExternalLink key={name} href={link}>
{name}
Expand Down
8 changes: 7 additions & 1 deletion src/app/i18next/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
"writeTitle": "Write a title of English notice here"
},

"sentPushNotificationAlert": {
"title": "You can't edit once you send a notification.",
"action": "Send Push Notification"
},

"authorActions": {
"edit": "Edit / Add English Version",
"remove": "Remove",
Expand Down Expand Up @@ -319,7 +324,8 @@
"attachAdditionalNoticeFail": "Failed to post additional notice. Please try posting it again.",
"copyAdditionalNotice": "Copy additional notice",
"attachInternationalAdditionalNoticeFail": "Failed to post English additional notice. Please try posting it again.",
"copyInternationalAdditionalNotice": "Copy En. add. notice"
"copyInternationalAdditionalNotice": "Copy En. add. notice",
"pushWillDelayedNotice": "Users will receive a push notification after 15 minutes. If it's urgent, you can use Send Notification button in your notice page."
}
},
"group": {
Expand Down
8 changes: 7 additions & 1 deletion src/app/i18next/locales/ko/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
"writeTitle": "영어 공지 제목을 입력하세요"
},

"sentPushNotificationAlert": {
"title": "알림을 보내면 수정이 불가능합니다.",
"action": "알림 보내기"
},

"authorActions": {
"edit": "수정 / 영어공지 작성",
"remove": "삭제",
Expand Down Expand Up @@ -305,7 +310,8 @@
"attachAdditionalNoticeFail": "추가 공지 작성에 실패했습니다",
"copyAdditionalNotice": "추가 공지 복사",
"attachInternationalAdditionalNoticeFail": "영어 추가 공지 작성에 실패했습니다",
"copyInternationalAdditionalNotice": "영어 추가 공지 복사"
"copyInternationalAdditionalNotice": "영어 추가 공지 복사",
"pushWillDelayedNotice": "15분 뒤에 사용자들에게 푸시알람이 전송됩니다. 긴급한 경우 내 공지 > 알림 보내기 기능을 사용하세요."
}
},
"group": {
Expand Down
Loading