Loading...
+ }
+
+ const handleSubmit = async () => {
+ if (confirm('submit?')) {
+ if (surveyDetail?.id) {
+ await submitSurvey()
+ }
+ }
+ }
+ const handleUpdate = () => {
+ router.push(`/survey-sale/basic-info?id=${id}`)
+ }
+ const handleDelete = async () => {
+ if (confirm('delete?')) {
+ if (surveyDetail?.id) {
+ await deleteSurvey()
+ router.push('/survey-sale')
+ }
+ }
+ }
+
return (
<>
-
-
+
提出
-
+
修正
-
+
削除
diff --git a/src/components/survey-sale/list/ListTable.tsx b/src/components/survey-sale/list/ListTable.tsx
index 6d15b1e..fcf7769 100644
--- a/src/components/survey-sale/list/ListTable.tsx
+++ b/src/components/survey-sale/list/ListTable.tsx
@@ -1,31 +1,53 @@
'use client'
+import LoadMoreButton from '@/components/LoadMoreButton'
+import { useServey } from '@/hooks/useSurvey'
+import { useState } from 'react'
+import { useRouter } from 'next/navigation'
+
export default function ListTable() {
+ const router = useRouter()
+ const { surveyList, isLoadingSurveyList } = useServey()
+ const [hasMore, setHasMore] = useState(surveyList.length > 5)
+ const [visibleItems, setVisibleItems] = useState(5)
+
+ const handleLoadMore = () => {
+ const newVisibleItems = Math.min(visibleItems + 5, surveyList.length)
+ setVisibleItems(newVisibleItems)
+ setHasMore(newVisibleItems < surveyList.length)
+ }
+
+ const handleScrollToTop = () => {
+ window.scrollTo({ top: 0, behavior: 'smooth' })
+ }
+
+ const handleDetail = (id: number) => {
+ router.push(`/survey-sale/${id}`)
+ }
+
return (
<>
- {Array.from({ length: 4 }).map((_, idx) => (
- -
+ {surveyList.slice(0, visibleItems).map((survey) => (
+
- handleDetail(survey.id)}>
-
0000000021
-
2025.04.22
+
{survey.id}
+
{survey.investigation_date}
-
Hanwha Building
-
Gil dong
+
{survey.building_name}
+
{survey.customer_name}
-
Hong Gildong
-
2025.04.22 10:00:21
+
{survey.representative}
+
{new Date(survey.updated_at).toLocaleString()}
))}
-
- もっと見る
-
+
>
diff --git a/src/components/survey-sale/list/SearchForm.tsx b/src/components/survey-sale/list/SearchForm.tsx
index 5763dbf..67794a2 100644
--- a/src/components/survey-sale/list/SearchForm.tsx
+++ b/src/components/survey-sale/list/SearchForm.tsx
@@ -1,10 +1,13 @@
'use client'
+import { useRouter } from 'next/navigation'
+
export default function SearchForm() {
+ const router = useRouter()
return (
-
+ router.push('/survey-sale/basic-info')}>
新規売買登録
diff --git a/src/components/survey-sales/EtcCheckbox.tsx b/src/components/survey-sales/EtcCheckbox.tsx
index 6e4a866..1dd6c03 100644
--- a/src/components/survey-sales/EtcCheckbox.tsx
+++ b/src/components/survey-sales/EtcCheckbox.tsx
@@ -1,17 +1,17 @@
'use client'
import { useState } from "react"
-import { SurveySalesDetailInfo } from "@/api/surveySales"
+import { SurveyDetailRequest } from "@/types/Survey"
interface EtcCheckboxProps {
- formName: keyof SurveySalesDetailInfo
+ formName: keyof SurveyDetailRequest
label: string
- detailInfoForm: SurveySalesDetailInfo
- setDetailInfoForm: (form: SurveySalesDetailInfo) => void
+ detailInfoForm: SurveyDetailRequest
+ setDetailInfoForm: (form: SurveyDetailRequest) => void
}
export default function EtcCheckbox({ formName, label, detailInfoForm, setDetailInfoForm }: EtcCheckboxProps) {
const [showEtcInput, setShowEtcInput] = useState(false)
- const etcFieldName = `${formName}_etc` as keyof SurveySalesDetailInfo
+ const etcFieldName = `${formName}_etc` as keyof SurveyDetailRequest
return (
diff --git a/src/components/survey-sales/SurveyDetail.tsx b/src/components/survey-sales/SurveyDetail.tsx
index 20145a3..a50b9ab 100644
--- a/src/components/survey-sales/SurveyDetail.tsx
+++ b/src/components/survey-sales/SurveyDetail.tsx
@@ -1,7 +1,6 @@
'use client'
import { useServey } from '@/hooks/useSurvey'
-import { SurveySalesBasicInfo } from '@/api/surveySales'
import { useParams, useRouter } from 'next/navigation'
export default function SurveyDetail() {
@@ -56,6 +55,7 @@ export default function SurveyDetail() {
back
+
)
}
diff --git a/src/components/survey-sales/write-survey-sales/BasicWriteForm.tsx b/src/components/survey-sales/write-survey-sales/BasicWriteForm.tsx
index bf73338..8fe0a6f 100644
--- a/src/components/survey-sales/write-survey-sales/BasicWriteForm.tsx
+++ b/src/components/survey-sales/write-survey-sales/BasicWriteForm.tsx
@@ -1,15 +1,15 @@
'use client'
-import { SurveySalesBasicInfo } from '@/api/surveySales'
+import { SurveyBasicRequest } from '@/types/Survey'
export default function BasicWriteForm({
basicInfoData,
setBasicInfoData,
}: {
- basicInfoData: SurveySalesBasicInfo
- setBasicInfoData: (basicInfoData: SurveySalesBasicInfo) => void
+ basicInfoData: SurveyBasicRequest
+ setBasicInfoData: (basicInfoData: SurveyBasicRequest) => void
}) {
- const handleChange = (key: keyof SurveySalesBasicInfo, value: string) => {
+ const handleChange = (key: keyof SurveyBasicRequest, value: string) => {
setBasicInfoData({ ...basicInfoData, [key]: value.toString() })
}
diff --git a/src/components/survey-sales/write-survey-sales/DetailWriteForm.tsx b/src/components/survey-sales/write-survey-sales/DetailWriteForm.tsx
index 488f046..032d6f1 100644
--- a/src/components/survey-sales/write-survey-sales/DetailWriteForm.tsx
+++ b/src/components/survey-sales/write-survey-sales/DetailWriteForm.tsx
@@ -1,24 +1,24 @@
'use client'
import React from 'react'
import EtcCheckbox from '../EtcCheckbox'
-import { SurveySalesDetailInfo } from '@/api/surveySales'
+import { SurveyDetailRequest } from '@/types/Survey'
interface DetailWriteFormProps {
- detailInfoForm: SurveySalesDetailInfo
- setDetailInfoForm: (form: SurveySalesDetailInfo) => void
+ detailInfoForm: SurveyDetailRequest
+ setDetailInfoForm: (form: SurveyDetailRequest) => void
}
export default function DetailWriteForm({ detailInfoForm, setDetailInfoForm }: DetailWriteFormProps) {
- const handleNumberInput = (field: keyof SurveySalesDetailInfo, value: string) => {
+ const handleNumberInput = (field: keyof SurveyDetailRequest, value: string) => {
const numberValue = value === '' ? null : Number(value)
setDetailInfoForm({ ...detailInfoForm, [field]: numberValue })
}
- const handleTextInput = (field: keyof SurveySalesDetailInfo, value: string) => {
+ const handleTextInput = (field: keyof SurveyDetailRequest, value: string) => {
setDetailInfoForm({ ...detailInfoForm, [field]: value || null })
}
- const handleBooleanInput = (field: keyof SurveySalesDetailInfo, checked: boolean) => {
+ const handleBooleanInput = (field: keyof SurveyDetailRequest, checked: boolean) => {
setDetailInfoForm({ ...detailInfoForm, [field]: checked })
}
diff --git a/src/components/survey-sales/write-survey-sales/MainSurveyForm.tsx b/src/components/survey-sales/write-survey-sales/MainSurveyForm.tsx
index f51aa2b..b49b96e 100644
--- a/src/components/survey-sales/write-survey-sales/MainSurveyForm.tsx
+++ b/src/components/survey-sales/write-survey-sales/MainSurveyForm.tsx
@@ -6,10 +6,12 @@ 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'
-const defaultDetailInfoForm: SurveySalesDetailInfo = {
+const defaultDetailInfoForm: SurveyDetailRequest = {
+ basic_info_id: 0,
contract_capacity: null,
retail_company: null,
supplementary_facilities: null,
@@ -47,7 +49,7 @@ const defaultDetailInfoForm: SurveySalesDetailInfo = {
memo: null,
}
-const defaultBasicInfoForm: SurveySalesBasicInfo = {
+const defaultBasicInfoForm: SurveyBasicRequest = {
representative: '',
store: null,
construction_point: null,
@@ -58,6 +60,7 @@ const defaultBasicInfoForm: SurveySalesBasicInfo = {
address: null,
address_detail: null,
submission_status: false,
+ submission_date: null,
}
export default function MainSurveyForm() {
@@ -74,8 +77,8 @@ export default function MainSurveyForm() {
const router = useRouter()
const { createSurvey, isCreatingSurvey, createSurveyDetail, surveyDetail, updateSurvey } = useServey(Number(id))
- const [detailInfoForm, setDetailInfoForm] = useState
(defaultDetailInfoForm)
- const [basicInfoData, setBasicInfoData] = useState(defaultBasicInfoForm)
+ const [detailInfoForm, setDetailInfoForm] = useState(defaultDetailInfoForm)
+ const [basicInfoData, setBasicInfoData] = useState(defaultBasicInfoForm)
useEffect(() => {
if (surveyDetail) {
@@ -94,8 +97,8 @@ export default function MainSurveyForm() {
if (id) {
updateSurvey({
...basicInfoData,
- detail_info: detailInfoForm,
submission_status: isSubmit,
+ submission_date: isSubmit ? new Date().toISOString() : null,
})
router.push('/survey-sales')
return
diff --git a/src/hooks/useSurvey.ts b/src/hooks/useSurvey.ts
index 7e99341..e8cc428 100644
--- a/src/hooks/useSurvey.ts
+++ b/src/hooks/useSurvey.ts
@@ -1,26 +1,29 @@
-import { SurveySalesBasicInfo, surveySalesApi, SurveySalesDetailInfo } from '@/api/surveySales'
import { axiosInstance } from '@/libs/axios'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
+import type { SurveyBasicInfo, SurveyBasicRequest, SurveyDetailInfo, SurveyDetailRequest } from '@/types/Survey'
export function useServey(id?: number): {
- surveyList: SurveySalesBasicInfo[] | []
- surveyDetail: SurveySalesBasicInfo | null
+ surveyList: SurveyBasicInfo[] | []
+ surveyDetail: SurveyBasicInfo | null
isLoadingSurveyList: boolean
isLoadingSurveyDetail: boolean
isCreatingSurvey: boolean
isUpdatingSurvey: boolean
isDeletingSurvey: boolean
- createSurvey: (survey: SurveySalesBasicInfo) => Promise
- createSurveyDetail: (params: { surveyId: number; surveyDetail: SurveySalesDetailInfo }) => void
- updateSurvey: (survey: SurveySalesBasicInfo) => void
- deleteSurvey: (params: { id: number; isDetail: boolean }) => void
- confirmSurvey: (id: number) => void
+ createSurvey: (survey: SurveyBasicRequest) => Promise
+ createSurveyDetail: (params: { surveyId: number; surveyDetail: SurveyDetailRequest }) => void
+ updateSurvey: (survey: SurveyBasicRequest) => void
+ deleteSurvey: () => Promise
+ submitSurvey: () => void
} {
const queryClient = useQueryClient()
const { data: surveyList, isLoading: isLoadingSurveyList } = useQuery({
queryKey: ['survey', 'list'],
- queryFn: () => surveySalesApi.getList(),
+ queryFn: async () => {
+ const resp = await axiosInstance.get('/api/survey-sales')
+ return resp.data
+ },
})
const { data: surveyDetail, isLoading: isLoadingSurveyDetail } = useQuery({
@@ -28,15 +31,15 @@ export function useServey(id?: number): {
queryFn: async () => {
if (id === undefined) throw new Error('id is required')
if (id === null) return null
- const resp = await axiosInstance.get(`/api/survey-sales/${id}`)
+ const resp = await axiosInstance.get(`/api/survey-sales/${id}`)
return resp.data
},
enabled: id !== undefined,
})
const { mutateAsync: createSurvey, isPending: isCreatingSurvey } = useMutation({
- mutationFn: async (survey: SurveySalesBasicInfo) => {
- const resp = await axiosInstance.post('/api/survey-sales', survey)
+ mutationFn: async (survey: SurveyBasicRequest) => {
+ const resp = await axiosInstance.post('/api/survey-sales', survey)
return resp.data.id ?? 0
},
onSuccess: (data) => {
@@ -46,9 +49,9 @@ export function useServey(id?: number): {
})
const { mutate: updateSurvey, isPending: isUpdatingSurvey } = useMutation({
- mutationFn: async (survey: SurveySalesBasicInfo) => {
+ mutationFn: async (survey: SurveyBasicRequest) => {
if (id === undefined) throw new Error('id is required')
- const resp = await axiosInstance.put(`/api/survey-sales/${id}`, survey)
+ const resp = await axiosInstance.put(`/api/survey-sales/${id}`, survey)
return resp.data
},
onSuccess: () => {
@@ -58,19 +61,9 @@ export function useServey(id?: number): {
})
const { mutateAsync: deleteSurvey, isPending: isDeletingSurvey } = useMutation({
- mutationFn: async ({ id, isDetail }: { id: number; isDetail: boolean }) => {
- if (id === undefined) throw new Error('id is required')
- const resp = await axiosInstance.delete(`/api/survey-sales/${id}`, { params: { isDetail } })
- return resp.data
- },
- onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: ['survey', 'list'] })
- },
- })
-
- const { mutateAsync: createSurveyDetail, isPending: isCreatingSurveyDetail } = useMutation({
- mutationFn: async ({ surveyId, surveyDetail }: { surveyId: number; surveyDetail: SurveySalesDetailInfo }) => {
- const resp = await axiosInstance.post(`/api/survey-sales/${surveyId}`, surveyDetail)
+ mutationFn: async () => {
+ if (id === null) throw new Error('id is required')
+ const resp = await axiosInstance.delete(`/api/survey-sales/${id}`)
return resp.data
},
onSuccess: () => {
@@ -79,8 +72,19 @@ export function useServey(id?: number): {
},
})
- const { mutateAsync: confirmSurvey, isPending: isConfirmingSurvey } = useMutation({
- mutationFn: async (id: number) => {
+ const { mutateAsync: createSurveyDetail, isPending: isCreatingSurveyDetail } = useMutation({
+ mutationFn: async ({ surveyId, surveyDetail }: { surveyId: number; surveyDetail: SurveyDetailRequest }) => {
+ const resp = await axiosInstance.post(`/api/survey-sales/${surveyId}`, surveyDetail)
+ return resp.data
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ['survey', 'list'] })
+ queryClient.invalidateQueries({ queryKey: ['survey', id] })
+ },
+ })
+
+ const { mutateAsync: submitSurvey } = useMutation({
+ mutationFn: async () => {
if (id === undefined) throw new Error('id is required')
const resp = await axiosInstance.patch(`/api/survey-sales/${id}`)
return resp.data
@@ -103,6 +107,6 @@ export function useServey(id?: number): {
updateSurvey,
deleteSurvey,
createSurveyDetail,
- confirmSurvey,
+ submitSurvey,
}
}
diff --git a/src/styles/base/_button.scss b/src/styles/base/_button.scss
index c6d11ad..b4d61a4 100644
--- a/src/styles/base/_button.scss
+++ b/src/styles/base/_button.scss
@@ -49,6 +49,14 @@
background-size: cover;
margin-left: 12px;
}
+ .btn-arr-up{
+ display: block;
+ width: 10px;
+ height: 6px;
+ background: url(/assets/images/common/btn_arr_up.svg)no-repeat center;
+ background-size: cover;
+ margin-left: 12px;
+ }
.btn-edit{
display: block;
width: 10px;
diff --git a/src/types/Survey.ts b/src/types/Survey.ts
new file mode 100644
index 0000000..aa7d61e
--- /dev/null
+++ b/src/types/Survey.ts
@@ -0,0 +1,111 @@
+export type SurveyBasicInfo = {
+ id: number
+ representative: string
+ store: string | null
+ construction_point: string | null
+ investigation_date: string | null
+ building_name: string | null
+ customer_name: string | null
+ post_code: string | null
+ address: string | null
+ address_detail: string | null
+ submission_status: boolean
+ submission_date: string | null
+ detail_info: SurveyDetailInfo | null
+ created_at: Date
+ updated_at: Date
+}
+
+export type SurveyDetailInfo = {
+ id: number
+ contract_capacity: string | null
+ retail_company: string | null
+ supplementary_facilities: number | null
+ supplementary_facilities_etc: string | null
+ installation_system: number | null
+ installation_system_etc: string | null
+ construction_year: number | null
+ construction_year_etc: string | null
+ roof_material: number | null
+ roof_material_etc: string | null
+ roof_shape: number | null
+ roof_shape_etc: string | null
+ roof_slope: string | null
+ house_structure: number | null
+ house_structure_etc: string | null
+ rafter_material: number | null
+ rafter_material_etc: string | null
+ rafter_size: number | null
+ rafter_size_etc: string | null
+ rafter_pitch: number | null
+ rafter_pitch_etc: string | null
+ rafter_direction: number | null
+ open_field_plate_kind: number | null
+ open_field_plate_kind_etc: string | null
+ open_field_plate_thickness: string | null
+ leak_trace: boolean | null
+ waterproof_material: number | null
+ waterproof_material_etc: string | null
+ insulation_presence: number | null
+ insulation_presence_etc: string | null
+ structure_order: number | null
+ structure_order_etc: string | null
+ installation_availability: number | null
+ installation_availability_etc: string | null
+ memo: string | null
+ created_at: Date
+ updated_at: Date
+}
+
+export type SurveyBasicRequest = {
+ representative: string
+ store: string | null
+ construction_point: string | null
+ investigation_date: string | null
+ building_name: string | null
+ customer_name: string | null
+ post_code: string | null
+ address: string | null
+ address_detail: string | null
+ submission_status: boolean
+ submission_date: string | null
+}
+
+export type SurveyDetailRequest = {
+ contract_capacity: string | null
+ retail_company: string | null
+ supplementary_facilities: number | null
+ supplementary_facilities_etc: string | null
+ installation_system: number | null
+ installation_system_etc: string | null
+ construction_year: number | null
+ construction_year_etc: string | null
+ roof_material: number | null
+ roof_material_etc: string | null
+ roof_shape: number | null
+ roof_shape_etc: string | null
+ roof_slope: string | null
+ house_structure: number | null
+ house_structure_etc: string | null
+ rafter_material: number | null
+ rafter_material_etc: string | null
+ rafter_size: number | null
+ rafter_size_etc: string | null
+ rafter_pitch: number | null
+ rafter_pitch_etc: string | null
+ rafter_direction: number | null
+ open_field_plate_kind: number | null
+ open_field_plate_kind_etc: string | null
+ open_field_plate_thickness: string | null
+ leak_trace: boolean | null
+ waterproof_material: number | null
+ waterproof_material_etc: string | null
+ insulation_presence: number | null
+ insulation_presence_etc: string | null
+ structure_order: number | null
+ structure_order_etc: string | null
+ installation_availability: number | null
+ installation_availability_etc: string | null
+ memo: string | null
+ basic_info_id: number
+}