feat: add submit popup page
- 제출 팝업 페이지 추가 - 조사매물 작성 시 숫자 입력 항목 모바일에서 숫자 키패드만 나오도록 설정 - 제출 필수값 validation 구현
This commit is contained in:
parent
0fbb8025f2
commit
35b1002908
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
151
src/components/popup/SurveySaleSubmitPopup.tsx
Normal file
151
src/components/popup/SurveySaleSubmitPopup.tsx
Normal file
@ -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<SubmitFormData>({
|
||||
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 (
|
||||
<div className="data-input-form-bx" key={field.id}>
|
||||
<div className="data-input-form-tit">
|
||||
{field.name} {field.required && <i className="import">*</i>}
|
||||
</div>
|
||||
<div className="data-input">
|
||||
{field.id === 'contents' ? (
|
||||
<textarea
|
||||
className="textarea-form"
|
||||
id={field.id}
|
||||
value={submitData[field.id]}
|
||||
onChange={(e) => handleInputChange(field.id, e.target.value)}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className="input-frame"
|
||||
type="text"
|
||||
id={field.id}
|
||||
value={submitData[field.id]}
|
||||
onChange={(e) => handleInputChange(field.id, e.target.value)}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="modal-popup">
|
||||
<div className="modal-dialog">
|
||||
<div className="modal-content">
|
||||
<div className="modal-header">
|
||||
<div className="modal-header-inner">
|
||||
<div className="modal-name-wrap">
|
||||
<div className="modal-img">
|
||||
<Image src="/assets/images/layout/modal_header_icon04.svg" width={19} height={22} alt="" />
|
||||
</div>
|
||||
<div className="modal-name">調査物件の提出</div>
|
||||
</div>
|
||||
<button className="modal-close" onClick={handleClose}></button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div className="data-form-wrap">{FORM_FIELDS.map(renderFormField)}</div>
|
||||
<div className="btn-flex-wrap">
|
||||
<div className="btn-bx">
|
||||
<button className="btn-frame n-blue icon" onClick={handleClose}>
|
||||
閉じる<i className="btn-arr"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div className="btn-bx">
|
||||
<button className="btn-frame red icon" onClick={handleSubmit} disabled={isSubmittingSurvey}>
|
||||
転送<i className="btn-arr"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -28,7 +28,6 @@ export default function ZipCodePopup() {
|
||||
const popupController = usePopupController()
|
||||
|
||||
const handleApply = () => {
|
||||
console.log(addressInfo?.[0])
|
||||
setAddressData({
|
||||
post_code: addressInfo?.[0]?.zipcode || '',
|
||||
address: addressInfo?.[0]?.address1 || '',
|
||||
|
||||
@ -141,7 +141,7 @@ export default function BasicForm(props: { basicInfo: SurveyBasicRequest; setBas
|
||||
<div className="form-flex">
|
||||
{/* 우편번호 */}
|
||||
<div className="form-bx">
|
||||
<input type="text" className="input-frame" readOnly={mode === 'READ'} defaultValue={basicInfo?.postCode ?? ''} disabled />
|
||||
<input type="text" className="input-frame" readOnly={true} defaultValue={basicInfo?.postCode ?? ''} />
|
||||
</div>
|
||||
{/* 도도부현 */}
|
||||
<div className="form-bx">
|
||||
@ -149,11 +149,13 @@ export default function BasicForm(props: { basicInfo: SurveyBasicRequest; setBas
|
||||
</div>
|
||||
</div>
|
||||
{/* 주소 */}
|
||||
<div className="form-btn">
|
||||
<button className="btn-frame n-blue icon" onClick={() => popupController.setZipCodePopup(true)}>
|
||||
郵便番号<i className="btn-arr"></i>
|
||||
</button>
|
||||
</div>
|
||||
{mode !== 'READ' && (
|
||||
<div className="form-btn">
|
||||
<button className="btn-frame n-blue icon" onClick={() => popupController.setZipCodePopup(true)}>
|
||||
郵便番号<i className="btn-arr"></i>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="data-input-form-bx">
|
||||
|
||||
@ -5,6 +5,7 @@ import { useSessionStore } from '@/store/session'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useParams, useRouter, useSearchParams } from 'next/navigation'
|
||||
import { requiredFields, useServey } from '@/hooks/useSurvey'
|
||||
import { usePopupController } from '@/store/popupController'
|
||||
|
||||
export default function ButtonForm(props: {
|
||||
mode: Mode
|
||||
@ -22,14 +23,12 @@ export default function ButtonForm(props: {
|
||||
const params = useParams()
|
||||
const routeId = params.id
|
||||
|
||||
const popupController = usePopupController()
|
||||
// ------------------------------------------------------------
|
||||
const [saveData, setSaveData] = useState({
|
||||
...props.data.basic,
|
||||
detailInfo: props.data.roof,
|
||||
})
|
||||
|
||||
// !!!!!!!!!!
|
||||
const [tempTargetId, setTempTargetId] = useState('TEST')
|
||||
// --------------------------------------------------------------
|
||||
// 권한
|
||||
|
||||
@ -73,8 +72,8 @@ export default function ButtonForm(props: {
|
||||
// 저장/임시저장/수정
|
||||
const id = Number(routeId) ? Number(routeId) : Number(idParam)
|
||||
|
||||
const { deleteSurvey, submitSurvey, updateSurvey } = useServey(Number(id))
|
||||
const { validateSurveyDetail, createSurvey } = useServey()
|
||||
const { deleteSurvey, updateSurvey, isDeletingSurvey, isUpdatingSurvey } = useServey(Number(id))
|
||||
const { validateSurveyDetail, createSurvey, isCreatingSurvey } = useServey()
|
||||
|
||||
const handleSave = (isTemporary: boolean, isSubmitProcess = false) => {
|
||||
const emptyField = validateSurveyDetail(props.data.roof)
|
||||
@ -112,35 +111,19 @@ export default function ButtonForm(props: {
|
||||
const saveProcess = async (emptyField: string | null, isSubmitProcess?: boolean) => {
|
||||
if (emptyField?.trim() === '') {
|
||||
if (idParam) {
|
||||
if (isSubmitProcess) {
|
||||
const updatedData = {
|
||||
...saveData,
|
||||
submissionStatus: true,
|
||||
submissionDate: new Date().toISOString(),
|
||||
submissionTargetId: tempTargetId,
|
||||
}
|
||||
await updateSurvey({ survey: updatedData, isTemporary: false, storeId: session.storeId ?? '' })
|
||||
router.push(`/survey-sale/${idParam}`)
|
||||
} else {
|
||||
await updateSurvey({ survey: saveData, isTemporary: false, storeId: session.storeId ?? '' })
|
||||
router.push(`/survey-sale/${idParam}`)
|
||||
await updateSurvey({ survey: saveData, isTemporary: false, storeId: session.storeId ?? '' })
|
||||
router.push(`/survey-sale/${idParam}`)
|
||||
} else {
|
||||
const id = await createSurvey(saveData)
|
||||
router.push(`/survey-sale/${id}`)
|
||||
}
|
||||
if (isSubmitProcess) {
|
||||
if (!isCreatingSurvey && !isUpdatingSurvey) {
|
||||
popupController.setSurveySaleSubmitPopup(true)
|
||||
}
|
||||
} else {
|
||||
if (isSubmitProcess) {
|
||||
const updatedData = {
|
||||
...saveData,
|
||||
submissionStatus: true,
|
||||
submissionDate: new Date().toISOString(),
|
||||
submissionTargetId: tempTargetId,
|
||||
}
|
||||
const id = await createSurvey(updatedData)
|
||||
submitProcess(id)
|
||||
} else {
|
||||
const id = await createSurvey(saveData)
|
||||
router.push(`/survey-sale/${id}`)
|
||||
}
|
||||
alert('保存されました。')
|
||||
}
|
||||
alert('保存されました。')
|
||||
} else {
|
||||
if (emptyField?.includes('Unit')) {
|
||||
alert('電気契約容量の単位を入力してください。')
|
||||
@ -158,35 +141,30 @@ export default function ButtonForm(props: {
|
||||
if (routeId) {
|
||||
window.neoConfirm('削除しますか?', async () => {
|
||||
await deleteSurvey()
|
||||
alert('削除されました。')
|
||||
router.push('/survey-sale')
|
||||
if (!isDeletingSurvey) {
|
||||
alert('削除されました。')
|
||||
router.push('/survey-sale')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (props.data.basic.srlNo?.startsWith('一時保存')) {
|
||||
if (props.data.basic.srlNo?.startsWith('一時保存') && Number(routeId)) {
|
||||
alert('一時保存されたデータは提出できません。')
|
||||
return
|
||||
}
|
||||
if (tempTargetId.trim() === '') {
|
||||
alert('提出対象店舗を入力してください。')
|
||||
return
|
||||
}
|
||||
window.neoConfirm('提出しますか?', async () => {
|
||||
if (Number(routeId)) {
|
||||
submitProcess()
|
||||
} else {
|
||||
if (Number(routeId)) {
|
||||
window.neoConfirm('提出しますか?', async () => {
|
||||
popupController.setSurveySaleSubmitPopup(true)
|
||||
})
|
||||
} else {
|
||||
window.neoConfirm('記入した情報を保存して送信しますか?', async () => {
|
||||
handleSave(false, true)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const submitProcess = async (saveId?: number) => {
|
||||
await submitSurvey({ saveId: saveId, targetId: tempTargetId, storeId: session.storeId ?? '', srlNo: '一時保存' })
|
||||
alert('提出されました。')
|
||||
router.push('/survey-sale')
|
||||
}
|
||||
// ------------------------------------------------------------
|
||||
|
||||
if (mode === 'READ' && isSubmit && isSubmiter) {
|
||||
@ -209,7 +187,7 @@ export default function ButtonForm(props: {
|
||||
<ListButton />
|
||||
<EditButton setMode={setMode} id={id.toString()} mode={mode} />
|
||||
{(isWriter || !isSubmiter) && <DeleteButton handleDelete={handleDelete} />}
|
||||
{!isSubmit && isSubmiter && <SubmitButton handleSubmit={handleSubmit} setTempTargetId={setTempTargetId} />}
|
||||
{!isSubmit && isSubmiter && <SubmitButton handleSubmit={handleSubmit} />}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@ -220,7 +198,7 @@ export default function ButtonForm(props: {
|
||||
<ListButton />
|
||||
<TempButton setMode={setMode} handleSave={handleSave} />
|
||||
<SaveButton handleSave={handleSave} />
|
||||
{session?.role !== 'T01' && <SubmitButton handleSubmit={handleSubmit} setTempTargetId={setTempTargetId} />}{' '}
|
||||
{session?.role !== 'T01' && <SubmitButton handleSubmit={handleSubmit} />}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@ -260,8 +238,8 @@ function EditButton(props: { setMode: (mode: Mode) => void; id: string; mode: Mo
|
||||
)
|
||||
}
|
||||
|
||||
function SubmitButton(props: { handleSubmit: () => void; setTempTargetId: (targetId: string) => void }) {
|
||||
const { handleSubmit, setTempTargetId } = props
|
||||
function SubmitButton(props: { handleSubmit: () => void }) {
|
||||
const { handleSubmit } = props
|
||||
return (
|
||||
<>
|
||||
<div className="btn-bx">
|
||||
|
||||
@ -54,9 +54,10 @@ export default function DataTable() {
|
||||
<td>
|
||||
{surveyDetail?.submissionStatus && surveyDetail?.submissionDate ? (
|
||||
<>
|
||||
{/* TODO: 제출한 판매점 ID 추가 필요 */}
|
||||
<div>{new Date(surveyDetail.submissionDate).toLocaleString()}</div>
|
||||
<div>{surveyDetail.store}</div>
|
||||
<div>
|
||||
({surveyDetail.store} - {surveyDetail.storeId})
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
'-'
|
||||
|
||||
@ -265,11 +265,12 @@ export default function RoofForm(props: {
|
||||
<div className="data-input-form-bx">
|
||||
{/* 전기 계약 용량 */}
|
||||
<div className="data-input-form-tit">電気契約容量</div>
|
||||
{mode === 'READ' && <input type="text" className="input-frame" value={roofInfo?.contractCapacity ?? ''} disabled={mode === 'READ'} />}
|
||||
{mode === 'READ' && <input type="text" className="input-frame" value={roofInfo?.contractCapacity ?? ''} readOnly={mode === 'READ'} />}
|
||||
{mode !== 'READ' && (
|
||||
<div className="data-input mb5">
|
||||
<input
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
id="contractCapacity"
|
||||
className="input-frame"
|
||||
value={roofInfo?.contractCapacity?.split(' ')[0] ?? ''}
|
||||
@ -343,11 +344,13 @@ export default function RoofForm(props: {
|
||||
</div>
|
||||
</div>
|
||||
<div className="data-input-form-bx">
|
||||
{/* 지붕 경사도도 */}
|
||||
{/* 지붕 경사도 */}
|
||||
<div className="data-input-form-tit">屋根の斜面</div>
|
||||
<div className="data-input flex">
|
||||
<input
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
id="roofSlope"
|
||||
className="input-frame"
|
||||
value={roofInfo?.roofSlope ?? ''}
|
||||
disabled={mode === 'READ'}
|
||||
@ -388,7 +391,7 @@ export default function RoofForm(props: {
|
||||
</div>
|
||||
</div>
|
||||
<div className="data-input-form-bx">
|
||||
{/* 노지판 종류류 */}
|
||||
{/* 노지판 종류 */}
|
||||
<div className="data-input-form-tit">路地板の種類</div>
|
||||
<div className="data-input mb5">
|
||||
<SelectedBox mode={mode} column="openFieldPlateKind" detailInfoData={roofInfo as SurveyDetailInfo} setRoofInfo={setRoofInfo} />
|
||||
@ -401,7 +404,9 @@ export default function RoofForm(props: {
|
||||
</div>
|
||||
<div className="data-input flex">
|
||||
<input
|
||||
type="text"
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
id="openFieldPlateThickness"
|
||||
className="input-frame"
|
||||
value={roofInfo?.openFieldPlateThickness ?? ''}
|
||||
disabled={mode === 'READ'}
|
||||
@ -516,7 +521,7 @@ const SelectedBox = ({
|
||||
name={column}
|
||||
id={column}
|
||||
disabled={mode === 'READ'}
|
||||
value={selectedId ? Number(selectedId) : etcValue ? 'etc' : ''}
|
||||
value={selectedId ? Number(selectedId) : etcValue || isEtcSelected ? 'etc' : ''}
|
||||
onChange={handleSelectChange}
|
||||
>
|
||||
{selectBoxOptions[column as keyof typeof selectBoxOptions].map((item) => (
|
||||
@ -536,11 +541,12 @@ const SelectedBox = ({
|
||||
<div className={`data-input ${column === 'constructionYear' ? 'flex' : ''}`}>
|
||||
<input
|
||||
type={column === 'constructionYear' ? 'number' : 'text'}
|
||||
inputMode={column === 'constructionYear' ? 'numeric' : 'text'}
|
||||
className="input-frame"
|
||||
placeholder="-"
|
||||
value={detailInfoData[`${column}Etc` as keyof SurveyDetailInfo]?.toString() ?? ''}
|
||||
onChange={handleEtcInputChange}
|
||||
disabled={isInputDisabled()}
|
||||
readOnly={isInputDisabled()}
|
||||
/>
|
||||
{column === 'constructionYear' && <span>年</span>}
|
||||
</div>
|
||||
@ -644,7 +650,7 @@ const RadioSelected = ({
|
||||
placeholder="-"
|
||||
value={detailInfoData[`${column}Etc` as keyof SurveyDetailInfo]?.toString() ?? ''}
|
||||
onChange={handleEtcInputChange}
|
||||
disabled={isInputDisabled()}
|
||||
readOnly={isInputDisabled()}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@ -678,7 +684,7 @@ const MultiCheck = ({
|
||||
newValue = selectedValues.filter((v) => v !== String(id))
|
||||
} else {
|
||||
if (isRoofMaterial) {
|
||||
const totalSelected = selectedValues.length + (isOtherSelected ? 1 : 0)
|
||||
const totalSelected = selectedValues.length + (isOtherSelected || isOtherCheck ? 1 : 0)
|
||||
if (totalSelected >= 2) {
|
||||
alert('屋根材は最大2個まで選択できます。')
|
||||
return
|
||||
@ -749,7 +755,7 @@ const MultiCheck = ({
|
||||
placeholder="-"
|
||||
value={roofInfo[`${column}Etc` as keyof SurveyDetailInfo]?.toString() ?? ''}
|
||||
onChange={handleOtherInputChange}
|
||||
disabled={isInputDisabled()}
|
||||
readOnly={isInputDisabled()}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@ -7,6 +7,7 @@ import ZipCodePopup from '../popup/ZipCodePopup'
|
||||
import Alert from './common/Alert'
|
||||
import DoubleBtnAlert from './common/DoubleBtnAlert'
|
||||
import SuitableDetailPopup from '../popup/SuitableDetailPopup'
|
||||
import SurveySaleSubmitPopup from '../popup/SurveySaleSubmitPopup'
|
||||
|
||||
export default function PopupController() {
|
||||
const popupController = usePopupController()
|
||||
@ -15,9 +16,10 @@ export default function PopupController() {
|
||||
<>
|
||||
{popupController.memberInfomationPopup && <MemberInfomationPopup />}
|
||||
{popupController.zipCodePopup && <ZipCodePopup />}
|
||||
{popupController.suitableDetailPopup && <SuitableDetailPopup />}
|
||||
{popupController.surveySaleSubmitPopup && <SurveySaleSubmitPopup />}
|
||||
{popupController.alert && <Alert />}
|
||||
{popupController.alert2 && <DoubleBtnAlert />}
|
||||
{popupController.suitableDetailPopup && <SuitableDetailPopup />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@ -62,6 +62,7 @@ export function useServey(id?: number): {
|
||||
isCreatingSurvey: boolean
|
||||
isUpdatingSurvey: boolean
|
||||
isDeletingSurvey: boolean
|
||||
isSubmittingSurvey: boolean
|
||||
createSurvey: (survey: SurveyRegistRequest) => Promise<number>
|
||||
updateSurvey: ({ survey, isTemporary, storeId }: { survey: SurveyRegistRequest; isTemporary: boolean; storeId?: string }) => void
|
||||
deleteSurvey: () => Promise<boolean>
|
||||
@ -134,7 +135,6 @@ export function useServey(id?: number): {
|
||||
|
||||
const { mutate: updateSurvey, isPending: isUpdatingSurvey } = useMutation({
|
||||
mutationFn: async ({ survey, isTemporary, storeId }: { survey: SurveyRegistRequest; isTemporary: boolean; storeId?: string }) => {
|
||||
console.log('updateSurvey, survey:: ', survey)
|
||||
if (id === undefined) throw new Error('id is required')
|
||||
const resp = await axiosInstance(null).put<SurveyRegistRequest>(`/api/survey-sales/${id}`, {
|
||||
survey: survey,
|
||||
@ -162,11 +162,10 @@ export function useServey(id?: number): {
|
||||
},
|
||||
})
|
||||
|
||||
const { mutateAsync: submitSurvey } = useMutation({
|
||||
mutationFn: async ({ saveId, targetId, storeId, srlNo }: { saveId?: number; targetId?: string; storeId?: string; srlNo?: string }) => {
|
||||
const submitId = saveId ?? id
|
||||
if (!submitId) throw new Error('id is required')
|
||||
const resp = await axiosInstance(null).patch<boolean>(`/api/survey-sales/${submitId}`, {
|
||||
const { mutateAsync: submitSurvey, isPending: isSubmittingSurvey } = useMutation({
|
||||
mutationFn: async ({ targetId, storeId, srlNo }: { targetId?: string; storeId?: string; srlNo?: string }) => {
|
||||
if (!id) throw new Error('id is required')
|
||||
const resp = await axiosInstance(null).patch<boolean>(`/api/survey-sales/${id}`, {
|
||||
targetId,
|
||||
storeId,
|
||||
srlNo,
|
||||
@ -231,6 +230,7 @@ export function useServey(id?: number): {
|
||||
isCreatingSurvey,
|
||||
isUpdatingSurvey,
|
||||
isDeletingSurvey,
|
||||
isSubmittingSurvey,
|
||||
createSurvey,
|
||||
updateSurvey,
|
||||
deleteSurvey,
|
||||
|
||||
@ -10,6 +10,8 @@ type PoupControllerState = {
|
||||
alert2: boolean
|
||||
alert2BtnYes: Function
|
||||
alert2BtnNo: Function
|
||||
surveySaleSubmitPopup: boolean
|
||||
setSurveySaleSubmitPopup: (value: boolean) => void
|
||||
setMemberInfomationPopup: (value: boolean) => void
|
||||
setZipCodePopup: (value: boolean) => void
|
||||
setAlert: (value: boolean) => void
|
||||
@ -32,6 +34,7 @@ type InitialState = {
|
||||
alert2BtnYes: Function
|
||||
alert2BtnNo: Function
|
||||
suitableDetailPopup: boolean
|
||||
surveySaleSubmitPopup: boolean
|
||||
}
|
||||
|
||||
const initialState: InitialState = {
|
||||
@ -44,6 +47,7 @@ const initialState: InitialState = {
|
||||
alert2BtnYes: () => {},
|
||||
alert2BtnNo: () => {},
|
||||
suitableDetailPopup: false,
|
||||
surveySaleSubmitPopup: false,
|
||||
}
|
||||
|
||||
export const usePopupController = create<PoupControllerState>((set) => ({
|
||||
@ -57,5 +61,6 @@ export const usePopupController = create<PoupControllerState>((set) => ({
|
||||
setAlert2BtnYes: (value: Function) => set((state) => ({ ...state, alert2BtnYes: value })),
|
||||
setAlert2BtnNo: (value: Function) => set((state) => ({ ...state, alert2BtnNo: value })),
|
||||
setSuitableDetailPopup: (value: boolean) => set((state) => ({ ...state, suitableDetailPopup: value })),
|
||||
setSurveySaleSubmitPopup: (value: boolean, id?: number) => set((state) => ({ ...state, surveySaleSubmitPopup: value, surveySaleSubmitId: id })),
|
||||
reset: () => set(initialState),
|
||||
}))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user