diff --git a/.env.development b/.env.development index 1a372fa..6bc3000 100644 --- a/.env.development +++ b/.env.development @@ -7,7 +7,10 @@ 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 +# NEXT_PUBLIC_INQUIRY_API_URL=http://1.248.227.176:38080 +NEXT_PUBLIC_INQUIRY_API_URL=http://172.23.4.129:8110 +# NEXT_PUBLIC_INQUIRY_API_URL=http://172.30.1.93:8120 + #QPARTNER 로그인 api DB_HOST=202.218.61.226 diff --git a/.env.production b/.env.production index 4c39e83..f741721 100644 --- a/.env.production +++ b/.env.production @@ -5,7 +5,9 @@ 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 +# NEXT_PUBLIC_INQUIRY_API_URL=http://1.248.227.176:38080 +NEXT_PUBLIC_INQUIRY_API_URL=http://172.23.4.129:8110 + #QPARTNER 로그인 api DB_HOST=202.218.61.226 diff --git a/src/app/api/qna/detail/route.ts b/src/app/api/qna/detail/route.ts new file mode 100644 index 0000000..315c18e --- /dev/null +++ b/src/app/api/qna/detail/route.ts @@ -0,0 +1,24 @@ +import { queryStringFormatter } from '@/utils/common-utils' +import axios from 'axios' +import { NextResponse } from 'next/server' + +export async function GET(request: Request) { + const { searchParams } = new URL(request.url) + const params = { + compCd: searchParams.get('compCd'), + qnaNo: 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 }) + } +} diff --git a/src/app/api/qna/file/route.ts b/src/app/api/qna/file/route.ts new file mode 100644 index 0000000..a122da6 --- /dev/null +++ b/src/app/api/qna/file/route.ts @@ -0,0 +1,22 @@ +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') + + if (!encodeFileNo) { + return NextResponse.json({ error: 'encodeFileNo is required' }, { status: 400 }) + } + try { + const response = await axios.get(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/file/downloadFile`, { + params: { + encodeFileNo, + }, + }) + return NextResponse.json(response.data) + } catch (error: any) { + console.error(error.response) + return NextResponse.json({ error: error.response.data }, { status: 500 }) + } +} diff --git a/src/app/api/qna/list/route.ts b/src/app/api/qna/list/route.ts new file mode 100644 index 0000000..f793b98 --- /dev/null +++ b/src/app/api/qna/list/route.ts @@ -0,0 +1,28 @@ +import axios from 'axios' +import { NextResponse } from 'next/server' +import { queryStringFormatter } from '@/utils/common-utils' + +export async function GET(request: Request) { + const { searchParams } = new URL(request.url) + + const params: Record = {} + searchParams.forEach((value, key) => { + const match = key.match(/inquiryListRequest\[(.*)\]/) + if (match) { + params[match[1]] = value + } else { + params[key] = value + } + }) + + 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 }) + } +} diff --git a/src/app/api/qna/save/route.ts b/src/app/api/qna/save/route.ts new file mode 100644 index 0000000..f51ae66 --- /dev/null +++ b/src/app/api/qna/save/route.ts @@ -0,0 +1,20 @@ +import axios from 'axios' +import { NextResponse } from 'next/server' + +export async function POST(request: Request) { + const formData = await request.formData() + try { + const response = await axios.post(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/qna/save`, formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }) + if (response.status === 200) { + return NextResponse.json(response.data) + } + return NextResponse.json({ error: response.data }, { status: response.status }) + } catch (error: any) { + console.error('error:: ', error.response) + return NextResponse.json({ error: 'Failed to save qna' }, { status: 500 }) + } +} diff --git a/src/app/inquiry/list/page.tsx b/src/app/inquiry/list/page.tsx index 93fb334..3e69749 100644 --- a/src/app/inquiry/list/page.tsx +++ b/src/app/inquiry/list/page.tsx @@ -1,11 +1,9 @@ -import ListForm from '@/components/inquiry/ListForm' -import ListTable from '@/components/inquiry/ListTable' +import ListTable from '@/components/inquiry/list/ListTable' export default function page() { return ( <>
-
diff --git a/src/components/inquiry/Answer.tsx b/src/components/inquiry/Answer.tsx index 4eaa9a0..76da68a 100644 --- a/src/components/inquiry/Answer.tsx +++ b/src/components/inquiry/Answer.tsx @@ -1,35 +1,31 @@ 'use client' -export default function Answer() { +import { Inquiry } from '@/types/Inquiry' + +export default function Answer({ inquiryDetail, downloadFile }: { inquiryDetail: Inquiry; downloadFile: (encodeFileNo: number) => Promise }) { return ( <>
Hanwha Japan 回答
- 佐藤一貴/ 2025.04.02 16:54:00 + {inquiryDetail?.ansRegNm}/ {inquiryDetail?.ansRegDt}
回答
-
- 一次側接続は, 自動切替開閉器と住宅分電盤昼間遮断器との間に蓄電システム遮断器を配線する方法です. 二次側接続は, - 住宅分電盤週間ブレーカの二次側に蓄電システムブレーカを接続する -
+
{inquiryDetail?.ansContents}
ファイル添付
    -
  • - -
  • -
  • - -
  • + {inquiryDetail?.ansListFile?.map((file) => ( +
  • + +
  • + ))}
diff --git a/src/components/inquiry/Detail.tsx b/src/components/inquiry/Detail.tsx index 3dcb625..29482d4 100644 --- a/src/components/inquiry/Detail.tsx +++ b/src/components/inquiry/Detail.tsx @@ -1,20 +1,24 @@ 'use client' -import { useState } from 'react' import Answer from './Answer' +import { useInquiry } from '@/hooks/useInquiry' +import { useParams, useRouter } from 'next/navigation' export default function Detail() { - //todo: 답변 완료 표시를 위해 임시로 추가 해 놓은 state - // 추후에 api 작업 완료후 삭제 - // 답변 완료 클래스 & 하단 답변내용 출력도 - const [inquiry, setInquiry] = useState(true) + const params = useParams() + const id = params.id + + const { inquiryDetail, downloadFile } = useInquiry(Number(id), '5200') + const router = useRouter() return ( <>
-
回答完了
+
+ {inquiryDetail?.answerYn === 'Y' ? '回答完了' : '回答待ち'} +
@@ -25,71 +29,54 @@ export default function Detail() { - + - - - - - - - - - + - + - + - +
登録日2025.04.10{inquiryDetail?.regDt}
作者Hong gi
名前Kim
番号070-1234-5678{inquiryDetail?.regNm}
販売店interplug{inquiryDetail?.storeNm}
施工店interplugs{inquiryDetail?.compCd}
E-mailHong@interplug.co.kr{inquiryDetail?.regEmail}
- 屋根 - 適合性 - 屋根材 -
-
屋根材適合性確認依頼
-
- 入力した内容が表示されます. -
- インストール可能であることを確認してください. -
- 屋根の写真を添付しました. + {inquiryDetail?.qnaClsLrgCd} + {inquiryDetail?.qnaClsMidCd} + {inquiryDetail?.qnaClsSmlCd}
+
{inquiryDetail?.qstTitle}
+
{inquiryDetail?.qstContents}
ファイル添付
    -
  • - -
  • -
  • - -
  • + {inquiryDetail?.listFile?.map((file) => ( +
  • + +
  • + ))}
- {inquiry && } + {inquiryDetail?.answerYn === 'Y' && inquiryDetail && }
-
diff --git a/src/components/inquiry/ListForm.tsx b/src/components/inquiry/ListForm.tsx deleted file mode 100644 index 14f38bb..0000000 --- a/src/components/inquiry/ListForm.tsx +++ /dev/null @@ -1,23 +0,0 @@ -'use client' -import { useRouter } from 'next/navigation' - -export default function ListForm() { - const router = useRouter() - return ( - <> -
-
- -
-
-
- - -
-
-
- - ) -} diff --git a/src/components/inquiry/ListTable.tsx b/src/components/inquiry/ListTable.tsx index d65fa85..95911a6 100644 --- a/src/components/inquiry/ListTable.tsx +++ b/src/components/inquiry/ListTable.tsx @@ -1,52 +1,5 @@ 'use client' - -import { use, useEffect, useState } from 'react' -import LoadMoreButton from '../LoadMoreButton' - -const inquiryDummy = [ - { id: 1, category: '屋根', title: '屋根材適合性確認依頼', date: '2025.04.02', status: 'completed' }, - { id: 2, category: '外壁', title: '外壁仕上げ材確認', date: '2025.04.03', status: 'completed' }, - { id: 3, category: '設備', title: '換気システム図面確認', date: '2025.04.04', status: 'completed' }, - { id: 4, category: '基礎', title: '基礎配筋検査依頼', date: '2025.04.05', status: 'completed' }, - { id: 5, category: '内装', title: 'クロス仕様確認', date: '2025.04.06', status: 'waiting' }, - { id: 6, category: '構造', title: '耐震壁位置変更申請', date: '2025.04.07', status: 'completed' }, - { id: 7, category: '屋根', title: '雨樋取付方法確認', date: '2025.04.08', status: 'completed' }, - { id: 8, category: '外構', title: 'フェンス高さ変更相談', date: '2025.04.09', status: 'completed' }, - { id: 9, category: '設備', title: '給湯器設置位置確認', date: '2025.04.10', status: 'completed' }, - { id: 10, category: '外壁', title: 'タイル割付案確認依頼', date: '2025.04.11', status: 'waiting' }, - { id: 11, category: '内装', title: '照明配置図面確認', date: '2025.04.12', status: 'completed' }, - { id: 12, category: '構造', title: '梁補強案確認', date: '2025.04.13', status: 'completed' }, - { id: 13, category: '基礎', title: '杭長設計確認依頼', date: '2025.04.14', status: 'completed' }, - { id: 14, category: '屋根', title: '断熱材施工方法確認', date: '2025.04.15', status: 'completed' }, - { id: 15, category: '外構', title: '駐車場勾配図確認', date: '2025.04.16', status: 'completed' }, -] - -const badgeStyle = [ - { - id: 'completed', - label: '回答完了', - color: 'blue', - }, - { - id: 'waiting', - label: '回答待ち', - color: 'orange', - }, -] export default function ListTable() { - const [offset, setOffset] = useState(0) - const [hasMore, setHasMore] = useState(true) - - const inquiryList = inquiryDummy.slice(0, offset + 10) - - useEffect(() => { - if (inquiryDummy.length > offset + 10) { - setHasMore(true) - } else { - setHasMore(false) - } - }, [inquiryList]) - return ( <>
@@ -60,8 +13,10 @@ export default function ListTable() {
@@ -125,7 +80,9 @@ export default function ListTable() {
- setOffset(offset + 10)} /> +
diff --git a/src/components/inquiry/RegistForm.tsx b/src/components/inquiry/RegistForm.tsx index fc55a63..dd02baa 100644 --- a/src/components/inquiry/RegistForm.tsx +++ b/src/components/inquiry/RegistForm.tsx @@ -1,5 +1,102 @@ 'use client' + +import { useInquiry } from '@/hooks/useInquiry' +import { useSessionStore } from '@/store/session' +import { InquiryRequest } from '@/types/Inquiry' + +import { useEffect, useState } from 'react' +import { useRouter } from 'next/navigation' export default function RegistForm() { + const { saveInquiry, isSavingInquiry } = useInquiry() + const { session } = useSessionStore() + const router = useRouter() + + const [inquiryRequest, setInquiryRequest] = useState({ + compCd: '5200', + siteTpCd: 'QC', + qnaClsLrgCd: '', + qnaClsMidCd: '', + qnaClsSmlCd: null, + title: '', + contents: '', + regId: '', + regUserNm: '', + regUserTelNo: null, + storeId: '', + qstMail: '', + }) + const requiredFieldNames = [ + { id: 'qnaClsLrgCd', name: 'お問い合わせタイプ' }, + { id: 'qnaClsMidCd', name: 'お問い合わせタイプ' }, + { id: 'regUserNm', name: '名前' }, + { id: 'qstMail', name: 'E-mail' }, + { id: 'title', name: 'お問い合わせタイトル' }, + { id: 'contents', name: 'お問い合わせ内容' }, + ] + + useEffect(() => { + if (session?.isLoggedIn) { + setInquiryRequest({ ...inquiryRequest, regId: session?.userId ?? '', regUserNm: session?.userNm ?? '', storeId: session?.storeId ?? '' }) + } + }, [session]) + + const [attachedFiles, setAttachedFiles] = useState([]) + + const handleFileChange = (e: React.ChangeEvent) => { + const files = e.target.files + if (files && files.length > 0) { + setAttachedFiles(attachedFiles.concat(Array.from(files))) + } + e.target.value = '' + } + + const handleRemoveFile = (index: number) => { + setAttachedFiles(attachedFiles.filter((_, i) => i !== index)) + } + + const focusOnRequiredField = (fieldId: string) => { + const element = document.getElementById(fieldId) + if (element) element.focus() + } + + const handleSubmit = async () => { + const emptyField = requiredFieldNames.find((field) => inquiryRequest[field.id as keyof InquiryRequest] === '') + if (emptyField) { + alert(`${emptyField?.name}を入力してください。`) + focusOnRequiredField(emptyField?.id ?? '') + return + } + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ + if (!emailRegex.test(inquiryRequest.qstMail)) { + alert('有効なメールアドレスを入力してください。') + focusOnRequiredField('qstMail') + return + } + + const formData = new FormData() + attachedFiles.forEach((file) => { + formData.append('files', file) + }) + Object.entries(inquiryRequest).forEach(([key, value]) => { + formData.append(key, value ?? '') + }) + + const formDataObj: Record = {} + formData.forEach((value, key) => { + formDataObj[key] = value + }) + + window.neoConfirm( + 'お問い合わせを登録しますか? Hanwha Japanの担当者にお問い合わせメールが送信されます。', + async () => { + const res = await saveInquiry(formData) + alert('保存されました。') + router.push(`/inquiry/${res.qnaNo}`) + }, + () => null, + ) + } + return ( <>
@@ -9,30 +106,42 @@ export default function RegistForm() { お問い合わせタイプ *
- setInquiryRequest({ ...inquiryRequest, qnaClsLrgCd: e.target.value })} + > + + +
- setInquiryRequest({ ...inquiryRequest, qnaClsMidCd: e.target.value })} + > + + +
- setInquiryRequest({ ...inquiryRequest, qnaClsSmlCd: e.target.value })} + > + + +
@@ -41,13 +150,40 @@ export default function RegistForm() { 名前 *
- + setInquiryRequest({ ...inquiryRequest, regUserNm: e.target.value })} + value={inquiryRequest.regUserNm} + id="regUserNm" + />
電話番号
- + setInquiryRequest({ ...inquiryRequest, regUserTelNo: e.target.value })} + id="regUserTelNo" + /> +
+
+
+
+ E-mail * +
+
+ setInquiryRequest({ ...inquiryRequest, qstMail: e.target.value })} + id="qstMail" + />
@@ -55,7 +191,13 @@ export default function RegistForm() { お問い合わせタイトル *
- + setInquiryRequest({ ...inquiryRequest, title: e.target.value })} + id="title" + />
@@ -63,7 +205,13 @@ export default function RegistForm() { お問い合わせタイプ *
- +
@@ -72,29 +220,25 @@ export default function RegistForm() { - +
- 添付ファイル2個 + 添付ファイル{attachedFiles.length}
    -
  • -
    -
    添付ファイル名.jpg
    - -
    -
  • -
  • -
    -
    添付ファイル名.jpg
    - -
    -
  • + {attachedFiles.map((file, index) => ( +
  • +
    +
    {file.name}
    +
    +
  • + ))}
-
diff --git a/src/components/inquiry/list/ListForm.tsx b/src/components/inquiry/list/ListForm.tsx new file mode 100644 index 0000000..bb41fb3 --- /dev/null +++ b/src/components/inquiry/list/ListForm.tsx @@ -0,0 +1,46 @@ +'use client' +import { useInquiryFilterStore } from '@/store/inquiryFilterStore' +import { useRouter } from 'next/navigation' +import { useState } from 'react' + +export default function ListForm() { + const router = useRouter() + const { inquiryListRequest, setInquiryListRequest } = useInquiryFilterStore() + const [searchKeyword, setSearchKeyword] = useState(inquiryListRequest.schTitle ?? '') + + const handleSearch = () => { + if (searchKeyword.length >= 2) { + setInquiryListRequest({ ...inquiryListRequest, schTitle: searchKeyword }) + } + } + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + handleSearch() + } + } + + return ( + <> +
+
+ +
+
+
+ setSearchKeyword(e.target.value)} + onKeyDown={handleKeyDown} + /> + +
+
+
+ + ) +} diff --git a/src/components/inquiry/list/ListTable.tsx b/src/components/inquiry/list/ListTable.tsx new file mode 100644 index 0000000..bf5ce88 --- /dev/null +++ b/src/components/inquiry/list/ListTable.tsx @@ -0,0 +1,146 @@ +'use client' + +import { useEffect, useState } from 'react' +import LoadMoreButton from '../../LoadMoreButton' +import { useInquiry } from '@/hooks/useInquiry' +import { InquiryList } from '@/types/Inquiry' +import { usePathname, useRouter } from 'next/navigation' +import { useInquiryFilterStore } from '@/store/inquiryFilterStore' +import { useSessionStore } from '@/store/session' +import ListForm from './ListForm' + +const badgeStyle = [ + { + id: 'Y', + label: '回答完了', + color: 'blue', + }, + { + id: 'N', + label: '回答待ち', + color: 'orange', + }, +] +export default function ListTable() { + const router = useRouter() + const pathname = usePathname() + + const { inquiryList } = useInquiry() + const { inquiryListRequest, setInquiryListRequest, reset } = useInquiryFilterStore() + + const [offset, setOffset] = useState(inquiryListRequest.startRow) + const [hasMore, setHasMore] = useState(false) + + const [heldInquiryList, setHeldInquiryList] = useState([]) + + const { session } = useSessionStore() + + useEffect(() => { + setInquiryListRequest({ ...inquiryListRequest, startRow: 1, endRow: 10 }) + setHeldInquiryList([]) + setOffset(1) + setHasMore(false) + }, [pathname]) + + useEffect(() => { + if (!session.isLoggedIn || !inquiryList) return + if (session.isLoggedIn) { + setInquiryListRequest({ ...inquiryListRequest, storeId: session.storeId ?? '', loginId: session.userId ?? '' }) + // setInquiryListRequest({ ...inquiryListRequest, storeId: 'X112', loginId: 'x112' }) + } + console.log('inquiryListRequest', inquiryListRequest) + if (inquiryList.length > 0 && inquiryList[0].totCnt > 0) { + if (inquiryListRequest.startRow > 1) { + const isDuplicate = inquiryList.every((newItem) => heldInquiryList.some((existingItem) => existingItem.qnaNo === newItem.qnaNo)) + if (isDuplicate) return + setHeldInquiryList((prev) => [...prev, ...inquiryList]) + } else { + setHeldInquiryList(inquiryList) + } + setHasMore(inquiryList[0].totCnt > inquiryListRequest.endRow) + } else { + setHeldInquiryList([]) + setHasMore(false) + } + }, [session, inquiryList, inquiryListRequest.startRow]) + + const handleMyInquiry = () => { + setInquiryListRequest({ ...inquiryListRequest, schRegId: inquiryListRequest.schRegId ? null : session.userId }) + } + + const handleFilter = (e: React.ChangeEvent) => { + switch (e.target.value) { + case 'N': + setInquiryListRequest({ ...inquiryListRequest, schAnswerYn: 'N' }) + break + case 'Y': + setInquiryListRequest({ ...inquiryListRequest, schAnswerYn: 'Y' }) + break + default: + reset() + break + } + } + + return ( + <> + +
+
+
+
+ + +
+
+
+ +
+
+
+
+ 合計 {heldInquiryList.length > 0 ? heldInquiryList[0].totCnt : 0}個 +
+ {heldInquiryList.length === 0 || (heldInquiryList.length > 0 && heldInquiryList[0].totCnt === 0) ? ( +
+
照会されたデータがありません。
+
+ ) : ( +
    + {heldInquiryList.length > 0 && + heldInquiryList.map((inquiry: InquiryList) => ( +
  • router.push(`/inquiry/${inquiry.qnaNo}`)}> +
    +
    + {inquiry.qnaClsLrgCd} + {inquiry.qnaClsMidCd} + {inquiry.qnaClsSmlCd} +
    +
    {inquiry.qstTitle}
    +
    {inquiry.regDt}
    +
    badge.id === inquiry.answerYn)?.color}`}> + {badgeStyle.find((badge) => badge.id === inquiry.answerYn)?.label} +
    +
    +
  • + ))} +
+ )} +
+ { + setInquiryListRequest({ ...inquiryListRequest, startRow: offset + 10, endRow: offset + 19 }) + setOffset(inquiryListRequest.startRow) + }} + /> +
+
+
+ + ) +} diff --git a/src/hooks/useInquiry.ts b/src/hooks/useInquiry.ts new file mode 100644 index 0000000..816f31d --- /dev/null +++ b/src/hooks/useInquiry.ts @@ -0,0 +1,90 @@ +import { InquiryList, Inquiry, InquirySaveResponse } from '@/types/Inquiry' +import { useAxios } from '@/hooks/useAxios' +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' +import { useInquiryFilterStore } from '@/store/inquiryFilterStore' +import { useMemo } from 'react' +import { useSessionStore } from '@/store/session' + +export function useInquiry( + qnoNo?: number, + compCd?: string, +): { + inquiryList: InquiryList[] + isLoadingInquiryList: boolean + inquiryDetail: Inquiry | null + isLoadingInquiryDetail: boolean + isSavingInquiry: boolean + saveInquiry: (formData: FormData) => Promise + downloadFile: (encodeFileNo: number) => Promise +} { + const queryClient = useQueryClient() + const { inquiryListRequest } = useInquiryFilterStore() + const { session } = useSessionStore() + const { axiosInstance } = useAxios() + + const { data: inquiryList, isLoading: isLoadingInquiryList } = useQuery({ + queryKey: ['inquiryList', inquiryListRequest], + queryFn: async () => { + 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 [] + } + }, + placeholderData: (previousData) => previousData, + }) + + const inquriyListData = useMemo(() => { + if (isLoadingInquiryList) { + return { inquiryList: inquiryList ?? [] } + } + return { + inquiryList: inquiryList ?? [], + } + }, [inquiryList, isLoadingInquiryList]) + + const { data: inquiryDetail, isLoading: isLoadingInquiryDetail } = useQuery({ + queryKey: ['inquiryDetail', qnoNo, compCd, session?.userId], + queryFn: async () => { + try { + const resp = await axiosInstance(null).get<{ data: Inquiry }>(`/api/qna/detail`, { + params: { qnoNo, compCd, langCd: 'JA', loginId: session?.userId ?? '' }, + }) + 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 (formData: FormData) => { + const resp = await axiosInstance(null).post<{ data: InquirySaveResponse }>('/api/qna/save', formData) + return resp.data.data + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['inquiryList'] }) + }, + }) + + const downloadFile = async (encodeFileNo: number) => { + const resp = await axiosInstance(null).get(`/api/qna/file`, { params: { encodeFileNo } }) + return resp.data + } + + return { + inquiryList: inquriyListData.inquiryList, + inquiryDetail: inquiryDetail ?? null, + isLoadingInquiryList, + isLoadingInquiryDetail, + isSavingInquiry, + saveInquiry, + downloadFile, + } +} diff --git a/src/store/inquiryFilterStore.ts b/src/store/inquiryFilterStore.ts index 0960c85..62f70df 100644 --- a/src/store/inquiryFilterStore.ts +++ b/src/store/inquiryFilterStore.ts @@ -1,41 +1,43 @@ +import { InquiryListRequest } from '@/types/Inquiry' import { create } from 'zustand' -export const FILTER_OPTIONS = [ - { - id: 'all', - label: '全体', - }, - { - id: 'completed', - label: '回答完了', - }, - { - id: 'waiting', - label: '回答待ち', - }, -] -export type FILTER_OPTIONS_ENUM = (typeof FILTER_OPTIONS)[number]['id'] - type InquiryFilterState = { - keyword: string - filter: FILTER_OPTIONS_ENUM - isMySurvey: string | null - offset: number - setKeyword: (keyword: string) => void - setFilter: (filter: FILTER_OPTIONS_ENUM) => void - setIsMySurvey: (isMySurvey: string | null) => void - setOffset: (offset: number) => void + inquiryListRequest: InquiryListRequest + setInquiryListRequest: (inquiryListRequest: InquiryListRequest) => void reset: () => void } export const useInquiryFilterStore = create((set) => ({ - keyword: '', - filter: 'all', - isMySurvey: null, - offset: 0, - setKeyword: (keyword) => set({ keyword }), - setFilter: (filter) => set({ filter }), - setIsMySurvey: (isMySurvey) => set({ isMySurvey }), - setOffset: (offset) => set({ offset }), - reset: () => set({ keyword: '', filter: 'all', isMySurvey: null, offset: 0 }), + inquiryListRequest: { + compCd: '5200', + langCd: 'JA', + storeId: '', + siteTpCd: 'QC', + schTitle: null, + schRegId: null, + schFromDt: null, + schToDt: null, + schAnswerYn: null, + startRow: 1, + endRow: 10, + loginId: '', + }, + setInquiryListRequest: (inquiryListRequest) => set({ inquiryListRequest }), + reset: () => + set({ + inquiryListRequest: { + compCd: '5200', + langCd: 'JA', + storeId: '', + siteTpCd: 'QC', + schTitle: '', + schRegId: '', + schFromDt: '', + schToDt: '', + schAnswerYn: null, + startRow: 1, + endRow: 10, + loginId: '', + }, + }), })) diff --git a/src/types/Inquiry.ts b/src/types/Inquiry.ts new file mode 100644 index 0000000..79ac368 --- /dev/null +++ b/src/types/Inquiry.ts @@ -0,0 +1,91 @@ +export type InquiryListRequest = { + compCd: string //company code + langCd: string //language code + storeId: string //store id + siteTpCd: string //site type code (QC: QCast, QR: QRead) + schTitle: string | null //search title + schRegId: string | null //search regId + schFromDt: string | null //search start date + schToDt: string | null //search end date + schAnswerYn: string | null //search answer yn + startRow: number //start row + endRow: number //end row + loginId: string //login id +} + +export type InquiryList = { + totCnt: number //total count + rowNumber: number //row number + compCd: string //company code + qnaNo: number //qna number + qstTitle: string //title + regDt: string //registration date + regId: string //registration Userid + regNm: string //registration User name + answerYn: string //answer yn - Y / N + attachYn: string | null //attach yn - Y / N + qnaClsLrgCd: string //qna CLS large Code + qnaClsMidCd: string //qna CLS Mid Code + qnaClsSmlCd: string | null //qna CLS Small Code +} + +export type InquiryDetailRequest = { + compCd: string //company code + langCd: string //language code + qnaNo: number //qna number + loginId: string //login id +} + +export type Inquiry = { + compCd: string //company code + qnaNo: number //qna number + qstTitle: string //title + qstContents: string //content + regDt: string //registration date + regId: string //registration Userid + regNm: string //registration User name + regEmail: string //registration User email + answerYn: string //answer yn - Y / N + ansContents: string | null //answer content + ansRegDt: string | null //answer registration date + ansRegNm: string | null //answer registration User name + storeId: string | null //store id + storeNm: string | null //store name + regUserNm: string //registration User name + regUserTelNo: string | null //registration User tel number + qnaClsLrgCd: string //qna CLS large Code + qnaClsMidCd: string //qna CLS Mid Code + qnaClsSmlCd: string | null //qna CLS Small Code + listFile: listFile[] | null //Question list file + ansListFile: listFile[] | null //Answer list file +} + +export type listFile = { + fileNo: number //file number + encodeFileNo: string //encode file number + srcFileNm: string //source file name + fileCours: string //file course + fileSize: number //file size(Byte) + regDt: string //registration date +} + +export type InquiryRequest = { + compCd: string //company code + siteTpCd: string //site type code(QC: QCast, QR: QRead) + qnaClsLrgCd: string //qna CLS large Code + qnaClsMidCd: string //qna CLS Mid Code + qnaClsSmlCd: string | null //qna CLS Small Code + title: string //title + contents: string //contents + regId: string //registration Userid + storeId: string //store id + regUserNm: string //registration User name + regUserTelNo: string | null //registration User tel number + qstMail: string //mail +} + +export type InquirySaveResponse = { + cnt: number | null //count + qnaNo: number //qna number + mailYn: string //mail yn - Y / N +}