From 35b1002908fb7d12632b44e65f2d0d4d77381850 Mon Sep 17 00:00:00 2001 From: keyy1315 Date: Tue, 27 May 2025 09:08:45 +0900 Subject: [PATCH] feat: add submit popup page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 제출 팝업 페이지 추가 - 조사매물 작성 시 숫자 입력 항목 모바일에서 숫자 키패드만 나오도록 설정 - 제출 필수값 validation 구현 --- .env.development | 2 +- .env.localhost | 2 +- src/app/api/survey-sales/[id]/route.ts | 6 +- .../popup/SurveySaleSubmitPopup.tsx | 151 ++++++++++++++++++ src/components/popup/ZipCodePopup.tsx | 1 - .../survey-sale/detail/BasicForm.tsx | 14 +- .../survey-sale/detail/ButtonForm.tsx | 84 ++++------ .../survey-sale/detail/DataTable.tsx | 5 +- .../survey-sale/detail/RoofForm.tsx | 24 +-- src/components/ui/PopupController.tsx | 4 +- src/hooks/useSurvey.ts | 12 +- src/store/popupController.ts | 5 + 12 files changed, 225 insertions(+), 85 deletions(-) create mode 100644 src/components/popup/SurveySaleSubmitPopup.tsx diff --git a/.env.development b/.env.development index 47cfa78..f9cbda5 100644 --- a/.env.development +++ b/.env.development @@ -2,7 +2,7 @@ NEXT_PUBLIC_RUN_MODE=development # 모바일 디바이스로 로컬 서버 확인하려면 자신 IP 주소로 변경 # 다시 로컬에서 개발할때는 localhost로 변경 #route handler -NEXT_PUBLIC_API_URL=http://localhost:3000 +NEXT_PUBLIC_API_URL=http://172.30.1.65:3000 #qsp 로그인 api NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 diff --git a/.env.localhost b/.env.localhost index 966e366..944ee6f 100644 --- a/.env.localhost +++ b/.env.localhost @@ -2,7 +2,7 @@ NEXT_PUBLIC_RUN_MODE=local # 모바일 디바이스로 로컬 서버 확인하려면 자신 IP 주소로 변경 # 다시 로컬에서 개발할때는 localhost로 변경 #route handler -NEXT_PUBLIC_API_URL=http://localhost:3000 +NEXT_PUBLIC_API_URL=http://172.30.1.65:3000 #qsp 로그인 api NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 diff --git a/src/app/api/survey-sales/[id]/route.ts b/src/app/api/survey-sales/[id]/route.ts index 7c03530..eb718f4 100644 --- a/src/app/api/survey-sales/[id]/route.ts +++ b/src/app/api/survey-sales/[id]/route.ts @@ -116,9 +116,6 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise< const { id } = await params const body = await request.json() - // 제출 시 기존 SRL_NO 확인 후 '임시저장'으로 시작하면 새로운 SRL_NO 생성 - const newSrlNo = await getNewSrlNo(body.srlNo, body.storeId, body.role) - if (body.targetId) { // @ts-ignore const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({ @@ -128,10 +125,9 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise< SUBMISSION_DATE: new Date(), SUBMISSION_TARGET_ID: body.targetId, UPT_DT: new Date(), - SRL_NO: newSrlNo, }, }) - return NextResponse.json({ message: 'Survey confirmed successfully' }) + return NextResponse.json({ message: 'Survey confirmed successfully', data: survey }) } } catch (error) { console.error('Error updating survey:', error) diff --git a/src/components/popup/SurveySaleSubmitPopup.tsx b/src/components/popup/SurveySaleSubmitPopup.tsx new file mode 100644 index 0000000..1d61da1 --- /dev/null +++ b/src/components/popup/SurveySaleSubmitPopup.tsx @@ -0,0 +1,151 @@ +import Image from 'next/image' +import { usePopupController } from '@/store/popupController' +import { useParams } from 'next/navigation' +import { useServey } from '@/hooks/useSurvey' +import { useState } from 'react' +import { useSessionStore } from '@/store/session' + +interface SubmitFormData { + store: string + sender: string + receiver: string + reference: string + title: string + contents: string +} + +interface FormField { + id: keyof SubmitFormData + name: string + required: boolean +} + +const FORM_FIELDS: FormField[] = [ + { id: 'store', name: '提出販売店', required: true }, + { id: 'sender', name: '発送者', required: true }, + { id: 'receiver', name: '受信者', required: true }, + { id: 'reference', name: '参考', required: false }, + { id: 'title', name: 'タイトル', required: true }, + { id: 'contents', name: '内容', required: true }, +] + +export default function SurveySaleSubmitPopup() { + const popupController = usePopupController() + const { session } = useSessionStore() + const params = useParams() + const routeId = params.id + + const [submitData, setSubmitData] = useState({ + store: '', + sender: session?.email ?? '', + receiver: '', + reference: '', + title: '[HANASYS現地調査] 調査物件が提出.', + contents: '', + }) + + const { submitSurvey, isSubmittingSurvey } = useServey(Number(routeId)) + + const handleInputChange = (field: keyof SubmitFormData, value: string) => { + setSubmitData((prev) => ({ ...prev, [field]: value })) + } + + const validateData = (data: SubmitFormData): boolean => { + const requiredFields = FORM_FIELDS.filter((field) => field.required) + + for (const field of requiredFields) { + if (!data[field.id].trim()) { + const element = document.getElementById(field.id) + if (element) { + element.focus() + } + alert(`${field.name}は必須入力項目です。`) + return false + } + } + + return true + } + + const handleSubmit = () => { + if (validateData(submitData)) { + window.neoConfirm('送信しますか? 送信後は変更・修正することはできません。', () => { + submitSurvey({ targetId: submitData.store }) + if (!isSubmittingSurvey) { + popupController.setSurveySaleSubmitPopup(false) + } + }) + } + } + + const handleClose = () => { + popupController.setSurveySaleSubmitPopup(false) + } + + const renderFormField = (field: FormField) => { + // const isReadOnly = (field.id === 'store' && session?.role !== 'Partner') || (field.id === 'receiver' && session?.role !== 'Partner') + const isReadOnly = false + + return ( +
+
+ {field.name} {field.required && *} +
+
+ {field.id === 'contents' ? ( +