feat: implement UserType custom hook for filtering login user type
This commit is contained in:
parent
901b7b1ae8
commit
7173ec2496
@ -24,7 +24,9 @@ export default function DetailButton({ isTemporary, surveyId }: { isTemporary: b
|
|||||||
router.push(`/survey-sale/basic-info?id=${surveyId}&isTemp=${isTemporary}`)
|
router.push(`/survey-sale/basic-info?id=${surveyId}&isTemp=${isTemporary}`)
|
||||||
}
|
}
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
if (confirm('削除しますか?')) {
|
const result = confirm('削除しますか?')
|
||||||
|
console.log('🚀 ~ handleDelete ~ result:', result)
|
||||||
|
if (result) {
|
||||||
if (surveyId) {
|
if (surveyId) {
|
||||||
await deleteSurvey()
|
await deleteSurvey()
|
||||||
router.push('/survey-sale')
|
router.push('/survey-sale')
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { useSurveySaleTabState } from '@/store/surveySaleTabState'
|
|||||||
import { usePopupController } from '@/store/popupController'
|
import { usePopupController } from '@/store/popupController'
|
||||||
import { useAddressStore } from '@/store/addressStore'
|
import { useAddressStore } from '@/store/addressStore'
|
||||||
import { useSessionStore } from '@/store/session'
|
import { useSessionStore } from '@/store/session'
|
||||||
|
import { useUserType } from '@/hooks/useUserType'
|
||||||
|
|
||||||
const defaultBasicInfoForm: SurveyBasicRequest = {
|
const defaultBasicInfoForm: SurveyBasicRequest = {
|
||||||
representative: '',
|
representative: '',
|
||||||
@ -23,7 +24,7 @@ const defaultBasicInfoForm: SurveyBasicRequest = {
|
|||||||
submission_date: null,
|
submission_date: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
const REQUIRED_FIELDS: (keyof SurveyBasicRequest)[] = ['representative', 'store', 'construction_point']
|
const REQUIRED_FIELDS: (keyof SurveyBasicRequest)[] = ['representative', 'building_name', 'customer_name']
|
||||||
|
|
||||||
export default function BasicForm() {
|
export default function BasicForm() {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
@ -36,6 +37,8 @@ export default function BasicForm() {
|
|||||||
const [basicInfoData, setBasicInfoData] = useState<SurveyBasicRequest>(defaultBasicInfoForm)
|
const [basicInfoData, setBasicInfoData] = useState<SurveyBasicRequest>(defaultBasicInfoForm)
|
||||||
|
|
||||||
const { addressData } = useAddressStore()
|
const { addressData } = useAddressStore()
|
||||||
|
const { userType, store, construction_point } = useUserType()
|
||||||
|
const { session } = useSessionStore()
|
||||||
|
|
||||||
const popupController = usePopupController()
|
const popupController = usePopupController()
|
||||||
|
|
||||||
@ -52,8 +55,14 @@ export default function BasicForm() {
|
|||||||
address_detail: addressData.address_detail,
|
address_detail: addressData.address_detail,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (session?.isLoggedIn) {
|
||||||
|
setBasicInfoData((prev) => ({
|
||||||
|
...prev,
|
||||||
|
representative: session?.userNm ?? '',
|
||||||
|
}))
|
||||||
|
}
|
||||||
setBasicInfoSelected()
|
setBasicInfoSelected()
|
||||||
}, [surveyDetail, addressData])
|
}, [surveyDetail, addressData, session?.isLoggedIn, session?.userNm])
|
||||||
|
|
||||||
const focusInput = (input: keyof SurveyBasicRequest) => {
|
const focusInput = (input: keyof SurveyBasicRequest) => {
|
||||||
const inputElement = document.getElementById(input)
|
const inputElement = document.getElementById(input)
|
||||||
@ -64,7 +73,6 @@ export default function BasicForm() {
|
|||||||
|
|
||||||
const validateSurvey = (basicInfoData: SurveyBasicRequest) => {
|
const validateSurvey = (basicInfoData: SurveyBasicRequest) => {
|
||||||
const emptyField = REQUIRED_FIELDS.find((field) => !basicInfoData[field])
|
const emptyField = REQUIRED_FIELDS.find((field) => !basicInfoData[field])
|
||||||
|
|
||||||
if (emptyField) {
|
if (emptyField) {
|
||||||
focusInput(emptyField)
|
focusInput(emptyField)
|
||||||
return false
|
return false
|
||||||
@ -109,30 +117,36 @@ export default function BasicForm() {
|
|||||||
type="text"
|
type="text"
|
||||||
className="input-frame"
|
className="input-frame"
|
||||||
id="representative"
|
id="representative"
|
||||||
value={basicInfoData.representative}
|
value={session?.userNm ? session?.userNm : basicInfoData.representative}
|
||||||
onChange={(e) => handleChange('representative', e.target.value)}
|
onChange={(e) => handleChange('representative', e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="data-input-form-bx">
|
{(userType === 'musubi' || userType === 'order' || userType?.includes('musubi')) && (
|
||||||
<div className="data-input-form-tit">販売店</div>
|
<>
|
||||||
<input
|
<div className="data-input-form-bx">
|
||||||
type="text"
|
<div className="data-input-form-tit">販売店</div>
|
||||||
className="input-frame"
|
<input
|
||||||
id="store"
|
type="text"
|
||||||
value={basicInfoData.store ?? ''}
|
className="input-frame"
|
||||||
onChange={(e) => handleChange('store', e.target.value)}
|
id="store"
|
||||||
/>
|
value={store ? store : basicInfoData.store ?? ''}
|
||||||
</div>
|
onChange={(e) => handleChange('store', e.target.value)}
|
||||||
<div className="data-input-form-bx">
|
/>
|
||||||
<div className="data-input-form-tit">施工店</div>
|
</div>
|
||||||
<input
|
</>
|
||||||
type="text"
|
)}
|
||||||
className="input-frame"
|
{(userType === 'partner' || userType === 'musubi_con') && (
|
||||||
id="construction_point"
|
<div className="data-input-form-bx">
|
||||||
value={basicInfoData.construction_point ?? ''}
|
<div className="data-input-form-tit">施工店</div>
|
||||||
onChange={(e) => handleChange('construction_point', e.target.value)}
|
<input
|
||||||
/>
|
type="text"
|
||||||
</div>
|
className="input-frame"
|
||||||
|
id="construction_point"
|
||||||
|
value={construction_point ? construction_point : basicInfoData.construction_point ?? ''}
|
||||||
|
onChange={(e) => handleChange('construction_point', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,8 @@ 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 { MEMBER_TYPE, useSurveyFilterStore } from '@/store/surveyFilterStore'
|
import { useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||||
// import { useSessionStore } from '@/store/session'
|
import { UserType } from '@/hooks/useUserType'
|
||||||
import { dummyUser } from '@/types/Survey'
|
|
||||||
|
|
||||||
export default function ListTable() {
|
export default function ListTable() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -16,10 +15,7 @@ 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 [memberType, setMemberType] = useState<UserType>('hwj')
|
||||||
|
|
||||||
// TODO : 회원 유형 설정 이후 변경
|
|
||||||
// const { session } = useSessionStore()
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (surveyList && surveyList.length > 0) {
|
if (surveyList && surveyList.length > 0) {
|
||||||
@ -33,10 +29,7 @@ export default function ListTable() {
|
|||||||
}
|
}
|
||||||
setHasMore(surveyListCount > offset + 10)
|
setHasMore(surveyListCount > offset + 10)
|
||||||
}
|
}
|
||||||
// TODO : 회원 유형 설정 이후 변경
|
// 회원 유형 설정 이후 변경
|
||||||
// if (session?.userId) {
|
|
||||||
// setMemberType(session.userId)
|
|
||||||
// }
|
|
||||||
setMemberType('hwj')
|
setMemberType('hwj')
|
||||||
}, [surveyList, surveyListCount, offset])
|
}, [surveyList, surveyListCount, offset])
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { MEMBER_TYPE, SEARCH_OPTIONS, SEARCH_OPTIONS_ENUM, SEARCH_OPTIONS_PARTNERS, useSurveyFilterStore } from '@/store/surveyFilterStore'
|
import { SEARCH_OPTIONS, SEARCH_OPTIONS_ENUM, SEARCH_OPTIONS_PARTNERS, useSurveyFilterStore } from '@/store/surveyFilterStore'
|
||||||
|
import { UserType } from '@/hooks/useUserType'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
export default function SearchForm({ onItemsInit, memberType }: { onItemsInit: () => void; memberType: MEMBER_TYPE }) {
|
export default function SearchForm({ onItemsInit, memberType }: { onItemsInit: () => void; memberType: UserType }) {
|
||||||
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)
|
||||||
|
|||||||
@ -1,34 +1,24 @@
|
|||||||
import { dummyUser } from '@/types/Survey'
|
import { useSessionStore } from '@/store/session'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
export type UserType = 'hwj' | 'order' | 'musubi' | 'musubi_con' | 'partner'
|
||||||
|
|
||||||
|
// 로그인 된 회원 유형에 따라 조사 매물 목록 변경됨
|
||||||
export function useUserType() {
|
export function useUserType() {
|
||||||
|
const { session } = useSessionStore()
|
||||||
|
const [userType, setUserType] = useState<UserType | null>(null)
|
||||||
const [store, setStore] = useState<string | null>(null)
|
const [store, setStore] = useState<string | null>(null)
|
||||||
const [construction_point, setConstructionPoint] = useState<string | null>(null)
|
const [construction_point, setConstructionPoint] = useState<string | null>(null)
|
||||||
|
|
||||||
|
// TODO: 회원 유형 설정
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (dummyUser.userType === 'hwj') {
|
if (!session?.isLoggedIn) return
|
||||||
// hwj는 작성된 모든 매물 조회 가능
|
setUserType('musubi_con')
|
||||||
setStore(null)
|
}, [session])
|
||||||
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 }
|
return {
|
||||||
|
userType,
|
||||||
|
store,
|
||||||
|
construction_point,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,6 @@ export const SEARCH_OPTIONS_PARTNERS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export type MEMBER_TYPE = 'hwj' | 'order' | 'musubi' | 'partner'
|
|
||||||
export type SEARCH_OPTIONS_ENUM = (typeof SEARCH_OPTIONS)[number]['id']
|
export type SEARCH_OPTIONS_ENUM = (typeof SEARCH_OPTIONS)[number]['id']
|
||||||
export type SEARCH_OPTIONS_PARTNERS_ENUM = (typeof SEARCH_OPTIONS_PARTNERS)[number]['id']
|
export type SEARCH_OPTIONS_PARTNERS_ENUM = (typeof SEARCH_OPTIONS_PARTNERS)[number]['id']
|
||||||
export type SORT_OPTIONS_ENUM = 'created' | 'updated'
|
export type SORT_OPTIONS_ENUM = 'created' | 'updated'
|
||||||
|
|||||||
@ -115,13 +115,3 @@ 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