qcast-front/src/hooks/useSwal.js
ysCha c2d8aeb572 [2089] useSwal alert html 지원 + 저구배 경고 줄바꿈 수정
- useSwal alert 분기에 html 옵션 지원 추가 (html 있으면 html, 없으면 text)
- roof-pitch-warning: text → html + \n을 <br>로 치환하여 줄바꿈 렌더링
- ja.json: 構造物 → 架台 용어 수정 + \n 추가
- ko.json: 문구 다듬기 + \n 추가
2026-06-04 09:46:47 +09:00

63 lines
1.6 KiB
JavaScript

import Swal from 'sweetalert2'
import withReactContent from 'sweetalert2-react-content'
import { useMessage } from '@/hooks/useMessage'
/**
* title: 제목
* text: 내용
* html: html
* type: alert, confirm
* icon: icontype (success, error, warning, info, question)
* confirmFn: 확인 버튼 클릭 시 실행할 함수
* denyFn: 취소 버튼 클릭 시 실행할 함수
* @returns
*/
export const useSwal = () => {
const MySwal = withReactContent(Swal)
const { getMessage } = useMessage()
const swalFire = ({
title = '',
text = '',
html = '',
type = 'alert',
icon = '',
confirmButtonText = '',
cancelButtonText = '',
confirmFn = () => {},
denyFn = () => {},
}) => {
if (type === 'alert') {
MySwal.fire({
title,
...(html ? { html } : { text }),
icon: icon === '' ? 'success' : icon,
confirmButtonText: getMessage('common.ok'),
}).then(() => {
confirmFn()
})
} else if (type === 'confirm') {
MySwal.fire({
title,
text,
html,
icon: icon === '' ? 'question' : icon,
showCloseButton: true,
showCancelButton: true,
confirmButtonText: confirmButtonText === '' ? getMessage('common.ok') : confirmButtonText,
cancelButtonText: cancelButtonText === '' ? getMessage('common.cancel') : cancelButtonText,
}).then((result) => {
if (result.isConfirmed) {
confirmFn()
} else if (result.isDismissed) {
denyFn()
}
})
}
}
return {
swalFire,
}
}