feat: add data for download survey-sale pdf
This commit is contained in:
parent
6d837d3e98
commit
67ba964eec
@ -1,8 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useRef } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import generatePDF, { Margin, Resolution } from 'react-to-pdf'
|
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 { useSurvey } from '@/hooks/useSurvey'
|
||||||
import { radioEtcData, roofMaterial, selectBoxOptions, supplementaryFacilities } from '../survey-sale/detail/RoofForm'
|
import { radioEtcData, roofMaterial, selectBoxOptions, supplementaryFacilities } from '../survey-sale/detail/RoofForm'
|
||||||
|
|
||||||
@ -11,13 +11,18 @@ export default function SurveySaleDownloadPdf() {
|
|||||||
const id = params.id
|
const id = params.id
|
||||||
|
|
||||||
const { surveyDetail, isLoadingSurveyDetail } = useSurvey(Number(id))
|
const { surveyDetail, isLoadingSurveyDetail } = useSurvey(Number(id))
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
useEffect(() => {
|
const router = useRouter()
|
||||||
if (isLoadingSurveyDetail) return
|
|
||||||
handleDownPdf()
|
|
||||||
}, [surveyDetail, isLoadingSurveyDetail])
|
|
||||||
|
|
||||||
const targetRef = useRef<HTMLDivElement>(null)
|
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 handleDownPdf = () => {
|
||||||
const options = {
|
const options = {
|
||||||
method: 'open' as const,
|
method: 'open' as const,
|
||||||
@ -41,14 +46,30 @@ export default function SurveySaleDownloadPdf() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
generatePDF(targetRef, options)
|
generatePDF(targetRef, options).then(() => {
|
||||||
// generatePDF(targetRef, { filename: 'page.pdf' })
|
router.push(`/survey-sale/${id}`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* <button onClick={handleDownPdf}>down</button> */}
|
<button onClick={handleDownPdf}>down</button>
|
||||||
<div ref={targetRef} style={{ boxSizing: 'border-box' }}>
|
<div
|
||||||
<div style={{ margin: '0 auto', padding: 0, maxWidth: '800px', minWidth: '800px' }}>
|
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={{ padding: '20px 20px 50px', borderBottom: '2px solid #2E3A59' }}>
|
||||||
<div style={{ float: 'left', verticalAlign: 'middle', fontSize: '18px', color: '#101010', fontWeight: 600, fontFamily: 'M-Gothic' }}>
|
<div style={{ float: 'left', verticalAlign: 'middle', fontSize: '18px', color: '#101010', fontWeight: 600, fontFamily: 'M-Gothic' }}>
|
||||||
HWJ 現地調査シート1/2
|
HWJ 現地調査シート1/2
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useSurvey } from '@/hooks/useSurvey'
|
import { useSurvey } from '@/hooks/useSurvey'
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams, useRouter } from 'next/navigation'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import DetailForm from './DetailForm'
|
import DetailForm from './DetailForm'
|
||||||
|
|
||||||
export default function DataTable() {
|
export default function DataTable() {
|
||||||
const params = useParams()
|
const params = useParams()
|
||||||
const id = params.id
|
const id = params.id
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Number.isNaN(Number(id))) {
|
if (Number.isNaN(Number(id))) {
|
||||||
@ -67,7 +68,7 @@ export default function DataTable() {
|
|||||||
<tr>
|
<tr>
|
||||||
<th>ダウンロード</th>
|
<th>ダウンロード</th>
|
||||||
<td>
|
<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>
|
HWJ現地調査票確認<i className="down-icon"></i>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import getConfigs from '@/config/config.common'
|
import getConfigs from '@/config/config.common'
|
||||||
|
|
||||||
// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 local 환경에 맞는 값을 지정합니다.)
|
// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 local 환경에 맞는 값을 지정합니다.)
|
||||||
const baseUrl = 'http://localhost:3000'
|
const baseUrl = 'http://172.30.1.23:3000'
|
||||||
const mode = 'local'
|
const mode = 'local'
|
||||||
|
|
||||||
// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다.
|
// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user