Files
a301_client/src/components/confirm/ConfirmProvider.jsx
tolelom 4e0716c1cb refactor: components/ 정리
- ConfirmProvider useMemo 불필요한 래핑 제거
- DownloadAdmin useCallback 적용, toast 중복 제거, eslint-disable 정리
- UserAdmin useCallback 적용, PAGE_SIZE 컴포넌트 밖으로 이동, 페이지네이션 버튼 가독성 개선
- UploadForm 에러 처리 fail 헬퍼로 중복 제거
- DownloadSection 후행 빈 줄 제거

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 19:17:17 +09:00

45 lines
1.4 KiB
JavaScript

import { useState, useCallback, useRef } from 'react';
import { ConfirmContext } from './confirmContextValue';
import './Confirm.css';
export function ConfirmProvider({ children }) {
const [dialog, setDialog] = useState(null);
const resolveRef = useRef(null);
const confirm = useCallback((message) => {
return new Promise((resolve) => {
resolveRef.current = resolve;
setDialog({ message });
});
}, []);
const handleConfirm = useCallback(() => {
resolveRef.current?.(true);
resolveRef.current = null;
setDialog(null);
}, []);
const handleCancel = useCallback(() => {
resolveRef.current?.(false);
resolveRef.current = null;
setDialog(null);
}, []);
return (
<ConfirmContext.Provider value={confirm}>
{children}
{dialog && (
<div className="confirm-overlay" onClick={handleCancel}>
<div className="confirm-dialog" role="alertdialog" aria-modal="true" aria-label={dialog.message} onClick={(e) => e.stopPropagation()}>
<p className="confirm-message">{dialog.message}</p>
<div className="confirm-actions">
<button className="confirm-btn confirm-btn-cancel" onClick={handleCancel}>취소</button>
<button className="confirm-btn confirm-btn-ok" onClick={handleConfirm} autoFocus>확인</button>
</div>
</div>
</div>
)}
</ConfirmContext.Provider>
);
}