diff --git a/src/apis/getBoardDataPosts.ts b/src/apis/getBoardDataPosts.ts
index 8b14d66a..c80bf3eb 100644
--- a/src/apis/getBoardDataPosts.ts
+++ b/src/apis/getBoardDataPosts.ts
@@ -11,11 +11,16 @@ interface GetBoardDataPostsParams {
export const getBoardDataPosts = ({ filters = {}, page }: GetBoardDataPostsParams) => {
const accessToken = localStorage.getItem('accessToken');
+ const headers: { [key: string]: any } = {
+ 'Content-Type': 'multipart/form-data',
+ };
+
+ if (accessToken) {
+ headers['Authorization'] = `Bearer ${accessToken}`;
+ }
+
return client.get('/board/data/posts', {
- headers: {
- Authorization: `Bearer ${accessToken}`,
- 'Content-Type': 'multipart/form-data', // FormData를 보내는 경우 Content-Type은 자동으로 설정됨
- },
+ headers,
params: {
take: 5,
page: page - 1,
diff --git a/src/pages/data/containers/dataBoxSection.tsx b/src/pages/data/containers/dataBoxSection.tsx
index 781a8aaf..9b9729a7 100644
--- a/src/pages/data/containers/dataBoxSection.tsx
+++ b/src/pages/data/containers/dataBoxSection.tsx
@@ -194,7 +194,7 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
createdAt: new Date(post.date).setHours(0, 0, 0, 0),
uploadName: post.title || 'Unnamed Upload',
uploadDate: post.date || 'Unknown Date',
- fileData: post.files ? post.files.map((file: File) => file.fileName) : [],
+ fileData: post.files ? post.files.map((file: File) => file) : [],
fileNames: post.files ? post.files.map((file: File) => file.fileName) : [],
fileUrl: post.files ? post.files.map((file: File) => file.fileUrl) : [],
fileType: post.files ? post.files.map((file: File) => file.fileType) : [],
@@ -238,6 +238,10 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
}
}, [currentPage, filters]);
+ useEffect(() => {
+ fetchData();
+ }, []);
+
const handleDownload = (fileUrl: string, fileName: string) => {
const link = document.createElement('a');
link.href = fileUrl;
@@ -300,15 +304,15 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
-
+
{displayedData.length > 0 ? (
displayedData.map((data, index) => (
handleSendData(data)}
- className="h-[100px] border-b border-[#C2C2C2] py-4 sm:w-[344px] md:w-[630px] lg:w-[963px] xl:w-[1040px] xxl:w-[1533px]"
+ className="h-[100px] border-b border-[#C2C2C2] py-4 xs:w-[341px] sm:w-[344px] md:w-[630px] lg:w-[963px] xl:w-[1040px] xxl:w-[1533px]"
>
-
+
@@ -345,12 +349,14 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
데이터가 없습니다.
)}
-
{isAuthor ? : null}
+
+ {isAuthor ? : null}
+
-
+
{isAuthor && (
-
+
)}
diff --git a/src/pages/data/containers/edit/UploadSection.tsx b/src/pages/data/containers/edit/UploadSection.tsx
index e4d5c010..6e6a3d10 100644
--- a/src/pages/data/containers/edit/UploadSection.tsx
+++ b/src/pages/data/containers/edit/UploadSection.tsx
@@ -52,7 +52,7 @@ export default function UploadSection({ userId }: { userId: string }) {
const [categories, setCategories] = useState
([]);
const [fileCategories, setFileCategories] = useState([]);
const [fileInputSelecType, setfileInputSelecType] = useState('');
- const [selectType, setSelectType] = useState([]);
+ const [selectType, setSelectType] = useState();
const [fileInputs, setFileInputs] = useState(() => [
{
@@ -106,10 +106,15 @@ export default function UploadSection({ userId }: { userId: string }) {
}, [fileInputs, categories, trigger]);
const isFormValid = () => {
+ /*
const category = getValues('category');
+ console.log('isFormValid category', category);
+ */
+
const fileInputsArray = getValues('fileInputs');
+ console.log('isFormValid fileInputsArray', fileInputsArray);
- return category && fileInputsArray;
+ return /*category && */ fileInputsArray;
};
useEffect(() => {
@@ -146,6 +151,8 @@ export default function UploadSection({ userId }: { userId: string }) {
// type이 배열일 경우, 문자열로 변환하여 accept 속성에 적용
const selectedType = Array.isArray(selectedInput?.type) ? selectedInput.type.join(',') : selectedInput?.type;
+ console.log('selectedType', selectedType);
+ setSelectType(selectedType);
if (fileInputRef.current && selectedType) {
fileInputRef.current.accept = selectedType; // 선택된 파일 타입 설정
@@ -171,7 +178,9 @@ export default function UploadSection({ userId }: { userId: string }) {
console.log('fileInputsArray', fileInputsArray);
const currentFileInput = fileInputsArray[fileInputsArray.length - 1];
console.log('currentFileInput', currentFileInput);
+ console.log('selectType', selectType);
const fileType = selectType;
+ console.log('fileType', fileType);
const isNew = currentFileInput && 'isNew' in currentFileInput ? currentFileInput.isNew : false;
if (isNew && !fileType) {
@@ -189,12 +198,14 @@ export default function UploadSection({ userId }: { userId: string }) {
fileUrl: undefined,
};
+ console.log('newFile', newFile);
+
setTempFiles((prevFiles) => [...prevFiles, newFile]);
// Update fileInputs to include new file information
setFileInputs((prevInputs) => [
...prevInputs.slice(0, -1), // Remove the last input that was pending
- { ...currentFileInput, fileName: file.name, type: fileType, isNew: false }, // Update last input
+ { ...currentFileInput, fileName: file.name, type: fileType || 'hi', isNew: false }, // Update last input
{ id: prevInputs.length + 1, type: '', fileName: '', isNew: true }, // Add new input
]);
@@ -210,14 +221,15 @@ export default function UploadSection({ userId }: { userId: string }) {
}
const existingFiles = JSON.parse(localStorage.getItem('fileData') ?? '[]');
+ console.log('tempFiles', tempFiles);
const newFileData = {
uploadName: formValues.uploadName,
uploadDate: new Date().toLocaleDateString('en-GB'),
- fileData: tempFiles.map((file) => file.fileData),
- fileName: tempFiles.map((file) => file.fileName),
- category: tempFiles.map((file) => file.category),
- fileType: tempFiles.map((file) => file.fileType),
- postFileId: tempFiles.map((file) => file.postFileId),
+ fileData: fileInputs.map((file) => file.fileData), // Assuming fileData is to be fetched from somewhere else as fileInputs doesn't have it
+ fileName: fileInputs.map((file) => file.fileName),
+ category: fileInputs.map((file) => file.fileType), // Mapping fileType to category
+ fileType: fileInputs.map((file) => file.fileType),
+ postFileId: fileInputs.map((file) => file.postFileId),
};
existingFiles.push(newFileData);
@@ -227,9 +239,9 @@ export default function UploadSection({ userId }: { userId: string }) {
try {
const uploadName = newFileData.uploadName.length > 0 ? newFileData.uploadName : null;
const userName = userId || 'Unknown';
- const fileCategory = newFileData.category.length > 0 ? newFileData.category[0] : '중앙운영위원회'; // 'defaultCategory'를 기본값으로 설정
+ const fileCategory = newFileData.category.length > 0 ? newFileData.category[1] : '중앙운영위원회'; // 'defaultCategory'를 기본값으로 설정
const fileType = String(newFileData.fileType.length > 0 ? newFileData.fileType : null);
- const postFileId = newFileData.postFileId.length > 0 ? newFileData.postFileId : null;
+ const postFileId = newFileData.postFileId.length > 0 ? newFileData.postFileId[0] : null;
const accessToken = localStorage.getItem('accessToken');
@@ -244,7 +256,7 @@ export default function UploadSection({ userId }: { userId: string }) {
const patchFileResponse = await postBoardBoardCodeFiles(
boardCode,
accessToken,
- tempFiles.map((file) => file.file),
+ fileInputs.map((file) => file.file),
[]
);
@@ -270,6 +282,7 @@ export default function UploadSection({ userId }: { userId: string }) {
content: fileCategory,
categoryCode: userName,
thumbnailImage: null,
+ isNotice: true,
postFileList: [patchFileUrls[0]],
};
@@ -352,10 +365,13 @@ export default function UploadSection({ userId }: { userId: string }) {
fileInputs.find((input) => input.id === index)
);
console.log('index', index);
+
+ /*
console.log(
'input.id',
fileInputs.find((input) => input.id[index])
);
+ */
const inputToDelete = fileInputs.find((input) => input.id === index);
if (!inputToDelete) {
@@ -369,11 +385,18 @@ export default function UploadSection({ userId }: { userId: string }) {
// 삭제하려는 파일이 기존 파일인지 확인 (isNew가 false인 경우에만 postFileId가 있음)
if (post) {
// tempFiles에서 삭제하려는 파일의 postFileId를 기준으로 일치하는 파일을 찾음
+
+ console.log('post.fileData', post);
+ console.log('inputToDelete.postFileId', inputToDelete.postFileId);
+
const fileToDelete = post.fileData.find(
(file: { postFileId: any }) => file.postFileId === inputToDelete.postFileId
);
+ // 파일을 찾지 못했을 경우
if (!fileToDelete) {
- alert('삭제할 파일을 찾을 수 없습니다.');
+ // fileInputs에서 해당 항목을 삭제
+ setFileInputs((prevInputs) => prevInputs.filter((input) => input.id !== inputToDelete.id));
+ console.log('삭제할 파일을 찾지 못해 fileInputs에서 해당 항목을 삭제했습니다.');
return;
}
@@ -503,7 +526,7 @@ export default function UploadSection({ userId }: { userId: string }) {
setFileInputs(updatedFileInputs);
setTempFiles(updatedTempFiles);
- trigger(); // 폼 검증 트리거
+ trigger();
try {
console.log('fileToDelete', fileToDelete);
@@ -582,13 +605,13 @@ export default function UploadSection({ userId }: { userId: string }) {
{fileInputs.map((input, index) => (
-
-
+
+
{input.isNew ? (
<>>
) : (
<>
-
+
)}
/>
-