diff --git a/src/app/api/qna/file/route.ts b/src/app/api/qna/file/route.ts index 01930f2..602bbd6 100644 --- a/src/app/api/qna/file/route.ts +++ b/src/app/api/qna/file/route.ts @@ -1,33 +1,73 @@ import axios from 'axios' import { NextResponse } from 'next/server' +// export async function GET(request: Request) { +// const { searchParams } = new URL(request.url) +// const encodeFileNo = searchParams.get('encodeFileNo') +// const srcFileNm = searchParams.get('srcFileNm') + +// if (!encodeFileNo) { +// return NextResponse.json({ error: 'encodeFileNo is required' }, { status: 400 }) +// } + +// try { +// const response = await axios.get(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/file/downloadFile2`, { +// params: { +// encodeFileNo, +// }, +// responseType: 'arraybuffer', +// }) + +// if (response.headers['content-type'] === 'text/html;charset=utf-8') { +// return NextResponse.json({ error: 'file not found' }, { status: 404 }) +// } + +// const contentType = response.headers['content-type'] || 'application/octet-stream' +// const contentDisposition = response.headers['content-disposition'] || 'inline' + +// return new NextResponse(response.data, { +// status: 200, +// headers: { +// 'Content-Type': contentType, +// 'Content-Disposition': contentDisposition, +// }, +// }) +// } catch (error: any) { +// console.error('File download error:', error) +// return NextResponse.json({ error: error.response?.data || 'Failed to download file' }, { status: 500 }) +// } +// } + export async function GET(request: Request) { const { searchParams } = new URL(request.url) const encodeFileNo = searchParams.get('encodeFileNo') - - const srcFileNm = searchParams.get('srcFileNm') + const srcFileNm = searchParams.get('srcFileNm') || 'downloaded-file' if (!encodeFileNo) { return NextResponse.json({ error: 'encodeFileNo is required' }, { status: 400 }) } + + const url = `${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/file/downloadFile2?encodeFileNo=${encodeFileNo}` + try { - const response = await axios.get(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/file/downloadFile2`, { - responseType: 'arraybuffer', - params: { - encodeFileNo, - }, - }) - if (response.headers['content-type'] === 'text/html;charset=utf-8') { - return NextResponse.json({ error: 'file not found' }, { status: 404 }) + const resp = await fetch(url) + + if (!resp.ok) { + return NextResponse.json({ error: 'Failed to download file' }, { status: 500 }) } - return new NextResponse(response.data, { + + const contentType = resp.headers.get('content-type') || 'application/octet-stream' + const contentDisposition = resp.headers.get('content-disposition') || `attachment; filename="${srcFileNm}"` + + return new NextResponse(resp.body, { status: 200, headers: { - 'Content-Type': 'application/octet-stream;charset=UTF-8', - 'Content-Disposition': `attachment; filename="${srcFileNm}"`, + 'Content-Type': contentType, + 'Content-Disposition': contentDisposition, }, }) } catch (error: any) { - return NextResponse.json({ error: error.response.data }, { status: 500 }) + console.error('File download error:', error) + return NextResponse.json({ error: error.response?.data || 'Failed to download file' }, { status: 500 }) } } diff --git a/src/components/inquiry/list/ListForm.tsx b/src/components/inquiry/list/ListForm.tsx index badcbcd..878a7e5 100644 --- a/src/components/inquiry/list/ListForm.tsx +++ b/src/components/inquiry/list/ListForm.tsx @@ -5,7 +5,7 @@ import { useState } from 'react' export default function ListForm() { const router = useRouter() - const { inquiryListRequest, setInquiryListRequest, reset } = useInquiryFilterStore() + const { inquiryListRequest, setInquiryListRequest, reset, setOffset } = useInquiryFilterStore() const [searchKeyword, setSearchKeyword] = useState(inquiryListRequest.schTitle ?? '') const handleSearch = () => { @@ -40,6 +40,19 @@ export default function ListForm() { onChange={(e) => setSearchKeyword(e.target.value)} onKeyDown={handleKeyDown} /> + {searchKeyword && ( + + )} diff --git a/src/components/inquiry/list/ListTable.tsx b/src/components/inquiry/list/ListTable.tsx index cbb88af..14ffece 100644 --- a/src/components/inquiry/list/ListTable.tsx +++ b/src/components/inquiry/list/ListTable.tsx @@ -86,7 +86,7 @@ export default function ListTable() {
- +
diff --git a/src/components/survey-sale/list/SearchForm.tsx b/src/components/survey-sale/list/SearchForm.tsx index 491e8db..3b910ee 100644 --- a/src/components/survey-sale/list/SearchForm.tsx +++ b/src/components/survey-sale/list/SearchForm.tsx @@ -15,7 +15,7 @@ export default function SearchForm({ memberRole, userId }: { memberRole: string; alert('2文字以上入力してください') return } - reset() + setOffset(0) setKeyword(searchKeyword) setSearchOption(option) } @@ -72,6 +72,16 @@ export default function SearchForm({ memberRole, userId }: { memberRole: string; } }} /> + {searchKeyword && ( + + )}
diff --git a/src/components/ui/common/Header.tsx b/src/components/ui/common/Header.tsx index c8dd2f0..3c146cb 100644 --- a/src/components/ui/common/Header.tsx +++ b/src/components/ui/common/Header.tsx @@ -11,6 +11,8 @@ import { useSideNavState } from '@/store/sideNavState' import { useHeaderStore } from '@/store/header' import { useSessionStore } from '@/store/session' import { usePopupController } from '@/store/popupController' +import { useSurveyFilterStore } from '@/store/surveyFilterStore' +import { useInquiryFilterStore } from '@/store/inquiryFilterStore' import { useTitle } from '@/hooks/useTitle' import { useAxios } from '@/hooks/useAxios' @@ -30,6 +32,9 @@ export default function Header() { const popupController = usePopupController() + const { setIsMySurvey } = useSurveyFilterStore() + const { setInquiryListRequest, inquiryListRequest } = useInquiryFilterStore() + if (pathname === '/login') { return null } @@ -80,13 +85,27 @@ export default function Header() {
-
+
{ + setIsMySurvey(session?.userId) + router.push('/survey-sale') + setSideNavIsOpen(false) + }} + >
私は作成した物件
-
+
{ + setInquiryListRequest({ ...inquiryListRequest, schRegId: session?.userId }) + router.push('/inquiry/list') + setSideNavIsOpen(false) + }} + >
私は作成したお問 い合わせ
@@ -105,7 +124,7 @@ export default function Header() {
  • - +
  • diff --git a/src/hooks/useInquiry.ts b/src/hooks/useInquiry.ts index a5ed2ab..23b433e 100644 --- a/src/hooks/useInquiry.ts +++ b/src/hooks/useInquiry.ts @@ -76,19 +76,22 @@ export function useInquiry( const downloadFile = async (encodeFileNo: number, srcFileNm: string) => { try { - const resp = await axiosInstance(null).get(`/api/qna/file`, { params: { encodeFileNo, srcFileNm } }) - const blob = new Blob([resp.data], { type: 'application/octet-stream;charset=UTF-8' }) + const resp = await fetch(`/api/qna/file?encodeFileNo=${encodeFileNo}&srcFileNm=${srcFileNm}`) + + const blob = await resp.blob() const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url - a.download = `${srcFileNm}` + a.download = srcFileNm + document.body.appendChild(a) a.click() + document.body.removeChild(a) URL.revokeObjectURL(url) + return blob - } catch (error: any) { - if (error.response.status === 404) { - alert('ファイルが見つかりません') - } + } catch (error) { + console.error('File download error:', error) + alert('ファイルのダウンロードに失敗しました') return null } }