Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _onSubmit(formValues) {
const store = this.store;
const save = this._isNew()
? this.createItem
: this.updateItem.bind(this, store.currentItem.id);
this.store.setFormSaving(true);
try {
const resp = await save(formValues);
if (this._isNew()) {
this.props.history.replace("/edit/" + this._getType() + "/" + resp.id);
}
toast.success("Changes saved");
this.store.setFormModalOpen(false);
this.store.setCurrentItem(formValues);
} catch (err) {
console.log(err);
let errorMsg = err.message;
if (err.message === "Conflict") {
errorMsg = "Page with that name already exists";
}
toast.error(errorMsg);
} finally {
this.store.setFormSaving(false);
}
}
}
let form = document.getElementById('submit-form')
if (!form.checkValidity()) {
toast.error('Please complete all fields.')
return
}
try {
await this.props.userActionSignup({
firstName: this.state.firstName,
lastName: this.state.lastName,
username: this.state.username,
email: this.state.email,
password: this.state.password
})
toast.success('Successfully signed up. Please login.');
this.props.history.push('/user/login')
} catch (error) {
console.log(error.message)
if (!error.message) {
toast.error('There was an error connecting to the server. Please try again.')
} else if (error.message === 'DUPLICATE_USERNAME') {
toast.error('Hmm, that username is already in use. Please try another one.')
} else if (error.message === 'DUPLICATE_EMAIL') {
toast.error('Hmm, that email is already in use. Please try another one.')
} else {
toast.error('There was an error connecting to the server. Please try again.')
}
}
}
"x-secret": process.env.REACT_APP_SERVER_SECRET,
}
});
if (!response.ok) {
toast.error('Failed to upload image. Please contact an administrator.');
this.setState({ loading: false });
return;
}
const user = await response.json();
this.props.onChangeImage(this.props.username, user);
this.setState({ loading: false });
this.closeDialog();
toast.success('Image upload success!');
} catch(err) {
console.error(err);
this.setState({ loading: false });
}
}
async function updateQuantity(id, quantity) {
const payload = await moltin.put(`carts/${cartId}/items/${id}`, {
type: 'cart_item',
id,
quantity
})
dispatch({ type: SET_CART, payload })
toast.success(`Quantity updated to ${quantity}`)
}
.then(() => {
toast.success(`Org ${org.name} deleted.`);
})
.catch(err => {
.then(res => {
const user = res.data
dispatch({ type: UPDATE_SETTINGS_SUCCESS })
dispatch({ type: UPDATE_USER_IN_STORE, payload: user })
toast.success(msg, {
position: toast.POSITION.BOTTOM_RIGHT
})
dispatch({ type: CLOSE_MODAL })
})
.catch(err => {
const handleDelete = async id => {
const originalCustomers = [...customers];
setCustomers(customers.filter(customer => customer.id !== id));
try {
await CustomersAPI.delete(id);
toast.success("Le client a bien été supprimé");
} catch (error) {
setCustomers(originalCustomers);
toast.error("La suppression du client n'a pas pu fonctionner");
}
};
event.preventDefault();
let errors = [];
if (bookmark && bookmark.title === "") {
errors.push({ name: "title", msg: "cant be empty" });
}
if (bookmark && bookmark.url === "") {
errors.push({ name: "url", msg: "cant be empty" });
}
setErrors(errors);
const isValid = errors.length === 0;
if (bookmark && isValid) {
const { id, title, url, tag, userId, pinned } = bookmark;
bookmarks.updateBookmark({ id, title, url, tag, userId, pinned });
history.push("/");
toast.success("updated bookmark");
}
};
export const realDataMsg = () => {
toast.success(
<>
{'It\'s a real data.'}
<br>
Your changes have been saved successfully
,
{
bodyClassName: 'toast__real-data',
className: 'toast__real-data',
progressClassName: 'real-data__progressbar',
},
);
};
const onSubmit = async e => {
e.preventDefault();
if (action === "logIn") {
if (email.value !== "") {
try {
const {
data: { requestSecret }
} = await requestSecretMutation();
if (!requestSecret) {
toast.error("You dont have an account yet, create one");
setTimeout(() => setAction("signUp"), 3000);
} else {
toast.success("Check your inbox for your login secret");
setAction("confirm");
}
} catch {
toast.error("Can't request secret, try again");
}
} else {
toast.error("Email is required");
}
} else if (action === "signUp") {
if (
email.value !== "" &&
username.value !== "" &&
firstName.value !== "" &&
lastName.value !== ""
) {
try {