From c78945b44ba8419e15728edf75be6c22edc7f53f Mon Sep 17 00:00:00 2001 From: Akira Date: Sun, 15 Feb 2026 14:34:02 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AE=8C=E4=BA=86=20frontend?= =?UTF-8?q?/src/app/import/page.tsx=20=E3=81=AB=E4=B8=AD=E5=B1=B1=E9=96=93?= =?UTF-8?q?=E3=83=9E=E3=82=B9=E3=82=BF=E5=8F=96=E8=BE=BC=E3=82=BB=E3=82=AF?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F=EF=BC=9A=20-=20State=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0:=20chusankanFile,=20chusankanResult,=20chusankanInput?= =?UTF-8?q?Ref=20-=20=E3=82=A2=E3=83=83=E3=83=97=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=83=89=E9=96=A2=E6=95=B0:=20handleChusankanUpload=20(endpoin?= =?UTF-8?q?t:=20/fields/import/chusankan/)=20-=20UI=E8=BF=BD=E5=8A=A0:=20?= =?UTF-8?q?=E3=80=8C=E4=B8=AD=E5=B1=B1=E9=96=93=E3=83=9E=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E5=8F=96=E8=BE=BC=E3=80=8D=E3=82=BB=E3=82=AF=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=EF=BC=88=E9=BB=84=E8=89=B2=EF=BC=89=20=E3=83=93?= =?UTF-8?q?=E3=83=AB=E3=83=89=E6=88=90=E5=8A=9F=E3=80=82http://localhost:3?= =?UTF-8?q?000/import=20=E3=81=A7=E7=A2=BA=E8=AA=8D=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=BE=E3=81=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/app/import/page.tsx | 126 +++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/frontend/src/app/import/page.tsx b/frontend/src/app/import/page.tsx index 552f50b..9a1dc36 100644 --- a/frontend/src/app/import/page.tsx +++ b/frontend/src/app/import/page.tsx @@ -15,11 +15,14 @@ interface ImportResult { export default function ImportPage() { const [kyosaiFile, setKyosaiFile] = useState(null); const [yoshidaFile, setYoshidaFile] = useState(null); + const [chusankanFile, setChusankanFile] = useState(null); const [uploading, setUploading] = useState(false); const [kyosaiResult, setKyosaiResult] = useState(null); const [yoshidaResult, setYoshidaResult] = useState(null); + const [chusankanResult, setChusankanResult] = useState(null); const kyosaiInputRef = useRef(null); const yoshidaInputRef = useRef(null); + const chusankanInputRef = useRef(null); const handleKyosaiUpload = async () => { if (!kyosaiFile) { @@ -109,6 +112,50 @@ export default function ImportPage() { } }; + const handleChusankanUpload = async () => { + if (!chusankanFile) { + alert('ファイルを選択してください'); + return; + } + + setUploading(true); + setChusankanResult(null); + + try { + const formData = new FormData(); + formData.append('file', chusankanFile); + + const response = await api.post('/fields/import/chusankan/', formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); + + const data = response.data; + setChusankanResult({ + success: true, + message: data.message || 'インポートが完了しました', + created: data.created, + updated: data.updated, + }); + } catch (error: unknown) { + console.error('Upload failed:', error); + let errorMessage = 'アップロードに失敗しました'; + if (error && typeof error === 'object' && 'response' in error) { + const axiosError = error as { response?: { data?: { error?: string } } }; + if (axiosError.response?.data?.error) { + errorMessage = axiosError.response.data.error; + } + } + setChusankanResult({ + success: false, + message: errorMessage, + }); + } finally { + setUploading(false); + } + }; + return (
@@ -195,6 +242,85 @@ export default function ImportPage() { )}
+ {/* 中山間マスタ取込 */} +
+

+ 中山間マスタ取込 +

+

+ 中山間指定データをインポートします(ID, 大字, 字, 地番...) +

+ +
+ setChusankanFile(e.target.files?.[0] || null)} + className="hidden" + /> + + {chusankanFile && ( + + )} +
+ + + + {chusankanResult && ( +
+ {chusankanResult.success ? ( + + ) : ( + + )} +
+

{chusankanResult.message}

+ {chusankanResult.success && chusankanResult.created !== undefined && ( +

+ 作成: {chusankanResult.created}件 / 更新: {chusankanResult.updated}件 +

+ )} +
+
+ )} +
+ {/* 実圃場データ取込 */}