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}件 +

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