Skip to content

Commit

Permalink
fix: 회의록 삭제는 마지막 회차만 가능
Browse files Browse the repository at this point in the history
  • Loading branch information
Limchansol committed Mar 4, 2025
1 parent 83ca9e5 commit f459f5c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
41 changes: 16 additions & 25 deletions app/[locale]/community/council/meeting-minute/MinutePageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PageLayout from '@/components/layout/pageLayout/PageLayout';
import { councilMinute } from '@/constants/segmentNode';
import { Link } from '@/i18n/routing';
import { getPath } from '@/utils/page';
import { CustomError, handleServerResponse } from '@/utils/serverActionError';
import { handleServerResponse } from '@/utils/serverActionError';

import CouncilAttachment from '../components/CouncilAttachments';

Expand All @@ -38,8 +38,14 @@ export default function MinutePageContent({
setSelectedTime={setSelectedYear}
/>
<div className="mt-7">
{selectedContents.map((minute) => {
return <Minutes minute={minute} key={`${minute.year}_${minute.index}`} />;
{selectedContents.map((minute, i) => {
return (
<Minutes
minute={minute}
key={`${minute.year}_${minute.index}`}
isLast={i === selectedContents.length - 1}
/>
);
})}
</div>
<MinuteAddButton year={selectedYear} />
Expand Down Expand Up @@ -75,24 +81,7 @@ function YearAddButton() {
);
}

function Buttons({
onDelete,
editHref,
}: {
onDelete: () => Promise<CustomError | void>;
editHref: string;
}) {
return (
<LoginVisible role={['ROLE_COUNCIL', 'ROLE_STAFF']}>
<div className="flex justify-end gap-3">
<DeleteButton onDelete={onDelete} />
<EditButton href={editHref} />
</div>
</LoginVisible>
);
}

function Minutes({ minute }: { minute: CouncilMeetingMinute }) {
function Minutes({ minute, isLast }: { minute: CouncilMeetingMinute; isLast: boolean }) {
const handleDelete = async () => {
const resp = await deleteMinuteAction(minute.year, minute.index);
handleServerResponse(resp, {
Expand All @@ -104,10 +93,12 @@ function Minutes({ minute }: { minute: CouncilMeetingMinute }) {
<div className="mb-10 w-fit border-b border-neutral-200 pb-10">
<div className="flex items-center justify-between gap-2.5 ">
<div className="font-semibold">{minute.index}차 회의 회의록</div>
<Buttons
onDelete={handleDelete}
editHref={`${minutePath}/edit?year=${minute.year}&index=${minute.index}`}
/>
<LoginVisible role={['ROLE_COUNCIL', 'ROLE_STAFF']}>
<div className="flex justify-end gap-3">
{isLast && <DeleteButton onDelete={handleDelete} />}
<EditButton href={`${minutePath}/edit?year=${minute.year}&index=${minute.index}`} />
</div>
</LoginVisible>
</div>
{minute.attachments.map((file) => (
<CouncilAttachment {...file} key={file.id} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export default function EditMinutePageContent({
const onCancel = () => router.push(minutePath);

const onSubmit = async (requestObject: MinuteFormData) => {
const removeFileIds = getAttachmentDeleteIds(requestObject.file, data.attachments);
const deleteIds = getAttachmentDeleteIds(requestObject.file, data.attachments);
const formData = contentToFormData(
'EDIT',
{ requestObject: removeFileIds, attachments: requestObject.file },
{ request: 'removeFileIds', attachments: 'addFiles' },
{ requestObject: deleteIds, attachments: requestObject.file },
{ request: 'deleteIds', attachments: 'addFiles' },
);

await putMinuteAction(year, index, formData);
};

Expand Down
7 changes: 4 additions & 3 deletions utils/formData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Attachment } from '@/apis/types/attachment';
import { EditorFile, EditorImage, isLocalFile, isLocalImage, isUploadedFile } from '@/types/form';

import { encodeFormDataFileName } from './string';
import { encodeFormDataFileName, FormDataFileName } from './string';

export const contentToFormData = (
type: 'CREATE' | 'EDIT',
Expand Down Expand Up @@ -31,13 +31,14 @@ export const contentToFormData = (
if (attachments) {
encodeFormDataFileName(
formData,
keys?.attachments || type === 'CREATE' ? 'attachments' : 'newAttachments',
(keys?.attachments as FormDataFileName) ||
(type === 'CREATE' ? 'attachments' : 'newAttachments'),
attachments.filter(isLocalFile).map((x) => x.file),
);
}

if (image && isLocalImage(image)) {
formData.append(keys?.image || type === 'CREATE' ? 'mainImage' : 'newMainImage', image.file);
formData.append(keys?.image || (type === 'CREATE' ? 'mainImage' : 'newMainImage'), image.file);
}

return formData;
Expand Down
2 changes: 1 addition & 1 deletion utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export const encodeFormDataFileName = (
fileList.forEach((file) => formData.append(key, file, encodeURI(file.name)));
};

type FormDataFileName = 'attachments' | 'newAttachments' | 'pdf' | 'addFiles';
export type FormDataFileName = 'attachments' | 'newAttachments' | 'pdf' | 'addFiles';

const isFile = (x: unknown): x is File => x instanceof File;

0 comments on commit f459f5c

Please sign in to comment.