Skip to content

Commit

Permalink
Merge pull request #20 from tsheporamantso/Minor-adjustments-remove-c…
Browse files Browse the repository at this point in the history
…onsole-statements

Minor adjustments remove console statements
  • Loading branch information
George7h authored Mar 6, 2024
2 parents 3eca3d1 + da2a49d commit 1b8e045
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ Also I would like to thank [Murat Korkmaz](https://www.behance.net/muratk) on Be

## 📝 License <a name="license"></a>

This project is [MIT](https://github.com/tsheporamantso/final-capstone-react-front-end/blob/1012050f1dd1a177d317f0a8c3b90ab76d956a7f/LICENSE) licensed.
This project is [MIT](./LICENSE) licensed.

<p align="right">(<a href="#readme-top">back to top</a>)</p>
4 changes: 3 additions & 1 deletion src/Components/AddReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ function AddReservation() {
const [numberOfDays, setNumberOfDays] = useState(0);
const status = useSelector((state) => state.addReservation.status);
const error = useSelector((state) => state.addReservation.error);
const [errorMessage, setErrorMessage] = useState('');

const fetchPlaces = async (userId) => {
try {
const response = await fetch(`http://localhost:3000/api/v1/users/${userId}/places`);
const data = await response.json();
setPlaces(data);
} catch (error) {
console.error('Error fetching places:', error);
setErrorMessage('Invalid Email or password.');
}
};

Expand Down Expand Up @@ -77,6 +78,7 @@ function AddReservation() {
}}
>
<h2>Add Reservation</h2>
{errorMessage && <p style={{ color: 'red' }}>{errorMessage}</p>}
<input type="date" name="start_date" placeholder="Start Date" value={reservationData.start_date} onChange={handleChange} />
<br />
<input type="date" name="end_date" placeholder="End Date" value={reservationData.end_date} onChange={handleChange} />
Expand Down
13 changes: 0 additions & 13 deletions src/Components/UserAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,25 @@ function UserAuth({ setLoggedIn }) {

const handleSubmit = async (e) => {
e.preventDefault();
console.log('Form data:', { email, password });

try {
console.log('Submitting sign in form...');
const response = await axios.post('http://localhost:3000/users/sign_in', {
user: {
email,
password,
},
});

console.log('Response Data:', response.data);

console.log('I want the User ID', response.data.status.data.id);

if (response.status === 200) {
localStorage.setItem('authToken', response.data.token);
localStorage.setItem('userId', response.data.status.data.id);

const userId = localStorage.getItem('userId');
console.log('User ID from local storage:', userId);

setLoggedIn(true);
navigate('/layout/placelist');
} else {
console.error('Unexpected response status:', response.status);
setErrorMessage('Invalid Email or password.');
}
} catch (error) {
console.log('Error:', error.response.data);
console.error('Axios error:', error);
setErrorMessage('Invalid Email or password.');
}
};
Expand All @@ -52,7 +40,6 @@ function UserAuth({ setLoggedIn }) {
<h1>Sign In</h1>
{errorMessage && <p style={{ color: 'red' }}>{errorMessage}</p>}
{' '}
{/* Display error message */}
<form onSubmit={handleSubmit}>
<input className="mail-border" type="email" placeholder="Email" value={email} onChange={(e) => setEmail(e.target.value)} />
<br />
Expand Down
12 changes: 6 additions & 6 deletions src/Components/UserSignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ function UserSignUp() {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();

console.log('Form data:', { name, email, password });
try {
console.log('Submitting form...');
const response = await axios.post('http://localhost:3000/users', {
await axios.post('http://localhost:3000/users', {
user: {
name,
email,
password,
},
});
console.log('Response:', response.data);
navigate('/');
} catch (error) {
console.log('Error:', error.response.data);
console.error('Axios error:', error);
setErrorMessage('Invalid Email or password.');
}
};

return (
<>
<h1>Sign Up</h1>
{errorMessage && <p style={{ color: 'red' }}>{errorMessage}</p>}
{' '}
<form onSubmit={handleSubmit}>
<input className="mail-border" type="text" placeholder="Name" value={name} onChange={(e) => setName(e.target.value)} />
<br />
Expand Down

0 comments on commit 1b8e045

Please sign in to comment.