Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| efcd1410bb | |||
| 8f42ee1068 | |||
| 69a60de914 | |||
| 9334773023 | |||
| 681d3942f2 | |||
| 818ecb724b | |||
| adfe6d7a32 | |||
| 56c2693bb7 | |||
| 17641d2b57 | |||
| 45b244d309 | |||
| 01e41fd1f5 | |||
| f801bacd12 | |||
| 08d99fb4e7 | |||
| 37a40989dd | |||
| ab1e89f5d6 | |||
| a684a3e5be | |||
| 68ea411064 | |||
| 65a30310a5 | |||
| 8240b434fd | |||
| bfbbdc01b8 | |||
| d36084add5 | |||
| cc8ef6a7d3 |
2
.env
2
.env
@ -5,7 +5,7 @@
|
|||||||
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
||||||
|
|
||||||
# DATABASE_URL="sqlserver://3team.devgrr.kr:1433;database=onsitesurvey;user=sa;password=1q2w3e4r!;encrypt=true;trustServerCertificate=true;"
|
# DATABASE_URL="sqlserver://3team.devgrr.kr:1433;database=onsitesurvey;user=sa;password=1q2w3e4r!;encrypt=true;trustServerCertificate=true;"
|
||||||
DATABASE_URL="sqlserver://172.30.1.35:1433;database=onsitesurvey;user=sa;password=1q2w3e4r!;encrypt=true;trustServerCertificate=true;"
|
DATABASE_URL="sqlserver://3team.devgrr.kr:1433;database=onsitesurvey;user=sa;password=1q2w3e4r!;encrypt=true;trustServerCertificate=true;"
|
||||||
|
|
||||||
# SESSION_PASSWORD="QWERASDFZXCV1234567890REWQFDSAVCXZ"
|
# SESSION_PASSWORD="QWERASDFZXCV1234567890REWQFDSAVCXZ"
|
||||||
SESSION_PASSWORD="This application is for mobile field research"
|
SESSION_PASSWORD="This application is for mobile field research"
|
||||||
@ -7,31 +7,10 @@ const nextConfig: NextConfig = {
|
|||||||
includePaths: [path.join(__dirname, './src/styles')],
|
includePaths: [path.join(__dirname, './src/styles')],
|
||||||
},
|
},
|
||||||
async rewrites() {
|
async rewrites() {
|
||||||
return [
|
|
||||||
{
|
|
||||||
source: '/:path*',
|
|
||||||
destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
async headers() {
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
source: '/api/:path*',
|
source: '/api/:path*',
|
||||||
headers: [
|
destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`,
|
||||||
{
|
|
||||||
key: 'Access-Control-Allow-Origin',
|
|
||||||
value: '*',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'Access-Control-Allow-Methods',
|
|
||||||
value: 'GET, POST, PUT, DELETE, OPTIONS',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'Access-Control-Allow-Headers',
|
|
||||||
value: 'Content-Type, Authorization',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
"@tanstack/react-query-devtools": "^5.71.0",
|
"@tanstack/react-query-devtools": "^5.71.0",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
"iron-session": "^8.0.4",
|
"iron-session": "^8.0.4",
|
||||||
|
"lucide": "^0.503.0",
|
||||||
"mssql": "^11.0.1",
|
"mssql": "^11.0.1",
|
||||||
"next": "15.2.4",
|
"next": "15.2.4",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
|
|||||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@ -23,6 +23,9 @@ importers:
|
|||||||
iron-session:
|
iron-session:
|
||||||
specifier: ^8.0.4
|
specifier: ^8.0.4
|
||||||
version: 8.0.4
|
version: 8.0.4
|
||||||
|
lucide:
|
||||||
|
specifier: ^0.503.0
|
||||||
|
version: 0.503.0
|
||||||
mssql:
|
mssql:
|
||||||
specifier: ^11.0.1
|
specifier: ^11.0.1
|
||||||
version: 11.0.1
|
version: 11.0.1
|
||||||
@ -1100,6 +1103,9 @@ packages:
|
|||||||
lodash.once@4.1.1:
|
lodash.once@4.1.1:
|
||||||
resolution: {integrity: sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==}
|
resolution: {integrity: sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==}
|
||||||
|
|
||||||
|
lucide@0.503.0:
|
||||||
|
resolution: {integrity: sha512-ZAVlxBU4dbSUAVidb2eT0fH3bTtKCj7M2aZNAVsFOrcnazvYJFu6I8OxFE+Fmx5XNf22Cw4Ln3NBHfBxNfoFOw==}
|
||||||
|
|
||||||
math-intrinsics@1.1.0:
|
math-intrinsics@1.1.0:
|
||||||
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
|
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
@ -2319,6 +2325,8 @@ snapshots:
|
|||||||
|
|
||||||
lodash.once@4.1.1: {}
|
lodash.once@4.1.1: {}
|
||||||
|
|
||||||
|
lucide@0.503.0: {}
|
||||||
|
|
||||||
math-intrinsics@1.1.0: {}
|
math-intrinsics@1.1.0: {}
|
||||||
|
|
||||||
micromatch@4.0.8:
|
micromatch@4.0.8:
|
||||||
|
|||||||
@ -38,14 +38,31 @@ export interface Suitable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const suitableApi = {
|
export const suitableApi = {
|
||||||
getList: async (): Promise<Suitable[]> => {
|
getList: async (category?: string, keyword?: string): Promise<Suitable[]> => {
|
||||||
const response = await axiosInstance.get<Suitable[]>('/api/suitable/list')
|
let condition: any = {}
|
||||||
|
if (category) {
|
||||||
|
condition['category'] = category
|
||||||
|
}
|
||||||
|
if (keyword) {
|
||||||
|
condition['keyword'] = {
|
||||||
|
contains: keyword,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('🚀 ~ getList: ~ condition:', condition)
|
||||||
|
const response = await axiosInstance.get<Suitable[]>('/api/suitable/list', { params: condition })
|
||||||
console.log('🚀 ~ getList: ~ response:', response)
|
console.log('🚀 ~ getList: ~ response:', response)
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getCategory: async (): Promise<Suitable[]> => {
|
||||||
|
const response = await axiosInstance.get<Suitable[]>('/api/suitable/category')
|
||||||
|
console.log('🚀 ~ getCategory: ~ response:', response)
|
||||||
|
return response.data
|
||||||
|
},
|
||||||
|
|
||||||
getDetails: async (roofMaterial: string): Promise<Suitable[]> => {
|
getDetails: async (roofMaterial: string): Promise<Suitable[]> => {
|
||||||
const response = await axiosInstance.get<Suitable[]>(`/api/suitable/details?roof-material=${roofMaterial}`)
|
const response = await axiosInstance.get<Suitable[]>(`/api/suitable/details?roof-material=${roofMaterial}`)
|
||||||
|
console.log('🚀 ~ getDetails: ~ response:', response)
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -2,66 +2,126 @@ import { axiosInstance } from '@/libs/axios'
|
|||||||
|
|
||||||
export interface SurveySalesBasicInfo {
|
export interface SurveySalesBasicInfo {
|
||||||
id?: number
|
id?: number
|
||||||
representative: String
|
representative: string
|
||||||
store: String | null
|
store: string | null
|
||||||
construction_point: String | null
|
construction_point: string | null
|
||||||
investigation_date: String | null
|
investigation_date: string | null
|
||||||
building_name: String | null
|
building_name: string | null
|
||||||
customer_name: String | null
|
customer_name: string | null
|
||||||
post_code: String | null
|
post_code: string | null
|
||||||
address: String | null
|
address: string | null
|
||||||
address_detail: String | null
|
address_detail: string | null
|
||||||
submission_status: Boolean
|
submission_status: boolean
|
||||||
submission_date?: String | null
|
submission_date?: string | null
|
||||||
detail_info?: SurveySalesDetailInfo | null
|
detail_info?: SurveySalesDetailInfo | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SurveySalesDetailInfo {
|
export interface SurveySalesDetailInfo {
|
||||||
id?: number
|
id?: number
|
||||||
contract_capacity: String | null
|
contract_capacity: string | null
|
||||||
retail_company: String | null
|
retail_company: string | null
|
||||||
supplementary_facilities: Number | null
|
supplementary_facilities: number | null
|
||||||
supplementary_facilities_etc: String | null
|
supplementary_facilities_etc: string | null
|
||||||
installation_system: Number | null
|
installation_system: number | null
|
||||||
installation_system_etc: String | null
|
installation_system_etc: string | null
|
||||||
construction_year: Number | null
|
construction_year: number | null
|
||||||
construction_year_etc: String | null
|
construction_year_etc: string | null
|
||||||
roof_material: Number | null
|
roof_material: number | null
|
||||||
roof_material_etc: String | null
|
roof_material_etc: string | null
|
||||||
roof_shape: Number | null
|
roof_shape: number | null
|
||||||
roof_shape_etc: String | null
|
roof_shape_etc: string | null
|
||||||
roof_slope: String | null
|
roof_slope: string | null
|
||||||
house_structure: Number | null
|
house_structure: number | null
|
||||||
house_structure_etc: String | null
|
house_structure_etc: string | null
|
||||||
rafter_material: Number | null
|
rafter_material: number | null
|
||||||
rafter_material_etc: String | null
|
rafter_material_etc: string | null
|
||||||
rafter_size: Number | null
|
rafter_size: number | null
|
||||||
rafter_size_etc: String | null
|
rafter_size_etc: string | null
|
||||||
rafter_pitch: Number | null
|
rafter_pitch: number | null
|
||||||
rafter_pitch_etc: String | null
|
rafter_pitch_etc: string | null
|
||||||
rafter_direction: Number | null
|
rafter_direction: number | null
|
||||||
open_field_plate_kind: Number | null
|
open_field_plate_kind: number | null
|
||||||
open_field_plate_kind_etc: String | null
|
open_field_plate_kind_etc: string | null
|
||||||
open_field_plate_thickness: String | null
|
open_field_plate_thickness: string | null
|
||||||
leak_trace: Boolean | null
|
leak_trace: boolean | null
|
||||||
waterproof_material: Number | null
|
waterproof_material: number | null
|
||||||
waterproof_material_etc: String | null
|
waterproof_material_etc: string | null
|
||||||
insulation_presence: Number | null
|
insulation_presence: number | null
|
||||||
insulation_presence_etc: String | null
|
insulation_presence_etc: string | null
|
||||||
structure_order: Number | null
|
structure_order: number | null
|
||||||
structure_order_etc: String | null
|
structure_order_etc: string | null
|
||||||
installation_availability: Number | null
|
installation_availability: number | null
|
||||||
installation_availability_etc: String | null
|
installation_availability_etc: string | null
|
||||||
memo: String | null
|
memo: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const surveySalesApi = {
|
export const surveySalesApi = {
|
||||||
create: async (data: SurveySalesBasicInfo): Promise<SurveySalesBasicInfo> => {
|
create: async (data: SurveySalesBasicInfo): Promise<number> => {
|
||||||
|
try {
|
||||||
const response = await axiosInstance.post<SurveySalesBasicInfo>('/api/survey-sales', data)
|
const response = await axiosInstance.post<SurveySalesBasicInfo>('/api/survey-sales', data)
|
||||||
return response.data
|
return response.data.id ?? 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getList: async (): Promise<SurveySalesBasicInfo[]> => {
|
getList: async (): Promise<SurveySalesBasicInfo[] | []> => {
|
||||||
|
try {
|
||||||
const response = await axiosInstance.get<SurveySalesBasicInfo[]>('/api/survey-sales')
|
const response = await axiosInstance.get<SurveySalesBasicInfo[]>('/api/survey-sales')
|
||||||
return response.data
|
return response.data
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
getDetail: async (id: number): Promise<SurveySalesBasicInfo | null> => {
|
||||||
|
try {
|
||||||
|
const response = await axiosInstance.get<SurveySalesBasicInfo>(`/api/survey-sales/${id}`)
|
||||||
|
return response.data
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update: async (id: number, data: SurveySalesBasicInfo): Promise<SurveySalesBasicInfo | null> => {
|
||||||
|
try {
|
||||||
|
const response = await axiosInstance.put<SurveySalesBasicInfo>(`/api/survey-sales/${id}`, data)
|
||||||
|
return response.data
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
delete: async (id: number, isDetail: boolean = false): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
await axiosInstance.delete(`/api/survey-sales/${id}`, {
|
||||||
|
params: {
|
||||||
|
detail_id: isDetail ? id : undefined,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
} catch (error) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createDetail: async (surveyId: number, data: SurveySalesDetailInfo): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
await axiosInstance.post<SurveySalesDetailInfo>(`/api/survey-sales/${surveyId}`, data)
|
||||||
|
return true
|
||||||
|
} catch (error) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirm: async (id: number): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
await axiosInstance.patch<SurveySalesBasicInfo>(`/api/survey-sales/${id}`)
|
||||||
|
return true
|
||||||
|
} catch (error) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// update: async (data: SurveySalesBasicInfo): Promise<SurveySalesBasicInfo> => {
|
||||||
|
// const response = await axiosInstance.put<SurveySalesBasicInfo>(`/api/survey-sales`, data)
|
||||||
|
// return response.data
|
||||||
|
// },
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/app/api/suitable/category/route.ts
Normal file
16
src/app/api/suitable/category/route.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
import { prisma } from '@/libs/prisma'
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
// @ts-ignore
|
||||||
|
const roofMaterialCategory = await prisma.MS_SUITABLE.findMany({
|
||||||
|
select: {
|
||||||
|
roof_material: true,
|
||||||
|
},
|
||||||
|
distinct: ['roof_material'],
|
||||||
|
orderBy: {
|
||||||
|
roof_material: 'asc',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return NextResponse.json(roofMaterialCategory)
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
|
import { prisma } from '@/libs/prisma'
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const { searchParams } = new URL(request.url)
|
const { searchParams } = new URL(request.url)
|
||||||
|
|||||||
@ -1,8 +1,35 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
import { prisma } from '@/libs/prisma'
|
import { prisma } from '@/libs/prisma'
|
||||||
|
|
||||||
export async function GET() {
|
|
||||||
|
export async function GET(request: NextRequest) {
|
||||||
|
try {
|
||||||
|
const searchParams = request.nextUrl.searchParams
|
||||||
|
const category = searchParams.get('category')
|
||||||
|
const keyword = searchParams.get('keyword')
|
||||||
|
|
||||||
|
let whereCondition: any = {}
|
||||||
|
if (category) {
|
||||||
|
whereCondition['roof_material'] = category
|
||||||
|
}
|
||||||
|
if (keyword) {
|
||||||
|
whereCondition['product_name'] = {
|
||||||
|
contains: keyword,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('🚀 ~ /api/suitable/list: ~ prisma where condition:', whereCondition)
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const suitables = await prisma.MS_SUITABLE.findMany()
|
const suitables = await prisma.MS_SUITABLE.findMany({
|
||||||
|
where: whereCondition,
|
||||||
|
orderBy: {
|
||||||
|
product_name: 'asc',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
return NextResponse.json(suitables)
|
return NextResponse.json(suitables)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 데이터 조회 중 오류가 발생했습니다:', error)
|
||||||
|
return NextResponse.json({ error: '데이터 조회 중 오류가 발생했습니다' }, { status: 500 })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
72
src/app/api/survey-sales/[id]/route.ts
Normal file
72
src/app/api/survey-sales/[id]/route.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
|
||||||
|
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||||
|
const body = await request.json()
|
||||||
|
const { id } = await context.params
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.update({
|
||||||
|
where: { id: Number(id) },
|
||||||
|
data: {
|
||||||
|
detail_info: {
|
||||||
|
create: body,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return NextResponse.json({ message: 'Survey detail created successfully' })
|
||||||
|
}
|
||||||
|
export async function GET(request: Request, context: { params: { id: string } }) {
|
||||||
|
const { id } = await context.params
|
||||||
|
// @ts-ignore
|
||||||
|
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.findUnique({
|
||||||
|
where: { id: Number(id) },
|
||||||
|
include: {
|
||||||
|
detail_info: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return NextResponse.json(survey)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||||
|
const { id } = await context.params
|
||||||
|
const body = await request.json()
|
||||||
|
// @ts-ignore
|
||||||
|
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.update({
|
||||||
|
where: { id: Number(id) },
|
||||||
|
data: {
|
||||||
|
...body,
|
||||||
|
detail_info: {
|
||||||
|
update: body.detail_info,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return NextResponse.json(survey)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DELETE(request: Request, context: { params: { id: string; detail_id: string } }) {
|
||||||
|
const { id, detail_id } = await context.params
|
||||||
|
if (detail_id) {
|
||||||
|
// @ts-ignore
|
||||||
|
const survey = await prisma.SD_SERVEY_SALES_DETAIL_INFO.delete({
|
||||||
|
where: { id: Number(detail_id) },
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
|
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.delete({
|
||||||
|
where: { id: Number(id) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return NextResponse.json({ message: 'Survey deleted successfully' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PATCH(request: Request, context: { params: { id: string } }) {
|
||||||
|
const { id } = await context.params
|
||||||
|
// @ts-ignore
|
||||||
|
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.update({
|
||||||
|
where: { id: Number(id) },
|
||||||
|
data: {
|
||||||
|
submission_status: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return NextResponse.json({ message: 'Survey confirmed successfully' })
|
||||||
|
}
|
||||||
@ -3,11 +3,41 @@ import { prisma } from '@/libs/prisma'
|
|||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.create({
|
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.create({
|
||||||
data: body,
|
data: body,
|
||||||
})
|
})
|
||||||
|
return NextResponse.json(res)
|
||||||
return NextResponse.json({ message: 'Survey sales created successfully' })
|
}
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.findMany()
|
||||||
|
return NextResponse.json(res)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// export async function GET(request: Request) {
|
||||||
|
// // @ts-ignore
|
||||||
|
// const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.findMany({
|
||||||
|
// include: {
|
||||||
|
// detail_info: true,
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// return NextResponse.json(res)
|
||||||
|
// }
|
||||||
|
|
||||||
|
export async function PUT(request: Request) {
|
||||||
|
const body = await request.json()
|
||||||
|
console.log('🚀 ~ PUT ~ body:', body)
|
||||||
|
const detailInfo = { ...body.detail_info, basic_info_id: body.id }
|
||||||
|
console.log('🚀 ~ PUT ~ detailInfo:', detailInfo)
|
||||||
|
// @ts-ignore
|
||||||
|
const res = await prisma.SD_SERVEY_SALES_DETAIL_INFO.create({
|
||||||
|
data: detailInfo,
|
||||||
|
})
|
||||||
|
return NextResponse.json({ message: 'Survey sales updated successfully' })
|
||||||
}
|
}
|
||||||
|
|||||||
9
src/app/inquiry/[id]/page.tsx
Normal file
9
src/app/inquiry/[id]/page.tsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import InquiryDetail from '@/components/inquiry/InquiryDetail'
|
||||||
|
|
||||||
|
export default function InquiryDetails() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<InquiryDetail />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
9
src/app/inquiry/page.tsx
Normal file
9
src/app/inquiry/page.tsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import InquiryList from '@/components/inquiry/InquiryList'
|
||||||
|
|
||||||
|
export default function Inquiry() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<InquiryList />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
9
src/app/inquiry/write/page.tsx
Normal file
9
src/app/inquiry/write/page.tsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import InquiryWriteForm from '@/components/inquiry/InquiryWriteForm'
|
||||||
|
|
||||||
|
export default function InquiryWrite() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<InquiryWriteForm />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ import SuitableDetails from '@/components/SuitableDetails'
|
|||||||
|
|
||||||
export default async function page({ params }: { params: Promise<{ slug: string }> }) {
|
export default async function page({ params }: { params: Promise<{ slug: string }> }) {
|
||||||
const { slug } = await params
|
const { slug } = await params
|
||||||
|
console.log('🚀 ~ page ~ slug:', slug)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Suitable Details</h1>
|
<h1>Suitable Details</h1>
|
||||||
|
|||||||
6
src/app/survey-sales/[id]/page.tsx
Normal file
6
src/app/survey-sales/[id]/page.tsx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import SurveyDetail from '@/components/survey-sales/SurveyDetail'
|
||||||
|
|
||||||
|
export default function SurveySalesDetailPage() {
|
||||||
|
return <SurveyDetail />
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,10 +1,12 @@
|
|||||||
import SurveySales from '@/components/SurveySales'
|
import SurveySales from '@/components/SurveySales'
|
||||||
|
import SurveySaleList from '@/components/survey-sales/SurveySaleList'
|
||||||
|
|
||||||
export default function page() {
|
export default function page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-2xl font-bold my-4 flex justify-center">조사 매물 정보</h1>
|
<h1 className="text-2xl font-bold my-4 flex justify-center">조사 매물 정보</h1>
|
||||||
<SurveySales />
|
{/* <SurveySales /> */}
|
||||||
|
<SurveySaleList />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
9
src/app/survey-sales/write/page.tsx
Normal file
9
src/app/survey-sales/write/page.tsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import MainSurveyForm from '@/components/survey-sales/write-survey-sales/MainSurveyForm'
|
||||||
|
|
||||||
|
export default function SurveyWritePage() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<MainSurveyForm />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
11
src/components/LoadMoreButton.tsx
Normal file
11
src/components/LoadMoreButton.tsx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
interface LoadMoreButtonProps {
|
||||||
|
hasMore: boolean
|
||||||
|
onLoadMore: () => void
|
||||||
|
onScrollToTop: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function LoadMoreButton({ hasMore, onLoadMore, onScrollToTop }: LoadMoreButtonProps) {
|
||||||
|
return <div>{hasMore ? <button onClick={onLoadMore}>Load More</button> : <button onClick={onScrollToTop}>Scroll to Top</button>}</div>
|
||||||
|
}
|
||||||
@ -1,16 +1,33 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { suitableApi } from '@/api/suitable'
|
import { useSuitableStore } from '@/store/useSuitableStore'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
|
import type { Suitable as SuitableType } from '@/api/suitable'
|
||||||
|
|
||||||
export default function Suitable() {
|
export default function Suitable() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { data, error, isPending } = useQuery({
|
const queryClient = useQueryClient()
|
||||||
queryKey: ['suitable-list'],
|
const { selectedItems, addSelectedItem, removeSelectedItem } = useSuitableStore()
|
||||||
queryFn: suitableApi.getList,
|
|
||||||
|
const handleItemClick = (item: SuitableType) => {
|
||||||
|
if (!item.id) return // 초기 데이터 import 때문에 Suitable.id가 optional 타입이라서 방어 처리 추가
|
||||||
|
selectedItems.some((selected) => selected.id === item.id) ? removeSelectedItem(item.id) : addSelectedItem(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: suitableList, isLoading } = useQuery<SuitableType[]>({
|
||||||
|
queryKey: ['suitables', 'search'],
|
||||||
|
queryFn: async () => {
|
||||||
|
const data = queryClient.getQueryData(['suitables', 'search']) as SuitableType[]
|
||||||
|
return data ?? []
|
||||||
|
},
|
||||||
|
enabled: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (isLoading || !suitableList || suitableList.length === 0) {
|
||||||
|
return <div>Loading...</div>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-4xl font-bold">Suitable</h1>
|
<h1 className="text-4xl font-bold">Suitable</h1>
|
||||||
@ -22,9 +39,31 @@ export default function Suitable() {
|
|||||||
>
|
>
|
||||||
HOME
|
HOME
|
||||||
</button>
|
</button>
|
||||||
{error && <div>Error: {error.message}</div>}
|
<div>
|
||||||
{isPending && <div>Loading...</div>}
|
<h2 className="text-lg font-semibold mb-2">선택된 아이템</h2>
|
||||||
{data && data.map((item) => <div key={item.id}>{item.product_name}</div>)}
|
{selectedItems.length > 0 ? (
|
||||||
|
selectedItems.map((item) => (
|
||||||
|
<div key={item.id} onClick={() => handleItemClick(item)}>
|
||||||
|
{item.product_name}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div>선택된 아이템이 없습니다.</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
<div>
|
||||||
|
<h2 className="text-lg font-semibold mb-2">데이터 목록</h2>
|
||||||
|
{suitableList ? (
|
||||||
|
suitableList.map((item: SuitableType) => (
|
||||||
|
<div key={item.id} className="p-2 border rounded cursor-pointer hover:bg-gray-100" onClick={() => handleItemClick(item)}>
|
||||||
|
{item.product_name}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div>검색 결과가 없습니다.</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,19 +2,70 @@
|
|||||||
|
|
||||||
import { suitableApi } from '@/api/suitable'
|
import { suitableApi } from '@/api/suitable'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
import generatePDF, { usePDF, Options } from 'react-to-pdf'
|
||||||
|
import PDFContent from './SuitablePdf'
|
||||||
|
|
||||||
|
const pdfOptions: Options = {
|
||||||
|
filename: 'page.pdf',
|
||||||
|
method: 'save',
|
||||||
|
page: { format: 'a4', margin: 10 },
|
||||||
|
overrides: {
|
||||||
|
pdf: {
|
||||||
|
compress: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
export default function SuitableDetails({ roofMaterial }: { roofMaterial: string }) {
|
export default function SuitableDetails({ roofMaterial }: { roofMaterial: string }) {
|
||||||
console.log('🚀 ~ SuitableDetails ~ roofMaterial:', roofMaterial)
|
const { data, isLoading } = useQuery({
|
||||||
const { data, error, isPending } = useQuery({
|
|
||||||
queryKey: ['suitable-details'],
|
queryKey: ['suitable-details'],
|
||||||
queryFn: () => suitableApi.getDetails(roofMaterial),
|
queryFn: () => suitableApi.getDetails(roofMaterial),
|
||||||
staleTime: 0,
|
staleTime: 0,
|
||||||
|
enabled: !!roofMaterial,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { toPDF, targetRef } = usePDF({ ...pdfOptions, method: 'open' })
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <div>Loading...</div>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-4xl font-bold">Searched Roof Material: {roofMaterial}</h1>
|
<button className="inline-block bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={() => toPDF()}>
|
||||||
{data && data.map((item) => <div key={item.id}>{item.product_name}</div>)}
|
OPEN PDF
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="inline-block bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
|
||||||
|
onClick={() => generatePDF(targetRef, pdfOptions)}
|
||||||
|
>
|
||||||
|
SAVE PDF
|
||||||
|
</button>
|
||||||
|
{/* <button onClick={handleDownloadPDF}>Download PDF</button> */}
|
||||||
|
{/* <div ref={targetRef} className="pdf-content"> */}
|
||||||
|
<div>
|
||||||
|
<h1 className="text-4xl font-bold">Searched Roof Material: {decodeURIComponent(roofMaterial as string)}</h1>
|
||||||
|
{data &&
|
||||||
|
data.map((item) => (
|
||||||
|
<div key={item.id}>
|
||||||
|
<br />
|
||||||
|
<div>product_name: {item.product_name}</div>
|
||||||
|
<div>manufacturer: {item.manufacturer}</div>
|
||||||
|
<div>roof_material: {item.roof_material}</div>
|
||||||
|
<div>shape: {item.shape}</div>
|
||||||
|
<div>support_roof_tile: {item.support_roof_tile}</div>
|
||||||
|
<div>support_roof_bracket: {item.support_roof_bracket}</div>
|
||||||
|
<div>yg_anchor: {item.yg_anchor}</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{/* <div style={{ display: 'none' }}> */}
|
||||||
|
<div>
|
||||||
|
<div ref={targetRef}>
|
||||||
|
<h1 className="text-4xl font-bold">PDF 내용 나와라</h1>
|
||||||
|
<PDFContent data={data ?? []} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
116
src/components/SuitablePdf.tsx
Normal file
116
src/components/SuitablePdf.tsx
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import { Suitable } from '@/api/suitable'
|
||||||
|
|
||||||
|
interface StatusInfo {
|
||||||
|
statusIcon: string
|
||||||
|
statusText: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FittingItem {
|
||||||
|
name: string
|
||||||
|
value: string
|
||||||
|
memo: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatusInfo(value: string): StatusInfo | null {
|
||||||
|
const val = value?.trim()?.replace(/ー|-/g, '-') || ''
|
||||||
|
|
||||||
|
if (['○', '〇'].includes(val)) {
|
||||||
|
return {
|
||||||
|
statusIcon: '✅',
|
||||||
|
statusText: '設置可',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['×', '✕'].includes(val)) {
|
||||||
|
return {
|
||||||
|
statusIcon: '❌',
|
||||||
|
statusText: '設置不可',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['-', '-', 'ー'].includes(val)) {
|
||||||
|
return {
|
||||||
|
statusIcon: '❓',
|
||||||
|
statusText: 'お問い合わせください',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val === '') return null
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusIcon: '✅',
|
||||||
|
statusText: `${val} で設置可`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFittingItems(item: Suitable): FittingItem[] {
|
||||||
|
return [
|
||||||
|
{ name: '屋根瓦用支持金具', value: item.support_roof_tile, memo: item.support_roof_tile_memo },
|
||||||
|
{ name: '屋根ブラケット用支持金具', value: item.support_roof_bracket, memo: item.support_roof_bracket_memo },
|
||||||
|
{ name: 'YGアンカー', value: item.yg_anchor, memo: item.yg_anchor_memo },
|
||||||
|
{ name: 'RG屋根瓦パーツ', value: item.rg_roof_tile_part, memo: item.rg_roof_tile_part_memo },
|
||||||
|
{ name: 'DIDOハント支持瓦2', value: item.dido_hunt_support_tile_2, memo: item.dido_hunt_support_tile_2_memo },
|
||||||
|
{ name: '高島パワーベース', value: item.takashima_power_base, memo: item.takashima_power_base_memo },
|
||||||
|
{ name: '高島瓦ブラケット', value: item.takashima_tile_bracket, memo: item.takashima_tile_bracket_memo },
|
||||||
|
{ name: 'スレートブラケット4', value: item.slate_bracket_4, memo: item.slate_bracket_4_memo },
|
||||||
|
{ name: 'スレートシングルメタルブラケット', value: item.slate_single_metal_bracket, memo: item.slate_single_metal_bracket_memo },
|
||||||
|
{ name: 'DIDOハントショートラック4', value: item.dido_hunt_short_rack_4, memo: item.dido_hunt_short_rack_4_memo },
|
||||||
|
{
|
||||||
|
name: '高島スレートブラケットスレートシングル',
|
||||||
|
value: item.takashima_slate_bracket_slate_single,
|
||||||
|
memo: item.takashima_slate_bracket_slate_single_memo,
|
||||||
|
},
|
||||||
|
{ name: 'DFメタルブラケット', value: item.df_metal_bracket, memo: item.df_metal_bracket_memo },
|
||||||
|
{ name: 'スレートメタルブラケット', value: item.slate_metal_bracket, memo: item.slate_metal_bracket_memo },
|
||||||
|
{ name: '高島スレートブラケットメタル屋根', value: item.takashima_slate_bracket_metal_roof, memo: item.takashima_slate_bracket_metal_roof_memo },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
function FittingItem({ fitting }: { fitting: FittingItem }) {
|
||||||
|
const statusInfo = getStatusInfo(fitting.value)
|
||||||
|
if (!statusInfo) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li>
|
||||||
|
<span>{statusInfo.statusIcon}</span>
|
||||||
|
<span>
|
||||||
|
<strong>{fitting.name}</strong>:{statusInfo.statusText}
|
||||||
|
</span>
|
||||||
|
{fitting.memo && (
|
||||||
|
<span>
|
||||||
|
<strong>備考:</strong>
|
||||||
|
{fitting.memo}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PDFContent({ data }: { data: Suitable[] }) {
|
||||||
|
return (
|
||||||
|
<div className="pdf-content">
|
||||||
|
<style jsx global>{`
|
||||||
|
.pdf-content,
|
||||||
|
.pdf-content * {
|
||||||
|
color: black !important;
|
||||||
|
-webkit-print-color-adjust: exact !important;
|
||||||
|
print-color-adjust: exact !important;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
<h1>適合結果 (적합결과)</h1>
|
||||||
|
{data.map((item) => (
|
||||||
|
<div key={item.id}>
|
||||||
|
<br />
|
||||||
|
<h2>
|
||||||
|
{item.product_name}({item.manufacturer} / {item.roof_material} / {item.shape})
|
||||||
|
</h2>
|
||||||
|
<ul>
|
||||||
|
{getFittingItems(item).map((fitting, index) => (
|
||||||
|
<FittingItem key={index} fitting={fitting} />
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -1,21 +1,88 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
import { useSuitable } from '@/hooks/useSuitable'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
export default function SuitableSearch() {
|
export default function SuitableSearch() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [selectedValue, setSelectedValue] = useState('')
|
const [selectedCategory, setSelectedCategory] = useState<string>('')
|
||||||
|
const [searchValue, setSearchValue] = useState<string>('')
|
||||||
|
const { getCategories, getSuitables } = useSuitable()
|
||||||
|
|
||||||
|
const { data: categories } = useQuery({
|
||||||
|
queryKey: ['categories'],
|
||||||
|
queryFn: getCategories,
|
||||||
|
staleTime: 1000 * 60 * 60, // 60분
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: suitableList } = useQuery({
|
||||||
|
queryKey: ['suitables', 'list'],
|
||||||
|
queryFn: async () => await getSuitables(),
|
||||||
|
staleTime: 1000 * 60 * 10, // 10분
|
||||||
|
gcTime: 1000 * 60 * 10, // 10분
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: suitableSearch, refetch: refetchBySearch } = useQuery({
|
||||||
|
queryKey: ['suitables', 'search'],
|
||||||
|
queryFn: async () => {
|
||||||
|
// api를 호출하는 검색 방법
|
||||||
|
// return await updateSearchResults(selectedCategory || undefined, searchValue || undefined)
|
||||||
|
// useQuery 캐시 데이터를 사용하는 검색 방법
|
||||||
|
return (
|
||||||
|
suitableList?.filter((item) => {
|
||||||
|
const categoryMatch = !selectedCategory || item.roof_material === selectedCategory
|
||||||
|
const searchMatch = !searchValue || item.product_name.includes(searchValue)
|
||||||
|
return categoryMatch && searchMatch
|
||||||
|
}) ?? []
|
||||||
|
)
|
||||||
|
},
|
||||||
|
staleTime: 1000 * 60 * 10,
|
||||||
|
gcTime: 1000 * 60 * 10,
|
||||||
|
enabled: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
// 초기 데이터 로딩된 후 검색 결과 없으면 검색 결과 로딩
|
||||||
|
useEffect(() => {
|
||||||
|
if (suitableList && (!suitableSearch || suitableSearch.length === 0)) {
|
||||||
|
refetchBySearch()
|
||||||
|
}
|
||||||
|
}, [suitableList, suitableSearch])
|
||||||
|
|
||||||
|
// 카테고리 선택 시 검색 결과 로딩
|
||||||
|
useEffect(() => {
|
||||||
|
refetchBySearch()
|
||||||
|
}, [selectedCategory])
|
||||||
|
|
||||||
|
const handleSearch = async () => {
|
||||||
|
if (!searchValue.trim()) {
|
||||||
|
alert('검색어를 입력하세요.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
refetchBySearch()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<select onChange={(e) => setSelectedValue(e.target.value)}>
|
<div>
|
||||||
<option value="">선택 고고</option>
|
<select value={selectedCategory || ''} onChange={(e) => setSelectedCategory(e.target.value)}>
|
||||||
<option value="瓦">瓦</option>
|
<option value="">지붕재 카테고리 선택 고고</option>
|
||||||
<option value="スレート">スレート</option>
|
{categories?.map((category) => (
|
||||||
<option value="アスファルトシングル">アスファルトシングル</option>
|
<option key={category.roof_material} value={category.roof_material}>
|
||||||
|
{category.roof_material}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
</select>
|
</select>
|
||||||
<button onClick={() => router.push(`/suitable/${selectedValue}`)}>검색</button>
|
<Link href={`/suitable/${selectedCategory}`} className="inline-block bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||||
|
지붕재 종류 상세보기 페이지 이동
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="text" placeholder="검색어를 입력하세요" onChange={(e) => setSearchValue(e.target.value)} />
|
||||||
|
<button onClick={handleSearch}>검색</button>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { surveySalesApi, SurveySalesBasicInfo } from '@/api/surveySales'
|
import { surveySalesApi, SurveySalesBasicInfo, SurveySalesDetailInfo } from '@/api/surveySales'
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
export default function SurveySales() {
|
export default function SurveySales() {
|
||||||
|
const [isSearch, setIsSearch] = useState(false)
|
||||||
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -34,6 +37,68 @@ export default function SurveySales() {
|
|||||||
createSurveySales(data)
|
createSurveySales(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { data, error: errorList } = useQuery({
|
||||||
|
queryKey: ['survey-sales', 'list'],
|
||||||
|
queryFn: surveySalesApi.getList,
|
||||||
|
enabled: isSearch,
|
||||||
|
})
|
||||||
|
|
||||||
|
// const { mutate: updateSurveySales } = useMutation({
|
||||||
|
// mutationFn: surveySalesApi.update,
|
||||||
|
// onSuccess: () => {
|
||||||
|
// queryClient.invalidateQueries({ queryKey: ['survey-sales', 'list'] })
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
|
||||||
|
const handleUpdateSurveySales = () => {
|
||||||
|
const detailData: SurveySalesDetailInfo = {
|
||||||
|
contract_capacity: '1100',
|
||||||
|
retail_company: 'test company',
|
||||||
|
supplementary_facilities: 1,
|
||||||
|
supplementary_facilities_etc: '',
|
||||||
|
installation_system: 3,
|
||||||
|
installation_system_etc: '',
|
||||||
|
construction_year: 4,
|
||||||
|
construction_year_etc: '',
|
||||||
|
roof_material: 1,
|
||||||
|
roof_material_etc: '',
|
||||||
|
roof_shape: 2,
|
||||||
|
roof_shape_etc: '',
|
||||||
|
roof_slope: '4.5',
|
||||||
|
house_structure: 1,
|
||||||
|
house_structure_etc: '',
|
||||||
|
rafter_material: 5,
|
||||||
|
rafter_material_etc: 'test message',
|
||||||
|
rafter_size: 3,
|
||||||
|
rafter_size_etc: '',
|
||||||
|
rafter_pitch: 2,
|
||||||
|
rafter_pitch_etc: '',
|
||||||
|
rafter_direction: 3,
|
||||||
|
open_field_plate_kind: 3,
|
||||||
|
open_field_plate_kind_etc: '',
|
||||||
|
open_field_plate_thickness: '',
|
||||||
|
leak_trace: false,
|
||||||
|
waterproof_material: 2,
|
||||||
|
waterproof_material_etc: '',
|
||||||
|
insulation_presence: 3,
|
||||||
|
insulation_presence_etc: '',
|
||||||
|
structure_order: 2,
|
||||||
|
structure_order_etc: '',
|
||||||
|
installation_availability: 1,
|
||||||
|
installation_availability_etc: '',
|
||||||
|
memo: 'test memo',
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data) return
|
||||||
|
|
||||||
|
const surveySalesData: SurveySalesBasicInfo = {
|
||||||
|
...data[0],
|
||||||
|
detail_info: { ...detailData },
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateSurveySales(surveySalesData)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex items-center justify-center">
|
<div className="flex items-center justify-center">
|
||||||
@ -41,13 +106,22 @@ export default function SurveySales() {
|
|||||||
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={handleSurveySales}>
|
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={handleSurveySales}>
|
||||||
신규 등록
|
신규 등록
|
||||||
</button>
|
</button>
|
||||||
<button className="bg-blue-500 text-white px-4 py-2 rounded-md">조회</button>
|
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={() => setIsSearch(true)}>
|
||||||
|
조회
|
||||||
|
</button>
|
||||||
|
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={handleUpdateSurveySales}>
|
||||||
|
수정 (detail info add)
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4 m-4" role="alert">
|
{/* <div className="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4 m-4" role="alert">
|
||||||
<p className="font-bold">Be Warned</p>
|
<p className="font-bold">Be Warned</p>
|
||||||
<p>기본 데이터 세팅 되어있습니다.</p>
|
<p>기본 데이터 세팅 되어있습니다.</p>
|
||||||
</div> */}
|
</div> */}
|
||||||
|
<div>
|
||||||
|
{errorList && <div>Error: {errorList.message}</div>}
|
||||||
|
{data && data.map((item) => <div key={item.id}>{JSON.stringify(item)}</div>)}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
73
src/components/inquiry/InquiryDetail.tsx
Normal file
73
src/components/inquiry/InquiryDetail.tsx
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useParams } from 'next/navigation'
|
||||||
|
|
||||||
|
const inquiryDummyData = {
|
||||||
|
writer: {
|
||||||
|
name: 'writer',
|
||||||
|
email: 'writer@example.com',
|
||||||
|
},
|
||||||
|
title: 'title',
|
||||||
|
content: 'content',
|
||||||
|
files: ['file1.jpg', 'file2.jpg', 'file3.jpg'],
|
||||||
|
createdAt: '2021-01-01',
|
||||||
|
answer: {
|
||||||
|
writer: '佐藤一貴',
|
||||||
|
content:
|
||||||
|
'一次側接続は、自動切替開閉器と住宅分電盤主幹ブレーカの間に蓄電システムブレーカを配線する方法です。\n二次側接続は、住宅分電盤主幹ブレ―カの二次側に蓄電システムブレーカを接続する',
|
||||||
|
createdAt: '2021-01-01 12:00:00',
|
||||||
|
files: ['file4.jpg', 'file5.jpg', 'file6.jpg'],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function InquiryDetail() {
|
||||||
|
const params = useParams()
|
||||||
|
const id = params.id
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>InquiryDetail</h1>
|
||||||
|
<p>{id}</p>
|
||||||
|
<div className="mt-5">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<p>writer</p>
|
||||||
|
<p>{inquiryDummyData.writer.name}</p>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<p>email</p>
|
||||||
|
<p>{inquiryDummyData.writer.email}</p>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<p>title</p>
|
||||||
|
<p>{inquiryDummyData.title}</p>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<p>content</p>
|
||||||
|
<p>{inquiryDummyData.content}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>files</p>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{inquiryDummyData.files.map((file) => (
|
||||||
|
<span key={file}>{file}</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{inquiryDummyData.answer && (
|
||||||
|
<div className="mt-4">
|
||||||
|
<h1>Reply: Hanwha Japan</h1>
|
||||||
|
<div>
|
||||||
|
<p>{inquiryDummyData.answer.writer}</p>
|
||||||
|
<p>{inquiryDummyData.answer.createdAt}</p>
|
||||||
|
<p>{inquiryDummyData.answer.content}</p>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{inquiryDummyData.answer.files.map((file) => (
|
||||||
|
<span key={file}>{file}</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
20
src/components/inquiry/InquiryFilter.tsx
Normal file
20
src/components/inquiry/InquiryFilter.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { Search } from 'lucide-react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
|
||||||
|
export default function InquiryFilter({ handleSearch }: { handleSearch: (e: React.ChangeEvent<HTMLInputElement>) => void }) {
|
||||||
|
const router = useRouter()
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button onClick={() => router.push('/inquiry/write')}>write 1:1 Inquiry {'>'}</button>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input type="text" placeholder="Search" onChange={handleSearch} />
|
||||||
|
<button>
|
||||||
|
<Search />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
21
src/components/inquiry/InquiryItems.tsx
Normal file
21
src/components/inquiry/InquiryItems.tsx
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
export default function InquiryItems({ inquiryData }: { inquiryData: any }) {
|
||||||
|
const router = useRouter()
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{inquiryData.map((item: any) => (
|
||||||
|
<div key={item.id} onClick={() => router.push(`/inquiry/${item.id}`)}>
|
||||||
|
<div>{item.title}</div>
|
||||||
|
<div>{item.content}</div>
|
||||||
|
<div>{item.createdAt}</div>
|
||||||
|
<div>{item.writer}</div>
|
||||||
|
<div>{item.category}</div>
|
||||||
|
{item.file && <div>{item.file}</div>}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
171
src/components/inquiry/InquiryList.tsx
Normal file
171
src/components/inquiry/InquiryList.tsx
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
'use client'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import InquiryItems from './InquiryItems'
|
||||||
|
import InquiryFilter from './InquiryFilter'
|
||||||
|
import LoadMoreButton from '../LoadMoreButton'
|
||||||
|
|
||||||
|
const inquiryDummyData = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: 'file.png',
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer',
|
||||||
|
category: 'A',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: 'file.png',
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'B',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: null,
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'C',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: null,
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'A',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: null,
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'B',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: null,
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'C',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: 'file.png',
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer',
|
||||||
|
category: 'A',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 8,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: 'file.png',
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'B',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 9,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: null,
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'C',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: 10,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: 'file.png',
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'A',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 11,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: 'file.png',
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer',
|
||||||
|
category: 'B',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 12,
|
||||||
|
title: 'post',
|
||||||
|
content: 'content',
|
||||||
|
file: null,
|
||||||
|
createdAt: '2024-01-01',
|
||||||
|
writer: 'writer1',
|
||||||
|
category: 'C',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export default function InquiryList() {
|
||||||
|
const [visibleItems, setVisibleItems] = useState(5)
|
||||||
|
const [isMyPostsOnly, setIsMyPostsOnly] = useState(false)
|
||||||
|
const [category, setCategory] = useState('')
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [hasMore, setHasMore] = useState(inquiryDummyData.length > 5)
|
||||||
|
|
||||||
|
const inquriyData = () => {
|
||||||
|
if (isMyPostsOnly) {
|
||||||
|
return inquiryDummyData.filter((item) => item.writer === 'writer')
|
||||||
|
}
|
||||||
|
if (category.trim().length > 0) {
|
||||||
|
return inquiryDummyData.filter((item) => item.category === category)
|
||||||
|
}
|
||||||
|
if (search.trim().length > 0) {
|
||||||
|
return inquiryDummyData.filter((item) => item.title.includes(search))
|
||||||
|
}
|
||||||
|
return inquiryDummyData
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleLoadMore = () => {
|
||||||
|
const newVisibleItems = Math.min(visibleItems + 5, inquriyData().length)
|
||||||
|
setVisibleItems(newVisibleItems)
|
||||||
|
setHasMore(newVisibleItems < inquriyData().length)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSearch(e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleScrollToTop = () => {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<InquiryFilter handleSearch={handleSearch} />
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input type="checkbox" id="myPosts" checked={isMyPostsOnly} onChange={(e) => setIsMyPostsOnly(e.target.checked)} />
|
||||||
|
<label htmlFor="myPosts">my posts</label>
|
||||||
|
</div>
|
||||||
|
<select onChange={(e) => setCategory(e.target.value)}>
|
||||||
|
<option value="">All</option>
|
||||||
|
<option value="A">A</option>
|
||||||
|
<option value="B">B</option>
|
||||||
|
<option value="C">C</option>
|
||||||
|
</select>
|
||||||
|
<span>total {inquriyData().length}</span>
|
||||||
|
<InquiryItems inquiryData={inquriyData().slice(0, visibleItems)} />
|
||||||
|
<LoadMoreButton hasMore={hasMore} onLoadMore={handleLoadMore} onScrollToTop={handleScrollToTop} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
72
src/components/inquiry/InquiryWriteForm.tsx
Normal file
72
src/components/inquiry/InquiryWriteForm.tsx
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
export interface InquiryFormData {
|
||||||
|
category: string
|
||||||
|
title: string
|
||||||
|
content: string
|
||||||
|
file: File[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function InquiryWriteForm() {
|
||||||
|
const router = useRouter()
|
||||||
|
const [formData, setFormData] = useState<InquiryFormData>({
|
||||||
|
category: 'A',
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
file: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const file = Array.from(e.target.files || [])
|
||||||
|
setFormData({ ...formData, file: [...formData.file, ...file] })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleFileDelete = (fileToDelete: File) => {
|
||||||
|
setFormData({ ...formData, file: formData.file.filter((f) => f !== fileToDelete) })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
console.log('submit: ', formData)
|
||||||
|
// router.push(`/inquiry`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="category">category</label>
|
||||||
|
<select id="category" onChange={(e) => setFormData({ ...formData, category: e.target.value })}>
|
||||||
|
<option value="A">A</option>
|
||||||
|
<option value="B">B</option>
|
||||||
|
<option value="C">C</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="title">title</label>
|
||||||
|
<input type="text" id="title" onChange={(e) => setFormData({ ...formData, title: e.target.value })} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="content">content</label>
|
||||||
|
<textarea id="content" onChange={(e) => setFormData({ ...formData, content: e.target.value })} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="file">file</label>
|
||||||
|
<input type="file" id="file" accept="image/*" capture="environment" onChange={handleFileChange} />
|
||||||
|
<div>
|
||||||
|
<p>file count: {formData.file.length}</p>
|
||||||
|
{formData.file.map((f) => (
|
||||||
|
<div key={f.name}>
|
||||||
|
<div>{f.name}</div>
|
||||||
|
<div>
|
||||||
|
<button onClick={() => handleFileDelete(f)}>delete</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button onClick={handleSubmit}>submit</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
68
src/components/survey-sales/EtcCheckbox.tsx
Normal file
68
src/components/survey-sales/EtcCheckbox.tsx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
'use client'
|
||||||
|
import { useState } from "react"
|
||||||
|
import { SurveySalesDetailInfo } from "@/api/surveySales"
|
||||||
|
|
||||||
|
interface EtcCheckboxProps {
|
||||||
|
formName: keyof SurveySalesDetailInfo
|
||||||
|
label: string
|
||||||
|
detailInfoForm: SurveySalesDetailInfo
|
||||||
|
setDetailInfoForm: (form: SurveySalesDetailInfo) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EtcCheckbox({ formName, label, detailInfoForm, setDetailInfoForm }: EtcCheckboxProps) {
|
||||||
|
const [showEtcInput, setShowEtcInput] = useState(false)
|
||||||
|
const etcFieldName = `${formName}_etc` as keyof SurveySalesDetailInfo
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<label htmlFor={formName} className="block font-medium">{label}</label>
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id={formName}
|
||||||
|
checked={detailInfoForm[formName] === 1}
|
||||||
|
onChange={(e) => setDetailInfoForm({
|
||||||
|
...detailInfoForm,
|
||||||
|
[formName]: e.target.checked ? 1 : 0
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
<label htmlFor={formName}>있음</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id={`${formName}_etc_check`}
|
||||||
|
checked={showEtcInput}
|
||||||
|
onChange={(e) => {
|
||||||
|
setShowEtcInput(e.target.checked)
|
||||||
|
if (!e.target.checked) {
|
||||||
|
setDetailInfoForm({
|
||||||
|
...detailInfoForm,
|
||||||
|
[etcFieldName]: ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<label htmlFor={`${formName}_etc_check`}>기타</label>
|
||||||
|
|
||||||
|
{showEtcInput && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id={`${formName}_etc`}
|
||||||
|
value={(detailInfoForm[etcFieldName] as string | null) ?? ''}
|
||||||
|
placeholder="기타 사항을 입력하세요"
|
||||||
|
onChange={(e) => setDetailInfoForm({
|
||||||
|
...detailInfoForm,
|
||||||
|
[etcFieldName]: e.target.value
|
||||||
|
})}
|
||||||
|
className="border rounded px-2 py-1 ml-2"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
61
src/components/survey-sales/SurveyDetail.tsx
Normal file
61
src/components/survey-sales/SurveyDetail.tsx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useServey } from '@/hooks/useSurvey'
|
||||||
|
import { SurveySalesBasicInfo } from '@/api/surveySales'
|
||||||
|
import { useParams, useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
export default function SurveyDetail() {
|
||||||
|
const params = useParams()
|
||||||
|
const id = params.id
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const { surveyDetail, deleteSurvey, isDeletingSurvey, confirmSurvey } = useServey(Number(id))
|
||||||
|
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
22
src/components/survey-sales/SurveyFilter.tsx
Normal file
22
src/components/survey-sales/SurveyFilter.tsx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { Search } from 'lucide-react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
export default function SurveyFilter({ handleSearch, handleMyPosts }: { handleSearch: (e: React.ChangeEvent<HTMLInputElement>) => void, handleMyPosts: () => void }) {
|
||||||
|
const router = useRouter()
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button onClick={() => router.push('/survey-sales/write')}>write survey {'>'}</button>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input type="text" placeholder="Search" onChange={handleSearch} />
|
||||||
|
<button>
|
||||||
|
<Search />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<button onClick={handleMyPosts} className="cursor-pointer">
|
||||||
|
my posts
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
90
src/components/survey-sales/SurveySaleList.tsx
Normal file
90
src/components/survey-sales/SurveySaleList.tsx
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useServey } from '@/hooks/useSurvey'
|
||||||
|
import LoadMoreButton from '@/components/LoadMoreButton'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import SurveyFilter from './SurveyFilter'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
export default function SurveySaleList() {
|
||||||
|
const { surveyList, isLoadingSurveyList } = useServey()
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [isMyPostsOnly, setIsMyPostsOnly] = useState(false)
|
||||||
|
const [hasMore, setHasMore] = useState(surveyList.length > 5)
|
||||||
|
const [visibleItems, setVisibleItems] = useState(5)
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
// TEMP USERNAME
|
||||||
|
const username = 'test'
|
||||||
|
|
||||||
|
const surveyData = () => {
|
||||||
|
if (search.trim().length > 0) {
|
||||||
|
return surveyList.filter((survey) => survey.building_name?.includes(search))
|
||||||
|
}
|
||||||
|
if (isMyPostsOnly) {
|
||||||
|
return surveyList.filter((survey) => survey.representative === username)
|
||||||
|
}
|
||||||
|
return surveyList
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleLoadMore = () => {
|
||||||
|
const newVisibleItems = Math.min(visibleItems + 5, surveyData().length)
|
||||||
|
setVisibleItems(newVisibleItems)
|
||||||
|
setHasMore(newVisibleItems < surveyData().length)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleScrollToTop = () => {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSearch(e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDetail = (id: number | undefined) => {
|
||||||
|
if (id === undefined) throw new Error('id is required')
|
||||||
|
router.push(`/survey-sales/${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoadingSurveyList) {
|
||||||
|
return <div>Loading...</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-4xl mx-auto p-4">
|
||||||
|
<SurveyFilter handleSearch={handleSearch} handleMyPosts={() => setIsMyPostsOnly(!isMyPostsOnly)} />
|
||||||
|
|
||||||
|
<div className="grid gap-4 mt-6">
|
||||||
|
{surveyData().slice(0, visibleItems).map((survey) => (
|
||||||
|
<div
|
||||||
|
key={survey.id}
|
||||||
|
onClick={() => handleDetail(survey.id)}
|
||||||
|
className="bg-white rounded-lg shadow p-4 hover:shadow-md transition-shadow cursor-pointer border border-gray-200"
|
||||||
|
>
|
||||||
|
<div className="flex justify-between items-start">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h2 className="text-lg font-semibold text-gray-900">{survey.id}</h2>
|
||||||
|
<div className="space-y-1 text-sm text-gray-600">
|
||||||
|
<p>담당자: {survey.representative || '-'}</p>
|
||||||
|
<p>판매점: {survey.store || '-'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className={`px-3 py-1 rounded-full text-sm ${
|
||||||
|
survey.submission_status ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{survey.submission_status ? '제출' : '미제출'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-6">
|
||||||
|
<LoadMoreButton hasMore={hasMore} onLoadMore={handleLoadMore} onScrollToTop={handleScrollToTop} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { SurveySalesBasicInfo } from '@/api/surveySales'
|
||||||
|
|
||||||
|
export default function BasicWriteForm({
|
||||||
|
basicInfoData,
|
||||||
|
setBasicInfoData,
|
||||||
|
}: {
|
||||||
|
basicInfoData: SurveySalesBasicInfo
|
||||||
|
setBasicInfoData: (basicInfoData: SurveySalesBasicInfo) => void
|
||||||
|
}) {
|
||||||
|
const handleChange = (key: keyof SurveySalesBasicInfo, value: string) => {
|
||||||
|
setBasicInfoData({ ...basicInfoData, [key]: value.toString() })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="representative">담당자명</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="representative"
|
||||||
|
value={basicInfoData.representative}
|
||||||
|
onChange={(e) => handleChange('representative', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="store">판매점</label>
|
||||||
|
<input type="text" id="store" value={basicInfoData.store ?? ''} onChange={(e) => handleChange('store', e.target.value)} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="construction_point">시공점</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="construction_point"
|
||||||
|
value={basicInfoData.construction_point ?? ''}
|
||||||
|
onChange={(e) => handleChange('construction_point', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="investigation_date">현재 조사일</label>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
id="investigation_date"
|
||||||
|
value={basicInfoData.investigation_date ?? ''}
|
||||||
|
onChange={(e) => handleChange('investigation_date', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="building_name">건물명</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="building_name"
|
||||||
|
value={basicInfoData.building_name ?? ''}
|
||||||
|
onChange={(e) => handleChange('building_name', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="customer_name">고객명</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="customer_name"
|
||||||
|
value={basicInfoData.customer_name ?? ''}
|
||||||
|
onChange={(e) => handleChange('customer_name', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="post_code">우편번호</label>
|
||||||
|
<input type="text" id="post_code" value={basicInfoData.post_code ?? ''} onChange={(e) => handleChange('post_code', e.target.value)} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="address">주소</label>
|
||||||
|
<input type="text" id="address" value={basicInfoData.address ?? ''} onChange={(e) => handleChange('address', e.target.value)} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="address_detail">상세주소</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="address_detail"
|
||||||
|
value={basicInfoData.address_detail ?? ''}
|
||||||
|
onChange={(e) => handleChange('address_detail', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,157 @@
|
|||||||
|
'use client'
|
||||||
|
import React from 'react'
|
||||||
|
import EtcCheckbox from '../EtcCheckbox'
|
||||||
|
import { SurveySalesDetailInfo } from '@/api/surveySales'
|
||||||
|
|
||||||
|
interface DetailWriteFormProps {
|
||||||
|
detailInfoForm: SurveySalesDetailInfo
|
||||||
|
setDetailInfoForm: (form: SurveySalesDetailInfo) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DetailWriteForm({ detailInfoForm, setDetailInfoForm }: DetailWriteFormProps) {
|
||||||
|
const handleNumberInput = (field: keyof SurveySalesDetailInfo, value: string) => {
|
||||||
|
const numberValue = value === '' ? null : Number(value)
|
||||||
|
setDetailInfoForm({ ...detailInfoForm, [field]: numberValue })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleTextInput = (field: keyof SurveySalesDetailInfo, value: string) => {
|
||||||
|
setDetailInfoForm({ ...detailInfoForm, [field]: value || null })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBooleanInput = (field: keyof SurveySalesDetailInfo, checked: boolean) => {
|
||||||
|
setDetailInfoForm({ ...detailInfoForm, [field]: checked })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div>
|
||||||
|
<label htmlFor="contract_capacity">계약용량</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="contract_capacity"
|
||||||
|
value={detailInfoForm.contract_capacity ?? ''}
|
||||||
|
onChange={(e) => handleTextInput('contract_capacity', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="retail_company">소매회사</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="retail_company"
|
||||||
|
value={detailInfoForm.retail_company ?? ''}
|
||||||
|
onChange={(e) => handleTextInput('retail_company', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<EtcCheckbox
|
||||||
|
formName="supplementary_facilities"
|
||||||
|
label="부대설비"
|
||||||
|
detailInfoForm={detailInfoForm}
|
||||||
|
setDetailInfoForm={setDetailInfoForm}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="installation_system" label="설치시스템" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="construction_year" label="건축년도" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="roof_material" label="지붕재료" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="roof_shape" label="지붕형태" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="roof_slope">지붕 경사도</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="roof_slope"
|
||||||
|
value={detailInfoForm.roof_slope ?? ''}
|
||||||
|
onChange={(e) => handleTextInput('roof_slope', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="house_structure" label="주택 구조" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="rafter_material" label="주탑재료" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="rafter_size" label="주탑 크기" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="rafter_pitch" label="주탑 경사도" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="rafter_direction">오픈필드 판형</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="rafter_direction"
|
||||||
|
value={detailInfoForm.rafter_direction ?? ''}
|
||||||
|
onChange={(e) => handleTextInput('rafter_direction', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="open_field_plate_kind" label="노지판 형태" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="open_field_plate_thickness">노지판 두께</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="open_field_plate_thickness"
|
||||||
|
value={detailInfoForm.open_field_plate_thickness ?? ''}
|
||||||
|
onChange={(e) => handleTextInput('open_field_plate_thickness', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="leak_trace">누수 흔적</label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="leak_trace"
|
||||||
|
checked={detailInfoForm.leak_trace ?? false}
|
||||||
|
onChange={(e) => handleBooleanInput('leak_trace', e.target.checked)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="waterproof_material" label="방수재료" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="insulation_presence" label="보증금 존재" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="structure_order" label="구조체계" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<EtcCheckbox formName="installation_availability" label="설치가능" detailInfoForm={detailInfoForm} setDetailInfoForm={setDetailInfoForm} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="memo">메모</label>
|
||||||
|
<textarea
|
||||||
|
id="memo"
|
||||||
|
value={detailInfoForm.memo ?? ''}
|
||||||
|
onChange={(e) => handleTextInput('memo', e.target.value)}
|
||||||
|
className="w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,165 @@
|
|||||||
|
'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'
|
||||||
|
|
||||||
|
type TabType = 'basic' | 'detail'
|
||||||
|
|
||||||
|
const defaultDetailInfoForm: SurveySalesDetailInfo = {
|
||||||
|
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: SurveySalesBasicInfo = {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function MainSurveyForm() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
|
const id = searchParams.get('id')
|
||||||
|
|
||||||
|
const [activeTab, setActiveTab] = useState<TabType>('basic')
|
||||||
|
|
||||||
|
const handleTabClick = (tab: TabType) => {
|
||||||
|
setActiveTab(tab)
|
||||||
|
}
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const { createSurvey, isCreatingSurvey, createSurveyDetail, surveyDetail, updateSurvey } = useServey(Number(id))
|
||||||
|
|
||||||
|
const [detailInfoForm, setDetailInfoForm] = useState<SurveySalesDetailInfo>(defaultDetailInfoForm)
|
||||||
|
const [basicInfoData, setBasicInfoData] = useState<SurveySalesBasicInfo>(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])
|
||||||
|
|
||||||
|
const handleSave = async (isSubmit: boolean = false) => {
|
||||||
|
if (id) {
|
||||||
|
updateSurvey({
|
||||||
|
...basicInfoData,
|
||||||
|
detail_info: detailInfoForm,
|
||||||
|
submission_status: isSubmit,
|
||||||
|
})
|
||||||
|
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>
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
)
|
||||||
|
}
|
||||||
30
src/hooks/useSuitable.ts
Normal file
30
src/hooks/useSuitable.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { suitableApi } from '@/api/suitable'
|
||||||
|
|
||||||
|
export function useSuitable() {
|
||||||
|
const getCategories = async () => {
|
||||||
|
try {
|
||||||
|
return await suitableApi.getCategory()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('카테고리 데이터 로드 실패:', error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getSuitables = async () => {
|
||||||
|
try {
|
||||||
|
return await suitableApi.getList()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('지붕재 데이터 로드 실패:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateSearchResults = async (selectedCategory: string | undefined, searchValue: string | undefined) => {
|
||||||
|
try {
|
||||||
|
return await suitableApi.getList(selectedCategory, searchValue)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('지붕재 데이터 검색 실패:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { getCategories, getSuitables, updateSearchResults }
|
||||||
|
}
|
||||||
97
src/hooks/useSurvey.ts
Normal file
97
src/hooks/useSurvey.ts
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
import { SurveySalesBasicInfo, surveySalesApi, SurveySalesDetailInfo } from '@/api/surveySales'
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
|
||||||
|
export function useServey(id?: number): {
|
||||||
|
surveyList: SurveySalesBasicInfo[] | []
|
||||||
|
surveyDetail: SurveySalesBasicInfo | null
|
||||||
|
isLoadingSurveyList: boolean
|
||||||
|
isLoadingSurveyDetail: boolean
|
||||||
|
isCreatingSurvey: boolean
|
||||||
|
isUpdatingSurvey: boolean
|
||||||
|
isDeletingSurvey: boolean
|
||||||
|
createSurvey: (survey: SurveySalesBasicInfo) => Promise<number>
|
||||||
|
createSurveyDetail: (params: { surveyId: number; surveyDetail: SurveySalesDetailInfo }) => void
|
||||||
|
updateSurvey: (survey: SurveySalesBasicInfo) => void
|
||||||
|
deleteSurvey: (params: { id: number; isDetail: boolean }) => void
|
||||||
|
confirmSurvey: (id: number) => void
|
||||||
|
} {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
const { data: surveyList, isLoading: isLoadingSurveyList } = useQuery({
|
||||||
|
queryKey: ['survey', 'list'],
|
||||||
|
queryFn: () => surveySalesApi.getList(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: surveyDetail, isLoading: isLoadingSurveyDetail } = useQuery({
|
||||||
|
queryKey: ['survey', id],
|
||||||
|
queryFn: () => {
|
||||||
|
if (id === undefined) throw new Error('id is required')
|
||||||
|
if (id === null) return null
|
||||||
|
return surveySalesApi.getDetail(id)
|
||||||
|
},
|
||||||
|
enabled: id !== undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutateAsync: createSurvey, isPending: isCreatingSurvey } = useMutation({
|
||||||
|
mutationFn: (survey: SurveySalesBasicInfo) => surveySalesApi.create(survey),
|
||||||
|
onSuccess: (data) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey', 'list'] })
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutate: updateSurvey, isPending: isUpdatingSurvey } = useMutation({
|
||||||
|
mutationFn: (survey: SurveySalesBasicInfo) => {
|
||||||
|
if (id === undefined) throw new Error('id is required')
|
||||||
|
return surveySalesApi.update(id, survey)
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey', id] })
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey', 'list'] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutateAsync: deleteSurvey, isPending: isDeletingSurvey } = useMutation({
|
||||||
|
mutationFn: ({ id, isDetail }: { id: number; isDetail: boolean }) => {
|
||||||
|
if (id === undefined) throw new Error('id is required')
|
||||||
|
return surveySalesApi.delete(id, isDetail)
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey', 'list'] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutate: createSurveyDetail } = useMutation({
|
||||||
|
mutationFn: ({ surveyId, surveyDetail }: { surveyId: number; surveyDetail: SurveySalesDetailInfo }) =>
|
||||||
|
surveySalesApi.createDetail(surveyId, surveyDetail),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey', 'list'] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutate: confirmSurvey, isPending: isConfirmingSurvey } = useMutation({
|
||||||
|
mutationFn: (id: number) => {
|
||||||
|
if (id === undefined) throw new Error('id is required')
|
||||||
|
return surveySalesApi.confirm(id)
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey', 'list'] })
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey', id] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
surveyList: surveyList || [],
|
||||||
|
surveyDetail: surveyDetail || null,
|
||||||
|
isLoadingSurveyList,
|
||||||
|
isLoadingSurveyDetail,
|
||||||
|
isCreatingSurvey,
|
||||||
|
isUpdatingSurvey,
|
||||||
|
isDeletingSurvey,
|
||||||
|
createSurvey,
|
||||||
|
updateSurvey,
|
||||||
|
deleteSurvey,
|
||||||
|
createSurveyDetail,
|
||||||
|
confirmSurvey,
|
||||||
|
}
|
||||||
|
}
|
||||||
68
src/store/useSuitableStore.ts
Normal file
68
src/store/useSuitableStore.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { create } from 'zustand'
|
||||||
|
import { Suitable, suitableApi } from '@/api/suitable'
|
||||||
|
|
||||||
|
interface SuitableState {
|
||||||
|
// // 검색 결과 리스트
|
||||||
|
// searchResults: Suitable[]
|
||||||
|
// // 초기 데이터 로드
|
||||||
|
// fetchInitializeData: () => Promise<void>
|
||||||
|
// // 검색 결과 설정
|
||||||
|
// setSearchResults: (results: Suitable[]) => void
|
||||||
|
// // 검색 결과 초기화
|
||||||
|
// resetSearchResults: () => void
|
||||||
|
|
||||||
|
// 선택된 아이템 리스트
|
||||||
|
selectedItems: Suitable[]
|
||||||
|
// 선택된 아이템 추가
|
||||||
|
addSelectedItem: (item: Suitable) => void
|
||||||
|
// 선택된 아이템 제거
|
||||||
|
removeSelectedItem: (itemId: number) => void
|
||||||
|
// 선택된 아이템 모두 제거
|
||||||
|
clearSelectedItems: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSuitableStore = create<SuitableState>((set) => ({
|
||||||
|
// // 초기 상태
|
||||||
|
// searchResults: [],
|
||||||
|
|
||||||
|
// // 초기 데이터 로드
|
||||||
|
// fetchInitializeData: async () => {
|
||||||
|
// const suitables = await fetchInitialSuitablee()
|
||||||
|
// set({ searchResults: suitables })
|
||||||
|
// },
|
||||||
|
|
||||||
|
// // 검색 결과 설정
|
||||||
|
// setSearchResults: (results) => set({ searchResults: results }),
|
||||||
|
|
||||||
|
// // 검색 결과 초기화
|
||||||
|
// resetSearchResults: () => set({ searchResults: [] }),
|
||||||
|
|
||||||
|
// 초기 상태
|
||||||
|
selectedItems: [],
|
||||||
|
|
||||||
|
// 선택된 아이템 추가 (중복 방지)
|
||||||
|
addSelectedItem: (item) =>
|
||||||
|
set((state) => ({
|
||||||
|
selectedItems: state.selectedItems.some((i) => i.id === item.id) ? state.selectedItems : [...state.selectedItems, item],
|
||||||
|
})),
|
||||||
|
|
||||||
|
// 선택된 아이템 제거
|
||||||
|
removeSelectedItem: (itemId) =>
|
||||||
|
set((state) => ({
|
||||||
|
selectedItems: state.selectedItems.filter((item) => item.id !== itemId),
|
||||||
|
})),
|
||||||
|
|
||||||
|
// 선택된 아이템 모두 제거
|
||||||
|
clearSelectedItems: () => set({ selectedItems: [] }),
|
||||||
|
}))
|
||||||
|
|
||||||
|
// // 전체 데이터 초기화 함수
|
||||||
|
// async function fetchInitialSuitablee() {
|
||||||
|
// try {
|
||||||
|
// const suitable = await suitableApi.getList()
|
||||||
|
// return suitable
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error('초기 데이터 로드 실패:', error)
|
||||||
|
// return []
|
||||||
|
// }
|
||||||
|
// }
|
||||||
Loading…
x
Reference in New Issue
Block a user