diff --git a/src/pages/playlists/create.jsx b/src/pages/playlists/create.jsx index c23ed70..1ea8ef2 100644 --- a/src/pages/playlists/create.jsx +++ b/src/pages/playlists/create.jsx @@ -4,7 +4,10 @@ import API from '../../services/api'; const ModalCreatePlaylist = ({ opened, handler, addPlaylist }) => { const validated = (item) => { - addPlaylist(item); + if (item) { + addPlaylist(item); + } + console.log("call handler") handler(); }; diff --git a/src/pages/playlists/playlist-view-editor.jsx b/src/pages/playlists/playlist-view-editor.jsx index 80e7764..24fd6df 100644 --- a/src/pages/playlists/playlist-view-editor.jsx +++ b/src/pages/playlists/playlist-view-editor.jsx @@ -5,6 +5,7 @@ import { useState } from 'react'; const PlaylistViewEditor = ({ item, handler, buttonText, APICall }) => { const handleClose = (playlist) => { form.reset(); + console.log('call jiezf'); handler(playlist); }; @@ -25,10 +26,15 @@ const PlaylistViewEditor = ({ item, handler, buttonText, APICall }) => { if (form.validate().hasErrors) return; try { setIsLoading(true); - const res = await APICall(item?.id, { name: form.values.name }); + if (item) { + await APICall(item?.id, { name: form.values.name }); + item.name = form.values.name; + handleClose(item); + } else { + const res = await APICall({ name: form.values.name }); + handleClose(res.data); + } setIsLoading(false); - item.name = form.values.name; - handleClose(item); } catch (error) { setIsLoading(false); // todo