feat: implement survey list filter by Member Type for temporary
- 로그인 유저 타입 별 조사매물 필터링 임시 구현 - 로그인 유저 타입 구현 이후 변경 예정
This commit is contained in:
parent
da0d77724d
commit
29488b2412
@ -17,6 +17,8 @@ export async function GET(request: Request) {
|
|||||||
const isMySurvey = searchParams.get('isMySurvey')
|
const isMySurvey = searchParams.get('isMySurvey')
|
||||||
const sort = searchParams.get('sort')
|
const sort = searchParams.get('sort')
|
||||||
const offset = searchParams.get('offset')
|
const offset = searchParams.get('offset')
|
||||||
|
const store = searchParams.get('store')
|
||||||
|
const construction_point = searchParams.get('construction_point')
|
||||||
|
|
||||||
const searchOptions = ['building_name', 'representative', 'store', 'construction_point', 'customer_name', 'post_code', 'address', 'address_detail']
|
const searchOptions = ['building_name', 'representative', 'store', 'construction_point', 'customer_name', 'post_code', 'address', 'address_detail']
|
||||||
try {
|
try {
|
||||||
@ -54,6 +56,22 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
where.AND = []
|
||||||
|
if (store) {
|
||||||
|
where.AND.push({
|
||||||
|
store: {
|
||||||
|
equals: store,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (construction_point) {
|
||||||
|
where.AND.push({
|
||||||
|
construction_point: {
|
||||||
|
equals: construction_point,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (offset) {
|
if (offset) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.findMany({
|
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.findMany({
|
||||||
|
|||||||
@ -5,8 +5,9 @@ import { useServey } from '@/hooks/useSurvey'
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import SearchForm from './SearchForm'
|
import SearchForm from './SearchForm'
|
||||||
import { useSurveyFilterStore } from '@/store/surveyFilterStore'
|
import { MEMBER_TYPE, useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||||
import { useSessionStore } from '@/store/session'
|
// import { useSessionStore } from '@/store/session'
|
||||||
|
import { dummyUser } from '@/types/Survey'
|
||||||
|
|
||||||
export default function ListTable() {
|
export default function ListTable() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -15,9 +16,10 @@ export default function ListTable() {
|
|||||||
|
|
||||||
const [heldSurveyList, setHeldSurveyList] = useState<typeof surveyList>([])
|
const [heldSurveyList, setHeldSurveyList] = useState<typeof surveyList>([])
|
||||||
const [hasMore, setHasMore] = useState(false)
|
const [hasMore, setHasMore] = useState(false)
|
||||||
|
const [memberType, setMemberType] = useState<MEMBER_TYPE>('hwj')
|
||||||
|
|
||||||
const { session } = useSessionStore()
|
// TODO : 회원 유형 설정 이후 변경
|
||||||
console.log('session:: ', session)
|
// const { session } = useSessionStore()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (surveyList && surveyList.length > 0) {
|
if (surveyList && surveyList.length > 0) {
|
||||||
@ -31,6 +33,11 @@ export default function ListTable() {
|
|||||||
}
|
}
|
||||||
setHasMore(surveyListCount > offset + 10)
|
setHasMore(surveyListCount > offset + 10)
|
||||||
}
|
}
|
||||||
|
// TODO : 회원 유형 설정 이후 변경
|
||||||
|
// if (session?.userId) {
|
||||||
|
// setMemberType(session.userId)
|
||||||
|
// }
|
||||||
|
setMemberType('hwj')
|
||||||
}, [surveyList, surveyListCount, offset])
|
}, [surveyList, surveyListCount, offset])
|
||||||
|
|
||||||
const handleDetailClick = (id: number) => {
|
const handleDetailClick = (id: number) => {
|
||||||
@ -45,7 +52,7 @@ export default function ListTable() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SearchForm onItemsInit={handleItemsInit} />
|
<SearchForm onItemsInit={handleItemsInit} memberType={memberType} />
|
||||||
{heldSurveyList.length > 0 ? (
|
{heldSurveyList.length > 0 ? (
|
||||||
<div className="sale-frame">
|
<div className="sale-frame">
|
||||||
<ul className="sale-list-wrap">
|
<ul className="sale-list-wrap">
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { SEARCH_OPTIONS, SEARCH_OPTIONS_ENUM, useSurveyFilterStore } from '@/store/surveyFilterStore'
|
import { MEMBER_TYPE, SEARCH_OPTIONS, SEARCH_OPTIONS_ENUM, SEARCH_OPTIONS_PARTNERS, useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
export default function SearchForm({ onItemsInit }: { onItemsInit: () => void }) {
|
export default function SearchForm({ onItemsInit, memberType }: { onItemsInit: () => void; memberType: MEMBER_TYPE }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { setSearchOption, setSort, setIsMySurvey, setKeyword, isMySurvey, keyword, searchOption, sort } = useSurveyFilterStore()
|
const { setSearchOption, setSort, setIsMySurvey, setKeyword, isMySurvey, keyword, searchOption, sort } = useSurveyFilterStore()
|
||||||
const [searchKeyword, setSearchKeyword] = useState(keyword)
|
const [searchKeyword, setSearchKeyword] = useState(keyword)
|
||||||
@ -19,6 +19,7 @@ export default function SearchForm({ onItemsInit }: { onItemsInit: () => void })
|
|||||||
setKeyword(searchKeyword)
|
setKeyword(searchKeyword)
|
||||||
onItemsInit()
|
onItemsInit()
|
||||||
}
|
}
|
||||||
|
const searchOptions = memberType === 'partner' ? SEARCH_OPTIONS_PARTNERS : SEARCH_OPTIONS
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="sale-frame">
|
<div className="sale-frame">
|
||||||
@ -35,7 +36,7 @@ export default function SearchForm({ onItemsInit }: { onItemsInit: () => void })
|
|||||||
value={searchOption}
|
value={searchOption}
|
||||||
onChange={(e) => setSearchOption(e.target.value as SEARCH_OPTIONS_ENUM)}
|
onChange={(e) => setSearchOption(e.target.value as SEARCH_OPTIONS_ENUM)}
|
||||||
>
|
>
|
||||||
{SEARCH_OPTIONS.map((option) => (
|
{searchOptions.map((option) => (
|
||||||
<option key={option.id} value={option.id}>
|
<option key={option.id} value={option.id}>
|
||||||
{option.label}
|
{option.label}
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|||||||
import type { SurveyBasicInfo, SurveyBasicRequest, SurveyDetailInfo, SurveyDetailRequest, SurveyDetailCoverRequest } from '@/types/Survey'
|
import type { SurveyBasicInfo, SurveyBasicRequest, SurveyDetailInfo, SurveyDetailRequest, SurveyDetailCoverRequest } from '@/types/Survey'
|
||||||
import { axiosInstance } from '@/libs/axios'
|
import { axiosInstance } from '@/libs/axios'
|
||||||
import { useSurveyFilterStore } from '@/store/surveyFilterStore'
|
import { useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||||
|
import { useUserType } from './useUserType'
|
||||||
|
|
||||||
export function useServey(id?: number): {
|
export function useServey(id?: number): {
|
||||||
surveyList: SurveyBasicInfo[] | []
|
surveyList: SurveyBasicInfo[] | []
|
||||||
@ -21,12 +22,13 @@ export function useServey(id?: number): {
|
|||||||
} {
|
} {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const { keyword, searchOption, isMySurvey, sort, offset } = useSurveyFilterStore()
|
const { keyword, searchOption, isMySurvey, sort, offset } = useSurveyFilterStore()
|
||||||
|
const { store, construction_point } = useUserType()
|
||||||
|
|
||||||
const { data: surveyList, isLoading: isLoadingSurveyList } = useQuery({
|
const { data: surveyList, isLoading: isLoadingSurveyList } = useQuery({
|
||||||
queryKey: ['survey', 'list', keyword, searchOption, isMySurvey, sort, offset],
|
queryKey: ['survey', 'list', keyword, searchOption, isMySurvey, sort, offset, store, construction_point],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const resp = await axiosInstance(null).get<SurveyBasicInfo[]>('/api/survey-sales', {
|
const resp = await axiosInstance(null).get<SurveyBasicInfo[]>('/api/survey-sales', {
|
||||||
params: { keyword, searchOption, isMySurvey, sort, offset },
|
params: { keyword, searchOption, isMySurvey, sort, offset, store, construction_point },
|
||||||
})
|
})
|
||||||
return resp.data
|
return resp.data
|
||||||
},
|
},
|
||||||
|
|||||||
34
src/hooks/useUserType.ts
Normal file
34
src/hooks/useUserType.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { dummyUser } from '@/types/Survey'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
export function useUserType() {
|
||||||
|
const [store, setStore] = useState<string | null>(null)
|
||||||
|
const [construction_point, setConstructionPoint] = useState<string | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (dummyUser.userType === 'hwj') {
|
||||||
|
// hwj는 작성된 모든 매물 조회 가능
|
||||||
|
setStore(null)
|
||||||
|
setConstructionPoint(null)
|
||||||
|
} else if (dummyUser.userType === 'order') {
|
||||||
|
// order는 같은 판매점의 매물 조회 가능
|
||||||
|
setStore(dummyUser.store)
|
||||||
|
setConstructionPoint(null)
|
||||||
|
} else if (dummyUser.userType === 'musubi') {
|
||||||
|
if (dummyUser.construction_point) {
|
||||||
|
// musubi 시공점 id 존재 시 같은 시공점 매물 조회 가능
|
||||||
|
setStore(dummyUser.store)
|
||||||
|
setConstructionPoint(dummyUser.construction_point)
|
||||||
|
} else {
|
||||||
|
// musubi user&admin 같은 판매점 매물 조회 가능
|
||||||
|
setStore(dummyUser.store)
|
||||||
|
setConstructionPoint(null)
|
||||||
|
}
|
||||||
|
} else if (dummyUser.userType === 'partner') {
|
||||||
|
setStore(dummyUser.store)
|
||||||
|
setConstructionPoint(dummyUser.construction_point)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return { store, construction_point }
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { SEARCH_OPTIONS_ENUM, SEARCH_OPTIONS_PARTNERS_ENUM, SORT_OPTIONS_ENUM } from "@/store/surveyFilterStore"
|
import { SEARCH_OPTIONS_ENUM, SEARCH_OPTIONS_PARTNERS_ENUM, SORT_OPTIONS_ENUM } from '@/store/surveyFilterStore'
|
||||||
|
|
||||||
export type SurveyBasicInfo = {
|
export type SurveyBasicInfo = {
|
||||||
id: number
|
id: number
|
||||||
@ -115,3 +115,13 @@ export type SurveyDetailRequest = {
|
|||||||
export type SurveyDetailCoverRequest = {
|
export type SurveyDetailCoverRequest = {
|
||||||
detail_info: SurveyDetailRequest
|
detail_info: SurveyDetailRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: 회원 유형 설정 이후 변경
|
||||||
|
export const dummyUser = {
|
||||||
|
id: '1',
|
||||||
|
userNm: 'testUser',
|
||||||
|
memberType: 'hwj',
|
||||||
|
store: '1',
|
||||||
|
construction_point: '1',
|
||||||
|
userType: 'hwj',
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user