260303_01_ENH: TanStack Query 적용
This commit is contained in:
@@ -8,10 +8,8 @@ import {
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { useState, useRef } from 'react'
|
||||
import {Download, Upload, X} from 'lucide-react'
|
||||
import { useLoading } from '@/hooks/useLoading'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import type { DialogId } from '@/store/jotai/dialog'
|
||||
import {apiError} from "@/lib/http-util";
|
||||
@@ -35,14 +33,14 @@ const UserUploadDialog = ({
|
||||
onUpload,
|
||||
onDownloadTemplate,
|
||||
}: UserUploadDialogProps) => {
|
||||
const { withLoadingAsync } = useLoading()
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog()
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog();
|
||||
|
||||
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [selectedFile, setSelectedFile] = useState<File | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
//실제 Dialog에 넘길 open값 (props 우선, 없으면 jotai 사용)
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId);
|
||||
|
||||
// open change 공통 처리 (부모 콜백 + jotai 동시 반영)
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
@@ -92,23 +90,23 @@ const UserUploadDialog = ({
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedFile) {
|
||||
alert('파일을 선택해주세요.')
|
||||
return
|
||||
alert("파일을 선택해주세요.");
|
||||
return;
|
||||
}
|
||||
|
||||
withLoadingAsync(async () => {
|
||||
try {
|
||||
await onUpload(selectedFile)
|
||||
// 성공 시 초기화 + 닫기
|
||||
handleRemoveFile()
|
||||
handleOpenChange(false)
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
alert('업로드에 실패했습니다.')
|
||||
}
|
||||
})
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await onUpload(selectedFile);
|
||||
handleRemoveFile();
|
||||
handleOpenChange(false);
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
alert("업로드에 실패했습니다.");
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
// ✅ Dialog에서 닫힐 때: 파일도 초기화 + 상태 닫기
|
||||
const handleDialogOpenChange = (nextOpen: boolean) => {
|
||||
@@ -171,11 +169,7 @@ const UserUploadDialog = ({
|
||||
|
||||
<DialogFooter>
|
||||
<div className="flex items-center justify-end w-full gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={!selectedFile}
|
||||
>
|
||||
<Button type="button" onClick={handleSubmit} disabled={!selectedFile || submitting}>
|
||||
확인
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user