diff --git a/src/app/api/survey-sales/[id]/route.ts b/src/app/api/survey-sales/[id]/route.ts
index 4794a5f..3da5981 100644
--- a/src/app/api/survey-sales/[id]/route.ts
+++ b/src/app/api/survey-sales/[id]/route.ts
@@ -1,40 +1,62 @@
import { NextResponse } from 'next/server'
+import { prisma } from '@/libs/prisma'
export async function GET(request: Request, context: { params: { id: string } }) {
- const { id } = await context.params
- // @ts-ignore
- const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.findUnique({
- where: { ID: Number(id) },
- include: {
- DETAIL_INFO: true,
- },
- })
- return NextResponse.json(survey)
-}
-
-export async function PUT(request: Request, context: { params: { id: string } }) {
- const { id } = await context.params
- const body = await request.json()
try {
+ const { id } = await context.params
// @ts-ignore
- const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
+ const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.findUnique({
where: { ID: Number(id) },
- data: {
- ...body,
+ include: {
+ DETAIL_INFO: true,
},
})
return NextResponse.json(survey)
} catch (error) {
- console.error(error)
- throw error
+ console.error('Error fetching survey:', error)
+ return NextResponse.json({ error: 'Failed to fetch survey' }, { status: 500 })
+ }
+}
+
+export async function PUT(request: Request, context: { params: { id: string } }) {
+ try {
+ const { id } = await context.params
+ const body = await request.json()
+ console.log('body:: ', body)
+
+ // DETAIL_INFO를 분리
+ const { DETAIL_INFO, ...basicInfo } = body
+
+ // @ts-ignore
+ const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
+ where: { ID: Number(id) },
+ data: {
+ ...basicInfo,
+ UPT_DT: new Date(),
+ DETAIL_INFO: DETAIL_INFO
+ ? {
+ upsert: {
+ create: DETAIL_INFO,
+ update: DETAIL_INFO,
+ },
+ }
+ : undefined,
+ },
+ include: {
+ DETAIL_INFO: true,
+ },
+ })
+ return NextResponse.json(survey)
+ } catch (error) {
+ console.error('Error updating survey:', error)
+ return NextResponse.json({ error: 'Failed to update survey' }, { status: 500 })
}
}
export async function DELETE(request: Request, context: { params: { id: string } }) {
- const { id } = await context.params
-
try {
- //@ts-ignore
+ const { id } = await context.params
+
await prisma.$transaction(async (tx) => {
// @ts-ignore
const detailData = await tx.SD_SURVEY_SALES_BASIC_INFO.findUnique({
@@ -43,69 +65,75 @@ export async function DELETE(request: Request, context: { params: { id: string }
DETAIL_INFO: true,
},
})
- console.log('detailData:: ', detailData)
+
if (detailData?.DETAIL_INFO?.ID) {
// @ts-ignore
await tx.SD_SURVEY_SALES_DETAIL_INFO.delete({
- where: { ID: Number(detailData?.DETAIL_INFO?.ID) },
+ where: { ID: Number(detailData.DETAIL_INFO.ID) },
})
}
+
// @ts-ignore
await tx.SD_SURVEY_SALES_BASIC_INFO.delete({
where: { ID: Number(id) },
})
})
+
return NextResponse.json({ message: 'Survey deleted successfully' })
} catch (error) {
- console.error(error)
- throw error
+ console.error('Error deleting survey:', error)
+ return NextResponse.json({ error: 'Failed to delete survey' }, { status: 500 })
}
}
export async function PATCH(request: Request, context: { params: { id: string } }) {
- const { id } = await context.params
- const body = await request.json()
+ try {
+ const { id } = await context.params
+ const body = await request.json()
- if (body.submit) {
- // @ts-ignore
- const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
- where: { ID: Number(id) },
- data: {
- SUBMISSION_STATUS: true,
- SUBMISSION_DATE: new Date(),
- },
- })
- return NextResponse.json({ message: 'Survey confirmed successfully' })
- } else {
- // @ts-ignore
- const hasDetails = await prisma.SD_SURVEY_SALES_DETAIL_INFO.findUnique({
- where: { BASIC_INFO_ID: Number(id) },
- })
- console.log('hasDetails:: ', hasDetails)
- if (hasDetails) {
- //@ts-ignore
- const result = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
- where: { ID: Number(id) },
- data: {
- UPT_DT: new Date(),
- DETAIL_INFO: {
- update: body.DETAIL_INFO,
- },
- },
- })
- return NextResponse.json(result)
- } else {
+ if (body.submit) {
// @ts-ignore
const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
where: { ID: Number(id) },
data: {
- DETAIL_INFO: {
- create: body.DETAIL_INFO,
- },
+ SUBMISSION_STATUS: true,
+ SUBMISSION_DATE: new Date(),
},
})
- console.log(survey)
- return NextResponse.json({ message: 'Survey detail created successfully' })
+ return NextResponse.json({ message: 'Survey confirmed successfully' })
+ } else {
+ // @ts-ignore
+ const hasDetails = await prisma.SD_SURVEY_SALES_DETAIL_INFO.findUnique({
+ where: { BASIC_INFO_ID: Number(id) },
+ })
+
+ if (hasDetails) {
+ //@ts-ignore
+ const result = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
+ where: { ID: Number(id) },
+ data: {
+ UPT_DT: new Date(),
+ DETAIL_INFO: {
+ update: body.DETAIL_INFO,
+ },
+ },
+ })
+ return NextResponse.json(result)
+ } else {
+ // @ts-ignore
+ const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
+ where: { ID: Number(id) },
+ data: {
+ DETAIL_INFO: {
+ create: body.DETAIL_INFO,
+ },
+ },
+ })
+ return NextResponse.json({ message: 'Survey detail created successfully' })
+ }
}
+ } catch (error) {
+ console.error('Error updating survey:', error)
+ return NextResponse.json({ error: 'Failed to update survey' }, { status: 500 })
}
}
diff --git a/src/app/api/survey-sales/route.ts b/src/app/api/survey-sales/route.ts
index 1343880..d4b676a 100644
--- a/src/app/api/survey-sales/route.ts
+++ b/src/app/api/survey-sales/route.ts
@@ -1,16 +1,18 @@
import { NextResponse } from 'next/server'
import { prisma } from '@/libs/prisma'
-// Types
+/**
+ * 검색 파라미터
+ */
type SearchParams = {
- keyword?: string | null
- searchOption?: string | null
- isMySurvey?: string | null
- sort?: string | null
+ keyword?: string | null // 검색어
+ searchOption?: string | null // 검색 옵션 (select 옵션)
+ isMySurvey?: string | null // 내가 작성한 매물
+ sort?: string | null // 정렬 방식
offset?: string | null
- memberRole?: string | null
- store?: string | null
- builderNo?: string | null
+ role?: string | null // 회원권한한
+ store?: string | null // 판매점ID
+ builderNo?: string | null // 시공ID
}
type WhereCondition = {
@@ -19,133 +21,131 @@ type WhereCondition = {
[key: string]: any
}
-// Constants
+// 검색 가능한 필드 옵션
const SEARCH_OPTIONS = [
- 'BUILDING_NAME',
- 'REPRESENTATIVE',
- 'STORE',
- 'CONSTRUCTION_POINT',
- 'CUSTOMER_NAME',
- 'POST_CODE',
- 'ADDRESS',
- 'ADDRESS_DETAIL',
+ 'BUILDING_NAME', // 건물명
+ 'REPRESENTATIVE', // 담당자
+ 'STORE', // 판매점
+ 'CONSTRUCTION_POINT', // 시공점
+ 'CUSTOMER_NAME', // 고객명
+ 'POST_CODE', // 우편번호
+ 'ADDRESS', // 주소
+ 'ADDRESS_DETAIL', // 상세주소
] as const
+// 페이지당 항목 수
const ITEMS_PER_PAGE = 10
-// Helper functions
+/**
+ * 키워드 검색 조건 생성 함수
+ * @param keyword 검색 키워드
+ * @param searchOption 검색 옵션
+ * @returns 검색 조건 객체
+ */
const createKeywordSearchCondition = (keyword: string, searchOption: string): WhereCondition => {
const where: WhereCondition = {}
if (searchOption === 'all') {
+ // 모든 필드 검색 시 OR 조건 사용
where.OR = []
- // ID 검색 조건 추가
+ // ID가 숫자인 경우 ID 검색 조건 추가
if (keyword.match(/^\d+$/) || !isNaN(Number(keyword))) {
where.OR.push({
ID: { equals: Number(keyword) },
})
}
- // 다른 필드 검색 조건 추가
where.OR.push(
...SEARCH_OPTIONS.map((field) => ({
[field]: { contains: keyword },
})),
)
- } else if (SEARCH_OPTIONS.includes(searchOption as any)) {
- where[searchOption] = { contains: keyword }
+ } else if (SEARCH_OPTIONS.includes(searchOption.toUpperCase() as any)) {
+ // 특정 필드 검색
+ where[searchOption.toUpperCase()] = { contains: keyword }
} else if (searchOption === 'id') {
- where.ID = { equals: Number(keyword) }
+ // ID 검색 (숫자 변환 필요)
+ const number = Number(keyword)
+ if (!isNaN(number)) {
+ where.ID = { equals: number }
+ } else {
+ // 유효하지 않은 ID 검색 시 빈 결과 반환
+ where.ID = { equals: null }
+ }
}
return where
}
+/**
+ * 회원 역할별 검색 조건 생성 함수
+ * @param params 검색 파라미터
+ * @returns 검색 조건 객체
+ */
const createMemberRoleCondition = (params: SearchParams): WhereCondition => {
const where: WhereCondition = { AND: [] }
- switch (params.memberRole) {
- // 1차점: 같은 판매점에서 작성된 매물 + 2차점에서 제출받은 매물
- case 'Admin':
+ switch (params.role) {
+ case 'Admin': // 1차점
+ // 같은 판매점에서 작성된 매물 + 2차점에서 제출받은 매물
where.OR = [
{
- AND: [
- { STORE: { equals: params.store } },
- { SUBMISSION_STATUS: { equals: false } }
- ]
+ AND: [{ STORE: { equals: params.store } }],
},
{
- AND: [
- { STORE: { endsWith: params.store } },
- { SUBMISSION_STATUS: { equals: true } }
- ]
- }
+ AND: [{ STORE: { startsWith: params.store } }, { SUBMISSION_STATUS: { equals: true } }],
+ },
]
break
- // 2차점: 같은 판매점에서 작성된 매물 + Builder에게 제출받은 매물
- case 'Admin_Sub':
+ case 'Admin_Sub': // 2차점
where.OR = [
{
AND: [
{ STORE: { equals: params.store } },
- { CONSTRUCTION_POINT: { equals: null } },
- { SUBMISSION_STATUS: { equals: false } }
+ {
+ OR: [
+ { CONSTRUCTION_POINT: { equals: null } },
+ { CONSTRUCTION_POINT: { equals: '' } }
+ ]
+ }
]
},
{
AND: [
{ STORE: { equals: params.store } },
{ CONSTRUCTION_POINT: { not: null } },
+ { CONSTRUCTION_POINT: { not: '' } },
{ SUBMISSION_STATUS: { equals: true } }
]
}
]
break
- // 2차점 시공권한: 같은 시공ID에서 작성된 매물
- case 'Builder':
+ case 'Builder': // 2차점 시공권한
+ case 'Partner': // Partner
+ // 같은 시공ID에서 작성된 매물
where.AND?.push({
CONSTRUCTION_POINT: { equals: params.builderNo },
- SUBMISSION_STATUS: { equals: false },
})
break
- // 시공점: 같은 시공ID에서 작성된 매물
- case 'Partner':
- where.AND?.push({
- CONSTRUCTION_POINT: { equals: params.builderNo },
- SUBMISSION_STATUS: { equals: false },
- })
- break
-
- // 모든 매물 조회 가능
case 'T01':
case 'User':
+ // 모든 매물 조회 가능 (추가 조건 없음)
break
}
return where
}
-// API Routes
-export async function POST(request: Request) {
- try {
- const body = await request.json()
- // @ts-ignore
- const res = await prisma.SD_SURVEY_SALES_BASIC_INFO.create({
- data: body,
- })
- return NextResponse.json(res)
- } catch (error) {
- console.error('Error creating survey:', error)
- return NextResponse.json({ error: 'Failed to create survey' }, { status: 500 })
- }
-}
-
+/**
+ * GET 핸들러 - 설문 목록 조회
+ */
export async function GET(request: Request) {
try {
+ // URL 파라미터 파싱
const { searchParams } = new URL(request.url)
const params: SearchParams = {
keyword: searchParams.get('keyword'),
@@ -153,59 +153,95 @@ export async function GET(request: Request) {
isMySurvey: searchParams.get('isMySurvey'),
sort: searchParams.get('sort'),
offset: searchParams.get('offset'),
- memberRole: searchParams.get('memberRole'),
+ role: searchParams.get('role'),
store: searchParams.get('store'),
builderNo: searchParams.get('builderNo'),
}
+ // 검색 조건 구성
const where: WhereCondition = {}
- // 내가 작성한 매물 조건
+ // 내가 작성한 매물 조건 적용
if (params.isMySurvey) {
where.REPRESENTATIVE = params.isMySurvey
}
- // 키워드 검색 조건
+ // 키워드 검색 조건 적용
if (params.keyword && params.searchOption) {
Object.assign(where, createKeywordSearchCondition(params.keyword, params.searchOption))
}
- // 회원 유형 조건
+ // 회원 유형 조건 적용
Object.assign(where, createMemberRoleCondition(params))
- // 데이터 조회
+ // 데이터 조회 또는 카운트
if (params.offset) {
- // @ts-ignore
- const res = await prisma.SD_SURVEY_SALES_BASIC_INFO.findMany({
+ // 페이지네이션 데이터 조회
+ //@ts-ignore
+ const surveys = await prisma.SD_SURVEY_SALES_BASIC_INFO.findMany({
where,
orderBy: params.sort === 'created' ? { REG_DT: 'desc' } : { UPT_DT: 'desc' },
skip: Number(params.offset),
take: ITEMS_PER_PAGE,
})
- return NextResponse.json(res)
+ return NextResponse.json(surveys)
+ } else {
+ // 전체 개수만 조회
+ //@ts-ignore
+ const count = await prisma.SD_SURVEY_SALES_BASIC_INFO.count({ where })
+ return NextResponse.json(count)
}
-
- // 전체 개수 조회
- // @ts-ignore
- const count = await prisma.SD_SURVEY_SALES_BASIC_INFO.count({ where })
- return NextResponse.json(count)
} catch (error) {
- console.error('Error fetching surveys:', error)
- return NextResponse.json({ error: 'Failed to fetch surveys' }, { status: 500 })
+ console.error(error)
+ return NextResponse.json({ error: 'Fail Read Survey' }, { status: 500 })
}
}
+/**
+ * PUT 핸들러 - 상세 정보 추가
+ */
export async function PUT(request: Request) {
try {
const body = await request.json()
- const detailInfo = { ...body.detail_info, BASIC_INFO_ID: body.id }
- // @ts-ignore
- const res = await prisma.SD_SURVEY_SALES_DETAIL_INFO.create({
+
+ // 상세 정보 생성을 위한 데이터 구성
+ const detailInfo = {
+ ...body.detail_info,
+ BASIC_INFO_ID: body.id,
+ }
+
+ // 상세 정보 생성
+ //@ts-ignore
+ await prisma.SD_SURVEY_SALES_DETAIL_INFO.create({
data: detailInfo,
})
- return NextResponse.json({ message: 'Survey sales updated successfully' })
+
+ return NextResponse.json({
+ message: 'Success Update Survey',
+ })
} catch (error) {
- console.error('Error updating survey:', error)
- return NextResponse.json({ error: 'Failed to update survey' }, { status: 500 })
+ console.error(error)
+ return NextResponse.json({ error: 'Fail Update Survey' }, { status: 500 })
+ }
+}
+
+export async function POST(request: Request) {
+ try {
+ const body = await request.json()
+ const { DETAIL_INFO, ...basicInfo } = body
+ // 기본 정보 생성
+ //@ts-ignore
+ const result = await prisma.SD_SURVEY_SALES_BASIC_INFO.create({
+ data: {
+ ...basicInfo,
+ DETAIL_INFO: {
+ create: DETAIL_INFO,
+ },
+ },
+ })
+ return NextResponse.json(result)
+ } catch (error) {
+ console.error(error)
+ return NextResponse.json({ error: 'Fail Create Survey' }, { status: 500 })
}
}
diff --git a/src/app/survey-sale/regist/page.tsx b/src/app/survey-sale/regist/page.tsx
new file mode 100644
index 0000000..5090aaa
--- /dev/null
+++ b/src/app/survey-sale/regist/page.tsx
@@ -0,0 +1,9 @@
+import RegistForm from '@/components/survey-sale/temp/registForm'
+
+export default function RegistPage() {
+ return (
+ <>
+
+ >
+ )
+}
diff --git a/src/components/popup/ZipCodePopup.tsx b/src/components/popup/ZipCodePopup.tsx
index 2fec15c..4923833 100644
--- a/src/components/popup/ZipCodePopup.tsx
+++ b/src/components/popup/ZipCodePopup.tsx
@@ -28,10 +28,11 @@ export default function ZipCodePopup() {
const popupController = usePopupController()
const handleApply = () => {
+ console.log(addressInfo?.[0])
setAddressData({
post_code: addressInfo?.[0]?.zipcode || '',
- address: addressInfo?.[0]?.prefcode || '',
- address_detail: addressInfo?.[0]?.address1 + ' ' + addressInfo?.[0]?.address2 + ' ' + addressInfo?.[0]?.address3 || '',
+ address: addressInfo?.[0]?.address1 || '',
+ address_detail: addressInfo?.[0]?.address2 + ' ' + addressInfo?.[0]?.address3 || '',
})
popupController.setZipCodePopup(false)
}
diff --git a/src/components/survey-sale/common/NavTab.tsx b/src/components/survey-sale/common/NavTab.tsx
index 4131804..ffa6ea7 100644
--- a/src/components/survey-sale/common/NavTab.tsx
+++ b/src/components/survey-sale/common/NavTab.tsx
@@ -15,7 +15,7 @@ export default function NavTab() {
const params = useParams()
const detailId = params.id
- const { basicInfoSelected, roofInfoSelected, reset } = useSurveySaleTabState()
+ const { basicInfoSelected, roofInfoSelected, reset, setBasicInfoSelected, setRoofInfoSelected } = useSurveySaleTabState()
useEffect(() => {
return () => {
@@ -27,26 +27,36 @@ export default function NavTab() {
return null
}
- const handleBasicInfoClick = () => {
- if (id) {
- router.push(`/survey-sale/basic-info?id=${id}`)
- return
+ const scrollSection = (section: string) => {
+ const sectionElement = document.getElementById(section)
+ if (sectionElement) {
+ sectionElement.scrollIntoView({ behavior: 'smooth' })
}
+ }
+
+ const handleBasicInfoClick = () => {
+ // if (id) {
+ // router.push(`/survey-sale/basic-info?id=${id}`)
+ // return
+ // }
if (detailId) {
router.push(`/survey-sale/${detailId}`)
return
}
+ scrollSection('basic-form-section')
+
+ setBasicInfoSelected()
}
const handleRoofInfoClick = () => {
- if (id) {
- if (isTemp === 'true') {
- alert('基本情報が一時保存された状態です。')
- return
- }
- router.push(`/survey-sale/roof-info?id=${id}`)
- return
- }
+ // if (id) {
+ // if (isTemp === 'true') {
+ // alert('基本情報が一時保存された状態です。')
+ // return
+ // }
+ // router.push(`/survey-sale/roof-info?id=${id}`)
+ // return
+ // }
if (detailId) {
router.push(`/survey-sale/${detailId}?tab=roof-info`)
return
@@ -55,6 +65,10 @@ export default function NavTab() {
alert('基本情報を先に保存してください。')
return null
}
+ // if (pathname === '/survey-sale/regist') {
+ scrollSection('roof-form-section')
+ // }
+ setRoofInfoSelected()
}
return (
diff --git a/src/components/survey-sale/detail/DataTable.tsx b/src/components/survey-sale/detail/DataTable.tsx
index 2ec528e..e7ce554 100644
--- a/src/components/survey-sale/detail/DataTable.tsx
+++ b/src/components/survey-sale/detail/DataTable.tsx
@@ -2,10 +2,8 @@
import { useServey } from '@/hooks/useSurvey'
import { useParams, useSearchParams } from 'next/navigation'
-import { useEffect } from 'react'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
import DetailForm from './DetailForm'
-import { useSurveySaleTabState } from '@/store/surveySaleTabState'
import RoofDetailForm from './RoofDetailForm'
export default function DataTable() {
@@ -14,21 +12,21 @@ export default function DataTable() {
const searchParams = useSearchParams()
const tab = searchParams.get('tab')
+ const isTemp = searchParams.get('isTemporary')
const { surveyDetail, isLoadingSurveyDetail } = useServey(Number(id))
- const [isTemporary, setIsTemporary] = useState(true)
- const { setBasicInfoSelected, setRoofInfoSelected } = useSurveySaleTabState()
+ const [isTemporary, setIsTemporary] = useState(isTemp === 'true')
+
+ const { validateSurveyDetail } = useServey(Number(id))
useEffect(() => {
- if (surveyDetail?.REPRESENTATIVE && surveyDetail?.STORE && surveyDetail?.CONSTRUCTION_POINT) {
- setIsTemporary(false)
+ if (surveyDetail?.DETAIL_INFO) {
+ const validate = validateSurveyDetail(surveyDetail.DETAIL_INFO)
+ if (validate.trim() !== '') {
+ setIsTemporary(false)
+ }
}
- if (tab === 'roof-info') {
- setRoofInfoSelected()
- } else {
- setBasicInfoSelected()
- }
- }, [surveyDetail, tab, setBasicInfoSelected, setRoofInfoSelected])
+ }, [surveyDetail])
if (isLoadingSurveyDetail) {
return
Loading...
@@ -68,7 +66,7 @@ export default function DataTable() {
<>
{/* TODO: 제출한 판매점 ID 추가 필요 */}
{new Date(surveyDetail.SUBMISSION_DATE).toLocaleString()}
- 販売店 ID...
+ {surveyDetail.STORE}
>
) : (
'-'
diff --git a/src/components/survey-sale/detail/DetailButton.tsx b/src/components/survey-sale/detail/DetailButton.tsx
index d8471c9..3a871bf 100644
--- a/src/components/survey-sale/detail/DetailButton.tsx
+++ b/src/components/survey-sale/detail/DetailButton.tsx
@@ -1,86 +1,119 @@
'use client'
-import { useRouter } from 'next/navigation'
+import { useRouter, useSearchParams } from 'next/navigation'
import { useServey } from '@/hooks/useSurvey'
import { useSessionStore } from '@/store/session'
-import { useEffect, useState } from 'react'
+import { SurveyBasicInfo } from '@/types/Survey'
+import { useState } from 'react'
-export default function DetailButton({ isTemporary, surveyId, representative }: { isTemporary: boolean; surveyId: number; representative: string }) {
+export default function DetailButton({ surveyDetail }: { surveyDetail: SurveyBasicInfo | null }) {
const router = useRouter()
const { session } = useSessionStore()
- const { submitSurvey, deleteSurvey } = useServey(surveyId)
- const [userId, setUserId] = useState('')
+ const { submitSurvey, deleteSurvey } = useServey(surveyDetail?.ID ?? 0)
- useEffect(() => {
- if (session?.isLoggedIn) {
- setUserId(session?.userId ?? '')
+ const searchParams = useSearchParams()
+ const isTemp = searchParams.get('isTemporary')
+ const [isTemporary, setIsTemporary] = useState(isTemp === 'true')
+
+ const checkRole = () => {
+ switch (session?.role) {
+ case 'T01':
+ return session?.userNm === surveyDetail?.REPRESENTATIVE ? true : false
+ case 'Admin':
+ return session?.storeNm === surveyDetail?.STORE ? true : false
+ case 'Admin_Sub':
+ return session?.storeNm === surveyDetail?.STORE ? true : false
+ case 'Builder':
+ return session?.builderNo === surveyDetail?.CONSTRUCTION_POINT ? true : false
+ case 'Partner':
+ return session?.builderNo === surveyDetail?.CONSTRUCTION_POINT ? true : false
+ default:
+ return ''
}
- }, [session, setUserId])
+ }
const handleSubmit = async () => {
- if (isTemporary) {
- alert('一時保存されたデータは提出できません。')
- return
- }
- if (userId === representative) {
- if (confirm('提出しますか??')) {
- if (surveyId) {
- // TODO: 제출 페이지 추가
- alert('SUBMIT POPUP!!!!!!!!!!!')
- await submitSurvey()
- }
+ const result = checkRole()
+ if (result) {
+ if (isTemporary) {
+ alert('一時保存されたデータは提出できません。')
+ return
}
- } else {
- alert('担当者のみ提出可能です。')
+ window.neoConfirm(
+ '提出しますか??',
+ async () => {
+ if (surveyDetail?.ID) {
+ // TODO: 제출 페이지 추가
+ alert('SUBMIT POPUP!!!!!!!!!!!')
+ await submitSurvey()
+ }
+ },
+ () => null,
+ )
}
}
const handleUpdate = () => {
- if (userId === representative) {
- router.push(`/survey-sale/basic-info?id=${surveyId}&isTemp=${isTemporary}`)
+ const result = checkRole()
+ if (result) {
+ // router.push(`/survey-sale/basic-info?id=${surveyDetail?.ID}&isTemp=${isTemporary}`)
+ router.push(`/survey-sale/regist?id=${surveyDetail?.ID}`)
} else {
alert('担当者のみ修正可能です。')
}
}
const handleDelete = async () => {
- if (confirm('削除しますか?')) {
- if (surveyId) {
- if (userId === representative) {
- await deleteSurvey()
- router.push('/survey-sale')
- } else {
- alert('担当者のみ削除可能です。')
+ window.neoConfirm(
+ '削除しますか?',
+ async () => {
+ if (surveyDetail?.ID) {
+ if (session.userNm === surveyDetail?.REPRESENTATIVE) {
+ await deleteSurvey()
+ alert('削除されました。')
+ router.push('/survey-sale')
+ } else {
+ alert('担当者のみ削除可能です。')
+ }
}
- }
- }
+ },
+ () => null,
+ )
}
+ const isSubmitter = session?.storeNm === surveyDetail?.STORE && session?.builderNo === surveyDetail?.CONSTRUCTION_POINT
+
return (
- {isTemporary ? (
+
+
+
+ {isSubmitter && surveyDetail?.SUBMISSION_STATUS ? (
<>>
) : (
<>
+ {isTemporary || surveyDetail?.SUBMISSION_STATUS ? (
+ <>>
+ ) : (
+ <>
+
+
+
+ >
+ )}
-
-
- 提出
+
+ 削除
>
)}
-
-
- 修正
-
-
-
-
- 削除
-
-
)
}
diff --git a/src/components/survey-sale/detail/DetailForm.tsx b/src/components/survey-sale/detail/DetailForm.tsx
index 469c465..73ce5c7 100644
--- a/src/components/survey-sale/detail/DetailForm.tsx
+++ b/src/components/survey-sale/detail/DetailForm.tsx
@@ -1,6 +1,5 @@
'use client'
-import { useEffect, useState } from 'react'
import DetailButton from './DetailButton'
import { SurveyBasicInfo } from '@/types/Survey'
@@ -11,14 +10,6 @@ export default function DetailForm({
surveyDetail: SurveyBasicInfo | null
isLoadingSurveyDetail: boolean
}) {
- const [isTemporary, setIsTemporary] = useState(true)
-
- useEffect(() => {
- if (surveyDetail?.REPRESENTATIVE && surveyDetail?.STORE && surveyDetail?.CONSTRUCTION_POINT) {
- setIsTemporary(false)
- }
- }, [surveyDetail])
-
if (isLoadingSurveyDetail) {
return Loading...
}
@@ -56,7 +47,7 @@ export default function DetailForm({
-
+
>
)
diff --git a/src/components/survey-sale/detail/RoofDetailForm.tsx b/src/components/survey-sale/detail/RoofDetailForm.tsx
index a20f48a..a9a4031 100644
--- a/src/components/survey-sale/detail/RoofDetailForm.tsx
+++ b/src/components/survey-sale/detail/RoofDetailForm.tsx
@@ -1,8 +1,8 @@
import { SurveyBasicInfo, SurveyDetailInfo } from '@/types/Survey'
import DetailButton from './DetailButton'
-import { roof_material, supplementary_facilities } from './form/MultiCheckEtc'
-import { selectBoxOptions } from './form/SelectBoxEtc'
-import { radioEtcData } from './form/RadioEtc'
+import { roof_material, supplementary_facilities } from './form/etcProcess/MultiCheckEtc'
+import { selectBoxOptions } from './form/etcProcess/SelectBoxEtc'
+import { radioEtcData } from './form/etcProcess/RadioEtc'
export default function RoofDetailForm({
surveyDetail,
@@ -196,7 +196,10 @@ export default function RoofDetailForm({
-
+
>
)
diff --git a/src/components/survey-sale/detail/form/BasicForm.tsx b/src/components/survey-sale/detail/form/BasicForm.tsx
index a8dd228..1f55838 100644
--- a/src/components/survey-sale/detail/form/BasicForm.tsx
+++ b/src/components/survey-sale/detail/form/BasicForm.tsx
@@ -8,7 +8,7 @@ import { useSurveySaleTabState } from '@/store/surveySaleTabState'
import { usePopupController } from '@/store/popupController'
import { useAddressStore } from '@/store/addressStore'
import { useSessionStore } from '@/store/session'
-import { useUserType } from '@/hooks/useUserType'
+// import { useUserType } from '@/hooks/useUserType'
const defaultBasicInfoForm: SurveyBasicRequest = {
REPRESENTATIVE: '',
@@ -37,7 +37,6 @@ export default function BasicForm() {
const [basicInfoData, setBasicInfoData] = useState(defaultBasicInfoForm)
const { addressData } = useAddressStore()
- const { memberRole, store, builderNo } = useUserType()
const { session } = useSessionStore()
const popupController = usePopupController()
@@ -59,12 +58,12 @@ export default function BasicForm() {
setBasicInfoData((prev) => ({
...prev,
REPRESENTATIVE: session?.userId ?? '',
- STORE: store ?? '',
- CONSTRUCTION_POINT: builderNo ?? '',
+ STORE: session?.storeNm ?? '',
+ CONSTRUCTION_POINT: session?.builderNo ?? '',
}))
}
setBasicInfoSelected()
- }, [surveyDetail, addressData, session?.isLoggedIn, session?.userNm, store, builderNo])
+ }, [surveyDetail, addressData, session?.isLoggedIn, session?.userId, session?.storeNm, session?.builderNo])
const focusInput = (input: keyof SurveyBasicRequest) => {
const inputElement = document.getElementById(input)
@@ -88,19 +87,19 @@ export default function BasicForm() {
const handleSave = async (isTemporary: boolean) => {
if (id) {
- updateSurvey(basicInfoData)
+ // updateSurvey(basicInfoData)
alert('保存しました。')
- router.push(`/survey-sale/${id}?tab=basic-info`)
+ // router.push(`/survey-sale/${id}?tab=basic-info`)
}
if (isTemporary) {
- const saveId = await createSurvey(basicInfoData)
+ // const saveId = await createSurvey(basicInfoData)
alert('一時保存されました。')
- router.push(`/survey-sale/${saveId}?tab=basic-info`)
+ // router.push(`/survey-sale/${saveId}?tab=basic-info`)
} else {
if (validateSurvey(basicInfoData)) {
- const saveId = await createSurvey(basicInfoData)
- alert('保存しました。 登録番号: ' + saveId)
- router.push(`/survey-sale/${saveId}?tab=basic-info`)
+ // const saveId = await createSurvey(basicInfoData)
+ alert('保存しました。')
+ // router.push(`/survey-sale/${saveId}?tab=basic-info`)
}
}
}
@@ -123,7 +122,7 @@ export default function BasicForm() {
onChange={(e) => handleChange('REPRESENTATIVE', e.target.value)}
/>
- {(memberRole === 'Builder' || memberRole?.includes('Admin')) && (
+ {(session?.role === 'Builder' || session?.role?.includes('Admin')) && (
<>
販売店
@@ -131,20 +130,20 @@ export default function BasicForm() {
type="text"
className="input-frame"
id="store"
- value={store ? store : basicInfoData.STORE ?? ''}
+ value={session?.storeNm ? session?.storeNm : basicInfoData.STORE ?? ''}
onChange={(e) => handleChange('STORE', e.target.value)}
/>
>
)}
- {(memberRole === 'Partner' || memberRole === 'Builder') && (
+ {(session?.role === 'Partner' || session?.role === 'Builder') && (
@@ -196,15 +195,13 @@ export default function BasicForm() {
-
+
diff --git a/src/components/survey-sale/detail/form/RoofInfoForm.tsx b/src/components/survey-sale/detail/form/RoofInfoForm.tsx
index 582a423..2a465d4 100644
--- a/src/components/survey-sale/detail/form/RoofInfoForm.tsx
+++ b/src/components/survey-sale/detail/form/RoofInfoForm.tsx
@@ -6,9 +6,9 @@ import { useServey } from '@/hooks/useSurvey'
import { SurveyDetailRequest } from '@/types/Survey'
import { useRouter, useSearchParams } from 'next/navigation'
import { useEffect, useState } from 'react'
-import MultiCheckEtc from './MultiCheckEtc'
-import SelectBoxEtc from './SelectBoxEtc'
-import RadioEtc from './RadioEtc'
+import MultiCheckEtc from './etcProcess/MultiCheckEtc'
+import SelectBoxEtc from './etcProcess/SelectBoxEtc'
+import RadioEtc from './etcProcess/RadioEtc'
const defaultDetailInfoForm: SurveyDetailRequest = {
CONTRACT_CAPACITY: null,
diff --git a/src/components/survey-sale/detail/form/MultiCheckEtc.tsx b/src/components/survey-sale/detail/form/etcProcess/MultiCheckEtc.tsx
similarity index 100%
rename from src/components/survey-sale/detail/form/MultiCheckEtc.tsx
rename to src/components/survey-sale/detail/form/etcProcess/MultiCheckEtc.tsx
diff --git a/src/components/survey-sale/detail/form/RadioEtc.tsx b/src/components/survey-sale/detail/form/etcProcess/RadioEtc.tsx
similarity index 100%
rename from src/components/survey-sale/detail/form/RadioEtc.tsx
rename to src/components/survey-sale/detail/form/etcProcess/RadioEtc.tsx
diff --git a/src/components/survey-sale/detail/form/SelectBoxEtc.tsx b/src/components/survey-sale/detail/form/etcProcess/SelectBoxEtc.tsx
similarity index 100%
rename from src/components/survey-sale/detail/form/SelectBoxEtc.tsx
rename to src/components/survey-sale/detail/form/etcProcess/SelectBoxEtc.tsx
diff --git a/src/components/survey-sale/list/ListTable.tsx b/src/components/survey-sale/list/ListTable.tsx
index 2523aaa..16351b7 100644
--- a/src/components/survey-sale/list/ListTable.tsx
+++ b/src/components/survey-sale/list/ListTable.tsx
@@ -6,7 +6,6 @@ import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
import SearchForm from './SearchForm'
import { useSurveyFilterStore } from '@/store/surveyFilterStore'
-import { MemberRole } from '@/hooks/useUserType'
import { useSessionStore } from '@/store/session'
export default function ListTable() {
@@ -16,7 +15,6 @@ export default function ListTable() {
const [heldSurveyList, setHeldSurveyList] = useState
([])
const [hasMore, setHasMore] = useState(false)
- const [memberRole, setMemberRole] = useState()
const { session } = useSessionStore()
@@ -32,8 +30,7 @@ export default function ListTable() {
}
setHasMore(surveyListCount > offset + 10)
}
- setMemberRole(session.role as MemberRole)
- }, [surveyList, surveyListCount, offset, session])
+ }, [surveyList, surveyListCount, offset, session?.role])
const handleDetailClick = (id: number) => {
router.push(`/survey-sale/${id}`)
@@ -47,7 +44,7 @@ export default function ListTable() {
return (
<>
-
+
{heldSurveyList.length > 0 ? (
diff --git a/src/components/survey-sale/list/SearchForm.tsx b/src/components/survey-sale/list/SearchForm.tsx
index 1b46349..3f3d234 100644
--- a/src/components/survey-sale/list/SearchForm.tsx
+++ b/src/components/survey-sale/list/SearchForm.tsx
@@ -1,23 +1,22 @@
'use client'
import { SEARCH_OPTIONS, SEARCH_OPTIONS_ENUM, SEARCH_OPTIONS_PARTNERS, useSurveyFilterStore } from '@/store/surveyFilterStore'
-import { MemberRole } from '@/hooks/useUserType'
import { useRouter } from 'next/navigation'
import { useState } from 'react'
-export default function SearchForm({ onItemsInit, memberRole }: { onItemsInit: () => void; memberRole: MemberRole }) {
+export default function SearchForm({ onItemsInit, memberRole, userId }: { onItemsInit: () => void; memberRole: string; userId: string }) {
const router = useRouter()
const { setSearchOption, setSort, setIsMySurvey, setKeyword, isMySurvey, keyword, searchOption, sort } = useSurveyFilterStore()
const [searchKeyword, setSearchKeyword] = useState(keyword)
-
- const username = 'test'
+ const [option, setOption] = useState(searchOption)
const handleSearch = () => {
- if (searchKeyword.trim().length < 2) {
+ if (option !== 'id' && searchKeyword.trim().length < 2) {
alert('2文字以上入力してください')
return
}
setKeyword(searchKeyword)
+ setSearchOption(option)
onItemsInit()
}
const searchOptions = memberRole === 'Partner' ? SEARCH_OPTIONS_PARTNERS : SEARCH_OPTIONS
@@ -25,7 +24,7 @@ export default function SearchForm({ onItemsInit, memberRole }: { onItemsInit: (
return (
- router.push('/survey-sale/basic-info')}>
+ router.push('/survey-sale/regist')}>
新規売買登録
@@ -34,8 +33,18 @@ export default function SearchForm({ onItemsInit, memberRole }: { onItemsInit: (
className="select-form"
name="search-option"
id="search-option"
- value={searchOption}
- onChange={(e) => setSearchOption(e.target.value as SEARCH_OPTIONS_ENUM)}
+ value={option}
+ onChange={(e) => {
+ if (e.target.value === 'all') {
+ setKeyword('')
+ setSearchKeyword('')
+ onItemsInit()
+ setSearchOption('all')
+ setOption('all')
+ } else {
+ setOption(e.target.value as SEARCH_OPTIONS_ENUM)
+ }
+ }}
>
{searchOptions.map((option) => (