ChananelAzenkot / Final-Project-Full-Stack-Developer-App

The Final Project - integrates React for front-end and Node.js with MongoDB for back-end. Utilizes Bcrypt, Joi, JWT, Config, Morgan, Cors, Chalk, Mongoose for secure, scalable web apps. Demonstrates full stack proficiency, epitomizing modern development standards.
0 stars 0 forks source link

the MyOperation is not refreshing when the created operation come in #1

Open ChananelAzenkot opened 5 months ago

ChananelAzenkot commented 5 months ago

the my operation component :

const [operation, setOperation] = useState([]); useEffect(() => { fetch(http://localhost:4000/api/operationId, { credentials: "include", method: "GET", headers: { "Content-type": "application/json", Authorization: localStorage.token, }, }) .then((res) => res.json()) .then((data) => { setOperation(data); }); }, []); My operation create component handleSubmit

const handleSubmit = (e) => { e.preventDefault(); const { error } = schemaOperations.validate(formData); if(error){ snackbar(error.details[0].message); return; } fetch( http://localhost:4000/api/dailyOperationAgentStart, { credentials: "include", method: "POST", headers: { "Content-type": "application/json", 'Authorization': localStorage.token, }, body: JSON.stringify(formData), } ) .then((data) => { setFormData(data); localStorage.setItem('submitTime', new Date()); setOperation([...operation, data]); snackbar("the card was created successfully !"); navigate('/dailyOperation'); setDisabled(true); handleClose(); calculatePercentageTVcreate(formData, setFormData); calculatePercentageFiberCreate(formData, setFormData); }); };

ChananelAzenkot commented 5 months ago

To fix the problem to navigate to the daily operation is to set time out:

setTimeout(() => {
 window.location.href = "/dailyOperation";