feat: add data for download survey-sale pdf

This commit is contained in:
Dayoung 2025-05-28 14:22:22 +09:00
parent 6d837d3e98
commit 67ba964eec
3 changed files with 37 additions and 15 deletions

View File

@ -1,8 +1,8 @@
'use client'
import { useEffect, useRef } from 'react'
import { useEffect, useRef, useState } from 'react'
import generatePDF, { Margin, Resolution } from 'react-to-pdf'
import { useParams } from 'next/navigation'
import { useParams, useRouter } from 'next/navigation'
import { useSurvey } from '@/hooks/useSurvey'
import { radioEtcData, roofMaterial, selectBoxOptions, supplementaryFacilities } from '../survey-sale/detail/RoofForm'
@ -11,13 +11,18 @@ export default function SurveySaleDownloadPdf() {
const id = params.id
const { surveyDetail, isLoadingSurveyDetail } = useSurvey(Number(id))
useEffect(() => {
if (isLoadingSurveyDetail) return
handleDownPdf()
}, [surveyDetail, isLoadingSurveyDetail])
const [isLoading, setIsLoading] = useState(false)
const router = useRouter()
const targetRef = useRef<HTMLDivElement>(null)
const isGeneratedRef = useRef(false)
// useEffect(() => {
// if (isLoadingSurveyDetail || !surveyDetail || isGeneratedRef.current) return
// isGeneratedRef.current = true
// handleDownPdf()
// }, [surveyDetail?.id, isLoadingSurveyDetail])
const handleDownPdf = () => {
const options = {
method: 'open' as const,
@ -41,14 +46,30 @@ export default function SurveySaleDownloadPdf() {
},
}
generatePDF(targetRef, options)
// generatePDF(targetRef, { filename: 'page.pdf' })
generatePDF(targetRef, options).then(() => {
router.push(`/survey-sale/${id}`)
})
}
return (
<>
{/* <button onClick={handleDownPdf}>down</button> */}
<div ref={targetRef} style={{ boxSizing: 'border-box' }}>
<div style={{ margin: '0 auto', padding: 0, maxWidth: '800px', minWidth: '800px' }}>
<button onClick={handleDownPdf}>down</button>
<div
ref={targetRef}
style={{
// boxSizing: 'border-box'
width: '794px', // A4 너비
minHeight: '1123px', // A4 높이
transform: 'scale(1.0)',
transformOrigin: 'top left',
padding: '20px',
boxSizing: 'border-box',
backgroundColor: '#fff',
fontSize: '12px',
}}
>
<div
// style={{ margin: '0 auto', padding: 0, maxWidth: '800px', minWidth: '800px' }}
>
<div style={{ padding: '20px 20px 50px', borderBottom: '2px solid #2E3A59' }}>
<div style={{ float: 'left', verticalAlign: 'middle', fontSize: '18px', color: '#101010', fontWeight: 600, fontFamily: 'M-Gothic' }}>
HWJ 調1/2

View File

@ -1,13 +1,14 @@
'use client'
import { useSurvey } from '@/hooks/useSurvey'
import { useParams } from 'next/navigation'
import { useParams, useRouter } from 'next/navigation'
import { useEffect } from 'react'
import DetailForm from './DetailForm'
export default function DataTable() {
const params = useParams()
const id = params.id
const router = useRouter()
useEffect(() => {
if (Number.isNaN(Number(id))) {
@ -67,7 +68,7 @@ export default function DataTable() {
<tr>
<th></th>
<td>
<button className="data-down" onClick={() => window.open(`/pdf/survey-sale/${id}`, '_blank')}>
<button className="data-down" onClick={() => router.push(`/pdf/survey-sale/${id}`)}>
HWJ現地調査票確認<i className="down-icon"></i>
</button>
</td>

View File

@ -1,7 +1,7 @@
import getConfigs from '@/config/config.common'
// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 local 환경에 맞는 값을 지정합니다.)
const baseUrl = 'http://localhost:3000'
const baseUrl = 'http://172.30.1.23:3000'
const mode = 'local'
// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다.