From 866de531fa68560c29d812a212efe15c10461e6d Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Mon, 28 Apr 2025 17:36:51 +0900 Subject: [PATCH] feat: Implement Survey Sales API and UI components for creating and listing survey sales information --- src/api/surveySales.ts | 67 +++++++++++++++++++++++++++++++ src/app/api/survey-sales/route.ts | 13 ++++++ src/app/page.tsx | 6 +++ src/app/suitable/page.tsx | 3 +- src/app/survey-sales/page.tsx | 10 +++++ src/components/SurveySales.tsx | 53 ++++++++++++++++++++++++ 6 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 src/api/surveySales.ts create mode 100644 src/app/api/survey-sales/route.ts create mode 100644 src/app/survey-sales/page.tsx create mode 100644 src/components/SurveySales.tsx diff --git a/src/api/surveySales.ts b/src/api/surveySales.ts new file mode 100644 index 0000000..3d9d727 --- /dev/null +++ b/src/api/surveySales.ts @@ -0,0 +1,67 @@ +import { axiosInstance } from '@/libs/axios' + +export interface SurveySalesBasicInfo { + 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?: SurveySalesDetailInfo | null +} + +export interface SurveySalesDetailInfo { + 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 +} + +export const surveySalesApi = { + create: async (data: SurveySalesBasicInfo): Promise => { + const response = await axiosInstance.post('/api/survey-sales', data) + return response.data + }, + getList: async (): Promise => { + const response = await axiosInstance.get('/api/survey-sales') + return response.data + }, +} diff --git a/src/app/api/survey-sales/route.ts b/src/app/api/survey-sales/route.ts new file mode 100644 index 0000000..decd3a3 --- /dev/null +++ b/src/app/api/survey-sales/route.ts @@ -0,0 +1,13 @@ +import { NextResponse } from 'next/server' +import { prisma } from '@/libs/prisma' + +export async function POST(request: Request) { + const body = await request.json() + + // @ts-ignore + const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.create({ + data: body, + }) + + return NextResponse.json({ message: 'Survey sales created successfully' }) +} diff --git a/src/app/page.tsx b/src/app/page.tsx index 2407d84..7b7cc48 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -31,6 +31,12 @@ export default async function Home() { +
+ + + +
+ diff --git a/src/app/suitable/page.tsx b/src/app/suitable/page.tsx index 759c518..9bd4694 100644 --- a/src/app/suitable/page.tsx +++ b/src/app/suitable/page.tsx @@ -1,5 +1,4 @@ import Suitable from '@/components/Suitable' -import SuitableCreateBtn from '@/components/SuitableCreateBtn' import SuitableSearch from '@/components/SuitableSearch' export default function suitablePage() { @@ -8,7 +7,7 @@ export default function suitablePage() { {/* 최초 한번 밀어넣음 */} - + {/* */} ) } diff --git a/src/app/survey-sales/page.tsx b/src/app/survey-sales/page.tsx new file mode 100644 index 0000000..6671ce4 --- /dev/null +++ b/src/app/survey-sales/page.tsx @@ -0,0 +1,10 @@ +import SurveySales from '@/components/SurveySales' + +export default function page() { + return ( + <> +

조사 매물 정보

+ + + ) +} diff --git a/src/components/SurveySales.tsx b/src/components/SurveySales.tsx new file mode 100644 index 0000000..fbba048 --- /dev/null +++ b/src/components/SurveySales.tsx @@ -0,0 +1,53 @@ +'use client' + +import { surveySalesApi, SurveySalesBasicInfo } from '@/api/surveySales' +import { useMutation, useQueryClient } from '@tanstack/react-query' + +export default function SurveySales() { + const queryClient = useQueryClient() + + const { + mutate: createSurveySales, + isPending, + error, + } = useMutation({ + mutationFn: surveySalesApi.create, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['survey-sales', 'list'] }) + }, + }) + + const handleSurveySales = () => { + const data: SurveySalesBasicInfo = { + representative: 'keyy1315', + store: 'HWJ(T01)', + construction_point: 'HWJ(T01)', + investigation_date: '2025-04-28', + building_name: '한화재팬빌딩', + customer_name: 'Hong Gil Dong', + post_code: '1050013', + address: '서울특별시 강남구 테헤란로 14길 6 ', + address_detail: '남도빌딩 2층', + submission_status: false, + } + + createSurveySales(data) + } + + return ( + <> +
+
+ + +
+
+
+

Be Warned

+

기본 데이터 세팅 되어있습니다.

+
+ + ) +}