Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
submit = (e) => {
e.preventDefault();
this.setState({ pressed: true });
this.validate.forEach(el => el._reactInternalInstance._renderedComponent._instance.validate()); // eslint-disable-line no-underscore-dangle, max-len
if (this.state.maxValid !== this.state.numValid) {
return;
}
const { username, email, password } = this.state;
Relay.Store.commitUpdate(new RegisterUserMutation({ username, email, password }), {
onSuccess: ({ registerUser: res }) => {
if (res.error) {
this.setState({ error: res.error });
return;
}
this.setState({ error: '' });
fetch('/login/local', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
credentials: 'same-origin',
body: JSON.stringify({
return new Promise((resolve, reject) => {
// Note: tried to use primeCache, works fine for the first req, but fails for the 2nd
// (Relay.Store as any).primeCache({query: request._query}, readyState => {
let data: any[] = []
let cachedData = (Relay.Store as any).readQuery(request._query)
if (cachedData && cachedData.length && cachedData[0] && cachedData[0].recentMessages) {
const messagesToPush = pushMessagesStore.getState().messagesToPush
data = data.concat(cachedData[0].recentMessages).concat(messagesToPush)
pushMessagesStore.dispatch({ type: 'CLEAR_MESSAGES'})
const response = { 'data': { 'root': { 'recentMessages': data } } }
const jsonResponsePromise = new Promise((res) => {
res({ json: () => { return response } })
})
resolve(jsonResponsePromise)
} else {
resolve(super._sendQuery(request))
}
})
}
_handleCreatePost(data) {
Relay.Store.commitUpdate(new PostMutations({
viewer: this.props.root,
data: data,
}), {onFailure, onSuccess});
const _this = this;
const onSuccess = () => {
_this.setState({
formToggled: false,
});
};
const onFailure = (transaction) => {
const error = transaction.getError() || new Error('Mutation failed.');
console.error(error);
_this.setState({
var resto = restaurant.toJS();
delete resto.__dataID__;
delete resto.orders;
resto.schedule.map(object => {
delete object.__dataID__;
object.openHours.map(op => delete op.__dataID__);
});
console.log('resto', resto);
var onFailure = () => {
console.log('onFailure');
};
var onSuccess = () => {
console.log('onSuccess');
this.setState({save: false});
};
Relay.Store.commitUpdate(new UpdateRestaurantMutation({restaurant: resto}), {onFailure, onSuccess});
};
//
_logout = () => {
console.log('LoginButton:Logout', this.props);
//the easiest way to logout is to login with unknown user
Relay.Store.update(new LoginMutation({credentials: {pseudo:'', password:''}, user: this.props}));
};
_expand = () => {
render() {
return (
Relay.QL`query { viewer }`},
params: {projectId: this.props.projectId, close: this.props.close},
}}
/>
)
}
}
.forEach((edge) => Relay.Store.commitUpdate(
new DeleteTodoMutation({
id: edge.node.id,
viewer: this.props.viewer,
})
));
};
handleInputSave = (text) => {
Relay.Store.commitUpdate(
new AddTodoMutation({
text,
viewer: this.props.viewer,
}),
);
}
return new Promise((resolve, reject) => {
Relay.Store.commitUpdate(new RegisterMutation({
input: {
username: username,
password: password
},
user: null
}), {
onSuccess: (data) => {
resolve(login(username, password));
},
onFailure: (transaction) => {
reject(transaction.getError().message);
}
});
})
}
_saveComment(event) {
event.preventDefault();
if (!this.props.comment.is_owner) return;
const onFailure = (transaction) => {
const error = transaction.getError() || new Error('Mutation failed.');
alert(error);
};
const onSuccess = () => {
this.setState({ editing: false });
};
if (event.keyCode === 13) {
Relay.Store.commitUpdate(new EditComment({
id: this.props.comment.id,
body: event.target.value,
}), { onFailure, onSuccess });
}
}