diff --git a/.env.development b/.env.development index 9d7881a..4118bca 100644 --- a/.env.development +++ b/.env.development @@ -7,4 +7,6 @@ NEXT_PUBLIC_API_URL=http://localhost:3000 NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 #1:1문의 api -NEXT_PUBLIC_INQUIRY_API_URL=http://1.248.227.176:38080 \ No newline at end of file +NEXT_PUBLIC_INQUIRY_API_URL=http://172.23.4.129:8110 + + diff --git a/.env.production b/.env.production index 3d04f51..d46bcd0 100644 --- a/.env.production +++ b/.env.production @@ -5,4 +5,5 @@ NEXT_PUBLIC_API_URL=http://172.30.1.35:3000 NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 #1:1문의 api -NEXT_PUBLIC_INQUIRY_API_URL=http://1.248.227.176:38080 \ No newline at end of file +# NEXT_PUBLIC_INQUIRY_API_URL=http://1.248.227.176:38080 +NEXT_PUBLIC_INQUIRY_API_URL=http://172.23.4.129:8110 diff --git a/src/app/api/qna/detail/route.ts b/src/app/api/qna/detail/route.ts index a9b670e..c91931a 100644 --- a/src/app/api/qna/detail/route.ts +++ b/src/app/api/qna/detail/route.ts @@ -2,14 +2,23 @@ import { queryStringFormatter } from '@/utils/common-utils' import axios from 'axios' import { NextResponse } from 'next/server' -export const QSP_URL = 'http://localhost:8080' export async function GET(request: Request) { - const body = await request.json() - - const response = await axios.get(`${QSP_URL}/qna/detail?${queryStringFormatter(body)}`) - - if (response.status === 200) { - return NextResponse.json(response.data) + const { searchParams } = new URL(request.url) + const params = { + compCd: searchParams.get('compCd'), + qnoNo: searchParams.get('qnoNo'), + langCd: searchParams.get('langCd'), + loginId: searchParams.get('loginId'), + } + + try { + const response = await axios.get(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/qna/detail?${queryStringFormatter(params)}`) + if (response.status === 200) { + return NextResponse.json(response.data) + } + return NextResponse.json({ error: response.data.result }, { status: response.status }) + } catch (error: any) { + console.error(error.response) + return NextResponse.json({ error: 'route error' }, { status: 500 }) } - return NextResponse.json({ error: 'Failed to fetch qna detail' }, { status: response.status }) } diff --git a/src/app/api/qna/list/route.ts b/src/app/api/qna/list/route.ts index 9e0f651..2a63a3c 100644 --- a/src/app/api/qna/list/route.ts +++ b/src/app/api/qna/list/route.ts @@ -1,17 +1,30 @@ import axios from 'axios' import { NextResponse } from 'next/server' import { queryStringFormatter } from '@/utils/common-utils' -import { QSP_URL } from '../detail/route' export async function GET(request: Request) { const { searchParams } = new URL(request.url) - console.log('searchParams::: ', searchParams) - const response = await axios.get(`${QSP_URL}/qna/list?${queryStringFormatter(searchParams)}`) + const params: Record = {} + searchParams.forEach((value, key) => { + const match = key.match(/inquiryListRequest\[(.*)\]/) + if (match) { + params[match[1]] = value + } else { + params[key] = value + } + }) - if (response.status === 200) { - return NextResponse.json(response.data) + try { + const response = await axios.get(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/qna/list?${queryStringFormatter(params)}`) + + if (response.status === 200) { + return NextResponse.json(response.data) + } + + return NextResponse.json({ error: 'Failed to fetch qna list' }, { status: response.status }) + } catch (error: any) { + console.error('Error fetching qna list:', error.response.data) + return NextResponse.json({ error: 'route error' }, { status: 500 }) } - - return NextResponse.json({ error: 'Failed to fetch qna list' }, { status: response.status }) } diff --git a/src/app/api/qna/save/route.ts b/src/app/api/qna/save/route.ts index 8f29873..e16593a 100644 --- a/src/app/api/qna/save/route.ts +++ b/src/app/api/qna/save/route.ts @@ -1,11 +1,10 @@ import axios from 'axios' import { NextResponse } from 'next/server' -import { QSP_URL } from '../detail/route' export async function POST(request: Request) { const body = await request.json() - const response = await axios.post(`${QSP_URL}/qna/save`, body) + const response = await axios.post(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/qna/save`, body) if (response.status === 200) { return NextResponse.json(response.data) diff --git a/src/components/inquiry/Answer.tsx b/src/components/inquiry/Answer.tsx index 5628f36..485abde 100644 --- a/src/components/inquiry/Answer.tsx +++ b/src/components/inquiry/Answer.tsx @@ -2,7 +2,7 @@ import { Inquiry } from '@/types/Inquiry' -export default function Answer({ inquiryDetail }: { inquiryDetail: Inquiry }) { +export default function Answer({ inquiryDetail }: { inquiryDetail: Inquiry}) { return ( <>
diff --git a/src/components/inquiry/Detail.tsx b/src/components/inquiry/Detail.tsx index 51fe7d3..a983bca 100644 --- a/src/components/inquiry/Detail.tsx +++ b/src/components/inquiry/Detail.tsx @@ -1,15 +1,18 @@ 'use client' -import { useState } from 'react' import Answer from './Answer' import { useInquiry } from '@/hooks/useInquiry' -import { useRouter } from 'next/navigation' +import { useParams, useRouter } from 'next/navigation' export default function Detail() { //todo: 답변 완료 표시를 위해 임시로 추가 해 놓은 state // 추후에 api 작업 완료후 삭제 // 답변 완료 클래스 & 하단 답변내용 출력도 - const { inquiryDetail } = useInquiry() + + const params = useParams() + const id = params.id + + const { inquiryDetail } = useInquiry(Number(id), '5200') const router = useRouter() return ( @@ -17,7 +20,9 @@ export default function Detail() {
-
回答完了
+
+ {inquiryDetail?.answerYn === 'Y' ? '回答完了' : '回答待ち'} +
@@ -50,9 +55,11 @@ export default function Detail() {
-
屋根適合
+
+ {inquiryDetail?.qnaClsLrgCd} - {inquiryDetail?.qnaClsMidCd} +
{inquiryDetail?.qstTitle}
-
{inquiryDetail?.qstContent}
+
{inquiryDetail?.qstContents}
ファイル添付
@@ -68,7 +75,7 @@ export default function Detail() {
- {inquiryDetail?.answerYn === 'Y' && } + {inquiryDetail?.answerYn === 'Y' && inquiryDetail && }
@@ -23,12 +85,19 @@ export default function RegistForm() { お問い合わせタイトル *
- setInquiryRequest({ ...inquiryRequest, title: e.target.value })} + > + + + + +
@@ -37,7 +106,14 @@ export default function RegistForm() { お問い合わせタイプ *
- +
@@ -46,29 +122,25 @@ export default function RegistForm() { - +
- 添付ファイル2個 + 添付ファイル{attachedFiles.length}
-
diff --git a/src/components/inquiry/list/ListForm.tsx b/src/components/inquiry/list/ListForm.tsx index 14f38bb..d22d424 100644 --- a/src/components/inquiry/list/ListForm.tsx +++ b/src/components/inquiry/list/ListForm.tsx @@ -1,8 +1,25 @@ 'use client' +import { useInquiryFilterStore } from '@/store/inquiryFilterStore' import { useRouter } from 'next/navigation' +import { useState } from 'react' export default function ListForm() { const router = useRouter() + const [searchKeyword, setSearchKeyword] = useState('') + const { inquiryListRequest, setInquiryListRequest } = useInquiryFilterStore() + + const handleSearch = () => { + if (searchKeyword.length >= 2) { + setInquiryListRequest({ ...inquiryListRequest, schTitle: searchKeyword }) + } + } + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + handleSearch() + } + } + return ( <>
@@ -13,8 +30,15 @@ export default function ListForm() {
- - + setSearchKeyword(e.target.value)} + onKeyDown={handleKeyDown} + /> +
diff --git a/src/components/inquiry/list/ListTable.tsx b/src/components/inquiry/list/ListTable.tsx index 16314aa..9598117 100644 --- a/src/components/inquiry/list/ListTable.tsx +++ b/src/components/inquiry/list/ListTable.tsx @@ -4,6 +4,9 @@ import { useEffect, useState } from 'react' import LoadMoreButton from '../../LoadMoreButton' import { useInquiry } from '@/hooks/useInquiry' import { InquiryList } from '@/types/Inquiry' +import { useRouter } from 'next/navigation' +import { useInquiryFilterStore } from '@/store/inquiryFilterStore' +import { useSessionStore } from '@/store/session' const badgeStyle = [ { @@ -21,14 +24,30 @@ export default function ListTable() { const [offset, setOffset] = useState(0) const [hasMore, setHasMore] = useState(true) + const router = useRouter() + const { inquiryList } = useInquiry() + const { inquiryListRequest, setInquiryListRequest } = useInquiryFilterStore() + + const { session } = useSessionStore() + useEffect(() => { - if (inquiryList.length > offset + 10) { - setHasMore(true) + if (inquiryList.length !== 0) { + const hasMoreItems = inquiryList[0].totCnt > offset + 10 + setHasMore(hasMoreItems) } else { setHasMore(false) } - }, [inquiryList]) + }, [inquiryList, offset]) + + const handleMyInquiry = () => { + setInquiryListRequest({ ...inquiryListRequest, schRegId: inquiryListRequest.schRegId ? null : session.userId }) + } + + const handleLoadMore = () => { + setOffset(offset + 10) + setInquiryListRequest({ ...inquiryListRequest, startRow: offset, endRow: offset + 10 }) + } return ( <> @@ -36,7 +55,7 @@ export default function ListTable() {
- +
@@ -53,21 +72,22 @@ export default function ListTable() { 合計 {inquiryList.length}
- setOffset(offset + 10)} /> + handleLoadMore()} />
diff --git a/src/hooks/useInquiry.ts b/src/hooks/useInquiry.ts index 07e74fe..17c3099 100644 --- a/src/hooks/useInquiry.ts +++ b/src/hooks/useInquiry.ts @@ -1,4 +1,4 @@ -import { InquiryList, Inquiry, InquiryRequest } from '@/types/Inquiry' +import { InquiryList, Inquiry, InquiryRequest, InquirySaveResponse } from '@/types/Inquiry' import { axiosInstance } from '@/libs/axios' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { useInquiryFilterStore } from '@/store/inquiryFilterStore' @@ -12,37 +12,47 @@ export function useInquiry( inquiryDetail: Inquiry | null isLoadingInquiryDetail: boolean isSavingInquiry: boolean - saveInquiry: (inquiryRequest: InquiryRequest) => Promise + saveInquiry: (inquiryRequest: InquiryRequest) => Promise } { const { session } = useSessionStore() const queryClient = useQueryClient() const { inquiryListRequest } = useInquiryFilterStore() const { data: inquiryList, isLoading: isLoadingInquiryList } = useQuery({ - queryKey: ['inquiryList', qnoNo, compCd, inquiryListRequest], + queryKey: ['inquiryList', inquiryListRequest], queryFn: async () => { - const resp = await axiosInstance(null).get('/api/qna/list', { - params: { inquiryListRequest }, - }) - return resp.data + try { + const resp = await axiosInstance(null).get<{ data: InquiryList[] }>(`/api/qna/list`, { + params: { inquiryListRequest }, + }) + return resp.data.data + } catch (error: any) { + console.error(error.response.data) + return [] + } }, }) const { data: inquiryDetail, isLoading: isLoadingInquiryDetail } = useQuery({ queryKey: ['inquiryDetail', qnoNo, compCd], queryFn: async () => { - const resp = await axiosInstance(null).get(`/api/qna/detail`, { - params: { qnoNo, compCd, loginId: session?.userNm }, - }) - return resp.data + try { + const resp = await axiosInstance(null).get<{ data: Inquiry }>(`/api/qna/detail`, { + params: { qnoNo, compCd, langCd: 'JA', loginId: 'x112' }, + }) + return resp.data.data + } catch (error: any) { + console.error(error.response) + return null + } }, enabled: qnoNo !== undefined && compCd !== undefined, }) const { mutateAsync: saveInquiry, isPending: isSavingInquiry } = useMutation({ mutationFn: async (inquiryRequest: InquiryRequest) => { - const resp = await axiosInstance(null).post('/api/qna/save', inquiryRequest) - return resp.data + const resp = await axiosInstance(null).post<{ data: InquirySaveResponse }>('/api/qna/save', inquiryRequest) + return resp.data.data }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['inquiryList'] }) diff --git a/src/store/inquiryFilterStore.ts b/src/store/inquiryFilterStore.ts index edfadc4..af862c2 100644 --- a/src/store/inquiryFilterStore.ts +++ b/src/store/inquiryFilterStore.ts @@ -9,33 +9,33 @@ type InquiryFilterState = { export const useInquiryFilterStore = create((set) => ({ inquiryListRequest: { - compCd: '', - langCd: '', - storeId: '', - siteTpCd: '', - schTitle: '', - schRegId: '', - schFromDt: '', - schToDt: '', + compCd: '5200', + langCd: 'JA', + storeId: 'X112', + siteTpCd: 'QC', + schTitle: null, + schRegId: null, + schFromDt: null, + schToDt: null, startRow: 0, - endRow: 0, - loginId: '', + endRow: 10, + loginId: 'x112', }, setInquiryListRequest: (inquiryListRequest) => set({ inquiryListRequest }), reset: () => set({ inquiryListRequest: { - compCd: '', - langCd: '', - storeId: '', - siteTpCd: '', + compCd: '5200', + langCd: 'JA', + storeId: 'X112', + siteTpCd: 'QC', schTitle: '', schRegId: '', schFromDt: '', schToDt: '', startRow: 0, - endRow: 0, - loginId: '', + endRow: 50, + loginId: 'x112', }, }), }))