Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleNext = event => {
const { toggleStateVariable } = this.props;
const { activeStep, models, modelName } = this.state;
event.preventDefault();
// If step = 0 then need to check
// If model name exists
if (activeStep === 0) {
if (models.includes(modelName)) {
Swal.fire('Model Already Exists', '', 'info');
return;
}
}
// If step = 2 then model ready to submit
if (activeStep === 2) {
this.postModel();
toggleStateVariable(false, 'createOpen');
}
this.setState(state => ({
activeStep: state.activeStep + 1
}));
};
loadCollections = async () => {
const config = {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`
}
};
try {
const collections = await axios.get('/api/collections/videos', config);
if (collections) {
return collections.data;
}
} catch (error) {
console.log(error);
Swal.fire('Error Getting Collection', '', 'error');
return error;
}
return false;
};
}).then(async result => {
if (result.value) {
try {
await axios.delete(`/api/collections/videos/elements/${id}`, config);
Swal.fire('Deleted!', 'Videos have been removed.', 'success');
this.setState({
data: await this.loadCollections()
});
} catch (error) {
console.log(error);
Swal.fire('Error removing', '', 'error');
}
}
});
};
}).then(async result => {
if (result.value) {
try {
await axios.delete(`/api/collections/videos/elements/${id}`, config);
Swal.fire('Deleted!', 'Videos have been removed.', 'success');
this.setState({
data: await this.loadCollections()
});
} catch (error) {
console.log(error);
Swal.fire('Error removing', '', 'error');
}
}
});
};
removeVideo = async id => {
const { data } = this.state;
const videoList = data.find(col => col.id === id).checked;
console.log(`${id} ${videoList}`);
const config = {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`
},
data: {
videos: videoList
}
};
this.toggle(false, 'CollectionOpen');
Swal.fire({
title: 'Are you sure?',
text: `Removing ${videoList} from Collection ${id}`,
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then(async result => {
if (result.value) {
try {
await axios.delete(`/api/collections/videos/elements/${id}`, config);
Swal.fire('Deleted!', 'Videos have been removed.', 'success');
this.setState({
data: await this.loadCollections()
});
} catch (error) {
const { username, password, admin } = this.state;
event.preventDefault();
const config = {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`
}
};
const body = {
username,
password,
admin
};
try {
const newUserInfo = await axios.post('/api/users', body, config);
console.log(newUserInfo);
Swal.fire(
`Created a new user: ${newUserInfo.data.user.username}`,
'',
'success'
);
history.push('/');
} catch (error) {
console.log(error);
if (error.response) {
Swal.fire(error.response.data.detail, '', 'error');
}
}
};
};
try {
axios
.post(`/api/collections/concepts/${id}`, body, config)
.then(() => {
Swal.fire({
title: 'Saved!',
confirmButtonText: 'Lovely!'
});
this.loadCollections();
})
.catch(() => {
Swal.fire('Could not insert', '', 'error');
});
} catch (error) {
Swal.fire('', error, error);
}
};
}).then(async result => {
if (result.value) {
try {
await axios.delete('/api/models', config);
Swal.fire('Deleted!', 'Video has been deleted.', 'success');
this.loadExistingModels();
} catch (error) {
Swal.fire(error, '', 'error');
}
}
});
};
}).then(async result => {
if (result.value) {
try {
await axios.delete('/api/models', config);
Swal.fire('Deleted!', 'Model has been deleted.', 'success');
this.loadExistingModels();
} catch (error) {
Swal.fire(error, '', 'error');
}
}
});
};
deleteVideoCollection = async id => {
const config = {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`
}
};
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then(async result => {
if (result.value) {
try {
const response = await axios.delete(
`/api/collections/videos/${id}`,
config
);
if (response.status === 200) {
Swal.fire('Deleted!', 'Collection has been deleted.', 'success');