fix: solve conflict
- 충돌 해결 및 이전 sample page 주석 처리
This commit is contained in:
parent
ec9f0fa747
commit
8153dd9d18
@ -7,7 +7,6 @@ import { useEffect } from 'react'
|
||||
export default function NavTab() {
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
|
||||
if (pathname === '/survey-sale') {
|
||||
return null
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { useSurveySaleTabState } from '@/store/surveySaleTabState'
|
||||
|
||||
import { useServey } from '@/hooks/useSurvey'
|
||||
|
||||
@ -1,61 +1,61 @@
|
||||
'use client'
|
||||
// 'use client'
|
||||
|
||||
import { useServey } from '@/hooks/useSurvey'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
// import { useServey } from '@/hooks/useSurvey'
|
||||
// import { useParams, useRouter } from 'next/navigation'
|
||||
|
||||
export default function SurveyDetail() {
|
||||
const params = useParams()
|
||||
const id = params.id
|
||||
const router = useRouter()
|
||||
// export default function SurveyDetail() {
|
||||
// const params = useParams()
|
||||
// const id = params.id
|
||||
// const router = useRouter()
|
||||
|
||||
const { surveyDetail, deleteSurvey, isDeletingSurvey, confirmSurvey } = useServey(Number(id))
|
||||
// const { surveyDetail, deleteSurvey, isDeletingSurvey, confirmSurvey } = useServey(Number(id))
|
||||
|
||||
console.log('surveyDetail:: ', surveyDetail)
|
||||
// console.log('surveyDetail:: ', surveyDetail)
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (confirm('delete?')) {
|
||||
if (surveyDetail?.representative) {
|
||||
if (surveyDetail.detail_info?.id) {
|
||||
await deleteSurvey({ id: Number(surveyDetail.detail_info.id), isDetail: true })
|
||||
}
|
||||
await deleteSurvey({ id: Number(id), isDetail: false })
|
||||
}
|
||||
alert('delete success')
|
||||
router.push('/survey-sales')
|
||||
}
|
||||
}
|
||||
const handleSubmit = () => {
|
||||
if (confirm('submit?')) {
|
||||
confirmSurvey(Number(id))
|
||||
}
|
||||
alert('submit success')
|
||||
router.push('/survey-sales')
|
||||
}
|
||||
// const handleDelete = async () => {
|
||||
// if (confirm('delete?')) {
|
||||
// if (surveyDetail?.representative) {
|
||||
// if (surveyDetail.detail_info?.id) {
|
||||
// await deleteSurvey({ id: Number(surveyDetail.detail_info.id), isDetail: true })
|
||||
// }
|
||||
// await deleteSurvey({ id: Number(id), isDetail: false })
|
||||
// }
|
||||
// alert('delete success')
|
||||
// router.push('/survey-sales')
|
||||
// }
|
||||
// }
|
||||
// const handleSubmit = () => {
|
||||
// if (confirm('submit?')) {
|
||||
// confirmSurvey(Number(id))
|
||||
// }
|
||||
// alert('submit success')
|
||||
// router.push('/survey-sales')
|
||||
// }
|
||||
|
||||
if (isDeletingSurvey) {
|
||||
return <div>Deleting...</div>
|
||||
}
|
||||
// if (isDeletingSurvey) {
|
||||
// return <div>Deleting...</div>
|
||||
// }
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>SurveyDetail</h1>
|
||||
<p>{id}</p>
|
||||
<p>{surveyDetail?.representative}</p>
|
||||
<div className="flex gap-3">
|
||||
<button className="bg-blue-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={() => router.push('/survey-sales/write?id=' + id)}>
|
||||
edit
|
||||
</button>
|
||||
<button className="bg-blue-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={handleSubmit}>
|
||||
submit
|
||||
</button>
|
||||
<button className="bg-red-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={handleDelete}>
|
||||
delete
|
||||
</button>
|
||||
<button className="bg-gray-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={() => router.back()}>
|
||||
back
|
||||
</button>
|
||||
</div>
|
||||
<input type="text" className="input-frame" disabled defaultValue={surveyDetail?.store ?? ''} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
// return (
|
||||
// <div>
|
||||
// <h1>SurveyDetail</h1>
|
||||
// <p>{id}</p>
|
||||
// <p>{surveyDetail?.representative}</p>
|
||||
// <div className="flex gap-3">
|
||||
// <button className="bg-blue-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={() => router.push('/survey-sales/write?id=' + id)}>
|
||||
// edit
|
||||
// </button>
|
||||
// <button className="bg-blue-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={handleSubmit}>
|
||||
// submit
|
||||
// </button>
|
||||
// <button className="bg-red-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={handleDelete}>
|
||||
// delete
|
||||
// </button>
|
||||
// <button className="bg-gray-500 text-white px-2 py-1 rounded-md cursor-pointer" onClick={() => router.back()}>
|
||||
// back
|
||||
// </button>
|
||||
// </div>
|
||||
// <input type="text" className="input-frame" disabled defaultValue={surveyDetail?.store ?? ''} />
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
@ -1,168 +1,168 @@
|
||||
'use client'
|
||||
// 'use client'
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import BasicWriteForm from './BasicWriteForm'
|
||||
import DetailWriteForm from './DetailWriteForm'
|
||||
import { SurveySalesBasicInfo, SurveySalesDetailInfo } from '@/api/surveySales'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { useServey } from '@/hooks/useSurvey'
|
||||
import { SurveyBasicRequest, SurveyDetailRequest } from '@/types/Survey'
|
||||
// import { useState, useEffect } from 'react'
|
||||
// import BasicWriteForm from './BasicWriteForm'
|
||||
// import DetailWriteForm from './DetailWriteForm'
|
||||
// import { SurveySalesBasicInfo, SurveySalesDetailInfo } from '@/api/surveySales'
|
||||
// import { useRouter, useSearchParams } from 'next/navigation'
|
||||
// import { useServey } from '@/hooks/useSurvey'
|
||||
// import { SurveyBasicRequest, SurveyDetailRequest } from '@/types/Survey'
|
||||
|
||||
type TabType = 'basic' | 'detail'
|
||||
// type TabType = 'basic' | 'detail'
|
||||
|
||||
const defaultDetailInfoForm: SurveyDetailRequest = {
|
||||
basic_info_id: 0,
|
||||
contract_capacity: null,
|
||||
retail_company: null,
|
||||
supplementary_facilities: null,
|
||||
supplementary_facilities_etc: null,
|
||||
installation_system: null,
|
||||
installation_system_etc: null,
|
||||
construction_year: null,
|
||||
construction_year_etc: null,
|
||||
roof_material: null,
|
||||
roof_material_etc: null,
|
||||
roof_shape: null,
|
||||
roof_shape_etc: null,
|
||||
roof_slope: null,
|
||||
house_structure: null,
|
||||
house_structure_etc: null,
|
||||
rafter_material: null,
|
||||
rafter_material_etc: null,
|
||||
rafter_size: null,
|
||||
rafter_size_etc: null,
|
||||
rafter_pitch: null,
|
||||
rafter_pitch_etc: null,
|
||||
rafter_direction: null,
|
||||
open_field_plate_kind: null,
|
||||
open_field_plate_kind_etc: null,
|
||||
open_field_plate_thickness: null,
|
||||
leak_trace: false,
|
||||
waterproof_material: null,
|
||||
waterproof_material_etc: null,
|
||||
structure_order: null,
|
||||
structure_order_etc: null,
|
||||
insulation_presence: null,
|
||||
insulation_presence_etc: null,
|
||||
installation_availability: null,
|
||||
installation_availability_etc: null,
|
||||
memo: null,
|
||||
}
|
||||
// const defaultDetailInfoForm: SurveyDetailRequest = {
|
||||
// basic_info_id: 0,
|
||||
// contract_capacity: null,
|
||||
// retail_company: null,
|
||||
// supplementary_facilities: null,
|
||||
// supplementary_facilities_etc: null,
|
||||
// installation_system: null,
|
||||
// installation_system_etc: null,
|
||||
// construction_year: null,
|
||||
// construction_year_etc: null,
|
||||
// roof_material: null,
|
||||
// roof_material_etc: null,
|
||||
// roof_shape: null,
|
||||
// roof_shape_etc: null,
|
||||
// roof_slope: null,
|
||||
// house_structure: null,
|
||||
// house_structure_etc: null,
|
||||
// rafter_material: null,
|
||||
// rafter_material_etc: null,
|
||||
// rafter_size: null,
|
||||
// rafter_size_etc: null,
|
||||
// rafter_pitch: null,
|
||||
// rafter_pitch_etc: null,
|
||||
// rafter_direction: null,
|
||||
// open_field_plate_kind: null,
|
||||
// open_field_plate_kind_etc: null,
|
||||
// open_field_plate_thickness: null,
|
||||
// leak_trace: false,
|
||||
// waterproof_material: null,
|
||||
// waterproof_material_etc: null,
|
||||
// structure_order: null,
|
||||
// structure_order_etc: null,
|
||||
// insulation_presence: null,
|
||||
// insulation_presence_etc: null,
|
||||
// installation_availability: null,
|
||||
// installation_availability_etc: null,
|
||||
// memo: null,
|
||||
// }
|
||||
|
||||
const defaultBasicInfoForm: SurveyBasicRequest = {
|
||||
representative: '',
|
||||
store: null,
|
||||
construction_point: null,
|
||||
investigation_date: null,
|
||||
building_name: null,
|
||||
customer_name: null,
|
||||
post_code: null,
|
||||
address: null,
|
||||
address_detail: null,
|
||||
submission_status: false,
|
||||
submission_date: null,
|
||||
}
|
||||
// const defaultBasicInfoForm: SurveyBasicRequest = {
|
||||
// representative: '',
|
||||
// store: null,
|
||||
// construction_point: null,
|
||||
// investigation_date: null,
|
||||
// building_name: null,
|
||||
// customer_name: null,
|
||||
// post_code: null,
|
||||
// address: null,
|
||||
// address_detail: null,
|
||||
// submission_status: false,
|
||||
// submission_date: null,
|
||||
// }
|
||||
|
||||
export default function MainSurveyForm() {
|
||||
const searchParams = useSearchParams()
|
||||
// export default function MainSurveyForm() {
|
||||
// const searchParams = useSearchParams()
|
||||
|
||||
const id = searchParams.get('id')
|
||||
// const id = searchParams.get('id')
|
||||
|
||||
const [activeTab, setActiveTab] = useState<TabType>('basic')
|
||||
// const [activeTab, setActiveTab] = useState<TabType>('basic')
|
||||
|
||||
const handleTabClick = (tab: TabType) => {
|
||||
setActiveTab(tab)
|
||||
}
|
||||
// const handleTabClick = (tab: TabType) => {
|
||||
// setActiveTab(tab)
|
||||
// }
|
||||
|
||||
const router = useRouter()
|
||||
const { createSurvey, isCreatingSurvey, createSurveyDetail, surveyDetail, updateSurvey } = useServey(Number(id))
|
||||
// const router = useRouter()
|
||||
// const { createSurvey, isCreatingSurvey, createSurveyDetail, surveyDetail, updateSurvey } = useServey(Number(id))
|
||||
|
||||
const [detailInfoForm, setDetailInfoForm] = useState<SurveyDetailRequest>(defaultDetailInfoForm)
|
||||
const [basicInfoData, setBasicInfoData] = useState<SurveyBasicRequest>(defaultBasicInfoForm)
|
||||
// const [detailInfoForm, setDetailInfoForm] = useState<SurveyDetailRequest>(defaultDetailInfoForm)
|
||||
// const [basicInfoData, setBasicInfoData] = useState<SurveyBasicRequest>(defaultBasicInfoForm)
|
||||
|
||||
useEffect(() => {
|
||||
if (surveyDetail) {
|
||||
setBasicInfoData({
|
||||
...defaultBasicInfoForm,
|
||||
...(({ id, ...rest }) => rest)(surveyDetail),
|
||||
})
|
||||
setDetailInfoForm({
|
||||
...defaultDetailInfoForm,
|
||||
...(surveyDetail.detail_info ? (({ id, basic_info_id, updated_at, ...rest }) => rest)(surveyDetail.detail_info as any) : {}),
|
||||
})
|
||||
}
|
||||
}, [surveyDetail])
|
||||
// useEffect(() => {
|
||||
// if (surveyDetail) {
|
||||
// setBasicInfoData({
|
||||
// ...defaultBasicInfoForm,
|
||||
// ...(({ id, ...rest }) => rest)(surveyDetail),
|
||||
// })
|
||||
// setDetailInfoForm({
|
||||
// ...defaultDetailInfoForm,
|
||||
// ...(surveyDetail.detail_info ? (({ id, basic_info_id, updated_at, ...rest }) => rest)(surveyDetail.detail_info as any) : {}),
|
||||
// })
|
||||
// }
|
||||
// }, [surveyDetail])
|
||||
|
||||
const handleSave = async (isSubmit: boolean = false) => {
|
||||
if (id) {
|
||||
updateSurvey({
|
||||
...basicInfoData,
|
||||
submission_status: isSubmit,
|
||||
submission_date: isSubmit ? new Date().toISOString() : null,
|
||||
})
|
||||
router.push('/survey-sales')
|
||||
return
|
||||
}
|
||||
// const handleSave = async (isSubmit: boolean = false) => {
|
||||
// if (id) {
|
||||
// updateSurvey({
|
||||
// ...basicInfoData,
|
||||
// submission_status: isSubmit,
|
||||
// submission_date: isSubmit ? new Date().toISOString() : null,
|
||||
// })
|
||||
// router.push('/survey-sales')
|
||||
// return
|
||||
// }
|
||||
|
||||
const surveyId = await createSurvey(basicInfoData)
|
||||
if (surveyId && surveyId !== 0) {
|
||||
createSurveyDetail({
|
||||
surveyId,
|
||||
surveyDetail: detailInfoForm,
|
||||
})
|
||||
router.push('/survey-sales')
|
||||
return
|
||||
}
|
||||
throw new Error('‼️Survey creation failed')
|
||||
}
|
||||
if (isCreatingSurvey) {
|
||||
return <div>Loading...</div>
|
||||
}
|
||||
// const surveyId = await createSurvey(basicInfoData)
|
||||
// if (surveyId && surveyId !== 0) {
|
||||
// createSurveyDetail({
|
||||
// surveyId,
|
||||
// surveyDetail: detailInfoForm,
|
||||
// })
|
||||
// router.push('/survey-sales')
|
||||
// return
|
||||
// }
|
||||
// throw new Error('‼️Survey creation failed')
|
||||
// }
|
||||
// if (isCreatingSurvey) {
|
||||
// return <div>Loading...</div>
|
||||
// }
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* TAB BUTTONS */}
|
||||
<div>
|
||||
<button
|
||||
onClick={() => handleTabClick('basic')}
|
||||
className={`flex-1 px-4 py-2 text-center focus:outline-none focus:ring-2 focus:ring-blue-500
|
||||
${activeTab === 'basic' ? 'border-b-2 border-blue-500 font-semibold text-blue-600' : 'text-gray-500 hover:text-gray-700'}`}
|
||||
aria-selected={activeTab === 'basic'}
|
||||
role="tab"
|
||||
>
|
||||
Basic Info
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleTabClick('detail')}
|
||||
className={`flex-1 px-4 py-2 text-center focus:outline-none focus:ring-2 focus:ring-blue-500
|
||||
${activeTab === 'detail' ? 'border-b-2 border-blue-500 font-semibold text-blue-600' : 'text-gray-500 hover:text-gray-700'}`}
|
||||
aria-selected={activeTab === 'detail'}
|
||||
role="tab"
|
||||
>
|
||||
Detail Info
|
||||
</button>
|
||||
</div>
|
||||
// return (
|
||||
// <div>
|
||||
// {/* TAB BUTTONS */}
|
||||
// <div>
|
||||
// <button
|
||||
// onClick={() => handleTabClick('basic')}
|
||||
// className={`flex-1 px-4 py-2 text-center focus:outline-none focus:ring-2 focus:ring-blue-500
|
||||
// ${activeTab === 'basic' ? 'border-b-2 border-blue-500 font-semibold text-blue-600' : 'text-gray-500 hover:text-gray-700'}`}
|
||||
// aria-selected={activeTab === 'basic'}
|
||||
// role="tab"
|
||||
// >
|
||||
// Basic Info
|
||||
// </button>
|
||||
// <button
|
||||
// onClick={() => handleTabClick('detail')}
|
||||
// className={`flex-1 px-4 py-2 text-center focus:outline-none focus:ring-2 focus:ring-blue-500
|
||||
// ${activeTab === 'detail' ? 'border-b-2 border-blue-500 font-semibold text-blue-600' : 'text-gray-500 hover:text-gray-700'}`}
|
||||
// aria-selected={activeTab === 'detail'}
|
||||
// role="tab"
|
||||
// >
|
||||
// Detail Info
|
||||
// </button>
|
||||
// </div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<div className="mt-6">
|
||||
{activeTab === 'basic' && (
|
||||
<div className="rounded-lg border p-4">
|
||||
<h2 className="text-lg font-semibold">Basic Information</h2>
|
||||
<BasicWriteForm basicInfoData={basicInfoData} setBasicInfoData={setBasicInfoData} />
|
||||
</div>
|
||||
)}
|
||||
{activeTab === 'detail' && (
|
||||
<div className="rounded-lg border p-4">
|
||||
<h2 className="text-lg font-semibold">Detail Information</h2>
|
||||
<DetailWriteForm detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-start gap-4">
|
||||
<button onClick={() => handleSave(false)}>save</button>
|
||||
<button onClick={() => handleSave(true)}>submit</button>
|
||||
<button onClick={() => router.push('/survey-sales')}>cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
// {/* Tab Content */}
|
||||
// <div className="mt-6">
|
||||
// {activeTab === 'basic' && (
|
||||
// <div className="rounded-lg border p-4">
|
||||
// <h2 className="text-lg font-semibold">Basic Information</h2>
|
||||
// <BasicWriteForm basicInfoData={basicInfoData} setBasicInfoData={setBasicInfoData} />
|
||||
// </div>
|
||||
// )}
|
||||
// {activeTab === 'detail' && (
|
||||
// <div className="rounded-lg border p-4">
|
||||
// <h2 className="text-lg font-semibold">Detail Information</h2>
|
||||
// <DetailWriteForm detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||
// </div>
|
||||
// )}
|
||||
// </div>
|
||||
// <div className="flex justify-start gap-4">
|
||||
// <button onClick={() => handleSave(false)}>save</button>
|
||||
// <button onClick={() => handleSave(true)}>submit</button>
|
||||
// <button onClick={() => router.push('/survey-sales')}>cancel</button>
|
||||
// </div>
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user