fix update/create playlist

This commit is contained in:
grimhilt 2023-08-01 22:31:01 +02:00
parent 1efa52321a
commit a84a6f836a
2 changed files with 13 additions and 4 deletions

View File

@ -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();
};

View File

@ -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