Open helfreitas opened 1 month ago
// UserForm.js import React, { useState } from 'react'; import UserService from '../services/UserService';
const UserForm = () => { const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [street, setStreet] = useState(''); const [city, setCity] = useState(''); const [state, setState] = useState('');
const handleSubmit = async (event) => { event.preventDefault(); const user = { name, email, password, address: { street, city, state } }; try { await UserService.createUser(user); // Handle success } catch (error) { // Handle error } }; return ( <form onSubmit={handleSubmit}> {/* Form fields for name, email, password, street, city, and state */} <button type="submit">Criar Usuário</button> </form> );
};
export default UserForm;
// UserService.js import axios from 'axios';
const API_URL = 'http://localhost:8080/users'; // Replace with your actual API URL
class UserService { static createUser(user) { return axios.post(API_URL, user); }
// ... other methods for getting, updating, and deleting users
}
export default UserService;
add description to your issue properly.
// UserForm.js
import React, { useState } from 'react';
import UserService from '../services/UserService';
const UserForm = () => {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [street, setStreet] = useState('');
const [city, setCity] = useState('');
const [state, setState] = useState('');
};
export default UserForm;
// UserService.js
import axios from 'axios';
const API_URL = 'http://localhost:8080/users'; // Replace with your actual API URL
class UserService {
static createUser(user) {
return axios.post(API_URL, user);
}
}
export default UserService;