woocommerce graphql registerUser, sometime work something dont - woocommerce

i am sending data to make woocommerce graphql reigster a user, but sometimes it work some time it dont, speicalily once i succesful register a user, then right ahead to register again it wont register again. after i wait a while or refresh the page, it can be register again, is woocommerce graphql have somekind of delay system to prevent register spam, so i know is not my code problem. here is my code
const [username, setUsername] = useState('')
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [registerUser, { data, error, isLoading }] = client.useMutation((mutation, args: FormData) => {
const result = mutation.registerUser({
input: args,
})
console.log('REsult', result)
return result.user
})
const handleSubmit = async (event) => {
event.preventDefault()
await registerUser({
args: {
username,
email,
password,
},
})
.catch((error) => {
console.log('error:', error)
})
.then((response) => {
console.log('response:', response)
})
}
useEffect(() => {
console.log(data)
setUsername('')
setEmail('')
setPassword('')
}, [data])
here is my html:
return (
<div className="ps-page--default">
<form className="ps-form--auth" id="register__tab">
<div className="ps-tabs">
<div id="tab-2">
<div className="form-group form-group--space">
<input
className="form-control"
name="username"
id="register__tab--username"
type="text"
placeholder="What should we call you ?"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
</div>
<div className="form-group form-group--space">
<input
className="form-control"
name="email"
id="register__tab--email"
type="email"
placeholder="Enter your email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div className="form-group form-group--space">
<input
className="form-control"
name="password"
id="register__tab--password"
type="text"
placeholder="Create a password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
<div className="ps-form__desc">
<p>Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our privacy policy.
</p>
</div>
<div className="form-group submit">
<button type="submit" className="ps-btn ps-btn--fullwidth ps-btn--black" disabled={isLoading} onClick={handleSubmit}>
{isLoading ? 'Signing up...' : 'Sign up'}
</button>
</div>
</div>
</div>
</form>
</div>
)
do anyone know what do i miss ? or is just part of woocommerce graphql setting ?
the only error show on my console.log are this
[gqty] Warning! No data requested.
resolved2 # resolvers.mjs?c4ac:167
others are all my successful return

Related

How can I render user's input (which is stored in an array) with LINE BREAKS using react.js?

