Skip to content
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
5 changes: 3 additions & 2 deletions app/api/posts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export async function POST(req: Request) {
seriesId,
tags,
isPrivate,
sendToSubscribers,
} = await req.json();

if (!title || !content || !author || !content) {
Expand Down Expand Up @@ -176,8 +177,8 @@ export async function POST(req: Request) {
});
}

// 새 글이 공개 글인 경우 구독자들에게 이메일 발송
if (!post.isPrivate) {
// 공개 글이면서 구독자에게 발행 옵션이 활성화된 경우 이메일 발송
if (!post.isPrivate && sendToSubscribers) {
const { sendNewPostNotifications } = await import(
'@/app/lib/email/notifications'
);
Expand Down
29 changes: 27 additions & 2 deletions app/entities/post/write/PostMetadataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface PostMetadataFormProps {
seriesId?: string;
tags: string[];
isPrivate: boolean;
sendToSubscribers: boolean;
};
}

Expand All @@ -37,7 +38,8 @@ const PostMetadataForm = ({
}: PostMetadataFormProps) => {
const [tagInput, setTagInput] = useState<string>('');

const { title, subTitle, seriesId, tags, isPrivate } = formData;
const { title, subTitle, seriesId, tags, isPrivate, sendToSubscribers } =
formData;
const selectOptions = series.map((s) => ({
value: s._id,
label: s.title,
Expand Down Expand Up @@ -67,7 +69,15 @@ const PostMetadataForm = ({
};

const handlePublicChange = (e: ChangeEvent<HTMLInputElement>) => {
onFieldChange('isPrivate', e.target.checked);
const newIsPrivate = e.target.checked;
onFieldChange('isPrivate', newIsPrivate);
if (newIsPrivate) {
onFieldChange('sendToSubscribers', false);
}
};

const handleSendToSubscribersChange = (e: ChangeEvent<HTMLInputElement>) => {
onFieldChange('sendToSubscribers', e.target.checked);
};

return (
Expand Down Expand Up @@ -161,6 +171,21 @@ const PostMetadataForm = ({
/>
</label>
</div>
{/* 구독자에게 발행 체크박스 */}
<div className={'flex items-center gap-2'}>
<label
className={`inline-flex items-center text-nowrap gap-2 cursor-pointer ${isPrivate ? 'opacity-50' : ''}`}
>
<span className={'font-bold text-default'}>구독자에게 발행</span>
<input
type="checkbox"
checked={sendToSubscribers}
onChange={handleSendToSubscribersChange}
disabled={isPrivate}
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600 disabled:opacity-50"
/>
</label>
</div>
</div>

<button
Expand Down
5 changes: 5 additions & 0 deletions app/hooks/post/usePost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface FormData {
seriesId: string;
tags: string[];
isPrivate: boolean;
sendToSubscribers: boolean;
}

interface UIState {
Expand All @@ -32,6 +33,7 @@ const usePost = (slug = '') => {
seriesId: '',
tags: [],
isPrivate: false,
sendToSubscribers: false,
});

const [uiState, setUIState] = useState<UIState>({
Expand Down Expand Up @@ -60,6 +62,7 @@ const usePost = (slug = '') => {
seriesId: formData.seriesId || '',
tags: formData.tags,
isPrivate: formData.isPrivate,
sendToSubscribers: formData.sendToSubscribers,
};

useEffect(() => {
Expand Down Expand Up @@ -132,6 +135,7 @@ const usePost = (slug = '') => {
seriesId: seriesId || '',
tags: tags || [],
isPrivate: isPrivate || false,
sendToSubscribers: false,
});
setUploadedImages(draftImages || []);
}
Expand Down Expand Up @@ -180,6 +184,7 @@ const usePost = (slug = '') => {
seriesId: data.post.seriesId || '',
tags: data.post.tags || [],
isPrivate: data.post.isPrivate || false,
sendToSubscribers: false,
});
} catch (e) {
console.error('글 조회 중 오류 발생', e);
Expand Down
1 change: 1 addition & 0 deletions app/types/Post.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Post {
seriesId?: string;
tags?: string[];
isPrivate?: boolean;
sendToSubscribers?: boolean;
}
type PostBody = Omit<Post, '_id' | 'slug' | 'date' | 'timeToRead' | 'comment'>;

Expand Down