
μ΄λ² λ©μΈ νλ‘μ νΈμμ μ μ©νκ² μ΄ sweetAlert!
https://sweetalert2.github.io/
λ±λ‘μ΄λ κ°λ¨ν μλ¦Όμ°½μ κ·Έλ₯ λμμλ λ°μλ€κ° κΈμλ§ λ°κΎΈλ©΄ λλλ°,
μμ λ κ·Έλ₯ μμ νκ±°λ λ°κΉ₯ λλ¬μ λκ±°λ λμ€ νλμλλ°
μμ λ μ‘°κΈ μ λ₯Ό λ¨Ήμλ€..
μμ λ μμ νμκ² μ΅λκΉ? -> ok / cancel λκ°μ§ μ νμ§κ° μλλ°,
μ΄λ€ λ²νΌμ λλ¬λ μμ κ° λλ κ²μ΄λ€
κ·Έλ λ€κ³ μμ -μ·¨μ λ²νΌμ ν¬κΈ°νκ³ μΆμ§ μμμ
κ·Έλ₯ λλ€κ° λ§μ§λ§μ μ΄μ¬ν μ§Έλ €λ³Έ κ²°κ³Ό ꡬννλ°..
β (μ€ν¨ν μ½λ)
Swal.fire({
title: 'μ λ§λ‘ μμ νμκ² μ΅λκΉ?',
text: 'μμ§ λ¬μ±νμ§ λͺ»νμ μλ μμ΄μ!',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'λ€, μμ ν λμ!',
}).then((result) => {
axios
.delete(getURL_GOALS(goalID), getWITH_TOKEN())
.then(() => {
navigate('/goalList');
})
.catch((error) => {
const { message } = error;
enqueueSnackbar(getERROR_TEXT(Number(message.slice(-3))), {
variant: 'error',
});
});
if (result.isConfirmed) {
Swal.fire('μμ λμμ΄μ.', 'See You Again!', 'success');
} else {
GoalDetail();
}
});
βοΈ μμ ν μ½λ (μ±κ³΅1)
const swalWithBootstrapButtons = Swal.mixin({
customClass: {
confirmButton: 'btn btn-success',
cancelButton: 'btn btn-danger',
},
buttonsStyling: true,
});
const goalID = detailData.id;
const goalDelete = () => {
swalWithBootstrapButtons
.fire({
title: 'μ λ§λ‘ μμ νμκ² μ΅λκΉ?',
text: 'μμ§ λ¬μ±νμ§ λͺ»νμ μλ μμ΄μ!',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'λ€, μμ ν λμ!',
cancelButtonText: 'μλμ',
reverseButtons: true,
})
.then((result) => {
if (result.isConfirmed) {
axios.delete(getURL_GOALS(goalID), getWITH_TOKEN());
swalWithBootstrapButtons.fire(
'μμ λμμ΄μ.',
'See You Again!',
'success'
);
navigate('/goalList');
} else {
swalWithBootstrapButtons.fire(
'μ·¨μλμμ΄μ.',
'ν¬κΈ°νμ§ λ§μΈμ!',
'error'
);
}
})
.catch((error) => {
const { message } = error;
enqueueSnackbar(getERROR_TEXT(Number(message.slice(-3))), {
variant: 'error',
});
});
};
μλ¬ μ€λ΅λ°λ μ μ³λκ³ , (μ¬κΈ° λ¨κΈ΄ μ΄μ λ catch μ΄λ μΈμ§ ν·κ°λ¦΄κΉλ΄)
else if (!result.isConfirmed)λ‘ νλ©΄ λλ€
κ·Έκ² κ²°κ΅ if μ else κ·Έ μ체μ΄κΈ° λλ¬Έμ 쑰건문 μμ .
μ²μμ μ μ·¨μλμμ΄μ! μλμ°½μ΄ λμ€μ§ μμλλ° κ·Έ μ΄μ κ°,
μλ¦Όμ°½ μλμ¨ λΆλΆ
else {
swalWithBootstrapButtons.fire(
'μ·¨μλμμ΄μ.',
'ν¬κΈ°νμ§ λ§μΈμ!',
'error'
);
Swal.close();
}
ν΄μ λλ μ alertμ λ¨Όμ μ€ννκ³ λ«μ μ€ μμλλ, κ·Έλ₯ λ«μλ²λ¦¬λλΌ
κ·Έλμ μ λΆλΆμ μ§μ°λκΉ ν΄κ²°!

'TIL > etc.' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[TIL] postman + 곡곡 API λΆλ¬μ€κΈ° (0) | 2023.05.20 |
---|---|
[TIL] Local Storage (0) | 2023.05.19 |
[TIL] AXIOS (0) | 2023.05.18 |
[TIL] λΉκ΅¬μ‘°ν ν λΉ (ꡬ쑰λΆν΄ν λΉ) (0) | 2023.05.18 |
[TIL] Emotion (0) | 2023.05.18 |