Skip to content
Back

user input not storing in appwrite

  • 1
  • Web
Hmm
3 Apr, 2023, 13:04

create a appwriteconfig file and define all the initial content there

TL;DR
User is seeking help with storing user input in Appwrite. They have created a separate file for Appwrite initialization and need guidance on implementing the code. They are asking for assistance in implementing and improving the code provided. Suggestions are made to manage state and lift the state to handle user submissions. It is recommended to either get all the information at once and store it in the database or update the database when data is provided to each component. The user also asks about storing user details in a specific order and storing different inputs from different components. The solution is to import necessary variables like databaseID, projectId, and client and pass them where needed.
Maniac_Fighter
3 Apr, 2023, 13:04

Don't know much about web but you could make a global variable

Maniac_Fighter
3 Apr, 2023, 13:04

and just pass this everywhere

Hmm
3 Apr, 2023, 13:04

and import things like databaseID projectId and client

Hmm
3 Apr, 2023, 13:04

whatever u need

bharath
3 Apr, 2023, 13:04

but i want to store different inputs from different components

Hmm
3 Apr, 2023, 13:05

thats not a issue since client will be same

bharath
3 Apr, 2023, 13:05

i want to user in one collection

bharath
3 Apr, 2023, 13:07

https://printfc.in/ is my website once go through it please Printfc.in Web site created using create-react-app In my website user will signup and uploads his files and he will enter number of copies and next component he needs to select print type like b/w or color I need to store all the user details to get them print All the user inputs should store in an order 1.username 2.emailid 3.userfiles 4.number of pages 5.number of copies 6.b/w or color 7.front or both sides 8.price 9.total price In which section of appwrite can I store all of this except files cause that will be stored in storage

bharath
3 Apr, 2023, 13:08

@Hmm once go through it

Maniac_Fighter
3 Apr, 2023, 13:16

looks like you are creating a form. It's all about how you manage your state. Either get all the information at first and then store in the database or write to the database when data is given to every component. In the latter approach you need to keep hold of the database id so you can update it later

bharath
3 Apr, 2023, 14:28

How to implement it

Hmm
3 Apr, 2023, 14:34

You should lift the state and only write to the document when the user submit the data

Hmm
3 Apr, 2023, 14:35

until then store the user emails and other preferences inside global state

Hmm
3 Apr, 2023, 14:35

and pass the handlers as prop to specfic components

bharath
3 Apr, 2023, 14:35

Iam not using preferences

Hmm
3 Apr, 2023, 14:36

by preferences I mean the color , side etc

bharath
3 Apr, 2023, 14:36

Ok

bharath
3 Apr, 2023, 14:37
TypeScript
import { Client, Databases,ID } from "appwrite";
const Select = () => {
  const[color,setcolor]=useState("");
  const[side,setside]=useState("");
  const handleChange = (event) => {
    event.preventDefault();
  const client = new Client()
  client.setEndpoint('https://api.printfc.in/v1') // Your API Endpoint
  .setProject('');
  const databases = new Databases(client);
  const promise = databases.updateDocument(
      '',
      '',
      ID.unique(),
 {    
     color,
     side
    
      }
  );
  
  promise.then(function (response) {
      console.log(response);
  }, function (error) {
      console.log(error);
  });
}```
bharath
3 Apr, 2023, 14:37

can you say how to implement in this code

Hmm
3 Apr, 2023, 14:53

First of all create a separate file for appwrite initialisation and make the file cleaner and create handler on main file , all the specific states should be present in their components and pass the data to handler

bharath
3 Apr, 2023, 14:59

1.created a seperate file for appwrite initialisation

bharath
3 Apr, 2023, 14:59

done

bharath
3 Apr, 2023, 15:00

2.create handler on main file????

bharath
3 Apr, 2023, 15:03

@Binyamin help me please

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more