feat: 지붕재적합성 초기화면 전체 데이터 미표출, 검색조건 그룹코드로 변경
This commit is contained in:
parent
36bcdd00a1
commit
8bcffd43bb
@ -41,7 +41,7 @@ export async function GET(request: NextRequest) {
|
|||||||
) AS details
|
) AS details
|
||||||
ON msm.id = details.main_id
|
ON msm.id = details.main_id
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
--roofMtCd AND msm.roof_mt_cd = ':roofMtCd'
|
--roofMtCd AND msm.roof_mt_cd IN (:roofMtCd)
|
||||||
--productName AND msm.product_name LIKE '%:productName%'
|
--productName AND msm.product_name LIKE '%:productName%'
|
||||||
ORDER BY msm.product_name
|
ORDER BY msm.product_name
|
||||||
OFFSET (@P1 - 1) * @P2 ROWS
|
OFFSET (@P1 - 1) * @P2 ROWS
|
||||||
@ -50,8 +50,13 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
// 검색 조건 설정
|
// 검색 조건 설정
|
||||||
if (category) {
|
if (category) {
|
||||||
|
let roofMtQuery = `
|
||||||
|
SELECT roof_mt_cd
|
||||||
|
FROM ms_suitable_roof_material_group
|
||||||
|
WHERE roof_matl_grp_cd = ':roofMtGrpCd'
|
||||||
|
`
|
||||||
query = query.replace('--roofMtCd ', '')
|
query = query.replace('--roofMtCd ', '')
|
||||||
query = query.replace(':roofMtCd', category)
|
query = query.replace(':roofMtCd', roofMtQuery.replace(':roofMtGrpCd', category))
|
||||||
}
|
}
|
||||||
if (keyword) {
|
if (keyword) {
|
||||||
query = query.replace('--productName ', '')
|
query = query.replace('--productName ', '')
|
||||||
@ -60,6 +65,8 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
const suitable: Suitable[] = await prisma.$queryRawUnsafe(query, pageNumber, itemPerPage)
|
const suitable: Suitable[] = await prisma.$queryRawUnsafe(query, pageNumber, itemPerPage)
|
||||||
|
|
||||||
|
// console.log(`검색 조건 :::: 카테고리: ${category}, 키워드: ${keyword}`)
|
||||||
|
|
||||||
return NextResponse.json(suitable)
|
return NextResponse.json(suitable)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ 데이터 조회 중 오류가 발생했습니다:', error)
|
console.error('❌ 데이터 조회 중 오류가 발생했습니다:', error)
|
||||||
|
|||||||
@ -10,29 +10,28 @@ import { SUITABLE_HEAD_CODE } from '@/types/Suitable'
|
|||||||
|
|
||||||
export default function Suitable() {
|
export default function Suitable() {
|
||||||
const [reference, setReference] = useState(true)
|
const [reference, setReference] = useState(true)
|
||||||
|
const [searchValue, setSearchValue] = useState('')
|
||||||
|
|
||||||
const { getSuitableCommCode } = useSuitable()
|
const { getSuitableCommCode, clearSuitableSearch } = useSuitable()
|
||||||
const { suitableCommCode, selectedCategory, setSelectedCategory, searchValue, setSearchValue, setIsSearch, clearSelectedItems } = useSuitableStore()
|
const { suitableCommCode, selectedCategory, setSelectedCategory, setSearchKeyword, clearSearchKeyword } = useSuitableStore()
|
||||||
|
|
||||||
const handleInputSearch = async () => {
|
const handleInputSearch = async () => {
|
||||||
if (!searchValue.trim()) {
|
if (!searchValue.trim()) {
|
||||||
alert('屋根材の製品名を入力してください。')
|
alert('屋根材の製品名を入力してください。')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setIsSearch(true)
|
setSearchKeyword(searchValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInputClear = () => {
|
const handleInputClear = () => {
|
||||||
setSearchValue('')
|
setSearchValue('')
|
||||||
setIsSearch(false)
|
clearSearchKeyword()
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSuitableCommCode()
|
getSuitableCommCode()
|
||||||
return () => {
|
return () => {
|
||||||
setSelectedCategory('')
|
clearSuitableSearch()
|
||||||
setSearchValue('')
|
|
||||||
clearSelectedItems()
|
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ export default function Suitable() {
|
|||||||
<div className="sale-form-bx">
|
<div className="sale-form-bx">
|
||||||
<select className="select-form" name="" id="" value={selectedCategory || ''} onChange={(e) => setSelectedCategory(e.target.value)}>
|
<select className="select-form" name="" id="" value={selectedCategory || ''} onChange={(e) => setSelectedCategory(e.target.value)}>
|
||||||
<option value="">屋根材を選択してください.</option>
|
<option value="">屋根材を選択してください.</option>
|
||||||
{suitableCommCode.get(SUITABLE_HEAD_CODE.ROOF_MT_CD)?.map((category: CommCode, index: number) => (
|
{suitableCommCode.get(SUITABLE_HEAD_CODE.ROOF_MATERIAL_GROUP)?.map((category: CommCode, index: number) => (
|
||||||
<option key={index} value={category.code}>
|
<option key={index} value={category.code}>
|
||||||
{category.codeJp}
|
{category.codeJp}
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
@ -117,7 +117,7 @@ export default function SuitableList() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 아이템 리스트
|
// 아이템 리스트
|
||||||
const suitableList = suitables?.pages.flat() ?? []
|
const suitableList = useMemo(() => suitables?.pages.flat() ?? [], [suitables?.pages])
|
||||||
|
|
||||||
// Intersection Observer 설정
|
// Intersection Observer 설정
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -8,7 +8,17 @@ import { SUITABLE_HEAD_CODE, type Suitable, type SuitableDetail, type SuitableId
|
|||||||
export function useSuitable() {
|
export function useSuitable() {
|
||||||
const { axiosInstance } = useAxios()
|
const { axiosInstance } = useAxios()
|
||||||
const { getCommCode } = useCommCode()
|
const { getCommCode } = useCommCode()
|
||||||
const { itemPerPage, selectedCategory, searchValue, suitableCommCode, setSuitableCommCode, isSearch, selectedItems } = useSuitableStore()
|
const {
|
||||||
|
itemPerPage,
|
||||||
|
suitableCommCode,
|
||||||
|
setSuitableCommCode,
|
||||||
|
selectedCategory,
|
||||||
|
clearSelectedCategory,
|
||||||
|
searchKeyword,
|
||||||
|
clearSearchKeyword,
|
||||||
|
selectedItems,
|
||||||
|
clearSelectedItems,
|
||||||
|
} = useSuitableStore()
|
||||||
|
|
||||||
const getSuitables = async ({
|
const getSuitables = async ({
|
||||||
pageNumber,
|
pageNumber,
|
||||||
@ -39,7 +49,7 @@ export function useSuitable() {
|
|||||||
try {
|
try {
|
||||||
const params: Record<string, string> = {}
|
const params: Record<string, string> = {}
|
||||||
if (selectedCategory) params.category = selectedCategory
|
if (selectedCategory) params.category = selectedCategory
|
||||||
if (searchValue) params.keyword = searchValue
|
if (searchKeyword) params.keyword = searchKeyword
|
||||||
const response = await axiosInstance(null).get<SuitableIds[]>('/api/suitable/pick', { params })
|
const response = await axiosInstance(null).get<SuitableIds[]>('/api/suitable/pick', { params })
|
||||||
return response.data
|
return response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -105,13 +115,13 @@ export function useSuitable() {
|
|||||||
isError,
|
isError,
|
||||||
error,
|
error,
|
||||||
} = useInfiniteQuery<Suitable[]>({
|
} = useInfiniteQuery<Suitable[]>({
|
||||||
queryKey: ['suitables', 'list', selectedCategory, isSearch],
|
queryKey: ['suitables', 'list', selectedCategory, searchKeyword],
|
||||||
queryFn: async (context) => {
|
queryFn: async (context) => {
|
||||||
const pageParam = context.pageParam as number
|
const pageParam = context.pageParam as number
|
||||||
return await getSuitables({
|
return await getSuitables({
|
||||||
pageNumber: pageParam,
|
pageNumber: pageParam,
|
||||||
...(selectedCategory && { category: selectedCategory }),
|
...(selectedCategory && { category: selectedCategory }),
|
||||||
...(isSearch && { keyword: searchValue }),
|
...(searchKeyword && { keyword: searchKeyword }),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getNextPageParam: (lastPage: Suitable[], allPages: Suitable[][]) => {
|
getNextPageParam: (lastPage: Suitable[], allPages: Suitable[][]) => {
|
||||||
@ -120,6 +130,7 @@ export function useSuitable() {
|
|||||||
initialPageParam: 1,
|
initialPageParam: 1,
|
||||||
staleTime: 1000 * 60 * 10,
|
staleTime: 1000 * 60 * 10,
|
||||||
gcTime: 1000 * 60 * 10,
|
gcTime: 1000 * 60 * 10,
|
||||||
|
enabled: selectedCategory !== '' || searchKeyword !== '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const serializeSelectedItems = (): Map<string, string> => {
|
const serializeSelectedItems = (): Map<string, string> => {
|
||||||
@ -135,6 +146,12 @@ export function useSuitable() {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clearSuitableSearch = () => {
|
||||||
|
clearSelectedItems()
|
||||||
|
clearSearchKeyword()
|
||||||
|
clearSelectedCategory()
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getSuitables,
|
getSuitables,
|
||||||
getSuitableIds,
|
getSuitableIds,
|
||||||
@ -149,5 +166,6 @@ export function useSuitable() {
|
|||||||
isFetchingNextPage,
|
isFetchingNextPage,
|
||||||
isLoading,
|
isLoading,
|
||||||
serializeSelectedItems,
|
serializeSelectedItems,
|
||||||
|
clearSuitableSearch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,20 +11,19 @@ interface SuitableState {
|
|||||||
/* 공통코드 설정 */
|
/* 공통코드 설정 */
|
||||||
setSuitableCommCode: (headCode: string, commCode: CommCode[]) => void
|
setSuitableCommCode: (headCode: string, commCode: CommCode[]) => void
|
||||||
|
|
||||||
/* 검색 상태 */
|
|
||||||
isSearch: boolean
|
|
||||||
/* 검색 상태 설정 */
|
|
||||||
setIsSearch: (isSearch: boolean) => void
|
|
||||||
|
|
||||||
/* 선택된 카테고리 */
|
/* 선택된 카테고리 */
|
||||||
selectedCategory: string
|
selectedCategory: string
|
||||||
/* 선택된 카테고리 설정 */
|
/* 선택된 카테고리 설정 */
|
||||||
setSelectedCategory: (category: string) => void
|
setSelectedCategory: (category: string) => void
|
||||||
|
/* 선택된 카테고리 초기화 */
|
||||||
|
clearSelectedCategory: () => void
|
||||||
|
|
||||||
/* 검색 값 */
|
/* 검색 값 */
|
||||||
searchValue: string
|
searchKeyword: string
|
||||||
/* 검색 값 설정 */
|
/* 검색 값 설정 */
|
||||||
setSearchValue: (value: string) => void
|
setSearchKeyword: (value: string) => void
|
||||||
|
/* 검색 값 초기화 */
|
||||||
|
clearSearchKeyword: () => void
|
||||||
|
|
||||||
/* 선택된 아이템 리스트 */
|
/* 선택된 아이템 리스트 */
|
||||||
selectedItems: Map<number, Set<number>>
|
selectedItems: Map<number, Set<number>>
|
||||||
@ -41,9 +40,8 @@ interface SuitableState {
|
|||||||
export const useSuitableStore = create<SuitableState>((set) => ({
|
export const useSuitableStore = create<SuitableState>((set) => ({
|
||||||
itemPerPage: 100 as number,
|
itemPerPage: 100 as number,
|
||||||
suitableCommCode: new Map() as Map<string, CommCode[]>,
|
suitableCommCode: new Map() as Map<string, CommCode[]>,
|
||||||
isSearch: false as boolean,
|
|
||||||
selectedCategory: '' as string,
|
selectedCategory: '' as string,
|
||||||
searchValue: '' as string,
|
searchKeyword: '' as string,
|
||||||
selectedItems: new Map() as Map<number, Set<number>>,
|
selectedItems: new Map() as Map<number, Set<number>>,
|
||||||
|
|
||||||
/* 공통코드 설정 */
|
/* 공통코드 설정 */
|
||||||
@ -52,14 +50,15 @@ export const useSuitableStore = create<SuitableState>((set) => ({
|
|||||||
suitableCommCode: new Map(state.suitableCommCode).set(headCode, commCode),
|
suitableCommCode: new Map(state.suitableCommCode).set(headCode, commCode),
|
||||||
})),
|
})),
|
||||||
|
|
||||||
/* 검색 상태 설정 */
|
|
||||||
setIsSearch: (isSearch: boolean) => set({ isSearch }),
|
|
||||||
|
|
||||||
/* 선택된 카테고리 설정 */
|
/* 선택된 카테고리 설정 */
|
||||||
setSelectedCategory: (category: string) => set({ selectedCategory: category }),
|
setSelectedCategory: (category: string) => set({ selectedCategory: category }),
|
||||||
|
/* 선택된 카테고리 초기화 */
|
||||||
|
clearSelectedCategory: () => set({ selectedCategory: '' }),
|
||||||
|
|
||||||
/* 검색 값 설정 */
|
/* 검색 값 설정 */
|
||||||
setSearchValue: (value: string) => set({ searchValue: value }),
|
setSearchKeyword: (value: string) => set({ searchKeyword: value }),
|
||||||
|
/* 검색 값 초기화 */
|
||||||
|
clearSearchKeyword: () => set({ searchKeyword: '' }),
|
||||||
|
|
||||||
/* 선택된 아이템 추가 */
|
/* 선택된 아이템 추가 */
|
||||||
addSelectedItem: (mainId: number, detailId?: number, detailIds?: Set<number>) => {
|
addSelectedItem: (mainId: number, detailId?: number, detailIds?: Set<number>) => {
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
export enum SUITABLE_HEAD_CODE {
|
export enum SUITABLE_HEAD_CODE {
|
||||||
/* 지붕재 제조사명 */
|
/* 지붕재 제조사명 */
|
||||||
MANU_FT_CD = 'MANU_FT_CD',
|
MANU_FT_CD = 'MANU_FT_CD',
|
||||||
|
/* 지붕재 그룹 종류 */
|
||||||
|
ROOF_MATERIAL_GROUP = 'ROOF_MATL_GRP_CD',
|
||||||
/* 지붕재 종류 */
|
/* 지붕재 종류 */
|
||||||
ROOF_MT_CD = 'ROOF_MT_CD',
|
ROOF_MT_CD = 'ROOF_MT_CD',
|
||||||
/* 마운팅 브래킷 종류 */
|
/* 마운팅 브래킷 종류 */
|
||||||
ROOF_SH_CD = 'ROOF_SH_CD',
|
ROOF_SH_CD = 'ROOF_SH_CD',
|
||||||
/* 마운팅 브래킷 제조사명 및 제품코드드 */
|
/* 마운팅 브래킷 제조사명 및 제품코드 */
|
||||||
TRESTLE_MFPC_CD = 'TRESTLE_MFPC_CD',
|
TRESTLE_MFPC_CD = 'TRESTLE_MFPC_CD',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user