@@ -2,6 +2,7 @@ import React, { Component } from 'react';
22import DefaultLayout from '../../layouts/Default' ;
33import Task from './task' ;
44import TaskAdd from './task/add.js' ;
5+ import Swal from 'sweetalert2/dist/sweetalert2.js' ;
56import './css/index.css' ;
67
78class Index extends Component {
@@ -49,20 +50,25 @@ class Index extends Component {
4950 * TODO: Use Bootstrap alerts instead of default JS window.prompt
5051 * @param {number } taskId
5152 */
52- editTask ( taskId ) {
53- const name = window . prompt ( 'Enter task name' ) ;
53+ async editTask ( taskId ) {
54+ const tasks = this . state . tasks ;
5455
55- /** User cancels prompt */
56- if ( name === null ) return ;
56+ const { value : taskName } = await Swal . fire ( {
57+ title : 'Edit task' ,
58+ input : 'text' ,
59+ inputValue : tasks [ taskId ] . name ,
60+ showCancelButton : true ,
61+ inputValidator : ( value ) => {
62+ if ( ! value ) {
63+ return 'Task name cannot be empty!'
64+ }
65+ }
66+ } ) ;
5767
58- /** User sets name as empty */
59- if ( name . trim ( ) === '' ) {
60- alert ( 'Task name cannot be empty' ) ;
61- return ;
62- }
68+ /** User clicks cancel button */
69+ if ( typeof ( taskName ) === 'undefined' ) return ;
6370
64- const tasks = this . state . tasks ;
65- tasks [ taskId ] . name = name ;
71+ tasks [ taskId ] . name = taskName ;
6672 this . setTasks ( tasks ) ;
6773 }
6874
0 commit comments