feature/survey #38
@ -17,6 +17,8 @@ export async function GET(request: Request) {
|
||||
const isMySurvey = searchParams.get('isMySurvey')
|
||||
const sort = searchParams.get('sort')
|
||||
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']
|
||||
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) {
|
||||
// @ts-ignore
|
||||
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 { useRouter } from 'next/navigation'
|
||||
import SearchForm from './SearchForm'
|
||||
import { useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||
import { useSessionStore } from '@/store/session'
|
||||
import { MEMBER_TYPE, useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||
// import { useSessionStore } from '@/store/session'
|
||||
import { dummyUser } from '@/types/Survey'
|
||||
|
||||
export default function ListTable() {
|
||||
const router = useRouter()
|
||||
@ -15,9 +16,10 @@ export default function ListTable() {
|
||||
|
||||
const [heldSurveyList, setHeldSurveyList] = useState<typeof surveyList>([])
|
||||
const [hasMore, setHasMore] = useState(false)
|
||||
const [memberType, setMemberType] = useState<MEMBER_TYPE>('hwj')
|
||||
|
||||
const { session } = useSessionStore()
|
||||
console.log('session:: ', session)
|
||||
// TODO : 회원 유형 설정 이후 변경
|
||||
// const { session } = useSessionStore()
|
||||
|
||||
useEffect(() => {
|
||||
if (surveyList && surveyList.length > 0) {
|
||||
@ -31,6 +33,11 @@ export default function ListTable() {
|
||||
}
|
||||
setHasMore(surveyListCount > offset + 10)
|
||||
}
|
||||
// TODO : 회원 유형 설정 이후 변경
|
||||
// if (session?.userId) {
|
||||
// setMemberType(session.userId)
|
||||
// }
|
||||
setMemberType('hwj')
|
||||
}, [surveyList, surveyListCount, offset])
|
||||
|
||||
const handleDetailClick = (id: number) => {
|
||||
@ -45,7 +52,7 @@ export default function ListTable() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<SearchForm onItemsInit={handleItemsInit} />
|
||||
<SearchForm onItemsInit={handleItemsInit} memberType={memberType} />
|
||||
{heldSurveyList.length > 0 ? (
|
||||
<div className="sale-frame">
|
||||
<ul className="sale-list-wrap">
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
'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 { 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 { setSearchOption, setSort, setIsMySurvey, setKeyword, isMySurvey, keyword, searchOption, sort } = useSurveyFilterStore()
|
||||
const [searchKeyword, setSearchKeyword] = useState(keyword)
|
||||
@ -19,6 +19,7 @@ export default function SearchForm({ onItemsInit }: { onItemsInit: () => void })
|
||||
setKeyword(searchKeyword)
|
||||
onItemsInit()
|
||||
}
|
||||
const searchOptions = memberType === 'partner' ? SEARCH_OPTIONS_PARTNERS : SEARCH_OPTIONS
|
||||
|
||||
return (
|
||||
<div className="sale-frame">
|
||||
@ -35,7 +36,7 @@ export default function SearchForm({ onItemsInit }: { onItemsInit: () => void })
|
||||
value={searchOption}
|
||||
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.label}
|
||||
</option>
|
||||
|
||||
@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type { SurveyBasicInfo, SurveyBasicRequest, SurveyDetailInfo, SurveyDetailRequest, SurveyDetailCoverRequest } from '@/types/Survey'
|
||||
import { axiosInstance } from '@/libs/axios'
|
||||
import { useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||
import { useUserType } from './useUserType'
|
||||
|
||||
export function useServey(id?: number): {
|
||||
surveyList: SurveyBasicInfo[] | []
|
||||
@ -21,12 +22,13 @@ export function useServey(id?: number): {
|
||||
} {
|
||||
const queryClient = useQueryClient()
|
||||
const { keyword, searchOption, isMySurvey, sort, offset } = useSurveyFilterStore()
|
||||
const { store, construction_point } = useUserType()
|
||||
|
||||
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 () => {
|
||||
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
|
||||
},
|
||||
|
||||
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 = {
|
||||
id: number
|
||||
@ -115,3 +115,13 @@ export type SurveyDetailRequest = {
|
||||
export type SurveyDetailCoverRequest = {
|
||||
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