I've been trying to render {ingredients} with line breaks, each time the user presses Enter and keys in another ingredient. I've been getting all the user's inputs in one line e.g. grapeonionlettuce I'm not sure what, where or how to add code so that it'll have line breaks - tried using CSS too, by referencing the className return-ingredients-list and using white-space etc. but to no avail. Please help, thanks in advance, if possible.
//import { useState} from "react";
//import {Paper} from "#material-ui/core";
const {useState} = React;
const CRBUploadRecipe = () => {
const [recipeName, setRecipeName] = useState("");
const [selectedFile, setSelectedFile] = useState(undefined);
const [ingredients, setIngredients] = useState([]);
const handleEnterKeyPress = (e) => {
if(e.which === 13) {
const input = document.getElementById("ingredients");
setIngredients([input.value, ...ingredients])
console.log(ingredients)
}
};
return (
<div>
{/*<Paper elevation={12}>*/}
<div className="upload-recipe">
<form>
<label htmlFor="form-title" className="form-title">
Share to the Community <br/>
<input id="recipe-name" type="text" value={recipeName} placeholder="Recipe name"
onChange={e => setRecipeName(e.target.value)}
/>
</label>
<label htmlFor="upload-image" className="upload-image">
Upload image <br/>
<input id="upload-image" type="file" value={selectedFile}
onChange={e => setSelectedFile(e.target.files[0])}
/>
</label>
<label htmlFor="ingredients" className="ingredients">
Ingredients <br/>
<input id="ingredients" type="text" placeholder="Write ingredients"
onKeyPress={handleEnterKeyPress} />
</label>
<div className="return-ingredients-list">
{ingredients}
</div>
</form>
</div>
{/*</Paper>*/}
</div>
);
};
ReactDOM.render(
<div>
DEMO
<CRBUploadRecipe />
</div>,
document.getElementById("rd")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.0/umd/react-dom.production.min.js"></script>
<div id="rd" />
<div id="ingredients"></div>
first of all don't use document.getElementById("ingredients") in react app.
second of all you can put each ingredient in paragraph or div;
import { useState} from "react";
import {Paper} from "#material-ui/core";
const CRBUploadRecipe = () => {
const [recipeName, setRecipeName] = useState("");
const [selectedFile, setSelectedFile] = useState(undefined);
const [ingredients, setIngredients] = useState([]);
const handleEnterKeyPress = (e) => {
if(e.which === 13) {
const input = e.target; // your handler already has access to input;
setIngredients((prev) => [input.value, ...prev])
console.log(ingredients)
}
}
return (
<Paper elevation={12}>
<div className="upload-recipe">
<form>
<label htmlFor="form-title" className="form-title">
Share to the Community <br/>
<input id="recipe-name" type="text" value={recipeName} placeholder="Recipe name"
onChange={e => setRecipeName(e.target.value)}
/>
</label>
<label htmlFor="upload-image" className="upload-image">
Upload image <br/>
<input id="upload-image" type="file" value={selectedFile}
onChange={e => setSelectedFile(e.target.files[0])}
/>
</label>
<label htmlFor="ingredients" className="ingredients">
Ingredients <br/>
<input id="ingredients" type="text" placeholder="Write ingredients"
onKeyPress={handleEnterKeyPress} />
</label>
<div className="return-ingredients-list">
{ingredients.map((ingridient, id) => (<p key={id}>{ingridient}</p>)}
</div>
</form>
</div>
</Paper>
);
}
export default CRBUploadRecipe;

vue js realtime chat app without refreshing / firebase

I'm creating a chat app,
If the user enter message and press send button, the app is working fine. The informations going to the database and im taking a datas.
When the user refresh the page, so there is no problem, in mounted() instance im taking the datas from database(firebase) and im showing on the app. If another user comes to the chat, also there is no problem, all messages are appearing.
The problem is that: If the new message is coming, another user can not see it without refresh or without send message button. When the another user send a message then the user see all messages.
I explain the problem with a gif, if you help me i will be glad.
<template>
<div>
<div class="container">
<div class="row">
<div v-if="isLogin" class="offset-3 col-md-6 msg-area">
<header>
<h1>Group Chat</h1>
<p class="sm">Welcome, {{this.username }} </p>
</header>
<div class="msg">
<p class="mssgs" v-for="(message,index) in messages" :key="index">{{ message.msg }} <br> <span> {{ message.name }} - {{ message.time }} </span> </p>
</div>
<div class="sendMsg">
<form #submit.prevent="sendFunc">
<div class="form-group d-flex">
<input type="text" class="form-control" placeholder="Enter message.." v-model="msgInput">
<button class="btn">Send </button>
</div>
</form>
</div>
</div>
<div class="offset-3 col-md-6 login" v-else>
<form #submit.prevent="joinFunc">
<div class="form-group d-flex">
<input type="text" class="form-control" placeholder="Enter username.." v-model="username">
<button class="btn">Join to Group </button>
</div>
</form>
</div>
</div>
</div>
</div>
</template>
<script>
import firebase from "./firebase";
import 'firebase/firestore';
export default {
data() {
return {
db : firebase.firestore(),
isLogin: false,
username: '',
messages : [
],
msgInput: '',
}
},
methods: {
joinFunc() {
this.isLogin = true;
},
sendFunc() {
let date = new Date();
let hour = date.getHours();
let minute = date.getMinutes();
let nowTime = hour + ':' + minute;
this.db.collection("messages")
.add({ message: this.msgInput, name: this.username, time: nowTime, date: date })
.then(() => {
this.db.collection("messages").orderBy("date", "asc")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
this.messages.push({
name: doc.data().name,
msg: doc.data().message,
time: doc.data().time
});
});
})
})
.catch((error) => {
console.error("Error writing document: ", error);
});
},
},
mounted: function() {
this.db.collection("messages").orderBy("date", "asc")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
this.messages.push({
name: doc.data().name,
msg: doc.data().message,
time: doc.data().time
});
});
})
}
}
</script>
You're using get() to read the data from Firestore. As the documentation I linked explains, that reads the value from the database once, and does nothing more.
If you want to continue listening for updates to the database, you'll want to use a realtime listener. By using onSnapshot() your code will get called with a querySnapshot of the current state of the database right away, and will then also be called whenever the database changes. This is the perfect way to then update your UI.
So instead of
...
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
Do the following:
...
.onSnapshot((querySnapshot) => {
querySnapshot.forEach((doc) => {

Firebase Auth - ConfirmPasswordReset, how to grab oobcode from URL to pass thorugh function?

I'm trying to implement a reset password Page on my website using firebase auth. I got the send email to reset password page working. Now from what I understand you get an email with a link that you need to click and on this email there will be a code that is needed to reset the password. Now I'm at a loss on how to grab said code from the url and already display it for the user on the field. Is it possible to have the code come in the body of the email and have the user input the code? If not, how do I grab the code from the url and input it for the user so the user can only input the password? My website is using vue and this is what I have so far
<template>
<div class="container">
<h3>reset pw page</h3>
<div class="row">
<form #submit.prevent="ResetPw()" class="col s12">
<div class="row">
<div class="input-field col s12">
<input type="password" id="password" v-model="password" />
<label>Password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="text" id="code" v-model="code" />
<label>Code</label>
</div>
</div>
<button type="submit" class="btn">Submit</button>
</form>
</div>
</div>
</template>
<script>
import firebase from "firebase/app";
export default {
data() {
return {
password: "",
code: ""
};
},
methods: {
ResetPw() {
firebase
.auth()
.confirmPasswordReset(this.code, this.password)
.then(() => {
console.log(`Password Changed!`);
})
.catch(err => console.log(err));
}
}
};
</script>
I think I got everything done, I just need to understand how to grab the oobcode from the link https://my-project.firebaseapp.com/__/auth/action?mode=&oobCode=
If you are using react-router, it does not parse the query any more, but you can access it via location.search
const params = new URLSearchParams(this.props.location.search);
const code = params.get('oobCode')
const email = await firebase.auth().verifyPasswordResetCode(code)
Alternatively, instead of using this.props.location.search, you can do new URLSearchParams(window.location.pathname)
Not sure how to grab the oobCode from the body of the email but to grab the code from the URL once the page loads, you can refer to this question: how-can-i-get-query-string-values-in-javascript. In your form, create a hidden input for the code with an empty string value. Once window loads, code will be grabbed from URL and then you can pass the code and password into the function
<body>
<form>
<input type="text" id='newPass' name='newPass' placeholder='New password'>
<input type="hidden" id='code' name='code' value="">
<button type='submit'>Submit</button>
</form>
</body>
<script>
$(window).load(function () {
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
var code = getParameterByName('oobCode')
document.getElementById('code').value = code;
</script>
Hope this helps!

Any Crud example for Meteor and react with SimpleSchema

I make a simple page where data is inserted into database by a form using Refs of react.Can any body help me out how i can insert the data using aldeed:Simple schema or any curd example using that package.
please check my simple code for insertion.
import React,{Component} from 'react';
import {DoctorsList} from '../../../api/lists/DoctorsList.js';
export class DoctorCreate extends Component
{
addDoctor(event){
event.preventDefault();
var text= this.refs.DoctorName.value.trim();
console.log(text);
DoctorsList.insert({
name:text,
createdAt: new Date(),
owner: Meteor.userId(), // _id of logged in user
username: Meteor.user().username, // username of logged in user
});
this.refs.DoctorName.value="";
}
render()
{
return (
<div className="container">
<div className="row">
<div className="col-sm-12">
<form className="form" onSubmit={this.addDoctor.bind(this)}>
<div className="form-group">
<label> Name</label>
<input ref="DoctorName" type="text" className="form-control" placeholder="name..."/>
</div>
<div className="form-group">
<input type="submit" value="save" className="btn btn-primary"/>
</div>
</form>
</div>
<br/>
<a href="/doctors" >Back to list </a>
<hr/>
</div>
</div>
)
}
}
Thanks in advance.
Meteor official TODOs app is using simple schema. Link to github source https://github.com/meteor/todos/blob/1.3-module-exports/imports/api/lists/methods.js

Form validation in meteorjs

I am doing simple validation of inputs in meteorjs, after first tour it works, and every next time it doesn't work (until I reload the page) – it means error messages are not displayed.
//main.js//
Template.addMealForm.events({
'click #submitNewMeal': function (ev) {
ev.preventDefault();
var query = {
name: $("#name").val().trim(),
price: $("#price").val(),
calories: $("#calories").val(),
category: $("#category").val()
};
areInputsValid(query);
}
});
var areInputsValid = function (query) {
if ((query.name.length === 0) || (query.price.length === 0) || (query.calories.length === 0)) {
$("#warningLabel").addClass("di")
$(".warningLabel").text("All fields are required");
}
else if ((isNaN(query.price) === true) || (isNaN(query.calories) === true)) {
$("#warningLabel").addClass("di")
$(".warningLabel").text("To Price and Calories fields please enter a number");
}
else {
console.log('it works');
$('.dn').hide();
}
};
//main.html//
<template name="addMealForm">
<form role="form">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control input_form" id="name" placeholder="Name of the meal">
</div>
<div class="form-group">
<label for="price">Price</label>
<input class="form-control input_form" id="price" placeholder="Price">
</div>
<div class="form-group">
<label for="calories">Calories</label>
<input class="form-control input_form" id="calories" placeholder="Calories">
</div>
<div id="warningLabel" class="form-group has-error dn">
<label class="control-label warningLabel"></label>
</div>
<button id="submitNewMeal" type="submit" class="btn btn-rimary">Add</button>
</form>
</template>
The problem is that you are calling $('.dn').hide() in the success case. Because #warningLabel has a class of dn it will not be displayed again on subsequent errors.
One solution is to add $('.dn').show() to the top of areInputsValid.
You already have Tracker as part of Meteor, so I put a little tutorial and JSfiddle together on how to use it to implement a typical form validation scenario.
http://bit.ly/meteor-form-validation-video
http://bit.ly/meteor-form-validation-fiddle

Resources